Fix merging import helper
This commit is contained in:
parent
b63250078c
commit
13a17d3a5b
5 changed files with 102 additions and 25 deletions
|
@ -9,6 +9,7 @@ import androidx.fragment.app.FragmentManager;
|
|||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.FileUtils;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.plus.CustomOsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -25,7 +26,6 @@ import java.io.File;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.IndexConstants.TEMP_DIR;
|
||||
import static net.osmand.plus.AppInitializer.loadRoutingFiles;
|
||||
|
||||
class SettingsImportTask extends BaseImportAsyncTask<Void, Void, String> {
|
||||
|
@ -37,8 +37,8 @@ class SettingsImportTask extends BaseImportAsyncTask<Void, Void, String> {
|
|||
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, String latestChanges, int version,
|
||||
CallbackWithObject<List<SettingsItem>> callback) {
|
||||
super(activity);
|
||||
this.uri = uri;
|
||||
this.name = name;
|
||||
|
@ -49,17 +49,14 @@ class SettingsImportTask extends BaseImportAsyncTask<Void, Void, String> {
|
|||
|
||||
@Override
|
||||
protected String doInBackground(Void... voids) {
|
||||
File tempDir = app.getAppPath(TEMP_DIR);
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
}
|
||||
File tempDir = FileUtils.getTempDir(app);
|
||||
File dest = new File(tempDir, name);
|
||||
return ImportHelper.copyFile(app, dest, uri, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(String error) {
|
||||
File tempDir = app.getAppPath(TEMP_DIR);
|
||||
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() {
|
||||
|
|
|
@ -6,6 +6,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.FileUtils;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.importfiles.ImportHelper.ImportType;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -61,10 +62,7 @@ class UriImportTask extends BaseImportAsyncTask<Void, Void, String> {
|
|||
if (is != null) {
|
||||
fileSignature = Algorithms.readInt(is);
|
||||
if (isSupportedFileSignature()) {
|
||||
File tempDir = app.getAppPath(TEMP_DIR);
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs();
|
||||
}
|
||||
File tempDir = FileUtils.getTempDir(app);
|
||||
tempFileName = getTempFileName();
|
||||
File dest = new File(tempDir, tempFileName);
|
||||
|
||||
|
|
|
@ -2637,6 +2637,89 @@ public class SettingsHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static Map<ExportSettingsType, List<?>> getSettingsToOperate(List<SettingsItem> settingsItems, boolean importComplete) {
|
||||
Map<ExportSettingsType, List<?>> settingsToOperate = new HashMap<>();
|
||||
List<ApplicationModeBean> profiles = new ArrayList<>();
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||
List<ITileSource> tileSourceTemplates = new ArrayList<>();
|
||||
List<File> routingFilesList = new ArrayList<>();
|
||||
List<File> renderFilesList = new ArrayList<>();
|
||||
List<AvoidRoadInfo> avoidRoads = new ArrayList<>();
|
||||
for (SettingsItem item : settingsItems) {
|
||||
switch (item.getType()) {
|
||||
case PROFILE:
|
||||
profiles.add(((ProfileSettingsItem) item).getModeBean());
|
||||
break;
|
||||
case FILE:
|
||||
FileSettingsItem fileItem = (FileSettingsItem) item;
|
||||
if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.RENDERING_STYLE) {
|
||||
renderFilesList.add(fileItem.getFile());
|
||||
} else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.ROUTING_CONFIG) {
|
||||
routingFilesList.add(fileItem.getFile());
|
||||
}
|
||||
break;
|
||||
case QUICK_ACTIONS:
|
||||
QuickActionsSettingsItem quickActionsItem = (QuickActionsSettingsItem) item;
|
||||
if (importComplete) {
|
||||
quickActions.addAll(quickActionsItem.getAppliedItems());
|
||||
} else {
|
||||
quickActions.addAll(quickActionsItem.getItems());
|
||||
}
|
||||
break;
|
||||
case POI_UI_FILTERS:
|
||||
PoiUiFiltersSettingsItem poiUiFilterItem = (PoiUiFiltersSettingsItem) item;
|
||||
if (importComplete) {
|
||||
poiUIFilters.addAll(poiUiFilterItem.getAppliedItems());
|
||||
} else {
|
||||
poiUIFilters.addAll(poiUiFilterItem.getItems());
|
||||
}
|
||||
break;
|
||||
case MAP_SOURCES:
|
||||
MapSourcesSettingsItem mapSourcesItem = (MapSourcesSettingsItem) item;
|
||||
if (importComplete) {
|
||||
tileSourceTemplates.addAll(mapSourcesItem.getAppliedItems());
|
||||
} else {
|
||||
tileSourceTemplates.addAll(mapSourcesItem.getItems());
|
||||
}
|
||||
break;
|
||||
case AVOID_ROADS:
|
||||
AvoidRoadsSettingsItem avoidRoadsItem = (AvoidRoadsSettingsItem) item;
|
||||
if (importComplete) {
|
||||
avoidRoads.addAll(avoidRoadsItem.getAppliedItems());
|
||||
} else {
|
||||
avoidRoads.addAll(avoidRoadsItem.getItems());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!profiles.isEmpty()) {
|
||||
settingsToOperate.put(ExportSettingsType.PROFILE, profiles);
|
||||
}
|
||||
if (!quickActions.isEmpty()) {
|
||||
settingsToOperate.put(ExportSettingsType.QUICK_ACTIONS, quickActions);
|
||||
}
|
||||
if (!poiUIFilters.isEmpty()) {
|
||||
settingsToOperate.put(ExportSettingsType.POI_TYPES, poiUIFilters);
|
||||
}
|
||||
if (!tileSourceTemplates.isEmpty()) {
|
||||
settingsToOperate.put(ExportSettingsType.MAP_SOURCES, tileSourceTemplates);
|
||||
}
|
||||
if (!renderFilesList.isEmpty()) {
|
||||
settingsToOperate.put(ExportSettingsType.CUSTOM_RENDER_STYLE, renderFilesList);
|
||||
}
|
||||
if (!routingFilesList.isEmpty()) {
|
||||
settingsToOperate.put(ExportSettingsType.CUSTOM_ROUTING, routingFilesList);
|
||||
}
|
||||
if (!avoidRoads.isEmpty()) {
|
||||
settingsToOperate.put(ExportSettingsType.AVOID_ROADS, avoidRoads);
|
||||
}
|
||||
return settingsToOperate;
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public class ImportAsyncTask extends AsyncTask<Void, Void, List<SettingsItem>> {
|
||||
|
||||
|
|
|
@ -22,9 +22,6 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.helpers.ImportHelper;
|
||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||
import net.osmand.plus.settings.backend.SettingsHelper.SettingsItem;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
|
@ -33,6 +30,9 @@ import net.osmand.plus.dialogs.SelectMapStyleBottomSheetDialogFragment;
|
|||
import net.osmand.plus.quickaction.QuickActionListFragment;
|
||||
import net.osmand.plus.routepreparationmenu.AvoidRoadsBottomSheetDialogFragment;
|
||||
import net.osmand.plus.search.QuickSearchDialogFragment;
|
||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||
import net.osmand.plus.settings.backend.SettingsHelper;
|
||||
import net.osmand.plus.settings.backend.SettingsHelper.SettingsItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -118,7 +118,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment {
|
|||
if (settingsItems != null) {
|
||||
ImportedSettingsItemsAdapter adapter = new ImportedSettingsItemsAdapter(
|
||||
app,
|
||||
ImportHelper.getSettingsToOperate(settingsItems, true),
|
||||
SettingsHelper.getSettingsToOperate(settingsItems, true),
|
||||
nightMode,
|
||||
new ImportedSettingsItemsAdapter.OnItemClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -34,8 +34,14 @@ import net.osmand.plus.AppInitializer;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.SQLiteTileSource;
|
||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
|
||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||
import net.osmand.plus.settings.backend.SettingsHelper;
|
||||
import net.osmand.plus.settings.backend.SettingsHelper.AvoidRoadsSettingsItem;
|
||||
import net.osmand.plus.settings.backend.SettingsHelper.FileSettingsItem;
|
||||
|
@ -47,12 +53,6 @@ import net.osmand.plus.settings.backend.SettingsHelper.ProfileSettingsItem;
|
|||
import net.osmand.plus.settings.backend.SettingsHelper.QuickActionsSettingsItem;
|
||||
import net.osmand.plus.settings.backend.SettingsHelper.SettingsItem;
|
||||
import net.osmand.plus.settings.backend.SettingsHelper.SettingsItemType;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.widgets.TextViewEx;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
|
@ -64,7 +64,6 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static net.osmand.plus.helpers.ImportHelper.getSettingsToOperate;
|
||||
|
||||
public class ImportSettingsFragment extends BaseOsmAndFragment
|
||||
implements View.OnClickListener {
|
||||
|
@ -183,7 +182,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
|
|||
adapter = new ExportImportSettingsAdapter(app, nightMode, true);
|
||||
Map<ExportSettingsType, List<?>> itemsMap = new HashMap<>();
|
||||
if (settingsItems != null) {
|
||||
itemsMap = getSettingsToOperate(settingsItems, false);
|
||||
itemsMap = SettingsHelper.getSettingsToOperate(settingsItems, false);
|
||||
adapter.updateSettingsList(itemsMap);
|
||||
}
|
||||
expandableList.setAdapter(adapter);
|
||||
|
|
Loading…
Reference in a new issue