wip
This commit is contained in:
parent
5676e35bc9
commit
224cc71ce7
5 changed files with 475 additions and 99 deletions
|
@ -11,6 +11,11 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="shared_string_routing">Routing</string>
|
||||
<string name="shared_string_custom_rendering_style">Custom rendering style</string>
|
||||
<string name="shared_string_include_data">Include additional data</string>
|
||||
<string name="import_profile_dialog_description">The imported profile contains additional data. Click Import to import only profile data or select additional data to import.</string>
|
||||
<string name="export_profile_dialog_description">You can select additional data to export along with the profile.</string>
|
||||
<string name="permission_is_required">Permission is required to use this option.</string>
|
||||
<string name="logcat_buffer_descr">Check and share detailed logs of the application</string>
|
||||
<string name="file_does_not_contain_routing_rules">No routing rules in \'%1$s\'. Please choose another file.</string>
|
||||
|
|
|
@ -7,19 +7,12 @@ import android.content.DialogInterface;
|
|||
import android.os.AsyncTask;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.ApplicationMode.ApplicationModeBuilder;
|
||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.profiles.AdditionalDataWrapper;
|
||||
import net.osmand.plus.profiles.ExportImportProfileBottomSheet;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.quickaction.QuickActionFactory;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -100,6 +93,10 @@ public class SettingsHelper {
|
|||
void onSettingsExportFinished(@NonNull File file, boolean succeed);
|
||||
}
|
||||
|
||||
public interface SettingsImportPrepareListener {
|
||||
void onSettingsPrepared(boolean succeed, boolean empty, @NonNull List<SettingsItem> items);
|
||||
}
|
||||
|
||||
public SettingsHelper(OsmandApplication app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
@ -135,7 +132,9 @@ public class SettingsHelper {
|
|||
PLUGIN,
|
||||
DATA,
|
||||
FILE,
|
||||
QUICK_ACTION
|
||||
QUICK_ACTION_LIST,
|
||||
POI_UI_FILTERS_LIST,
|
||||
MAP_SOURCES_LIST,
|
||||
}
|
||||
|
||||
public abstract static class SettingsItem {
|
||||
|
@ -712,15 +711,18 @@ public class SettingsHelper {
|
|||
|
||||
private List<QuickAction> quickActions;
|
||||
|
||||
public QuickActionSettingsItem(@NonNull OsmandSettings settings,
|
||||
private OsmandApplication app;
|
||||
|
||||
public QuickActionSettingsItem(@NonNull OsmandApplication app,
|
||||
@NonNull List<QuickAction> quickActions) {
|
||||
super(SettingsItemType.QUICK_ACTION, settings);
|
||||
super(SettingsItemType.QUICK_ACTION_LIST, app.getSettings());
|
||||
this.app = app;
|
||||
this.quickActions = quickActions;
|
||||
}
|
||||
|
||||
public QuickActionSettingsItem(@NonNull OsmandSettings settings,
|
||||
@NonNull JSONObject jsonObject) throws JSONException {
|
||||
super(SettingsItemType.QUICK_ACTION, settings, jsonObject);
|
||||
super(SettingsItemType.QUICK_ACTION_LIST, settings, jsonObject);
|
||||
readFromJson(jsonObject);
|
||||
}
|
||||
|
||||
|
@ -728,6 +730,25 @@ public class SettingsHelper {
|
|||
return quickActions;
|
||||
}
|
||||
|
||||
// void readFromJson(JSONObject jsonObject) {
|
||||
// try {
|
||||
// JSONArray jsonArray = jsonObject.getJSONArray("");
|
||||
//
|
||||
// } catch (JSONException e) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
if (quickActions.isEmpty()) {
|
||||
QuickActionFactory factory = new QuickActionFactory();
|
||||
List<QuickAction> quickActionsList = factory.parseActiveActionsList(getSettings().QUICK_ACTION_LIST.get());
|
||||
quickActionsList.addAll(quickActions);
|
||||
getSettings().QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActionsList));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getName() {
|
||||
|
@ -746,6 +767,16 @@ public class SettingsHelper {
|
|||
return getName() + ".json";
|
||||
}
|
||||
|
||||
@Override
|
||||
void writeToJson(@NonNull JSONObject json) throws JSONException {
|
||||
super.writeToJson(json);
|
||||
// JSONArray jsonArray = new JSONArray();
|
||||
// for (QuickAction quickAction : quickActions) {
|
||||
// jsonArray.put(quickAction.getName(app));
|
||||
// }
|
||||
// json.put("name_list", jsonArray);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
SettingsItemReader getReader() {
|
||||
|
@ -773,13 +804,22 @@ public class SettingsHelper {
|
|||
throw new IllegalArgumentException("Cannot find json body");
|
||||
}
|
||||
final JSONObject json;
|
||||
String itemsString;
|
||||
try {
|
||||
quickActions = new ArrayList<>();
|
||||
json = new JSONObject(jsonStr);
|
||||
itemsString = json.getString("items");
|
||||
getSettings().QUICK_ACTION_LIST.set(itemsString);
|
||||
QuickActionFactory factory = new QuickActionFactory();
|
||||
quickActions = factory.parseActiveActionsList(itemsString);
|
||||
JSONArray items = json.getJSONArray("items");
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
JSONObject object = items.getJSONObject(i);
|
||||
String name = object.getString("name");
|
||||
int type = object.getInt("type");
|
||||
QuickAction quickAction = new QuickAction(type);
|
||||
quickAction.setName(name);
|
||||
quickActions.add(quickAction);
|
||||
}
|
||||
// QuickActionFactory factory = new QuickActionFactory();
|
||||
// List<QuickAction> quickActionsList = factory.parseActiveActionsList(getSettings().QUICK_ACTION_LIST.get());
|
||||
// quickActionsList.addAll(quickActions);
|
||||
// getSettings().QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActionsList));
|
||||
} catch (JSONException e) {
|
||||
throw new IllegalArgumentException("Json parse error", e);
|
||||
}
|
||||
|
@ -793,8 +833,82 @@ public class SettingsHelper {
|
|||
return new OsmandSettingsItemWriter(this, getSettings()) {
|
||||
@Override
|
||||
protected void writePreferenceToJson(@NonNull OsmandPreference<?> preference, @NonNull JSONObject json) throws JSONException {
|
||||
QuickActionFactory factory = new QuickActionFactory();
|
||||
json.put("items", new JSONArray(factory.quickActionListToString(quickActions)));
|
||||
JSONArray items = new JSONArray();
|
||||
if (!quickActions.isEmpty()) {
|
||||
for (QuickAction action : quickActions) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name", action.getName(app));
|
||||
jsonObject.put("params", action.getParams());
|
||||
jsonObject.put("type", action.getType());
|
||||
items.put(jsonObject);
|
||||
}
|
||||
json.put("items", items);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class PoiUiFilterSettingsItem extends OsmandSettingsItem {
|
||||
|
||||
private List<PoiUIFilter> poiUIFilters;
|
||||
|
||||
public PoiUiFilterSettingsItem(OsmandSettings settings, List<PoiUIFilter> poiUIFilters) {
|
||||
super(SettingsItemType.POI_UI_FILTERS_LIST, settings);
|
||||
this.poiUIFilters = poiUIFilters;
|
||||
}
|
||||
|
||||
public PoiUiFilterSettingsItem(OsmandSettings settings, JSONObject jsonObject) throws JSONException {
|
||||
super(SettingsItemType.POI_UI_FILTERS_LIST, settings, jsonObject);
|
||||
readFromJson(jsonObject);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "poi_ui_filters";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getPublicName(@NonNull Context ctx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getFileName() {
|
||||
return getName() + ".json";
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
SettingsItemReader getReader() {
|
||||
return new OsmandSettingsItemReader(this, getSettings()) {
|
||||
@Override
|
||||
protected void readPreferenceFromJson(@NonNull OsmandPreference<?> preference, @NonNull JSONObject json) throws JSONException {
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
SettingsItemWriter getWriter() {
|
||||
return new OsmandSettingsItemWriter(this, getSettings()) {
|
||||
@Override
|
||||
protected void writePreferenceToJson(@NonNull OsmandPreference<?> preference, @NonNull JSONObject json) throws JSONException {
|
||||
JSONArray items = new JSONArray();
|
||||
if (!poiUIFilters.isEmpty()) {
|
||||
for (PoiUIFilter filter : poiUIFilters) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name", filter.getName());
|
||||
jsonObject.put("filterId", filter.getFilterId());
|
||||
jsonObject.put("acceptedTypes", filter.getAcceptedTypes());
|
||||
items.put(jsonObject);
|
||||
}
|
||||
json.put("items", items);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -856,9 +970,15 @@ public class SettingsHelper {
|
|||
case FILE:
|
||||
item = new FileSettingsItem(app, json);
|
||||
break;
|
||||
case QUICK_ACTION:
|
||||
case QUICK_ACTION_LIST:
|
||||
item = new QuickActionSettingsItem(settings, json);
|
||||
break;
|
||||
case POI_UI_FILTERS_LIST:
|
||||
item = new PoiUiFilterSettingsItem(settings, json);
|
||||
break;
|
||||
// case MAP_SOURCES_LIST:
|
||||
// item = new
|
||||
// break;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
@ -998,6 +1118,164 @@ public class SettingsHelper {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public class PrepareImportFileAsyncTask extends AsyncTask<Void, Void, List<SettingsItem>> {
|
||||
|
||||
private File file;
|
||||
private SettingsImportPrepareListener listener;
|
||||
private SettingsImporter importer;
|
||||
|
||||
PrepareImportFileAsyncTask(@NonNull File settingsFile, @Nullable SettingsImportPrepareListener listener) {
|
||||
this.file = settingsFile;
|
||||
this.listener = listener;
|
||||
importer = new SettingsImporter(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<SettingsItem> doInBackground(Void... voids) {
|
||||
try {
|
||||
return importer.collectItems(file);
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOG.error("Failed to collect items from: " + file.getName(), e);
|
||||
} catch (IOException e) {
|
||||
LOG.error("Failed to collect items from: " + file.getName(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<SettingsItem> settingsItems) {
|
||||
super.onPostExecute(settingsItems);
|
||||
if (settingsItems != null && settingsItems.size() > 0) {
|
||||
listener.onSettingsPrepared(true, false, settingsItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private class ImportSettingsTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private File file;
|
||||
private String latestChanges;
|
||||
private int version;
|
||||
|
||||
private SettingsImportListener listener;
|
||||
private SettingsImporter importer;
|
||||
private List<SettingsItem> items;
|
||||
private List<SettingsItem> processedItems = new ArrayList<>();
|
||||
private SettingsItem currentItem;
|
||||
private AlertDialog dialog;
|
||||
|
||||
ImportSettingsTask(List<SettingsItem> items, File file, SettingsImportListener listener) {
|
||||
this.items = items;
|
||||
this.file = file;
|
||||
importer = new SettingsImporter(app);
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
processNextItem();
|
||||
}
|
||||
|
||||
private void processNextItem() {
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
if (items.size() == 0 && !importSuspended) {
|
||||
if (processedItems.size() > 0) {
|
||||
new ImportItemsAsyncTask(file, listener, processedItems).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
finishImport(listener, false, true, items);
|
||||
}
|
||||
return;
|
||||
}
|
||||
final SettingsItem item;
|
||||
if (importSuspended && currentItem != null) {
|
||||
item = currentItem;
|
||||
} else if (items.size() > 0) {
|
||||
item = items.remove(0);
|
||||
currentItem = item;
|
||||
} else {
|
||||
item = null;
|
||||
}
|
||||
importSuspended = false;
|
||||
if (item != null) {
|
||||
if (item.exists()) {
|
||||
switch (item.getType()) {
|
||||
case PROFILE: {
|
||||
String title = activity.getString(R.string.overwrite_profile_q, item.getPublicName(app));
|
||||
dialog = showConfirmDialog(item, title, latestChanges);
|
||||
break;
|
||||
}
|
||||
case FILE:
|
||||
// overwrite now
|
||||
acceptItem(item);
|
||||
break;
|
||||
default:
|
||||
acceptItem(item);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (item.getType() == SettingsItemType.PROFILE) {
|
||||
String title = activity.getString(R.string.add_new_profile_q, item.getPublicName(app));
|
||||
dialog = showConfirmDialog(item, title, latestChanges);
|
||||
} else {
|
||||
acceptItem(item);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
processNextItem();
|
||||
}
|
||||
}
|
||||
|
||||
private AlertDialog showConfirmDialog(final SettingsItem item, String title, String message) {
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(activity);
|
||||
b.setTitle(title);
|
||||
b.setMessage(message);
|
||||
b.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
acceptItem(item);
|
||||
}
|
||||
});
|
||||
b.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
processNextItem();
|
||||
}
|
||||
});
|
||||
b.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
ImportSettingsTask.this.dialog = null;
|
||||
}
|
||||
});
|
||||
b.setCancelable(false);
|
||||
return b.show();
|
||||
}
|
||||
|
||||
private void suspendImport() {
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
dialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void acceptItem(SettingsItem item) {
|
||||
// item.apply();
|
||||
processedItems.add(item);
|
||||
processNextItem();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private class ImportAsyncTask extends AsyncTask<Void, Void, List<SettingsItem>> {
|
||||
|
||||
|
@ -1184,6 +1462,11 @@ public class SettingsHelper {
|
|||
if (listener != null) {
|
||||
listener.onSettingsImportFinished(success, empty, items);
|
||||
}
|
||||
if (success) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, ""));
|
||||
} else if (!empty) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_import_error, "", app.getString(R.string.shared_string_unexpected_error)));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
|
@ -1240,4 +1523,12 @@ public class SettingsHelper {
|
|||
@NonNull SettingsItem... items) {
|
||||
exportSettings(fileDir, fileName, listener, new ArrayList<>(Arrays.asList(items)));
|
||||
}
|
||||
|
||||
public void prepareSettings(@NonNull File settingsFile, @Nullable SettingsImportPrepareListener listener) {
|
||||
new PrepareImportFileAsyncTask(settingsFile, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
public void importSettings(List<SettingsItem> items, File file, SettingsImportListener listener) {
|
||||
new ImportSettingsTask(items, file, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import android.provider.OpenableColumns;
|
|||
import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
|
@ -33,6 +34,7 @@ import net.osmand.data.FavouritePoint;
|
|||
import net.osmand.plus.AppInitializer;
|
||||
import net.osmand.plus.AppInitializer.AppInitializeListener;
|
||||
import net.osmand.plus.AppInitializer.InitEvents;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.GPXDatabase;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -49,6 +51,9 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
|||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.profiles.AdditionalDataWrapper;
|
||||
import net.osmand.plus.profiles.ExportImportProfileBottomSheet;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.router.RoutingConfiguration;
|
||||
|
@ -769,24 +774,43 @@ public class ImportHelper {
|
|||
@Override
|
||||
protected void onPostExecute(String error) {
|
||||
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
|
||||
File file = new File(tempDir, name);
|
||||
final File file = new File(tempDir, name);
|
||||
if (error == null && file.exists()) {
|
||||
app.getSettingsHelper().importSettings(file, latestChanges, version, new SettingsImportListener() {
|
||||
app.getSettingsHelper().prepareSettings(file, new SettingsHelper.SettingsImportPrepareListener() {
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
}
|
||||
if (succeed) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, name));
|
||||
if (callback != null) {
|
||||
callback.processResult(items);
|
||||
public void onSettingsPrepared(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
progress.dismiss();
|
||||
if (succeed && !empty) {
|
||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
if (fragmentManager != null) {
|
||||
ExportImportProfileBottomSheet.showInstance(
|
||||
fragmentManager,
|
||||
ExportImportProfileBottomSheet.State.IMPORT,
|
||||
file,
|
||||
items);
|
||||
}
|
||||
} else if (!empty) {
|
||||
app.showShortToastMessage(app.getString(R.string.file_import_error, name, app.getString(R.string.shared_string_unexpected_error)));
|
||||
} else {
|
||||
app.showShortToastMessage(app.getString(R.string.file_import_error, name, ""));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// app.getSettingsHelper().importSettings(file, latestChanges, version, new SettingsImportListener() {
|
||||
// @Override
|
||||
// public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
// if (isActivityNotDestroyed(activity)) {
|
||||
// progress.dismiss();
|
||||
// }
|
||||
// if (succeed) {
|
||||
// app.showShortToastMessage(app.getString(R.string.file_imported_successfully, name));
|
||||
// if (callback != null) {
|
||||
// callback.processResult(items);
|
||||
// }
|
||||
// } else if (!empty) {
|
||||
// app.showShortToastMessage(app.getString(R.string.file_import_error, name, app.getString(R.string.shared_string_unexpected_error)));
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
} else {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
progress.dismiss();
|
||||
|
|
|
@ -70,10 +70,11 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
private ApplicationMode profile;
|
||||
|
||||
private boolean includeAdditionalData = false;
|
||||
private boolean containsAdditionalData = false;
|
||||
|
||||
private State state;
|
||||
|
||||
private List<AdditionalDataWrapper> dataList;
|
||||
private List<AdditionalDataWrapper> dataList = new ArrayList<>();
|
||||
|
||||
private ExpandableListView listView;
|
||||
|
||||
|
@ -83,6 +84,8 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
|
||||
private List<SettingsHelper.SettingsItem> settingsItems;
|
||||
|
||||
private File file;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -94,14 +97,17 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
if (bundle != null) {
|
||||
this.state = (State) getArguments().getSerializable(STATE_KEY);
|
||||
}
|
||||
|
||||
dataList = state == State.IMPORT ? getDataFromSettingsItems() : getAdditionalData();
|
||||
for (AdditionalDataWrapper dataWrapper : dataList) {
|
||||
dataToOperate.addAll(dataWrapper.getItems());
|
||||
if (state == State.IMPORT) {
|
||||
containsAdditionalData = checkAdditionalDataContains();
|
||||
} else {
|
||||
dataList = getAdditionalData();
|
||||
for (AdditionalDataWrapper dataWrapper : dataList) {
|
||||
dataToOperate.addAll(dataWrapper.getItems());
|
||||
}
|
||||
}
|
||||
// dataList = state == State.IMPORT ? getDataFromSettingsItems() : getAdditionalData();
|
||||
}
|
||||
|
||||
|
||||
private ApplicationMode getAppModeFromItems() {
|
||||
for (SettingsHelper.SettingsItem item : settingsItems) {
|
||||
if (item.getType().equals(SettingsHelper.SettingsItemType.PROFILE)) {
|
||||
|
@ -142,50 +148,79 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
.create();
|
||||
items.add(profileItem);
|
||||
|
||||
BaseBottomSheetItem descriptionItem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(state == State.EXPORT ?
|
||||
getString(R.string.export_profile_dialog_description)
|
||||
: getString(R.string.import_profile_dialog_description))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_pref_info)
|
||||
.create();
|
||||
items.add(descriptionItem);
|
||||
if (state == State.IMPORT && containsAdditionalData || state == State.EXPORT && !dataList.isEmpty()) {
|
||||
BaseBottomSheetItem descriptionItem = new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(state == State.EXPORT ?
|
||||
getString(R.string.export_profile_dialog_description)
|
||||
: getString(R.string.import_profile_dialog_description))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_pref_info)
|
||||
.create();
|
||||
items.add(descriptionItem);
|
||||
|
||||
final View additionalDataView = View.inflate(new ContextThemeWrapper(context, themeRes),
|
||||
R.layout.bottom_sheet_item_additional_data, null);
|
||||
listView = additionalDataView.findViewById(R.id.list);
|
||||
Switch switchItem = additionalDataView.findViewById(R.id.switchItem);
|
||||
switchItem.setTextColor(getResources().getColor(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
|
||||
final View additionalDataView = View.inflate(new ContextThemeWrapper(context, themeRes),
|
||||
R.layout.bottom_sheet_item_additional_data, null);
|
||||
listView = additionalDataView.findViewById(R.id.list);
|
||||
Switch switchItem = additionalDataView.findViewById(R.id.switchItem);
|
||||
switchItem.setTextColor(getResources().getColor(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
|
||||
|
||||
switchItem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
includeAdditionalData = !includeAdditionalData;
|
||||
listView.setVisibility(includeAdditionalData ?
|
||||
View.VISIBLE : View.GONE);
|
||||
}
|
||||
});
|
||||
adapter = new ProfileAdditionalDataAdapter(requiredMyApplication(), dataList, profileColor);
|
||||
listView.setAdapter(adapter);
|
||||
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
||||
.setCustomView(additionalDataView)
|
||||
.create();
|
||||
items.add(titleItem);
|
||||
switchItem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
includeAdditionalData = !includeAdditionalData;
|
||||
listView.setVisibility(includeAdditionalData ?
|
||||
View.VISIBLE : View.GONE);
|
||||
if (includeAdditionalData && state == State.IMPORT) {
|
||||
updateDataFromSettingsItems();
|
||||
}
|
||||
}
|
||||
});
|
||||
adapter = new ProfileAdditionalDataAdapter(requiredMyApplication(), dataList, profileColor);
|
||||
listView.setAdapter(adapter);
|
||||
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
||||
.setCustomView(additionalDataView)
|
||||
.create();
|
||||
items.add(titleItem);
|
||||
}
|
||||
}
|
||||
|
||||
private List<AdditionalDataWrapper> getDataFromSettingsItems() {
|
||||
List<AdditionalDataWrapper> dataList = new ArrayList<>();
|
||||
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
for (SettingsHelper.SettingsItem item : settingsItems) {
|
||||
if (item.getType().equals(SettingsHelper.SettingsItemType.QUICK_ACTION)) {
|
||||
quickActions.addAll(((SettingsHelper.QuickActionSettingsItem) item).getQuickActions());
|
||||
private void updateDataFromSettingsItems() {
|
||||
app.getSettingsHelper().importSettings(settingsItems, file, new SettingsHelper.SettingsImportListener() {
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
List<AdditionalDataWrapper> dataList = new ArrayList<>();
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||
for (SettingsHelper.SettingsItem item : items) {
|
||||
if (item.getType().equals(SettingsHelper.SettingsItemType.QUICK_ACTION_LIST)) {
|
||||
quickActions.addAll(((SettingsHelper.QuickActionSettingsItem) item).getQuickActions());
|
||||
} else if (item.getType().equals(SettingsHelper.SettingsItemType.POI_UI_FILTERS_LIST)) {
|
||||
// poiUIFilters.addAll()
|
||||
}
|
||||
}
|
||||
if (!quickActions.isEmpty()) {
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.QUICK_ACTIONS,
|
||||
quickActions));
|
||||
}
|
||||
if (!poiUIFilters.isEmpty()) {
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.POI_TYPES,
|
||||
poiUIFilters));
|
||||
}
|
||||
adapter.updateList(dataList);
|
||||
}
|
||||
}
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.QUICK_ACTIONS,
|
||||
quickActions));
|
||||
});
|
||||
|
||||
return dataList;
|
||||
|
||||
}
|
||||
|
||||
private Boolean checkAdditionalDataContains() {
|
||||
boolean containsData = false;
|
||||
for (SettingsHelper.SettingsItem item : settingsItems) {
|
||||
containsData = item.getType().equals(SettingsHelper.SettingsItemType.QUICK_ACTION_LIST)
|
||||
|| item.getType().equals(SettingsHelper.SettingsItemType.POI_UI_FILTERS_LIST);
|
||||
}
|
||||
return containsData;
|
||||
}
|
||||
|
||||
private List<AdditionalDataWrapper> getAdditionalData() {
|
||||
|
@ -202,15 +237,15 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
poiList
|
||||
));
|
||||
|
||||
final LinkedHashMap<String, String> entriesMap = new LinkedHashMap<>(settings.getTileSourceEntries());
|
||||
List<MapSourceWrapper> mapSourceWrapperList = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : entriesMap.entrySet()) {
|
||||
mapSourceWrapperList.add(new MapSourceWrapper(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.MAP_SOURCES,
|
||||
mapSourceWrapperList
|
||||
));
|
||||
// final LinkedHashMap<String, String> entriesMap = new LinkedHashMap<>(settings.getTileSourceEntries());
|
||||
// List<MapSourceWrapper> mapSourceWrapperList = new ArrayList<>();
|
||||
// for (Map.Entry<String, String> entry : entriesMap.entrySet()) {
|
||||
// mapSourceWrapperList.add(new MapSourceWrapper(entry.getKey(), entry.getValue()));
|
||||
// }
|
||||
// dataList.add(new AdditionalDataWrapper(
|
||||
// AdditionalDataWrapper.Type.MAP_SOURCES,
|
||||
// mapSourceWrapperList
|
||||
// ));
|
||||
|
||||
return dataList;
|
||||
}
|
||||
|
@ -227,16 +262,22 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
@Override
|
||||
protected void onRightBottomButtonClick() {
|
||||
super.onRightBottomButtonClick();
|
||||
prepareFile();
|
||||
// if (state == State.EXPORT) {
|
||||
// if (includeAdditionalData) {
|
||||
// prepareFileWithAdditional();
|
||||
// } else {
|
||||
// prepareFile();
|
||||
// }
|
||||
// } else {
|
||||
//
|
||||
// }
|
||||
if (state == State.EXPORT) {
|
||||
prepareFile();
|
||||
} else {
|
||||
importSettings();
|
||||
}
|
||||
}
|
||||
|
||||
private void importSettings() {
|
||||
app.getSettingsHelper().importSettings(settingsItems, file, new SettingsHelper.SettingsImportListener() {
|
||||
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
|
||||
}
|
||||
});
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -267,11 +308,11 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
}
|
||||
}
|
||||
if (!quickActions.isEmpty()) {
|
||||
settingsItems.add(new SettingsHelper.QuickActionSettingsItem(app.getSettings(), quickActions));
|
||||
settingsItems.add(new SettingsHelper.QuickActionSettingsItem(app, quickActions));
|
||||
}
|
||||
if (!poiUIFilters.isEmpty()) {
|
||||
settingsItems.add(new SettingsHelper.PoiUiFilterSettingsItem(app.getSettings(), poiUIFilters));
|
||||
}
|
||||
// if (!poiUIFilters.isEmpty()) {
|
||||
// settingsItems.add();
|
||||
// }
|
||||
// if (!mapSourceWrappers.isEmpty()) {
|
||||
// settingsItems.add();
|
||||
// }
|
||||
|
@ -336,6 +377,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
|
||||
public static boolean showInstance(@NonNull FragmentManager fragmentManager,
|
||||
State state,
|
||||
File file,
|
||||
List<SettingsHelper.SettingsItem> items) {
|
||||
try {
|
||||
Bundle bundle = new Bundle();
|
||||
|
@ -343,6 +385,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
ExportImportProfileBottomSheet fragment = new ExportImportProfileBottomSheet();
|
||||
fragment.setArguments(bundle);
|
||||
fragment.setSettingsItems(items);
|
||||
fragment.setFile(file);
|
||||
fragment.show(fragmentManager, TAG);
|
||||
return true;
|
||||
} catch (RuntimeException e) {
|
||||
|
@ -350,6 +393,14 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
}
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
public void setFile(File file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public enum State {
|
||||
EXPORT,
|
||||
IMPORT
|
||||
|
@ -381,6 +432,11 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
this.profileColor = profileColor;
|
||||
}
|
||||
|
||||
public void updateList(List<AdditionalDataWrapper> list) {
|
||||
this.list = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGroupCount() {
|
||||
return list.size();
|
||||
|
|
|
@ -41,7 +41,7 @@ public class QuickAction {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
protected QuickAction(int type) {
|
||||
public QuickAction(int type) {
|
||||
this.id = System.currentTimeMillis();
|
||||
this.type = type;
|
||||
this.nameRes = QuickActionFactory.getActionName(type);
|
||||
|
|
Loading…
Reference in a new issue