Fix 393
This commit is contained in:
parent
a349213141
commit
425e772f20
8 changed files with 376 additions and 144 deletions
|
@ -1,11 +1,16 @@
|
|||
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="?attr/bottom_menu_view_bg"
|
||||
android:orientation="horizontal"
|
||||
tools:context="net.osmand.plus.download.ui.DataStoragePlaceDialogFragment">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/folderIconImageView"
|
||||
android:layout_width="56dp"
|
||||
|
@ -17,13 +22,26 @@
|
|||
tools:background="@color/color_warning"
|
||||
tools:src="@drawable/ic_action_folder"/>
|
||||
|
||||
<TextView
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_columnSpan="2"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:layout_marginTop="22dp"
|
||||
android:layout_row="0"
|
||||
android:layout_weight="1"
|
||||
android:paddingTop="22dp"
|
||||
android:text="@string/application_dir"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textSize="@dimen/dialog_header_text_size"/>
|
||||
|
@ -36,83 +54,166 @@
|
|||
android:src="@drawable/ic_action_remove_dark"
|
||||
tools:background="@color/color_warning"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_column="1"
|
||||
android:layout_columnSpan="2"
|
||||
android:id="@+id/description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:layout_row="1"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="@string/application_dir_description"
|
||||
android:textSize="16sp"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/deviceMemoryRow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/deviceMemoryImageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="56dp"
|
||||
android:layout_column="1"
|
||||
android:layout_row="2"
|
||||
android:layout_rowSpan="2"
|
||||
android:paddingRight="16dp"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_sdcard"
|
||||
tools:background="@color/color_warning"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/deviceMemoryTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_column="2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_row="2"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/storage_directory_default"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/deviceMemoryDescription"
|
||||
android:layout_width="0dp"
|
||||
android:layout_column="2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:layout_row="3"
|
||||
tools:text="Free: 568 Mb"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_column="1"
|
||||
android:layout_columnSpan="3"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:layout_row="4"
|
||||
android:background="@color/divider_color"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/sharedMemoryRow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/memoryStickImageView"
|
||||
android:id="@+id/sharedMemoryImageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="56dp"
|
||||
android:layout_column="1"
|
||||
android:layout_row="5"
|
||||
android:layout_rowSpan="2"
|
||||
android:paddingRight="16dp"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_sdcard"
|
||||
tools:background="@color/color_warning"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sharedMemoryTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:text="@string/storage_directory_shared"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sharedMemoryDescription"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
tools:text="Free: 9 Gb"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:background="@color/divider_color"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/memoryStickRow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/memoryStickImageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="56dp"
|
||||
android:paddingRight="16dp"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_sdcard"
|
||||
tools:background="@color/color_warning"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/memoryStickTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_column="2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_row="5"
|
||||
android:text="@string/storage_directory_external"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/memoryStickDescription"
|
||||
android:layout_width="0dp"
|
||||
android:layout_column="2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="fill_horizontal"
|
||||
android:layout_row="6"
|
||||
tools:text="Free: 9 Gb"/>
|
||||
</GridLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="storage_directory_readonly_desc">Currently selected Data storage folder is readonly. The storage folder was temporarily switched to Internal memory. Please choose valid storage directory.</string>
|
||||
<string name="storage_directory_shared">Shared memory</string>
|
||||
<string name="shared_string_topbar">Topbar</string>
|
||||
<string name="recalculate_route">Recalculate route</string>
|
||||
<string name="donations">Donations</string>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
|
@ -69,13 +70,14 @@ import static net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIn
|
|||
*/
|
||||
public class AppInitializer implements IProgress {
|
||||
// 22 - 2.2
|
||||
private static final int VERSION_2_2 = 22;
|
||||
private static final int CURRENT_VERSION_FOR_UGPRADE = VERSION_2_2;
|
||||
public static final int VERSION_2_2 = 22;
|
||||
// 23 - 2.3
|
||||
public static final int VERSION_2_3 = 23;
|
||||
|
||||
|
||||
public static final boolean TIPS_AND_TRICKS = false;
|
||||
private static final String FIRST_TIME_APP_RUN = "FIRST_TIME_APP_RUN"; //$NON-NLS-1$
|
||||
private static final String VERSION_INSTALLED_NUMBER = "VERSION_INSTALLED_NUMBER"; //$NON-NLS-1$
|
||||
public static final String FIRST_TIME_APP_RUN = "FIRST_TIME_APP_RUN"; //$NON-NLS-1$
|
||||
public static final String VERSION_INSTALLED_NUMBER = "VERSION_INSTALLED_NUMBER"; //$NON-NLS-1$
|
||||
public static final String NUMBER_OF_STARTS = "NUMBER_OF_STARTS"; //$NON-NLS-1$
|
||||
public static final String FIRST_INSTALLED = "FIRST_INSTALLED"; //$NON-NLS-1$
|
||||
private static final String VECTOR_INDEXES_CHECK = "VECTOR_INDEXES_CHECK"; //$NON-NLS-1$
|
||||
|
@ -93,6 +95,7 @@ public class AppInitializer implements IProgress {
|
|||
private boolean firstTime;
|
||||
private boolean activityChangesShowed = false;
|
||||
private boolean appVersionChanged;
|
||||
private int prevAppVersion;
|
||||
private long startTime;
|
||||
private long startBgTime;
|
||||
private boolean appInitializing = true;
|
||||
|
@ -130,11 +133,14 @@ public class AppInitializer implements IProgress {
|
|||
}
|
||||
|
||||
|
||||
private void initUiVars(Activity activity) {
|
||||
@SuppressLint("CommitPrefEdits")
|
||||
public void initVariables() {
|
||||
if(initSettings) {
|
||||
return;
|
||||
}
|
||||
startPrefs = activity.getPreferences(Context.MODE_WORLD_WRITEABLE);
|
||||
startPrefs = app.getSharedPreferences(
|
||||
getLocalClassName(app.getAppCustomization().getMapActivity().getName()),
|
||||
Context.MODE_WORLD_WRITEABLE);
|
||||
if(!startPrefs.contains(NUMBER_OF_STARTS)) {
|
||||
startPrefs.edit().putInt(NUMBER_OF_STARTS, 1).commit();
|
||||
} else {
|
||||
|
@ -147,14 +153,18 @@ public class AppInitializer implements IProgress {
|
|||
firstTime = true;
|
||||
startPrefs.edit().putBoolean(FIRST_TIME_APP_RUN, true).commit();
|
||||
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_2).commit();
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_3).commit();
|
||||
} else if (!Version.getFullVersion(app).equals(startPrefs.getString(VERSION_INSTALLED, ""))) {
|
||||
if(startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0) < VERSION_2_2) {
|
||||
prevAppVersion = startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0);
|
||||
if(prevAppVersion < VERSION_2_2) {
|
||||
app.getSettings().SHOW_DASHBOARD_ON_START.set(true);
|
||||
app.getSettings().SHOW_DASHBOARD_ON_MAP_SCREEN.set(true);
|
||||
app.getSettings().SHOW_CARD_TO_CHOOSE_DRAWER.set(true);
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_2).commit();
|
||||
}
|
||||
if(prevAppVersion < VERSION_2_3) {
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_3).commit();
|
||||
}
|
||||
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
|
||||
appVersionChanged = true;
|
||||
}
|
||||
|
@ -181,13 +191,21 @@ public class AppInitializer implements IProgress {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isFirstTime(Activity activity) {
|
||||
initUiVars(activity);
|
||||
public boolean isFirstTime() {
|
||||
initVariables();
|
||||
return firstTime;
|
||||
}
|
||||
|
||||
public boolean checkAppVersionChanged(Activity activity) {
|
||||
initUiVars(activity);
|
||||
public boolean isAppVersionChanged() {
|
||||
return appVersionChanged;
|
||||
}
|
||||
|
||||
public int getPrevAppVersion() {
|
||||
return prevAppVersion;
|
||||
}
|
||||
|
||||
public boolean checkAppVersionChanged() {
|
||||
initVariables();
|
||||
boolean showRecentChangesDialog = !firstTime && appVersionChanged;
|
||||
// showRecentChangesDialog = true;
|
||||
if (showRecentChangesDialog && !activityChangesShowed) {
|
||||
|
@ -210,7 +228,7 @@ public class AppInitializer implements IProgress {
|
|||
}
|
||||
|
||||
public boolean checkPreviousRunsForExceptions(Activity activity, boolean writeFileSize) {
|
||||
initUiVars(activity);
|
||||
initVariables();
|
||||
long size = activity.getPreferences(Context.MODE_WORLD_READABLE).getLong(EXCEPTION_FILE_SIZE, 0);
|
||||
final File file = app.getAppPath(OsmandApplication.EXCEPTION_PATH);
|
||||
if (file.exists() && file.length() > 0) {
|
||||
|
@ -729,5 +747,13 @@ public class AppInitializer implements IProgress {
|
|||
this.listeners.remove(listener);
|
||||
}
|
||||
|
||||
|
||||
private String getLocalClassName(String cls) {
|
||||
final String pkg = app.getPackageName();
|
||||
int packageLen = pkg.length();
|
||||
if (!cls.startsWith(pkg) || cls.length() <= packageLen
|
||||
|| cls.charAt(packageLen) != '.') {
|
||||
return cls;
|
||||
}
|
||||
return cls.substring(packageLen+1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,6 +103,7 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
private Locale preferredLocale = null;
|
||||
private Locale defaultLocale;
|
||||
private File externalStorageDirectory;
|
||||
private boolean externalStorageDirectoryReadOnly;
|
||||
|
||||
private String firstSelectedVoiceProvider;
|
||||
|
||||
|
@ -126,7 +127,17 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
appCustomization = new OsmAndAppCustomization();
|
||||
appCustomization.setup(this);
|
||||
osmandSettings = appCustomization.getOsmandSettings();
|
||||
appInitializer.initVariables();
|
||||
if (appInitializer.isAppVersionChanged() && appInitializer.getPrevAppVersion() < AppInitializer.VERSION_2_3) {
|
||||
osmandSettings.freezeExternalStorageDirectory();
|
||||
} else if (appInitializer.isFirstTime()) {
|
||||
osmandSettings.initExternalStorageDirectory();
|
||||
}
|
||||
externalStorageDirectory = osmandSettings.getExternalStorageDirectory();
|
||||
if (!OsmandSettings.isWritable(externalStorageDirectory)) {
|
||||
externalStorageDirectoryReadOnly = true;
|
||||
externalStorageDirectory = osmandSettings.getInternalAppPath();
|
||||
}
|
||||
|
||||
checkPreferredLocale();
|
||||
appInitializer.onCreateApplication();
|
||||
|
@ -141,6 +152,10 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
System.out.println("Time to init plugins " + (System.currentTimeMillis() - timeToStart) + " ms. Should be less < 800 ms");
|
||||
}
|
||||
|
||||
public boolean isExternalStorageDirectoryReadOnly() {
|
||||
return externalStorageDirectoryReadOnly;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
|
@ -618,6 +633,7 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
public void setExternalStorageDirectory(int type, String directory){
|
||||
osmandSettings.setExternalStorageDirectory(type, directory);
|
||||
externalStorageDirectory = osmandSettings.getExternalStorageDirectory();
|
||||
externalStorageDirectoryReadOnly = false;
|
||||
getResourceManager().resetStoreDirectory();
|
||||
}
|
||||
|
||||
|
|
|
@ -1282,12 +1282,31 @@ public class OsmandSettings {
|
|||
public static final int EXTERNAL_STORAGE_TYPE_SPECIFIED = 4;
|
||||
|
||||
|
||||
public void freezeExternalStorageDirectory() {
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
int type = settingsAPI.getInt(globalPreferences, EXTERNAL_STORAGE_DIR_TYPE_V19, -1);
|
||||
if (type == -1) {
|
||||
ValueHolder<Integer> vh = new ValueHolder<>();
|
||||
File f = getExternalStorageDirectoryV19(vh);
|
||||
setExternalStorageDirectoryV19(vh.value, f.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void initExternalStorageDirectory() {
|
||||
if (Build.VERSION.SDK_INT < 19) {
|
||||
setExternalStorageDirectoryPre19(getInternalAppPath().getAbsolutePath());
|
||||
} else {
|
||||
setExternalStorageDirectoryV19(EXTERNAL_STORAGE_TYPE_INTERNAL_FILE, getInternalAppPath().getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
public File getExternalStorageDirectory() {
|
||||
return getExternalStorageDirectory(null);
|
||||
}
|
||||
|
||||
public File getExternalStorageDirectory(ValueHolder<Integer> type) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
if (Build.VERSION.SDK_INT < 19) {
|
||||
return getExternalStorageDirectoryPre19();
|
||||
} else {
|
||||
return getExternalStorageDirectoryV19(type);
|
||||
|
@ -1395,7 +1414,7 @@ public class OsmandSettings {
|
|||
@SuppressLint("NewApi")
|
||||
@Nullable
|
||||
public File getSecondaryStorage() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
if (Build.VERSION.SDK_INT < 19) {
|
||||
return getExternalStorageDirectoryPre19();
|
||||
} else {
|
||||
File[] externals = ctx.getExternalFilesDirs(null);
|
||||
|
|
|
@ -72,6 +72,7 @@ import net.osmand.plus.dialogs.ErrorBottomSheetDialog;
|
|||
import net.osmand.plus.dialogs.RateUsBottomSheetDialog;
|
||||
import net.osmand.plus.dialogs.WhatsNewDialogFragment;
|
||||
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
|
||||
import net.osmand.plus.download.ui.DataStoragePlaceDialogFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.GpxImportHelper;
|
||||
import net.osmand.plus.helpers.WakeLockHelper;
|
||||
|
@ -207,7 +208,7 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents,
|
|||
int h = dm.heightPixels - statusBarHeight;
|
||||
|
||||
mapView = new OsmandMapTileView(this, w, h);
|
||||
if (app.getAppInitializer().checkAppVersionChanged(this) && WhatsNewDialogFragment.SHOW) {
|
||||
if (app.getAppInitializer().checkAppVersionChanged() && WhatsNewDialogFragment.SHOW) {
|
||||
WhatsNewDialogFragment.SHOW = false;
|
||||
new WhatsNewDialogFragment().show(getSupportFragmentManager(), null);
|
||||
}
|
||||
|
@ -276,7 +277,7 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents,
|
|||
}
|
||||
mapView.refreshMap(true);
|
||||
|
||||
if (getMyApplication().getAppInitializer().isFirstTime(this) && FirstUsageFragment.SHOW) {
|
||||
if (getMyApplication().getAppInitializer().isFirstTime() && FirstUsageFragment.SHOW) {
|
||||
FirstUsageFragment.SHOW = false;
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, new FirstUsageFragment(),
|
||||
|
@ -580,6 +581,11 @@ public class MapActivity extends AccessibleActivity implements DownloadEvents,
|
|||
if (System.currentTimeMillis() - tm > 50) {
|
||||
System.err.println("OnCreate for MapActivity took " + (System.currentTimeMillis() - tm) + " ms");
|
||||
}
|
||||
|
||||
if (app.isExternalStorageDirectoryReadOnly()
|
||||
&& getSupportFragmentManager().findFragmentByTag(DataStoragePlaceDialogFragment.TAG) == null) {
|
||||
DataStoragePlaceDialogFragment.showInstance(getSupportFragmentManager(), true);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseNavigationIntent(final Uri data) {
|
||||
|
|
|
@ -599,7 +599,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
|
|||
}
|
||||
|
||||
private void showFirstTimeExternalStorage() {
|
||||
final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime(this);
|
||||
final boolean firstTime = getMyApplication().getAppInitializer().isFirstTime();
|
||||
final boolean externalExists =
|
||||
getMyApplication().getSettings().getSecondaryStorage() != null;
|
||||
if (firstTime && (externalExists || !hasPermissionToWriteExternalStorage())
|
||||
|
@ -617,7 +617,7 @@ public class DownloadActivity extends AbstractDownloadActivity implements Downlo
|
|||
|
||||
private void chooseDataStorage() {
|
||||
if (getMyApplication().getSettings().getSecondaryStorage() != null) {
|
||||
new DataStoragePlaceDialogFragment().show(getSupportFragmentManager(), null);
|
||||
DataStoragePlaceDialogFragment.showInstance(getSupportFragmentManager(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ package net.osmand.plus.download.ui;
|
|||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.os.StatFs;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -19,15 +21,21 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||
import net.osmand.plus.dashboard.DashChooseAppDirFragment;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = "DataStoragePlaceDialogFragment";
|
||||
private static final String STORAGE_READOLNY_KEY = "storage_readolny_key";
|
||||
|
||||
private File internalStorage;
|
||||
private File sharedStorage;
|
||||
private File externalStorage;
|
||||
public static boolean isInterestedInFirstTime = true;
|
||||
boolean storageReadOnly;
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
|
@ -45,34 +53,50 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
|
|||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
internalStorage = getInternalStorageDirectory(getActivity());
|
||||
sharedStorage = getSharedStorageDirectory(getActivity());
|
||||
externalStorage = getMyApplication().getSettings().getSecondaryStorage();
|
||||
|
||||
Bundle args = null;
|
||||
if (savedInstanceState != null) {
|
||||
args = savedInstanceState;
|
||||
} else if (getArguments() != null) {
|
||||
args = getArguments();
|
||||
}
|
||||
|
||||
if (args != null) {
|
||||
storageReadOnly = args.getBoolean(STORAGE_READOLNY_KEY);
|
||||
}
|
||||
|
||||
final View view = inflater.inflate(R.layout.fragment_data_storage_place_dialog, container,
|
||||
false);
|
||||
((ImageView) view.findViewById(R.id.folderIconImageView))
|
||||
.setImageDrawable(getIcon(R.drawable.ic_action_folder, R.color.map_widget_blue));
|
||||
|
||||
if (storageReadOnly) {
|
||||
((TextView) view.findViewById(R.id.description))
|
||||
.setText(getString(R.string.storage_directory_readonly_desc));
|
||||
}
|
||||
|
||||
View internalStorageRow = view.findViewById(R.id.deviceMemoryRow);
|
||||
internalStorageRow.setOnClickListener(internalMemoryOnClickListener);
|
||||
ImageView internalStorageImageView = (ImageView) view.findViewById(R.id.deviceMemoryImageView);
|
||||
internalStorageImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard));
|
||||
internalStorageImageView.setOnClickListener(internalMemoryOnClickListener);
|
||||
|
||||
View internalStorageTitle = view.findViewById(R.id.deviceMemoryTitle);
|
||||
internalStorageTitle.setOnClickListener(internalMemoryOnClickListener);
|
||||
|
||||
TextView internalStorageDescription = (TextView) view.findViewById(R.id.deviceMemoryDescription);
|
||||
internalStorageDescription.setOnClickListener(internalMemoryOnClickListener);
|
||||
internalStorageDescription.setText(getFreeSpace(internalStorage));
|
||||
|
||||
ImageView externalStorageImageView = ((ImageView) view.findViewById(R.id.memoryStickImageView));
|
||||
externalStorageImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard));
|
||||
externalStorageImageView.setOnClickListener(externalMemoryOnClickListener);
|
||||
View sharedMemoryRow = view.findViewById(R.id.sharedMemoryRow);
|
||||
sharedMemoryRow.setOnClickListener(sharedMemoryOnClickListener);
|
||||
ImageView sharedMemoryImageView = (ImageView) view.findViewById(R.id.sharedMemoryImageView);
|
||||
sharedMemoryImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard));
|
||||
TextView sharedMemoryDescription = (TextView) view.findViewById(R.id.sharedMemoryDescription);
|
||||
sharedMemoryDescription.setText(getFreeSpace(sharedStorage));
|
||||
|
||||
View externalStorageTitle = view.findViewById(R.id.memoryStickTitle);
|
||||
externalStorageTitle.setOnClickListener(externalMemoryOnClickListener);
|
||||
|
||||
TextView externalStorageDescription = (TextView) view.findViewById(R.id.memoryStickDescription);
|
||||
externalStorageDescription.setOnClickListener(externalMemoryOnClickListener);
|
||||
externalStorageDescription.setText(getFreeSpace(externalStorage));
|
||||
View memoryStickRow = view.findViewById(R.id.memoryStickRow);
|
||||
memoryStickRow.setOnClickListener(externalMemoryOnClickListener);
|
||||
ImageView memoryStickImageView = (ImageView) view.findViewById(R.id.memoryStickImageView);
|
||||
memoryStickImageView.setImageDrawable(getContentIcon(R.drawable.ic_sdcard));
|
||||
TextView memoryStickDescription = (TextView) view.findViewById(R.id.memoryStickDescription);
|
||||
memoryStickDescription.setText(getFreeSpace(externalStorage));
|
||||
|
||||
final ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton);
|
||||
closeImageButton.setImageDrawable(getContentIcon(R.drawable.ic_action_remove_dark));
|
||||
|
@ -86,7 +110,18 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
|
|||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(STORAGE_READOLNY_KEY, storageReadOnly);
|
||||
}
|
||||
|
||||
public static File getInternalStorageDirectory(Activity activity) {
|
||||
return ((OsmandApplication) activity.getApplication()).getSettings()
|
||||
.getInternalAppPath();
|
||||
}
|
||||
|
||||
public static File getSharedStorageDirectory(Activity activity) {
|
||||
return ((OsmandApplication) activity.getApplication()).getSettings()
|
||||
.getDefaultInternalStorage();
|
||||
}
|
||||
|
@ -112,32 +147,59 @@ public class DataStoragePlaceDialogFragment extends BottomSheetDialogFragment {
|
|||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
saveFilesLocation(OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT,
|
||||
saveFilesLocation(OsmandSettings.EXTERNAL_STORAGE_TYPE_INTERNAL_FILE,
|
||||
internalStorage, getActivity());
|
||||
isInterestedInFirstTime = false;
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnClickListener sharedMemoryOnClickListener =
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
saveFilesLocation(OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT,
|
||||
sharedStorage, getActivity());
|
||||
isInterestedInFirstTime = false;
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
|
||||
private View.OnClickListener externalMemoryOnClickListener =
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
saveFilesLocation(OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE,
|
||||
boolean res = saveFilesLocation(OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE,
|
||||
externalStorage, getActivity());
|
||||
isInterestedInFirstTime = false;
|
||||
if (res) {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static void saveFilesLocation(int type, File selectedFile, Activity context) {
|
||||
public boolean saveFilesLocation(int type, File selectedFile, Activity context) {
|
||||
boolean wr = OsmandSettings.isWritable(selectedFile);
|
||||
if (wr) {
|
||||
((OsmandApplication) context.getApplication())
|
||||
.setExternalStorageDirectory(type, selectedFile.getAbsolutePath());
|
||||
reloadData();
|
||||
} else {
|
||||
AccessibleToast.makeText(context, R.string.specified_directiory_not_writeable,
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
return wr;
|
||||
}
|
||||
|
||||
private void reloadData() {
|
||||
new DashChooseAppDirFragment.ReloadData(getActivity(), getMyApplication()).execute((Void) null);
|
||||
}
|
||||
|
||||
public static void showInstance(FragmentManager fragmentManager, boolean storageReadOnly) {
|
||||
DataStoragePlaceDialogFragment f = new DataStoragePlaceDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putBoolean(STORAGE_READOLNY_KEY, storageReadOnly);
|
||||
f.setArguments(args);
|
||||
f.show(fragmentManager, DataStoragePlaceDialogFragment.TAG);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue