Import backup profile settings items
This commit is contained in:
parent
5c0f88b37a
commit
2a225f8659
3 changed files with 43 additions and 25 deletions
|
@ -162,6 +162,13 @@ public class AndroidUtils {
|
||||||
return intent.resolveActivity(context.getPackageManager()) != null;
|
return intent.resolveActivity(context.getPackageManager()) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isActivityNotDestroyed(Activity activity) {
|
||||||
|
if (Build.VERSION.SDK_INT >= 17) {
|
||||||
|
return !activity.isFinishing() && !activity.isDestroyed();
|
||||||
|
}
|
||||||
|
return !activity.isFinishing();
|
||||||
|
}
|
||||||
|
|
||||||
public static Spannable replaceCharsWithIcon(String text, Drawable icon, String[] chars) {
|
public static Spannable replaceCharsWithIcon(String text, Drawable icon, String[] chars) {
|
||||||
Spannable spannable = new SpannableString(text);
|
Spannable spannable = new SpannableString(text);
|
||||||
for (String entry : chars) {
|
for (String entry : chars) {
|
||||||
|
|
|
@ -243,7 +243,7 @@ public class ImportHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(GPXFile result) {
|
protected void onPostExecute(GPXFile result) {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
handleResult(result, fileName, save, useImportDir, false);
|
handleResult(result, fileName, save, useImportDir, false);
|
||||||
|
@ -315,7 +315,7 @@ public class ImportHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(final GPXFile result) {
|
protected void onPostExecute(final GPXFile result) {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ public class ImportHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(GPXFile result) {
|
protected void onPostExecute(GPXFile result) {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG)
|
Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG)
|
||||||
|
@ -426,7 +426,7 @@ public class ImportHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(GPXFile result) {
|
protected void onPostExecute(GPXFile result) {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
handleResult(result, name, save, useImportDir, false);
|
handleResult(result, name, save, useImportDir, false);
|
||||||
|
@ -474,7 +474,7 @@ public class ImportHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(GPXFile result) {
|
protected void onPostExecute(GPXFile result) {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
handleResult(result, name, save, useImportDir, false);
|
handleResult(result, name, save, useImportDir, false);
|
||||||
|
@ -506,7 +506,7 @@ public class ImportHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(String message) {
|
protected void onPostExecute(String message) {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
Toast.makeText(app, message, Toast.LENGTH_SHORT).show();
|
Toast.makeText(app, message, Toast.LENGTH_SHORT).show();
|
||||||
|
@ -587,7 +587,7 @@ public class ImportHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(String error) {
|
protected void onPostExecute(String error) {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
|
@ -696,7 +696,7 @@ public class ImportHelper {
|
||||||
loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
|
loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onRoutingFilesLoaded() {
|
public void onRoutingFilesLoaded() {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
RoutingConfiguration.Builder builder = app.getCustomRoutingConfig(mFileName);
|
RoutingConfiguration.Builder builder = app.getCustomRoutingConfig(mFileName);
|
||||||
|
@ -711,7 +711,7 @@ public class ImportHelper {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
app.showShortToastMessage(app.getString(R.string.file_import_error, mFileName, error));
|
app.showShortToastMessage(app.getString(R.string.file_import_error, mFileName, error));
|
||||||
|
@ -774,7 +774,7 @@ public class ImportHelper {
|
||||||
app.getSettingsHelper().importSettings(file, latestChanges, version, new SettingsImportListener() {
|
app.getSettingsHelper().importSettings(file, latestChanges, version, new SettingsImportListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
if (succeed) {
|
if (succeed) {
|
||||||
|
@ -788,7 +788,7 @@ public class ImportHelper {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
app.showShortToastMessage(app.getString(R.string.file_import_error, name, error));
|
app.showShortToastMessage(app.getString(R.string.file_import_error, name, error));
|
||||||
|
@ -811,13 +811,6 @@ public class ImportHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isActivityNotDestroyed(Activity activity) {
|
|
||||||
if (Build.VERSION.SDK_INT >= 17) {
|
|
||||||
return !activity.isFinishing() && !activity.isDestroyed();
|
|
||||||
}
|
|
||||||
return !activity.isFinishing();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleResult(final GPXFile result, final String name, final boolean save,
|
private void handleResult(final GPXFile result, final String name, final boolean save,
|
||||||
final boolean useImportDir, boolean forceImportFavourites) {
|
final boolean useImportDir, boolean forceImportFavourites) {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
|
|
@ -170,13 +170,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
|
||||||
if (appMode.isCustomProfile()) {
|
if (appMode.isCustomProfile()) {
|
||||||
File file = getBackupFileForCustomMode(appMode);
|
File file = getBackupFileForCustomMode(appMode);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
app.getSettingsHelper().importSettings(file, "", 1, new SettingsHelper.SettingsImportListener() {
|
restoreCustomModeFromFile(file);
|
||||||
@Override
|
|
||||||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
|
||||||
app.showToastMessage(R.string.profile_prefs_reset_successful);
|
|
||||||
updateCopiedOrResetPrefs();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
app.getSettings().resetPreferencesForProfile(appMode);
|
app.getSettings().resetPreferencesForProfile(appMode);
|
||||||
|
@ -186,6 +180,30 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void restoreCustomModeFromFile(final File file) {
|
||||||
|
app.getSettingsHelper().importSettings(file, "", 1, new SettingsHelper.SettingsImportListener() {
|
||||||
|
@Override
|
||||||
|
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||||
|
if (succeed) {
|
||||||
|
for (SettingsHelper.SettingsItem item : items) {
|
||||||
|
item.setShouldReplace(true);
|
||||||
|
}
|
||||||
|
importBackupSettingsItems(file, items);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void importBackupSettingsItems(File file, List<SettingsHelper.SettingsItem> items) {
|
||||||
|
app.getSettingsHelper().importSettings(file, items, "", 1, new SettingsHelper.SettingsImportListener() {
|
||||||
|
@Override
|
||||||
|
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||||
|
app.showToastMessage(R.string.profile_prefs_reset_successful);
|
||||||
|
updateCopiedOrResetPrefs();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private File getBackupFileForCustomMode(ApplicationMode appMode) {
|
private File getBackupFileForCustomMode(ApplicationMode appMode) {
|
||||||
String fileName = appMode.getStringKey() + IndexConstants.OSMAND_SETTINGS_FILE_EXT;
|
String fileName = appMode.getStringKey() + IndexConstants.OSMAND_SETTINGS_FILE_EXT;
|
||||||
File backupDir = app.getAppPath(IndexConstants.BACKUP_INDEX_DIR);
|
File backupDir = app.getAppPath(IndexConstants.BACKUP_INDEX_DIR);
|
||||||
|
|
Loading…
Reference in a new issue