Merge pull request #10292 from osmandapp/fix_strikelines
Fix strikelines
This commit is contained in:
commit
bbb228d696
8 changed files with 114 additions and 50 deletions
|
@ -34,6 +34,7 @@ import net.osmand.plus.dialogs.ImportGpxBottomSheetDialogFragment;
|
|||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
||||
import net.osmand.plus.measurementtool.MeasurementToolFragment;
|
||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsHelper;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsItem;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
@ -67,6 +68,8 @@ import static net.osmand.IndexConstants.WPT_CHART_FILE_EXT;
|
|||
import static net.osmand.data.FavouritePoint.DEFAULT_BACKGROUND_TYPE;
|
||||
import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB;
|
||||
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
|
||||
import static net.osmand.plus.settings.backend.backup.SettingsHelper.REPLACE_KEY;
|
||||
import static net.osmand.plus.settings.backend.backup.SettingsHelper.SETTINGS_TYPE_LIST_KEY;
|
||||
|
||||
/**
|
||||
* @author Koen Rabaey
|
||||
|
@ -203,10 +206,11 @@ public class ImportHelper {
|
|||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getNameFromContentUri(OsmandApplication app, Uri contentUri) {
|
||||
try {
|
||||
String name;
|
||||
Cursor returnCursor = app.getContentResolver().query(contentUri, new String[] {OpenableColumns.DISPLAY_NAME}, null, null, null);
|
||||
Cursor returnCursor = app.getContentResolver().query(contentUri, new String[]{OpenableColumns.DISPLAY_NAME}, null, null, null);
|
||||
if (returnCursor != null && returnCursor.moveToFirst()) {
|
||||
int columnIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||
if (columnIndex != -1) {
|
||||
|
@ -257,18 +261,32 @@ public class ImportHelper {
|
|||
}
|
||||
|
||||
private void handleOsmAndSettingsImport(Uri intentUri, String fileName, Bundle extras, CallbackWithObject<List<SettingsItem>> callback) {
|
||||
if (extras != null && extras.containsKey(SettingsHelper.SETTINGS_VERSION_KEY) && extras.containsKey(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY)) {
|
||||
if (extras != null
|
||||
&& extras.containsKey(SettingsHelper.SETTINGS_VERSION_KEY)
|
||||
&& extras.containsKey(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY)) {
|
||||
int version = extras.getInt(SettingsHelper.SETTINGS_VERSION_KEY, -1);
|
||||
String latestChanges = extras.getString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY);
|
||||
handleOsmAndSettingsImport(intentUri, fileName, latestChanges, version, callback);
|
||||
boolean replace = extras.getBoolean(REPLACE_KEY);
|
||||
ArrayList<String> settingsTypeKeys = extras.getStringArrayList(SETTINGS_TYPE_LIST_KEY);
|
||||
List<ExportSettingsType> settingsTypes = null;
|
||||
if (settingsTypeKeys != null) {
|
||||
settingsTypes = new ArrayList<>();
|
||||
for (String key : settingsTypeKeys) {
|
||||
settingsTypes.add(ExportSettingsType.valueOf(key));
|
||||
}
|
||||
}
|
||||
handleOsmAndSettingsImport(intentUri, fileName, settingsTypes, replace, latestChanges, version, callback);
|
||||
} else {
|
||||
handleOsmAndSettingsImport(intentUri, fileName, null, -1, callback);
|
||||
handleOsmAndSettingsImport(intentUri, fileName, null, false, null, -1,
|
||||
callback);
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleOsmAndSettingsImport(Uri uri, String name, String latestChanges, int version,
|
||||
CallbackWithObject<List<SettingsItem>> callback) {
|
||||
executeImportTask(new SettingsImportTask(activity, uri, name, latestChanges, version, callback));
|
||||
protected void handleOsmAndSettingsImport(Uri uri, String name, final List<ExportSettingsType> settingsTypes,
|
||||
final boolean replace, String latestChanges, int version,
|
||||
CallbackWithObject<List<SettingsItem>> callback) {
|
||||
executeImportTask(new SettingsImportTask(activity, uri, name, settingsTypes, replace, latestChanges, version,
|
||||
callback));
|
||||
}
|
||||
|
||||
protected void handleXmlFileImport(Uri intentUri, String fileName, CallbackWithObject routingCallback) {
|
||||
|
|
|
@ -11,38 +11,50 @@ import net.osmand.AndroidUtils;
|
|||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.FileUtils;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.plus.AppInitializer;
|
||||
import net.osmand.plus.CustomOsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.BaseLoadAsyncTask;
|
||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsHelper;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsHelper.CheckDuplicatesListener;
|
||||
import net.osmand.plus.settings.backend.backup.PluginSettingsItem;
|
||||
import net.osmand.plus.settings.backend.backup.ProfileSettingsItem;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsCollectListener;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsHelper.SettingsImportListener;
|
||||
import net.osmand.plus.settings.backend.backup.SettingsItem;
|
||||
import net.osmand.plus.settings.fragments.ImportCompleteFragment;
|
||||
import net.osmand.plus.settings.fragments.ImportSettingsFragment;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.osmand.plus.AppInitializer.loadRoutingFiles;
|
||||
import static net.osmand.plus.settings.backend.backup.SettingsHelper.getSettingsToOperate;
|
||||
|
||||
class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
|
||||
|
||||
private Uri uri;
|
||||
private String name;
|
||||
private List<ExportSettingsType> settingsTypes;
|
||||
private boolean replace;
|
||||
private String latestChanges;
|
||||
private int version;
|
||||
private CallbackWithObject<List<SettingsItem>> callback;
|
||||
|
||||
public SettingsImportTask(@NonNull FragmentActivity activity, @NonNull Uri uri,
|
||||
@NonNull String name, String latestChanges, int version,
|
||||
CallbackWithObject<List<SettingsItem>> callback) {
|
||||
@NonNull String name, List<ExportSettingsType> settingsTypes,
|
||||
boolean replace, String latestChanges, int version,
|
||||
CallbackWithObject<List<SettingsItem>> callback) {
|
||||
super(activity);
|
||||
this.uri = uri;
|
||||
this.name = name;
|
||||
this.settingsTypes = settingsTypes;
|
||||
this.replace = replace;
|
||||
this.latestChanges = latestChanges;
|
||||
this.version = version;
|
||||
this.callback = callback;
|
||||
|
@ -60,7 +72,8 @@ class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
|
|||
File tempDir = FileUtils.getTempDir(app);
|
||||
final File file = new File(tempDir, name);
|
||||
if (error == null && file.exists()) {
|
||||
app.getSettingsHelper().collectSettings(file, latestChanges, version, new SettingsCollectListener() {
|
||||
final SettingsHelper settingsHelper = app.getSettingsHelper();
|
||||
settingsHelper.collectSettings(file, latestChanges, version, new SettingsCollectListener() {
|
||||
@Override
|
||||
public void onSettingsCollectFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items) {
|
||||
hideProgress();
|
||||
|
@ -78,10 +91,16 @@ class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
|
|||
handlePluginImport(pluginItem, file);
|
||||
}
|
||||
if (!pluginIndependentItems.isEmpty()) {
|
||||
FragmentActivity activity = activityRef.get();
|
||||
if (activity != null) {
|
||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
ImportSettingsFragment.showInstance(fragmentManager, pluginIndependentItems, file);
|
||||
if (settingsTypes == null) {
|
||||
FragmentActivity activity = activityRef.get();
|
||||
if (activity != null) {
|
||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
ImportSettingsFragment.showInstance(fragmentManager, pluginIndependentItems, file);
|
||||
}
|
||||
} else {
|
||||
Map<ExportSettingsType, List<?>> allSettingsMap = getSettingsToOperate(pluginIndependentItems, false);
|
||||
List<SettingsItem> settingsList = settingsHelper.getFilteredSettingsItems(allSettingsMap, settingsTypes);
|
||||
settingsHelper.checkDuplicates(file, settingsList, settingsList, getDuplicatesListener(file, replace));
|
||||
}
|
||||
}
|
||||
} else if (empty) {
|
||||
|
@ -95,6 +114,42 @@ class SettingsImportTask extends BaseLoadAsyncTask<Void, Void, String> {
|
|||
}
|
||||
}
|
||||
|
||||
private CheckDuplicatesListener getDuplicatesListener(final File file, final boolean replace) {
|
||||
return new CheckDuplicatesListener() {
|
||||
@Override
|
||||
public void onDuplicatesChecked(@NonNull List<Object> duplicates, List<SettingsItem> items) {
|
||||
if (replace) {
|
||||
for (SettingsItem item : items) {
|
||||
item.setShouldReplace(true);
|
||||
}
|
||||
}
|
||||
app.getSettingsHelper().importSettings(file, items, "", 1, getImportListener(file));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private SettingsImportListener getImportListener(final File file) {
|
||||
return new SettingsImportListener() {
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, @NonNull List<SettingsItem> items) {
|
||||
if (succeed) {
|
||||
app.getRendererRegistry().updateExternalRenderers();
|
||||
app.getPoiFilters().loadSelectedPoiFilters();
|
||||
AppInitializer.loadRoutingFiles(app, null);
|
||||
FragmentActivity activity = activityRef.get();
|
||||
if (activity instanceof MapActivity) {
|
||||
((MapActivity) activity).getMapLayers().getMapWidgetRegistry().updateVisibleWidgets();
|
||||
((MapActivity) activity).updateApplicationModeSettings();
|
||||
}
|
||||
if (file != null && activity != null) {
|
||||
FragmentManager fm = activity.getSupportFragmentManager();
|
||||
ImportCompleteFragment.showInstance(fm, items, file.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void handlePluginImport(final PluginSettingsItem pluginItem, final File file) {
|
||||
FragmentActivity activity = activityRef.get();
|
||||
final ProgressDialog progress;
|
||||
|
|
|
@ -85,7 +85,8 @@ public class ZipImportTask extends BaseLoadAsyncTask<Void, Void, ImportType> {
|
|||
importHelper.handleKmzImport(uri, name + GPX_FILE_EXT, save, useImportDir);
|
||||
} else if (importType == ImportType.SETTINGS) {
|
||||
String name = createUniqueFileName(app, "settings", TEMP_DIR, OSMAND_SETTINGS_FILE_EXT);
|
||||
importHelper.handleOsmAndSettingsImport(uri, name + OSMAND_SETTINGS_FILE_EXT, null, -1, null);
|
||||
importHelper.handleOsmAndSettingsImport(uri, name + OSMAND_SETTINGS_FILE_EXT,
|
||||
null, false, null, -1, null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -287,20 +287,17 @@ public class OsmAndAppCustomization {
|
|||
if (!connectedAppDir.exists()) {
|
||||
connectedAppDir.mkdirs();
|
||||
}
|
||||
OutputStream fout = new FileOutputStream(new File(connectedAppDir, iconName));
|
||||
OutputStream fout = null;
|
||||
if (!Algorithms.isEmpty(iconName)) {
|
||||
fout = new FileOutputStream(new File(connectedAppDir, iconName));
|
||||
}
|
||||
try {
|
||||
Algorithms.streamCopy(is, fout);
|
||||
if (fout != null) {
|
||||
Algorithms.streamCopy(is, fout);
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
try {
|
||||
fout.close();
|
||||
} catch (IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
Algorithms.closeStream(is);
|
||||
Algorithms.closeStream(fout);
|
||||
}
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("", connectedAppDirPath + "/" + iconName);
|
||||
|
@ -406,8 +403,7 @@ public class OsmAndAppCustomization {
|
|||
return set.contains(appMode);
|
||||
}
|
||||
|
||||
public boolean setNavDrawerLogoWithParams(String imageUri, @Nullable String packageName,
|
||||
@Nullable String intent) {
|
||||
public boolean setNavDrawerLogoWithParams(String imageUri, @Nullable String packageName, @Nullable String intent) {
|
||||
return setNavDrawerLogo(imageUri, packageName, intent);
|
||||
}
|
||||
|
||||
|
|
|
@ -481,24 +481,19 @@ public class SettingsHelper {
|
|||
return getFilteredSettingsItems(typesMap, settingsTypes);
|
||||
}
|
||||
|
||||
public List<SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> additionalData,
|
||||
List<ExportSettingsType> settingsTypes) {
|
||||
public List<SettingsItem> getFilteredSettingsItems(Map<ExportSettingsType, List<?>> allSettingsMap,
|
||||
List<ExportSettingsType> settingsTypes) {
|
||||
List<SettingsItem> settingsItems = new ArrayList<>();
|
||||
for (ExportSettingsType settingsType : settingsTypes) {
|
||||
List<?> settingsDataObjects = additionalData.get(settingsType);
|
||||
List<?> settingsDataObjects = allSettingsMap.get(settingsType);
|
||||
if (settingsDataObjects != null) {
|
||||
for (Object object : settingsDataObjects) {
|
||||
if (object instanceof ApplicationModeBean) {
|
||||
settingsItems.add(new ProfileSettingsItem(app, null, (ApplicationModeBean) object));
|
||||
}
|
||||
}
|
||||
settingsItems.addAll(prepareAdditionalSettingsItems(new ArrayList<>(settingsDataObjects)));
|
||||
settingsItems.addAll(prepareSettingsItems(new ArrayList<>(settingsDataObjects)));
|
||||
}
|
||||
}
|
||||
return settingsItems;
|
||||
}
|
||||
|
||||
public Map<ExportSettingsCategory, SettingsCategoryItems> getAdditionalData(boolean globalExport) {
|
||||
public Map<ExportSettingsCategory, SettingsCategoryItems> getSettingsByCategory(boolean globalExport) {
|
||||
Map<ExportSettingsCategory, SettingsCategoryItems> dataList = new LinkedHashMap<>();
|
||||
|
||||
Map<ExportSettingsType, List<?>> settingsItems = getSettingsItems(globalExport);
|
||||
|
@ -692,7 +687,7 @@ public class SettingsHelper {
|
|||
return files;
|
||||
}
|
||||
|
||||
public List<SettingsItem> prepareAdditionalSettingsItems(List<? super Object> data) {
|
||||
public List<SettingsItem> prepareSettingsItems(List<? super Object> data) {
|
||||
List<SettingsItem> settingsItems = new ArrayList<>();
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||
|
@ -754,10 +749,7 @@ public class SettingsHelper {
|
|||
}
|
||||
if (!appModeBeans.isEmpty()) {
|
||||
for (ApplicationModeBean modeBean : appModeBeans) {
|
||||
ApplicationMode mode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
|
||||
if (mode != null) {
|
||||
settingsItems.add(new ProfileSettingsItem(app, mode));
|
||||
}
|
||||
settingsItems.add(new ProfileSettingsItem(app, null, modeBean));
|
||||
}
|
||||
}
|
||||
if (!osmNotesPointList.isEmpty()) {
|
||||
|
|
|
@ -276,7 +276,7 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
String profileName = modeBean.userProfileName;
|
||||
if (Algorithms.isEmpty(profileName)) {
|
||||
ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
|
||||
profileName = getString(appMode.getNameKeyResource());
|
||||
profileName = appMode.toHumanString();
|
||||
}
|
||||
builder.setTitle(profileName);
|
||||
|
||||
|
|
|
@ -43,12 +43,9 @@ public class ExportSettingsFragment extends BaseSettingsListFragment {
|
|||
public static final String TAG = ImportSettingsFragment.class.getSimpleName();
|
||||
public static final Log LOG = PlatformUtil.getLog(ImportSettingsFragment.class.getSimpleName());
|
||||
|
||||
private static final String EXPORT_SETTINGS_TAG = "import_settings_tag";
|
||||
private static final String GLOBAL_EXPORT_KEY = "global_export_key";
|
||||
private static final String EXPORT_START_TIME_KEY = "export_start_time_key";
|
||||
private static final String EXPORTING_STARTED_KEY = "exporting_started_key";
|
||||
private static final String INCLUDE_ADDITIONAL_DATA_KEY = "include_additional_data_key";
|
||||
private static final String INCLUDE_GLOBAL_SETTINGS_KEY = "include_global_settings_key";
|
||||
private static final String PROGRESS_MAX_KEY = "progress_max_key";
|
||||
private static final String PROGRESS_VALUE_KEY = "progress_value_key";
|
||||
|
||||
|
@ -76,7 +73,7 @@ public class ExportSettingsFragment extends BaseSettingsListFragment {
|
|||
progressValue = savedInstanceState.getInt(PROGRESS_VALUE_KEY);
|
||||
}
|
||||
exportMode = true;
|
||||
dataList = app.getSettingsHelper().getAdditionalData(globalExport);
|
||||
dataList = app.getSettingsHelper().getSettingsByCategory(globalExport);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -132,7 +129,7 @@ public class ExportSettingsFragment extends BaseSettingsListFragment {
|
|||
showExportProgressDialog();
|
||||
File tempDir = FileUtils.getTempDir(app);
|
||||
String fileName = getFileName();
|
||||
List<SettingsItem> items = app.getSettingsHelper().prepareAdditionalSettingsItems(adapter.getData());
|
||||
List<SettingsItem> items = app.getSettingsHelper().prepareSettingsItems(adapter.getData());
|
||||
progress.setMax(getMaxProgress(items));
|
||||
app.getSettingsHelper().exportSettings(tempDir, fileName, getSettingsExportListener(), items, true);
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.settings.backend.backup.ProfileSettingsItem;
|
||||
|
@ -873,6 +874,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
|||
private void customProfileSaved() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
if (activity instanceof MapActivity) {
|
||||
((MapActivity) activity).getMapLayers().getMapWidgetRegistry().updateVisibleWidgets();
|
||||
((MapActivity) activity).updateApplicationModeSettings();
|
||||
}
|
||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
if (!fragmentManager.isStateSaved()) {
|
||||
fragmentManager.popBackStack();
|
||||
|
|
Loading…
Reference in a new issue