Update default locations
This commit is contained in:
parent
55524c2129
commit
c2bcf0abcb
2 changed files with 52 additions and 6 deletions
|
@ -1160,31 +1160,66 @@ public class OsmandSettings {
|
|||
public static final int EXTERNAL_STORAGE_TYPE_OBB = 3; // ctx.getObbDirs
|
||||
public static final int EXTERNAL_STORAGE_TYPE_SPECIFIED = 4;
|
||||
|
||||
|
||||
public File getExternalStorageDirectory() {
|
||||
return getExternalStorageDirectory(null);
|
||||
}
|
||||
|
||||
public File getExternalStorageDirectory(ValueHolder<Integer> type) {
|
||||
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
|
||||
return getExternalStorageDirectoryPre19();
|
||||
} else {
|
||||
return getExternalStorageDirectoryV19();
|
||||
return getExternalStorageDirectoryV19(type);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(19)
|
||||
public File getInternalAppPath() {
|
||||
if(Build.VERSION.SDK_INT >= 21) {
|
||||
File fl = getNoBackupPath();
|
||||
if(fl != null) {
|
||||
return fl;
|
||||
}
|
||||
}
|
||||
return ctx.getFilesDir();
|
||||
}
|
||||
|
||||
@TargetApi(21)
|
||||
private File getNoBackupPath() {
|
||||
return ctx.getNoBackupFilesDir();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
public File getExternalStorageDirectoryV19() {
|
||||
public File getExternalStorageDirectoryV19(ValueHolder<Integer> tp) {
|
||||
int type = settingsAPI.getInt(globalPreferences, EXTERNAL_STORAGE_DIR_TYPE_V19, -1);
|
||||
File location = getDefaultLocationV19();
|
||||
if (type == -1) {
|
||||
if(isWritable(location)) {
|
||||
if(tp != null) {
|
||||
tp.value = settingsAPI.contains(globalPreferences, EXTERNAL_STORAGE_DIR_V19) ?
|
||||
EXTERNAL_STORAGE_TYPE_SPECIFIED :
|
||||
EXTERNAL_STORAGE_TYPE_DEFAULT;
|
||||
}
|
||||
return location;
|
||||
}
|
||||
File[] external = ctx.getExternalFilesDirs(null);
|
||||
if(external != null && external.length > 0 && external[0] != null) {
|
||||
location = external[0];
|
||||
if(tp != null) {
|
||||
tp.value = EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE;
|
||||
}
|
||||
} else {
|
||||
File[] obbDirs = ctx.getObbDirs();
|
||||
if(obbDirs != null && obbDirs.length > 0 && obbDirs[0] != null) {
|
||||
location = obbDirs[0];
|
||||
if(tp != null) {
|
||||
tp.value = EXTERNAL_STORAGE_TYPE_OBB;
|
||||
}
|
||||
} else {
|
||||
location = ctx.getFilesDir();
|
||||
location = getInternalAppPath();
|
||||
if(tp != null) {
|
||||
tp.value = EXTERNAL_STORAGE_TYPE_INTERNAL_FILE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1938,4 +1973,6 @@ public class OsmandSettings {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.util.List;
|
|||
import java.util.Locale;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.ValueHolder;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -54,7 +55,7 @@ public class DashChooseAppDirFragment extends DashBaseFragment {
|
|||
private View confirmBtn;
|
||||
private boolean mapsCopied = false;
|
||||
private TextView warningReadonly;
|
||||
private int type = OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT;
|
||||
private int type = -1;
|
||||
private File selectedFile = new File("/");
|
||||
private File currentAppFile;
|
||||
private OsmandSettings settings;
|
||||
|
@ -72,7 +73,7 @@ public class DashChooseAppDirFragment extends DashBaseFragment {
|
|||
}
|
||||
|
||||
public void updateView() {
|
||||
if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT) {
|
||||
if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT ) {
|
||||
locationPath.setText(R.string.storage_directory_default);
|
||||
} else if (type == OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE) {
|
||||
locationPath.setText(R.string.storage_directory_external);
|
||||
|
@ -116,6 +117,14 @@ public class DashChooseAppDirFragment extends DashBaseFragment {
|
|||
selectedFile = currentAppFile;
|
||||
if (settings.getExternalStorageDirectoryTypeV19() >= 0) {
|
||||
type = settings.getExternalStorageDirectoryTypeV19();
|
||||
} else {
|
||||
ValueHolder<Integer> vh = new ValueHolder<Integer>();
|
||||
settings.getExternalStorageDirectory(vh);
|
||||
if (vh.value != null && vh.value >= 0) {
|
||||
type = vh.value;
|
||||
} else {
|
||||
type = 0;
|
||||
}
|
||||
}
|
||||
editBtn = (ImageView) view.findViewById(R.id.edit_icon);
|
||||
copyMapsBtn = view.findViewById(R.id.copy_maps);
|
||||
|
@ -180,7 +189,7 @@ public class DashChooseAppDirFragment extends DashBaseFragment {
|
|||
}
|
||||
}
|
||||
|
||||
String pth = getMyApplication().getFilesDir().getAbsolutePath();
|
||||
String pth = settings.getInternalAppPath().getAbsolutePath();
|
||||
if(selectedFile.getAbsolutePath().equals(pth) ) {
|
||||
selected = items.size();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue