From 11e51ef318a4d79c4d3ed5f133fc845c72ac6549 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Mon, 10 Feb 2020 17:18:05 +0200 Subject: [PATCH] sqlite map sources with urls / screen rotating / quick action apply --- .../src/net/osmand/plus/SQLiteTileSource.java | 9 ++++-- .../src/net/osmand/plus/SettingsHelper.java | 27 ++++++++++++++--- .../ExportImportProfileBottomSheet.java | 29 ++++++++++++++++--- 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java index 3771b2c1b0..23553bede7 100644 --- a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java +++ b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java @@ -1,6 +1,6 @@ package net.osmand.plus; -import android.content.ContentValues; +import android.database.SQLException; import android.database.sqlite.SQLiteDiskIOException; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -23,7 +23,6 @@ import java.nio.ByteBuffer; import java.util.Arrays; import java.util.List; -import static net.osmand.IndexConstants.APP_DIR; import static net.osmand.IndexConstants.SQLITE_EXT; import static net.osmand.IndexConstants.TILES_INDEX_DIR; @@ -312,7 +311,11 @@ public class SQLiteTileSource implements ITileSource { private void addInfoColumn(String columnName, String value) { if(!onlyReadonlyAvailable) { - db.execSQL("alter table info add column "+columnName+" TEXT"); + try { + db.execSQL("alter table info add column " + columnName + " TEXT"); + } catch (SQLException e) { + LOG.info("Error adding column " + e); + } db.execSQL("update info set "+columnName+" = '"+value+"'"); } } diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index f7b4fd492e..289662c66d 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -20,6 +20,7 @@ import net.osmand.osm.PoiCategory; import net.osmand.plus.ApplicationMode.ApplicationModeBean; import net.osmand.plus.ApplicationMode.ApplicationModeBuilder; import net.osmand.plus.OsmandSettings.OsmandPreference; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickActionFactory; @@ -93,6 +94,7 @@ public class SettingsHelper { private boolean importing; private boolean importSuspended; + private boolean collectOnly; private ImportAsyncTask importTask; public interface SettingsImportListener { @@ -113,7 +115,7 @@ public class SettingsHelper { public void setActivity(Activity activity) { this.activity = activity; - if (importing) { + if (importing && !collectOnly) { importTask.processNextItem(); } } @@ -762,7 +764,7 @@ public class SettingsHelper { } } newActions.addAll(quickActions); - getSettings().QUICK_ACTION_LIST.set(factory.quickActionListToString(newActions)); + ((MapActivity) app.getSettingsHelper().getActivity()).getMapLayers().getQuickActionRegistry().updateQuickActions(newActions); } } @@ -1373,7 +1375,6 @@ public class SettingsHelper { private File file; private String latestChanges; private int version; - private boolean collectOnly; private SettingsImportListener listener; private SettingsImporter importer; @@ -1429,10 +1430,10 @@ public class SettingsHelper { @Override protected void onPostExecute(List items) { + this.items = items; if (collectOnly) { listener.onSettingsImportFinished(true, false, items); } else { - this.items = items; if (items != null && items.size() > 0) { processNextItem(); } @@ -1528,6 +1529,24 @@ public class SettingsHelper { processedItems.add(item); processNextItem(); } + + public List getItems() { + return this.items; + } + + public File getFile() { + return this.file; + } + } + + @Nullable + public List getSettingsItems() { + return this.importTask.getItems(); + } + + @Nullable + public File getSettingsFile() { + return this.importTask.getFile(); } @SuppressLint("StaticFieldLeak") diff --git a/OsmAnd/src/net/osmand/plus/profiles/ExportImportProfileBottomSheet.java b/OsmAnd/src/net/osmand/plus/profiles/ExportImportProfileBottomSheet.java index 710c649586..b5b7fc34c5 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/ExportImportProfileBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/profiles/ExportImportProfileBottomSheet.java @@ -63,6 +63,8 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet { private static final String STATE_KEY = "EXPORT_IMPORT_DIALOG_STATE_KEY"; + private static final String INCLUDE_ADDITIONAL_DATA_KEY = "INCLUDE_ADDITIONAL_DATA_KEY"; + private boolean includeAdditionalData = false; private boolean containsAdditionalData = false; @@ -89,6 +91,9 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet { @Override public void onCreate(Bundle savedInstanceState) { + if (savedInstanceState != null) { + includeAdditionalData = savedInstanceState.getBoolean(INCLUDE_ADDITIONAL_DATA_KEY); + } super.onCreate(savedInstanceState); app = requiredMyApplication(); Bundle bundle = getArguments(); @@ -96,6 +101,12 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet { this.state = (State) getArguments().getSerializable(STATE_KEY); } if (state == State.IMPORT) { + if (settingsItems == null) { + settingsItems = app.getSettingsHelper().getSettingsItems(); + } + if (file == null) { + file = app.getSettingsHelper().getSettingsFile(); + } containsAdditionalData = checkAdditionalDataContains(); } else { dataList = getAdditionalData(); @@ -105,6 +116,12 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet { } } + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(INCLUDE_ADDITIONAL_DATA_KEY, includeAdditionalData); + } + @Override public void createMenuItems(Bundle savedInstanceState) { final Context context = getContext(); @@ -150,7 +167,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet { listView = additionalDataView.findViewById(R.id.list); SwitchCompat switchItem = additionalDataView.findViewById(R.id.switchItem); switchItem.setTextColor(getResources().getColor(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light)); - + switchItem.setChecked(includeAdditionalData); switchItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -163,8 +180,8 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet { setupHeightAndBackground(getView()); } }); - - adapter = new ProfileAdditionalDataAdapter(requiredMyApplication(), dataList, profileColor); + listView.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE); + adapter = new ProfileAdditionalDataAdapter(app, dataList, profileColor); listView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() { @Override public void onGroupExpand(int i) { @@ -398,7 +415,11 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet { app.getSettingsHelper().importSettings(file, list, "", 1, new SettingsHelper.SettingsImportListener() { @Override public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { - + if (succeed) { + app.showShortToastMessage(app.getString(R.string.file_imported_successfully, file.getName())); + } else if (empty){ + app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error))); + } } }); dismiss();