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;
|
||||
}
|
||||
|
||||
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) {
|
||||
Spannable spannable = new SpannableString(text);
|
||||
for (String entry : chars) {
|
||||
|
|
|
@ -243,7 +243,7 @@ public class ImportHelper {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(GPXFile result) {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
handleResult(result, fileName, save, useImportDir, false);
|
||||
|
@ -315,7 +315,7 @@ public class ImportHelper {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(final GPXFile result) {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
|
||||
|
@ -353,7 +353,7 @@ public class ImportHelper {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(GPXFile result) {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG)
|
||||
|
@ -426,7 +426,7 @@ public class ImportHelper {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(GPXFile result) {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
handleResult(result, name, save, useImportDir, false);
|
||||
|
@ -474,7 +474,7 @@ public class ImportHelper {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(GPXFile result) {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
handleResult(result, name, save, useImportDir, false);
|
||||
|
@ -506,7 +506,7 @@ public class ImportHelper {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(String message) {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
Toast.makeText(app, message, Toast.LENGTH_SHORT).show();
|
||||
|
@ -587,7 +587,7 @@ public class ImportHelper {
|
|||
|
||||
@Override
|
||||
protected void onPostExecute(String error) {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
if (error == null) {
|
||||
|
@ -696,7 +696,7 @@ public class ImportHelper {
|
|||
loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() {
|
||||
@Override
|
||||
public void onRoutingFilesLoaded() {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
RoutingConfiguration.Builder builder = app.getCustomRoutingConfig(mFileName);
|
||||
|
@ -711,7 +711,7 @@ public class ImportHelper {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
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() {
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
if (succeed) {
|
||||
|
@ -788,7 +788,7 @@ public class ImportHelper {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
if (AndroidUtils.isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
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,
|
||||
final boolean useImportDir, boolean forceImportFavourites) {
|
||||
if (result != null) {
|
||||
|
|
|
@ -170,13 +170,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
|
|||
if (appMode.isCustomProfile()) {
|
||||
File file = getBackupFileForCustomMode(appMode);
|
||||
if (file.exists()) {
|
||||
app.getSettingsHelper().importSettings(file, "", 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();
|
||||
}
|
||||
});
|
||||
restoreCustomModeFromFile(file);
|
||||
}
|
||||
} else {
|
||||
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) {
|
||||
String fileName = appMode.getStringKey() + IndexConstants.OSMAND_SETTINGS_FILE_EXT;
|
||||
File backupDir = app.getAppPath(IndexConstants.BACKUP_INDEX_DIR);
|
||||
|
|
Loading…
Reference in a new issue