sqlite map sources with urls / screen rotating / quick action apply

This commit is contained in:
veliymolfar 2020-02-10 17:18:05 +02:00
parent 148e6a2b1e
commit 11e51ef318
3 changed files with 54 additions and 11 deletions

View file

@ -1,6 +1,6 @@
package net.osmand.plus; package net.osmand.plus;
import android.content.ContentValues; import android.database.SQLException;
import android.database.sqlite.SQLiteDiskIOException; import android.database.sqlite.SQLiteDiskIOException;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
@ -23,7 +23,6 @@ import java.nio.ByteBuffer;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static net.osmand.IndexConstants.APP_DIR;
import static net.osmand.IndexConstants.SQLITE_EXT; import static net.osmand.IndexConstants.SQLITE_EXT;
import static net.osmand.IndexConstants.TILES_INDEX_DIR; import static net.osmand.IndexConstants.TILES_INDEX_DIR;
@ -312,7 +311,11 @@ public class SQLiteTileSource implements ITileSource {
private void addInfoColumn(String columnName, String value) { private void addInfoColumn(String columnName, String value) {
if(!onlyReadonlyAvailable) { 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+"'"); db.execSQL("update info set "+columnName+" = '"+value+"'");
} }
} }

View file

@ -20,6 +20,7 @@ import net.osmand.osm.PoiCategory;
import net.osmand.plus.ApplicationMode.ApplicationModeBean; import net.osmand.plus.ApplicationMode.ApplicationModeBean;
import net.osmand.plus.ApplicationMode.ApplicationModeBuilder; import net.osmand.plus.ApplicationMode.ApplicationModeBuilder;
import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionFactory; import net.osmand.plus.quickaction.QuickActionFactory;
@ -93,6 +94,7 @@ public class SettingsHelper {
private boolean importing; private boolean importing;
private boolean importSuspended; private boolean importSuspended;
private boolean collectOnly;
private ImportAsyncTask importTask; private ImportAsyncTask importTask;
public interface SettingsImportListener { public interface SettingsImportListener {
@ -113,7 +115,7 @@ public class SettingsHelper {
public void setActivity(Activity activity) { public void setActivity(Activity activity) {
this.activity = activity; this.activity = activity;
if (importing) { if (importing && !collectOnly) {
importTask.processNextItem(); importTask.processNextItem();
} }
} }
@ -762,7 +764,7 @@ public class SettingsHelper {
} }
} }
newActions.addAll(quickActions); 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 File file;
private String latestChanges; private String latestChanges;
private int version; private int version;
private boolean collectOnly;
private SettingsImportListener listener; private SettingsImportListener listener;
private SettingsImporter importer; private SettingsImporter importer;
@ -1429,10 +1430,10 @@ public class SettingsHelper {
@Override @Override
protected void onPostExecute(List<SettingsItem> items) { protected void onPostExecute(List<SettingsItem> items) {
this.items = items;
if (collectOnly) { if (collectOnly) {
listener.onSettingsImportFinished(true, false, items); listener.onSettingsImportFinished(true, false, items);
} else { } else {
this.items = items;
if (items != null && items.size() > 0) { if (items != null && items.size() > 0) {
processNextItem(); processNextItem();
} }
@ -1528,6 +1529,24 @@ public class SettingsHelper {
processedItems.add(item); processedItems.add(item);
processNextItem(); processNextItem();
} }
public List<SettingsItem> getItems() {
return this.items;
}
public File getFile() {
return this.file;
}
}
@Nullable
public List<SettingsItem> getSettingsItems() {
return this.importTask.getItems();
}
@Nullable
public File getSettingsFile() {
return this.importTask.getFile();
} }
@SuppressLint("StaticFieldLeak") @SuppressLint("StaticFieldLeak")

View file

@ -63,6 +63,8 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
private static final String STATE_KEY = "EXPORT_IMPORT_DIALOG_STATE_KEY"; 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 includeAdditionalData = false;
private boolean containsAdditionalData = false; private boolean containsAdditionalData = false;
@ -89,6 +91,9 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null) {
includeAdditionalData = savedInstanceState.getBoolean(INCLUDE_ADDITIONAL_DATA_KEY);
}
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
app = requiredMyApplication(); app = requiredMyApplication();
Bundle bundle = getArguments(); Bundle bundle = getArguments();
@ -96,6 +101,12 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
this.state = (State) getArguments().getSerializable(STATE_KEY); this.state = (State) getArguments().getSerializable(STATE_KEY);
} }
if (state == State.IMPORT) { if (state == State.IMPORT) {
if (settingsItems == null) {
settingsItems = app.getSettingsHelper().getSettingsItems();
}
if (file == null) {
file = app.getSettingsHelper().getSettingsFile();
}
containsAdditionalData = checkAdditionalDataContains(); containsAdditionalData = checkAdditionalDataContains();
} else { } else {
dataList = getAdditionalData(); 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 @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
final Context context = getContext(); final Context context = getContext();
@ -150,7 +167,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
listView = additionalDataView.findViewById(R.id.list); listView = additionalDataView.findViewById(R.id.list);
SwitchCompat switchItem = additionalDataView.findViewById(R.id.switchItem); 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.setTextColor(getResources().getColor(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
switchItem.setChecked(includeAdditionalData);
switchItem.setOnClickListener(new View.OnClickListener() { switchItem.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -163,8 +180,8 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
setupHeightAndBackground(getView()); setupHeightAndBackground(getView());
} }
}); });
listView.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE);
adapter = new ProfileAdditionalDataAdapter(requiredMyApplication(), dataList, profileColor); adapter = new ProfileAdditionalDataAdapter(app, dataList, profileColor);
listView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() { listView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override @Override
public void onGroupExpand(int i) { public void onGroupExpand(int i) {
@ -398,7 +415,11 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
app.getSettingsHelper().importSettings(file, list, "", 1, new SettingsHelper.SettingsImportListener() { app.getSettingsHelper().importSettings(file, list, "", 1, new SettingsHelper.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 (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(); dismiss();