wip
This commit is contained in:
parent
224cc71ce7
commit
8294a0f08b
4 changed files with 194 additions and 78 deletions
|
@ -22,8 +22,7 @@
|
|||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/title_tv"
|
||||
android:layout_width="0dp"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
android:textAppearance="@style/TextAppearance.ListItemCategoryTitle"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
tools:text="Quick actions" />
|
||||
|
@ -42,7 +41,7 @@
|
|||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/divider_color"
|
||||
android:background="?attr/divider_color_basic"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
|
|
|
@ -30,14 +30,14 @@
|
|||
android:id="@+id/title_tv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
android:textAppearance="@style/TextAppearance.ListItemCategoryTitle"
|
||||
tools:text="Quick actions" />
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/sub_text_tv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
tools:text="8 of 4" />
|
||||
|
@ -50,7 +50,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="@dimen/content_padding"
|
||||
android:layout_marginBottom="@dimen/content_padding"
|
||||
android:background="?attr/divider_color" />
|
||||
android:background="?attr/divider_color_basic" />
|
||||
|
||||
<android.support.v7.widget.AppCompatCheckBox
|
||||
android:id="@+id/check_box"
|
||||
|
@ -65,7 +65,7 @@
|
|||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/divider_color"
|
||||
android:background="?attr/divider_color_basic"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ 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.ExportImportProfileBottomSheet;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.quickaction.QuickActionFactory;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -721,27 +722,52 @@ public class SettingsHelper {
|
|||
}
|
||||
|
||||
public QuickActionSettingsItem(@NonNull OsmandSettings settings,
|
||||
@NonNull JSONObject jsonObject) throws JSONException {
|
||||
@NonNull JSONObject jsonObject, File file) throws JSONException {
|
||||
super(SettingsItemType.QUICK_ACTION_LIST, settings, jsonObject);
|
||||
readFromJson(jsonObject);
|
||||
try {
|
||||
readFromJson(jsonObject, file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<QuickAction> getQuickActions() {
|
||||
return quickActions;
|
||||
}
|
||||
|
||||
// void readFromJson(JSONObject jsonObject) {
|
||||
// try {
|
||||
// JSONArray jsonArray = jsonObject.getJSONArray("");
|
||||
//
|
||||
// } catch (JSONException e) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
void readFromJson(JSONObject jsonObject, File file) throws IllegalArgumentException, IOException, JSONException {
|
||||
ZipInputStream zis = new ZipInputStream(new FileInputStream(file));
|
||||
InputStream ois = new BufferedInputStream(zis);
|
||||
ZipEntry entry;
|
||||
while ((entry = zis.getNextEntry()) != null){
|
||||
if (entry.getName().equals(getFileName())) {
|
||||
String itemsJson = null;
|
||||
try {
|
||||
itemsJson = Algorithms.readFromInputStream(ois).toString();
|
||||
} catch (IOException e) {
|
||||
LOG.error("Error reading items.json: " + itemsJson, e);
|
||||
throw new IllegalArgumentException("No items");
|
||||
} finally {
|
||||
zis.closeEntry();
|
||||
}
|
||||
quickActions = new ArrayList<>();
|
||||
JSONObject json = new JSONObject(itemsJson);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
if (quickActions.isEmpty()) {
|
||||
if (!quickActions.isEmpty()) {
|
||||
QuickActionFactory factory = new QuickActionFactory();
|
||||
List<QuickAction> quickActionsList = factory.parseActiveActionsList(getSettings().QUICK_ACTION_LIST.get());
|
||||
quickActionsList.addAll(quickActions);
|
||||
|
@ -914,13 +940,78 @@ public class SettingsHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static class MapSourcesSettingsItem extends OsmandSettingsItem {
|
||||
|
||||
private List<ExportImportProfileBottomSheet.MapSourceWrapper> mapSources;
|
||||
|
||||
public MapSourcesSettingsItem(OsmandSettings settings, List<ExportImportProfileBottomSheet.MapSourceWrapper> mapSources) {
|
||||
super(SettingsItemType.MAP_SOURCES_LIST, settings);
|
||||
this.mapSources = mapSources;
|
||||
}
|
||||
|
||||
public MapSourcesSettingsItem(OsmandSettings settings, JSONObject jsonObject) throws JSONException {
|
||||
super(SettingsItemType.MAP_SOURCES_LIST, settings, jsonObject);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "map_sources";
|
||||
}
|
||||
|
||||
@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 (!mapSources.isEmpty()) {
|
||||
for (ExportImportProfileBottomSheet.MapSourceWrapper mapSourceWrapper : mapSources) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name", mapSourceWrapper.getName());
|
||||
jsonObject.put("url", mapSourceWrapper.getUrl());
|
||||
items.put(jsonObject);
|
||||
}
|
||||
json.put("items", items);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static class SettingsItemsFactory {
|
||||
|
||||
private OsmandApplication app;
|
||||
private List<SettingsItem> items = new ArrayList<>();
|
||||
private File file;
|
||||
|
||||
SettingsItemsFactory(OsmandApplication app, String jsonStr) throws IllegalArgumentException, JSONException {
|
||||
SettingsItemsFactory(OsmandApplication app, String jsonStr, File file) throws IllegalArgumentException, JSONException {
|
||||
this.app = app;
|
||||
this.file = file;
|
||||
JSONObject json = new JSONObject(jsonStr);
|
||||
JSONArray itemsJson = json.getJSONArray("items");
|
||||
for (int i = 0; i < itemsJson.length(); i++) {
|
||||
|
@ -971,14 +1062,14 @@ public class SettingsHelper {
|
|||
item = new FileSettingsItem(app, json);
|
||||
break;
|
||||
case QUICK_ACTION_LIST:
|
||||
item = new QuickActionSettingsItem(settings, json);
|
||||
item = new QuickActionSettingsItem(settings, json, file);
|
||||
break;
|
||||
case POI_UI_FILTERS_LIST:
|
||||
item = new PoiUiFilterSettingsItem(settings, json);
|
||||
break;
|
||||
// case MAP_SOURCES_LIST:
|
||||
// item = new
|
||||
// break;
|
||||
case MAP_SOURCES_LIST:
|
||||
item = new MapSourcesSettingsItem(settings, json);
|
||||
break;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
@ -1079,7 +1170,7 @@ public class SettingsHelper {
|
|||
}
|
||||
SettingsItemsFactory itemsFactory;
|
||||
try {
|
||||
itemsFactory = new SettingsItemsFactory(app, itemsJson);
|
||||
itemsFactory = new SettingsItemsFactory(app, itemsJson, file);
|
||||
if (collecting) {
|
||||
items.addAll(itemsFactory.getItems());
|
||||
}
|
||||
|
@ -1462,11 +1553,6 @@ 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")
|
||||
|
@ -1531,4 +1617,8 @@ public class SettingsHelper {
|
|||
public void importSettings(List<SettingsItem> items, File file, SettingsImportListener listener) {
|
||||
new ImportSettingsTask(items, file, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
// public void preImportSettings(List<SettingsItem> items, File file, SettingsImportListener listener) {
|
||||
// new ImportSettingsTask(items, file, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
private ApplicationMode profile;
|
||||
|
||||
private boolean includeAdditionalData = false;
|
||||
|
||||
private boolean containsAdditionalData = false;
|
||||
|
||||
private State state;
|
||||
|
@ -86,6 +87,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
|
||||
private File file;
|
||||
|
||||
private SettingsHelper.ProfileSettingsItem profileSettingsItem;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -111,6 +113,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
private ApplicationMode getAppModeFromItems() {
|
||||
for (SettingsHelper.SettingsItem item : settingsItems) {
|
||||
if (item.getType().equals(SettingsHelper.SettingsItemType.PROFILE)) {
|
||||
profileSettingsItem = ((SettingsHelper.ProfileSettingsItem) item);
|
||||
return ((SettingsHelper.ProfileSettingsItem) item).getAppMode();
|
||||
}
|
||||
}
|
||||
|
@ -184,41 +187,49 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
}
|
||||
|
||||
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)) {
|
||||
|
||||
List<AdditionalDataWrapper> dataList = new ArrayList<>();
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||
for (SettingsHelper.SettingsItem item : settingsItems) {
|
||||
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)) {
|
||||
} 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);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
if (!quickActions.isEmpty()) {
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.QUICK_ACTIONS,
|
||||
quickActions));
|
||||
}
|
||||
if (!poiUIFilters.isEmpty()) {
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.POI_TYPES,
|
||||
poiUIFilters));
|
||||
}
|
||||
for (AdditionalDataWrapper dataWrapper : dataList) {
|
||||
dataToOperate.addAll(dataWrapper.getItems());
|
||||
}
|
||||
adapter.updateList(dataList);
|
||||
|
||||
// app.getSettingsHelper().importSettings(settingsItems, file, new SettingsHelper.SettingsImportListener() {
|
||||
// @Override
|
||||
// public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
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);
|
||||
|| item.getType().equals(SettingsHelper.SettingsItemType.POI_UI_FILTERS_LIST)
|
||||
|| item.getType().equals(SettingsHelper.SettingsItemType.MAP_SOURCES_LIST);
|
||||
if (containsData) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return containsData;
|
||||
}
|
||||
|
@ -228,24 +239,30 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
|
||||
QuickActionFactory factory = new QuickActionFactory();
|
||||
List<QuickAction> quickActions = factory.parseActiveActionsList(settings.QUICK_ACTION_LIST.get());
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.QUICK_ACTIONS, quickActions));
|
||||
if (!quickActions.isEmpty()) {
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.QUICK_ACTIONS, quickActions));
|
||||
}
|
||||
|
||||
List<PoiUIFilter> poiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.POI_TYPES,
|
||||
poiList
|
||||
));
|
||||
if (!poiList.isEmpty()) {
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.POI_TYPES,
|
||||
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()));
|
||||
}
|
||||
if (!mapSourceWrapperList.isEmpty()) {
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.MAP_SOURCES,
|
||||
mapSourceWrapperList
|
||||
));
|
||||
}
|
||||
|
||||
return dataList;
|
||||
}
|
||||
|
@ -270,13 +287,23 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
}
|
||||
|
||||
private void importSettings() {
|
||||
app.getSettingsHelper().importSettings(settingsItems, file, new SettingsHelper.SettingsImportListener() {
|
||||
if (includeAdditionalData) {
|
||||
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
} else {
|
||||
List<SettingsHelper.SettingsItem> list = new ArrayList<>();
|
||||
list.add(profileSettingsItem);
|
||||
app.getSettingsHelper().importSettings(list, file, new SettingsHelper.SettingsImportListener() {
|
||||
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
|
||||
if (succeed) {
|
||||
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)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
|
@ -313,9 +340,9 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
if (!poiUIFilters.isEmpty()) {
|
||||
settingsItems.add(new SettingsHelper.PoiUiFilterSettingsItem(app.getSettings(), poiUIFilters));
|
||||
}
|
||||
// if (!mapSourceWrappers.isEmpty()) {
|
||||
// settingsItems.add();
|
||||
// }
|
||||
if (!mapSourceWrappers.isEmpty()) {
|
||||
settingsItems.add(new SettingsHelper.MapSourcesSettingsItem(app.getSettings(), mapSourceWrappers));
|
||||
}
|
||||
}
|
||||
return settingsItems;
|
||||
}
|
||||
|
@ -599,7 +626,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
}
|
||||
}
|
||||
|
||||
class MapSourceWrapper {
|
||||
public class MapSourceWrapper {
|
||||
private String name;
|
||||
private String url;
|
||||
|
||||
|
|
Loading…
Reference in a new issue