wip / import export mapSources poiFilter
This commit is contained in:
parent
5f4285fe26
commit
ee4c34ac09
4 changed files with 260 additions and 184 deletions
|
@ -1,5 +1,8 @@
|
|||
package net.osmand.map;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.osm.io.NetworkUtils;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -17,6 +20,7 @@ import java.io.FileOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URLConnection;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -688,4 +692,15 @@ public class TileSourceManager {
|
|||
templ.setRandoms(randoms);
|
||||
return templ;
|
||||
}
|
||||
|
||||
public String templatesListToString(List<TileSourceTemplate> templates) {
|
||||
return new Gson().toJson(templates);
|
||||
}
|
||||
|
||||
public List<TileSourceTemplate> parseTemplatesList(String json) {
|
||||
Type type = new TypeToken<List<TileSourceTemplate>>() {
|
||||
}.getType();
|
||||
ArrayList<TileSourceTemplate> templates = new Gson().fromJson(json, type);
|
||||
return templates != null ? templates : new ArrayList<TileSourceTemplate>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
android:orientation="vertical"
|
||||
android:paddingBottom="20dp">
|
||||
|
||||
<Switch
|
||||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/switchItem"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -13,12 +13,13 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.map.TileSourceManager;
|
||||
import net.osmand.osm.MapPoiTypes;
|
||||
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.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;
|
||||
|
@ -752,9 +753,17 @@ public class SettingsHelper {
|
|||
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));
|
||||
List<QuickAction> savedActions = factory.parseActiveActionsList(getSettings().QUICK_ACTION_LIST.get());
|
||||
List<QuickAction> newActions = new ArrayList<>(savedActions);
|
||||
for (QuickAction action : quickActions) {
|
||||
for (QuickAction savedAction : savedActions) {
|
||||
if (action.getName(app).equals(savedAction.getName(app))) {
|
||||
newActions.remove(savedAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
newActions.addAll(quickActions);
|
||||
getSettings().QUICK_ACTION_LIST.set(factory.quickActionListToString(newActions));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -810,14 +819,20 @@ public class SettingsHelper {
|
|||
final JSONObject json;
|
||||
try {
|
||||
quickActions = new ArrayList<>();
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<HashMap<String, String>>() {
|
||||
}.getType();
|
||||
json = new JSONObject(jsonStr);
|
||||
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);
|
||||
int actionType = object.getInt("type");
|
||||
String paramsString = object.getString("params");
|
||||
HashMap<String, String> params = gson.fromJson(paramsString, type);
|
||||
QuickAction quickAction = new QuickAction(actionType);
|
||||
quickAction.setName(name);
|
||||
quickAction.setParams(params);
|
||||
quickActions.add(quickAction);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
|
@ -834,12 +849,15 @@ public class SettingsHelper {
|
|||
@Override
|
||||
protected void writePreferenceToJson(@NonNull OsmandPreference<?> preference, @NonNull JSONObject json) throws JSONException {
|
||||
JSONArray items = new JSONArray();
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<HashMap<String, String>>() {
|
||||
}.getType();
|
||||
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());
|
||||
jsonObject.put("params", gson.toJson(action.getParams(), type));
|
||||
items.put(jsonObject);
|
||||
}
|
||||
json.put("items", items);
|
||||
|
@ -867,6 +885,20 @@ public class SettingsHelper {
|
|||
readFromJson(jsonObject);
|
||||
}
|
||||
|
||||
public List<PoiUIFilter> getPoiUIFilters() {
|
||||
return this.poiUIFilters != null ? this.poiUIFilters : new ArrayList<PoiUIFilter>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
if (!poiUIFilters.isEmpty()) {
|
||||
for (PoiUIFilter filter : poiUIFilters) {
|
||||
app.getPoiFilters().createPoiFilter(filter, false);
|
||||
}
|
||||
app.getSearchUICore().refreshCustomPoiFilters();
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getName() {
|
||||
|
@ -921,16 +953,22 @@ public class SettingsHelper {
|
|||
json = new JSONObject(jsonStr);
|
||||
JSONArray items = json.getJSONArray("items");
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<HashMap<PoiCategory, LinkedHashSet<String>>>() {
|
||||
Type type = new TypeToken<HashMap<String, LinkedHashSet<String>>>() {
|
||||
}.getType();
|
||||
MapPoiTypes poiTypes = app.getPoiTypes();
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
JSONObject object = items.getJSONObject(i);
|
||||
String name = object.getString("name");
|
||||
String filterId = object.getString("filterId");
|
||||
String acceptedTypesString = object.getString("acceptedTypes");
|
||||
// Map<PoiCategory, LinkedHashSet<String>> acceptedTypes = gson.fromJson(acceptedTypesString, type);
|
||||
// PoiUIFilter filter = new PoiUIFilter(name, filterId, acceptedTypes, app);
|
||||
// poiUIFilters.add(filter);
|
||||
HashMap<String, LinkedHashSet<String>> acceptedTypes = gson.fromJson(acceptedTypesString, type);
|
||||
Map<PoiCategory, LinkedHashSet<String>> acceptedTypesDone = new HashMap<>();
|
||||
for (Map.Entry<String, LinkedHashSet<String>> mapItem : acceptedTypes.entrySet()) {
|
||||
final PoiCategory a = poiTypes.getPoiCategoryByName(mapItem.getKey());
|
||||
acceptedTypesDone.put(a, mapItem.getValue());
|
||||
}
|
||||
PoiUIFilter filter = new PoiUIFilter(name, filterId, acceptedTypesDone, app);
|
||||
poiUIFilters.add(filter);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new IllegalArgumentException("Json parse error", e);
|
||||
|
@ -966,9 +1004,9 @@ public class SettingsHelper {
|
|||
|
||||
public static class MapSourcesSettingsItem extends OsmandSettingsItem {
|
||||
|
||||
private List<ExportImportProfileBottomSheet.MapSourceWrapper> mapSources;
|
||||
private List<TileSourceManager.TileSourceTemplate> mapSources;
|
||||
|
||||
public MapSourcesSettingsItem(OsmandSettings settings, List<ExportImportProfileBottomSheet.MapSourceWrapper> mapSources) {
|
||||
public MapSourcesSettingsItem(OsmandSettings settings, List<TileSourceManager.TileSourceTemplate> mapSources) {
|
||||
super(SettingsItemType.MAP_SOURCES, settings);
|
||||
this.mapSources = mapSources;
|
||||
}
|
||||
|
@ -977,6 +1015,20 @@ public class SettingsHelper {
|
|||
super(SettingsItemType.MAP_SOURCES, settings, jsonObject);
|
||||
}
|
||||
|
||||
public List<TileSourceManager.TileSourceTemplate> getMapSources() {
|
||||
return this.mapSources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
if (!mapSources.isEmpty()) {
|
||||
for (TileSourceManager.TileSourceTemplate template : mapSources) {
|
||||
boolean writed = getSettings().installTileSource(template);
|
||||
LOG.info("Temaplate _" + writed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String getName() {
|
||||
|
@ -1008,6 +1060,35 @@ public class SettingsHelper {
|
|||
protected void readPreferenceFromJson(@NonNull OsmandPreference<?> preference, @NonNull JSONObject json) throws JSONException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||
String str;
|
||||
while ((str = in.readLine()) != null) {
|
||||
buf.append(str);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Cannot read json body", e);
|
||||
}
|
||||
String jsonStr = buf.toString();
|
||||
if (Algorithms.isEmpty(jsonStr)) {
|
||||
throw new IllegalArgumentException("Cannot find json body");
|
||||
}
|
||||
final JSONObject json;
|
||||
try {
|
||||
mapSources = new ArrayList<>();
|
||||
json = new JSONObject(jsonStr);
|
||||
String items = json.getString("items");
|
||||
TileSourceManager manager = new TileSourceManager();
|
||||
List<TileSourceManager.TileSourceTemplate> templates = manager.parseTemplatesList(items);
|
||||
mapSources.addAll(templates);
|
||||
} catch (JSONException e) {
|
||||
throw new IllegalArgumentException("Json parse error", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1017,15 +1098,9 @@ public class SettingsHelper {
|
|||
return new OsmandSettingsItemWriter(this, getSettings()) {
|
||||
@Override
|
||||
protected void writePreferenceToJson(@NonNull OsmandPreference<?> preference, @NonNull JSONObject json) throws JSONException {
|
||||
JSONArray items = new JSONArray();
|
||||
TileSourceManager manager = new TileSourceManager();
|
||||
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);
|
||||
json.put("items", manager.templatesListToString(mapSources));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -12,6 +12,8 @@ import android.support.v4.app.Fragment;
|
|||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.widget.CompoundButtonCompat;
|
||||
import android.support.v4.widget.NestedScrollView;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -26,6 +28,7 @@ import android.widget.Toast;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.map.TileSourceManager;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -107,17 +110,6 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
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)) {
|
||||
profileSettingsItem = ((SettingsHelper.ProfileSettingsItem) item);
|
||||
return ((SettingsHelper.ProfileSettingsItem) item).getAppMode();
|
||||
}
|
||||
}
|
||||
return getAppMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -160,10 +152,11 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
.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);
|
||||
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.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -175,9 +168,17 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
if (includeAdditionalData && state == State.IMPORT) {
|
||||
updateDataFromSettingsItems();
|
||||
}
|
||||
setupHeightAndBackground(getView());
|
||||
}
|
||||
});
|
||||
|
||||
adapter = new ProfileAdditionalDataAdapter(requiredMyApplication(), dataList, profileColor);
|
||||
listView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
|
||||
@Override
|
||||
public void onGroupExpand(int i) {
|
||||
setupHeightAndBackground(getView());
|
||||
}
|
||||
});
|
||||
listView.setAdapter(adapter);
|
||||
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
|
||||
.setCustomView(additionalDataView)
|
||||
|
@ -186,19 +187,139 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
}
|
||||
}
|
||||
|
||||
private void updateDataFromSettingsItems() {
|
||||
@Override
|
||||
protected int getRightBottomButtonTextId() {
|
||||
return state == State.EXPORT ? R.string.shared_string_export : R.string.shared_string_import;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRightBottomButtonClick() {
|
||||
super.onRightBottomButtonClick();
|
||||
if (state == State.EXPORT) {
|
||||
prepareFile();
|
||||
} else {
|
||||
importSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDismissButtonTextId() {
|
||||
return R.string.shared_string_cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean useScrollableItemsContainer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private ApplicationMode getAppModeFromItems() {
|
||||
for (SettingsHelper.SettingsItem item : settingsItems) {
|
||||
if (item.getType().equals(SettingsHelper.SettingsItemType.PROFILE)) {
|
||||
profileSettingsItem = ((SettingsHelper.ProfileSettingsItem) item);
|
||||
return ((SettingsHelper.ProfileSettingsItem) item).getAppMode();
|
||||
}
|
||||
}
|
||||
return getAppMode();
|
||||
}
|
||||
|
||||
private List<AdditionalDataWrapper> getAdditionalData() {
|
||||
List<AdditionalDataWrapper> dataList = new ArrayList<>();
|
||||
|
||||
QuickActionFactory factory = new QuickActionFactory();
|
||||
List<QuickAction> quickActions = factory.parseActiveActionsList(settings.QUICK_ACTION_LIST.get());
|
||||
if (!quickActions.isEmpty()) {
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.QUICK_ACTIONS, quickActions));
|
||||
}
|
||||
|
||||
List<PoiUIFilter> poiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
|
||||
if (!poiList.isEmpty()) {
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.POI_TYPES,
|
||||
poiList
|
||||
));
|
||||
}
|
||||
|
||||
List<TileSourceManager.TileSourceTemplate> mapSourceWrapperList = new ArrayList<>();
|
||||
final LinkedHashMap<String, String> entriesMap = new LinkedHashMap<>(settings.getTileSourceEntries(false));
|
||||
for (Map.Entry<String, String> entry : entriesMap.entrySet()) {
|
||||
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + entry.getKey());
|
||||
TileSourceManager.TileSourceTemplate template = TileSourceManager.createTileSourceTemplate(f);
|
||||
if (template != null) {
|
||||
mapSourceWrapperList.add(template);
|
||||
}
|
||||
}
|
||||
if (!mapSourceWrapperList.isEmpty()) {
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.MAP_SOURCES,
|
||||
mapSourceWrapperList
|
||||
));
|
||||
}
|
||||
|
||||
return dataList;
|
||||
}
|
||||
|
||||
private List<SettingsHelper.SettingsItem> prepareSettingsItems() {
|
||||
List<SettingsHelper.SettingsItem> settingsItems = new ArrayList<>();
|
||||
settingsItems.add(new SettingsHelper.ProfileSettingsItem(app.getSettings(), profile));
|
||||
|
||||
if (includeAdditionalData) {
|
||||
settingsItems.addAll(prepareAdditionalSettingsItems());
|
||||
}
|
||||
return settingsItems;
|
||||
}
|
||||
|
||||
private List<SettingsHelper.SettingsItem> prepareAdditionalSettingsItems() {
|
||||
List<SettingsHelper.SettingsItem> settingsItems = new ArrayList<>();
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||
List<TileSourceManager.TileSourceTemplate> mapSourceWrappers = new ArrayList<>();
|
||||
for (Object object : dataToOperate) {
|
||||
if (object instanceof QuickAction) {
|
||||
quickActions.add((QuickAction) object);
|
||||
} else if (object instanceof PoiUIFilter) {
|
||||
poiUIFilters.add((PoiUIFilter) object);
|
||||
} else if (object instanceof TileSourceManager.TileSourceTemplate) {
|
||||
mapSourceWrappers.add((TileSourceManager.TileSourceTemplate) object);
|
||||
}
|
||||
}
|
||||
if (!quickActions.isEmpty()) {
|
||||
settingsItems.add(new SettingsHelper.QuickActionSettingsItem(app, quickActions));
|
||||
}
|
||||
if (!poiUIFilters.isEmpty()) {
|
||||
settingsItems.add(new SettingsHelper.PoiUiFilterSettingsItem(app, poiUIFilters));
|
||||
}
|
||||
if (!mapSourceWrappers.isEmpty()) {
|
||||
settingsItems.add(new SettingsHelper.MapSourcesSettingsItem(app.getSettings(), mapSourceWrappers));
|
||||
}
|
||||
return settingsItems;
|
||||
}
|
||||
|
||||
private Boolean checkAdditionalDataContains() {
|
||||
boolean containsData = false;
|
||||
for (SettingsHelper.SettingsItem item : settingsItems) {
|
||||
containsData = item.getType().equals(SettingsHelper.SettingsItemType.QUICK_ACTION)
|
||||
|| item.getType().equals(SettingsHelper.SettingsItemType.POI_UI_FILTERS)
|
||||
|| item.getType().equals(SettingsHelper.SettingsItemType.MAP_SOURCES);
|
||||
if (containsData) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return containsData;
|
||||
}
|
||||
|
||||
private void updateDataFromSettingsItems() {
|
||||
List<AdditionalDataWrapper> dataList = new ArrayList<>();
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||
List<MapSourceWrapper> mapSourceWrappers = new ArrayList<>();
|
||||
List<TileSourceManager.TileSourceTemplate> mapSourceWrappers = new ArrayList<>();
|
||||
for (SettingsHelper.SettingsItem item : settingsItems) {
|
||||
if (item.getType().equals(SettingsHelper.SettingsItemType.QUICK_ACTION)) {
|
||||
quickActions.addAll(((SettingsHelper.QuickActionSettingsItem) item).getQuickActions());
|
||||
quickActions.addAll(((SettingsHelper.QuickActionSettingsItem) item).getQuickActions());
|
||||
} else if (item.getType().equals(SettingsHelper.SettingsItemType.POI_UI_FILTERS)) {
|
||||
// poiUIFilters.addAll(((SettingsHelper.PoiUiFilterSettingsItem) item).)
|
||||
poiUIFilters.addAll(((SettingsHelper.PoiUiFilterSettingsItem) item).getPoiUIFilters());
|
||||
} else if (item.getType().equals(SettingsHelper.SettingsItemType.MAP_SOURCES)) {
|
||||
// mapSourceWrappers.addAll(((SettingsHelper.MapSourcesSettingsItem) item).)
|
||||
mapSourceWrappers.addAll(((SettingsHelper.MapSourcesSettingsItem) item).getMapSources());
|
||||
}
|
||||
}
|
||||
if (!quickActions.isEmpty()) {
|
||||
|
@ -223,71 +344,6 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
adapter.updateList(dataList);
|
||||
}
|
||||
|
||||
private Boolean checkAdditionalDataContains() {
|
||||
boolean containsData = false;
|
||||
for (SettingsHelper.SettingsItem item : settingsItems) {
|
||||
containsData = item.getType().equals(SettingsHelper.SettingsItemType.QUICK_ACTION)
|
||||
|| item.getType().equals(SettingsHelper.SettingsItemType.POI_UI_FILTERS)
|
||||
|| item.getType().equals(SettingsHelper.SettingsItemType.MAP_SOURCES);
|
||||
if (containsData) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return containsData;
|
||||
}
|
||||
|
||||
private List<AdditionalDataWrapper> getAdditionalData() {
|
||||
List<AdditionalDataWrapper> dataList = new ArrayList<>();
|
||||
|
||||
QuickActionFactory factory = new QuickActionFactory();
|
||||
List<QuickAction> quickActions = factory.parseActiveActionsList(settings.QUICK_ACTION_LIST.get());
|
||||
if (!quickActions.isEmpty()) {
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.QUICK_ACTIONS, quickActions));
|
||||
}
|
||||
|
||||
List<PoiUIFilter> poiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
|
||||
if (!poiList.isEmpty()) {
|
||||
dataList.add(new AdditionalDataWrapper(
|
||||
AdditionalDataWrapper.Type.POI_TYPES,
|
||||
poiList
|
||||
));
|
||||
}
|
||||
|
||||
final LinkedHashMap<String, String> entriesMap = new LinkedHashMap<>(settings.getTileSourceEntries(false));
|
||||
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;
|
||||
}
|
||||
|
||||
public void setSettingsItems(List<SettingsHelper.SettingsItem> settingsItems) {
|
||||
this.settingsItems = settingsItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getRightBottomButtonTextId() {
|
||||
return state == State.EXPORT ? R.string.shared_string_export : R.string.shared_string_import;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRightBottomButtonClick() {
|
||||
super.onRightBottomButtonClick();
|
||||
if (state == State.EXPORT) {
|
||||
prepareFile();
|
||||
} else {
|
||||
importSettings();
|
||||
}
|
||||
}
|
||||
|
||||
private void importSettings() {
|
||||
List<SettingsHelper.SettingsItem> list = new ArrayList<>();
|
||||
list.add(profileSettingsItem);
|
||||
|
@ -303,56 +359,6 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDismissButtonTextId() {
|
||||
return R.string.shared_string_cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean useScrollableItemsContainer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
private List<SettingsHelper.SettingsItem> prepareSettingsItems() {
|
||||
List<SettingsHelper.SettingsItem> settingsItems = new ArrayList<>();
|
||||
settingsItems.add(new SettingsHelper.ProfileSettingsItem(app.getSettings(), profile));
|
||||
|
||||
if (includeAdditionalData) {
|
||||
settingsItems.addAll(prepareAdditionalSettingsItems());
|
||||
}
|
||||
return settingsItems;
|
||||
}
|
||||
|
||||
private List<SettingsHelper.SettingsItem> prepareAdditionalSettingsItems() {
|
||||
List<SettingsHelper.SettingsItem> settingsItems = new ArrayList<>();
|
||||
|
||||
List<QuickAction> quickActions = new ArrayList<>();
|
||||
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
|
||||
List<MapSourceWrapper> mapSourceWrappers = new ArrayList<>();
|
||||
for (Object object : dataToOperate) {
|
||||
if (object instanceof QuickAction) {
|
||||
quickActions.add((QuickAction) object);
|
||||
} else if (object instanceof PoiUIFilter) {
|
||||
poiUIFilters.add((PoiUIFilter) object);
|
||||
} else if (object instanceof MapSourceWrapper) {
|
||||
mapSourceWrappers.add((MapSourceWrapper) object);
|
||||
}
|
||||
}
|
||||
if (!quickActions.isEmpty()) {
|
||||
settingsItems.add(new SettingsHelper.QuickActionSettingsItem(app, quickActions));
|
||||
}
|
||||
if (!poiUIFilters.isEmpty()) {
|
||||
settingsItems.add(new SettingsHelper.PoiUiFilterSettingsItem(app, poiUIFilters));
|
||||
}
|
||||
if (!mapSourceWrappers.isEmpty()) {
|
||||
settingsItems.add(new SettingsHelper.MapSourcesSettingsItem(app.getSettings(), mapSourceWrappers));
|
||||
}
|
||||
return settingsItems;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void prepareFile() {
|
||||
if (app != null) {
|
||||
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
|
||||
|
@ -426,6 +432,10 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
}
|
||||
}
|
||||
|
||||
public void setSettingsItems(List<SettingsHelper.SettingsItem> settingsItems) {
|
||||
this.settingsItems = settingsItems;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
|
@ -434,11 +444,6 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
this.file = file;
|
||||
}
|
||||
|
||||
public enum State {
|
||||
EXPORT,
|
||||
IMPORT
|
||||
}
|
||||
|
||||
boolean isContainsInDataToOperate(AdditionalDataWrapper.Type type, Object object) {
|
||||
return dataToOperate.contains(object);
|
||||
|
||||
|
@ -450,6 +455,11 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
// return false;
|
||||
}
|
||||
|
||||
public enum State {
|
||||
EXPORT,
|
||||
IMPORT
|
||||
}
|
||||
|
||||
class ProfileAdditionalDataAdapter extends OsmandBaseExpandableListAdapter {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
@ -458,7 +468,6 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
|
||||
private int profileColor;
|
||||
|
||||
|
||||
ProfileAdditionalDataAdapter(OsmandApplication app, List<AdditionalDataWrapper> list, int profileColor) {
|
||||
this.app = app;
|
||||
this.list = list;
|
||||
|
@ -513,7 +522,6 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
group = inflater.inflate(R.layout.profile_data_list_item_group, parent, false);
|
||||
}
|
||||
|
||||
|
||||
boolean isLastGroup = groupPosition == getGroupCount() - 1;
|
||||
final AdditionalDataWrapper.Type type = list.get(groupPosition).getType();
|
||||
|
||||
|
@ -599,7 +607,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes != 0 ? iconRes : R.drawable.ic_person, profileColor));
|
||||
break;
|
||||
case MAP_SOURCES:
|
||||
title.setText(((MapSourceWrapper) currentItem).getName());
|
||||
title.setText(((TileSourceManager.TileSourceTemplate) currentItem).getName());
|
||||
icon.setVisibility(View.INVISIBLE);
|
||||
icon.setImageResource(R.drawable.ic_action_info_dark);
|
||||
break;
|
||||
|
@ -631,26 +639,4 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MapSourceWrapper {
|
||||
private String name;
|
||||
private String url;
|
||||
|
||||
MapSourceWrapper(String name, String url) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue