remove AdditionalDataWrapper

This commit is contained in:
veliymolfar 2020-03-11 16:08:57 +02:00
parent adb9464de5
commit c89450c694
6 changed files with 73 additions and 130 deletions

View file

@ -1,37 +0,0 @@
package net.osmand.plus.profiles;
import java.util.List;
public class AdditionalDataWrapper {
private Type type;
private List<?> items;
public AdditionalDataWrapper(Type type, List<?> items) {
this.type = type;
this.items = items;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public List<?> getItems() {
return items;
}
public enum Type {
PROFILE,
QUICK_ACTIONS,
POI_TYPES,
MAP_SOURCES,
CUSTOM_RENDER_STYLE,
CUSTOM_ROUTING,
AVOID_ROADS
}
}

View file

@ -22,7 +22,6 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.AdditionalDataWrapper;
import net.osmand.plus.profiles.ProfileIconColors;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.render.RenderingIcons;
@ -31,7 +30,9 @@ import net.osmand.view.ThreeStateCheckbox;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static net.osmand.view.ThreeStateCheckbox.State.CHECKED;
import static net.osmand.view.ThreeStateCheckbox.State.MISC;
@ -41,7 +42,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
private OsmandApplication app;
private List<? super Object> dataToOperate;
private List<AdditionalDataWrapper> dataList;
private Map<Type, List<?>> itemsMap;
private List<Type> itemsTypes;
private boolean nightMode;
private boolean importState;
private int profileColor;
@ -50,7 +52,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
this.app = app;
this.nightMode = nightMode;
this.importState = importState;
this.dataList = new ArrayList<>();
this.itemsMap = new HashMap<>();
this.itemsTypes = new ArrayList<>();
this.dataToOperate = new ArrayList<>();
this.profileColor = app.getSettings().getApplicationMode().getIconColorInfo().getColor(nightMode);
}
@ -64,7 +67,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
}
boolean isLastGroup = groupPosition == getGroupCount() - 1;
final AdditionalDataWrapper.Type type = dataList.get(groupPosition).getType();
final Type type = itemsTypes.get(groupPosition);
TextView titleTv = group.findViewById(R.id.title_tv);
TextView subTextTv = group.findViewById(R.id.sub_text_tv);
@ -81,7 +84,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
cardBottomDivider.setVisibility(importState && !isExpanded ? View.VISIBLE : View.GONE);
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, profileColor)));
final List<?> listItems = dataList.get(groupPosition).getItems();
final List<?> listItems = itemsMap.get(type);
subTextTv.setText(String.valueOf(listItems.size()));
if (dataToOperate.containsAll(listItems)) {
@ -123,10 +126,10 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
child = inflater.inflate(R.layout.profile_data_list_item_child, parent, false);
}
final Object currentItem = dataList.get(groupPosition).getItems().get(childPosition);
final Object currentItem = itemsMap.get(itemsTypes.get(groupPosition)).get(childPosition);
boolean isLastGroup = groupPosition == getGroupCount() - 1;
final AdditionalDataWrapper.Type type = dataList.get(groupPosition).getType();
final Type type = itemsTypes.get(groupPosition);
TextView title = child.findViewById(R.id.title_tv);
TextView subText = child.findViewById(R.id.sub_title_tv);
@ -226,22 +229,22 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
@Override
public int getGroupCount() {
return dataList.size();
return itemsMap.keySet().size();
}
@Override
public int getChildrenCount(int i) {
return dataList.get(i).getItems().size();
return itemsMap.get(itemsTypes.get(i)).size();
}
@Override
public Object getGroup(int i) {
return dataList.get(i);
return itemsMap.get(itemsTypes.get(i));
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return dataList.get(groupPosition).getItems().get(childPosition);
return itemsMap.get(itemsTypes.get(groupPosition)).get(childPosition);
}
@Override
@ -264,7 +267,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
return true;
}
private int getGroupTitle(AdditionalDataWrapper.Type type) {
private int getGroupTitle(Type type) {
switch (type) {
case PROFILE:
return R.string.shared_string_profiles;
@ -285,21 +288,23 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
}
}
public void updateSettingsList(List<AdditionalDataWrapper> settingsList) {
this.dataList = settingsList;
public void updateSettingsList(Map<Type, List<?>> itemsMap) {
this.itemsMap = itemsMap;
this.itemsTypes = new ArrayList<>(itemsMap.keySet());
notifyDataSetChanged();
}
public void clearSettingsList() {
this.dataList.clear();
this.itemsMap.clear();
this.itemsTypes.clear();
notifyDataSetChanged();
}
public void selectAll(boolean selectAll) {
dataToOperate.clear();
if (selectAll) {
for (AdditionalDataWrapper item : dataList) {
dataToOperate.addAll(item.getItems());
for (Map.Entry<Type, List<?>> map : itemsMap.entrySet()) {
dataToOperate.addAll(map.getValue());
}
}
notifyDataSetChanged();
@ -308,4 +313,14 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
List<? super Object> getDataToOperate() {
return this.dataToOperate;
}
public enum Type {
PROFILE,
QUICK_ACTIONS,
POI_TYPES,
MAP_SOURCES,
CUSTOM_RENDER_STYLE,
CUSTOM_ROUTING,
AVOID_ROADS
}
}

View file

@ -38,16 +38,17 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.AdditionalDataWrapper;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionFactory;
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
import net.osmand.plus.settings.ExportImportSettingsAdapter.Type;
import org.apache.commons.logging.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -63,7 +64,7 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
private OsmandApplication app;
private ApplicationMode profile;
private List<AdditionalDataWrapper> dataList = new ArrayList<>();
private Map<Type, List<?>> dataList = new HashMap<>();
private ExportImportSettingsAdapter adapter;
private SettingsHelper.SettingsExportListener exportListener;
@ -214,22 +215,18 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
}
}
private List<AdditionalDataWrapper> getAdditionalData() {
List<AdditionalDataWrapper> dataList = new ArrayList<>();
private Map<Type, List<?>> getAdditionalData() {
Map<Type, List<?>> dataList = new HashMap<>();
QuickActionFactory factory = new QuickActionFactory();
List<QuickAction> actionsList = factory.parseActiveActionsList(app.getSettings().QUICK_ACTION_LIST.get());
if (!actionsList.isEmpty()) {
dataList.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.QUICK_ACTIONS, actionsList));
dataList.put(Type.QUICK_ACTIONS, actionsList);
}
List<PoiUIFilter> poiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
if (!poiList.isEmpty()) {
dataList.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.POI_TYPES,
poiList
));
dataList.put(Type.POI_TYPES, poiList);
}
List<ITileSource> iTileSources = new ArrayList<>();
@ -249,37 +246,25 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
}
}
if (!iTileSources.isEmpty()) {
dataList.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.MAP_SOURCES,
iTileSources
));
dataList.put(Type.MAP_SOURCES, iTileSources);
}
Map<String, File> externalRenderers = app.getRendererRegistry().getExternalRenderers();
if (!externalRenderers.isEmpty()) {
dataList.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.CUSTOM_RENDER_STYLE,
new ArrayList<>(externalRenderers.values())
));
dataList.put(Type.CUSTOM_RENDER_STYLE, new ArrayList<>(externalRenderers.values()));
}
File routingProfilesFolder = app.getAppPath(IndexConstants.ROUTING_PROFILES_DIR);
if (routingProfilesFolder.exists() && routingProfilesFolder.isDirectory()) {
File[] fl = routingProfilesFolder.listFiles();
if (fl != null && fl.length > 0) {
dataList.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.CUSTOM_ROUTING,
Arrays.asList(fl)
));
dataList.put(Type.CUSTOM_ROUTING, Arrays.asList(fl));
}
}
Map<LatLon, AvoidRoadInfo> impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads();
if (!impassableRoads.isEmpty()) {
dataList.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.AVOID_ROADS,
new ArrayList<>(impassableRoads.values())
));
dataList.put(Type.AVOID_ROADS, new ArrayList<>(impassableRoads.values()));
}
return dataList;
}

View file

@ -25,10 +25,10 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dialogs.SelectMapStyleBottomSheetDialogFragment;
import net.osmand.plus.profiles.AdditionalDataWrapper;
import net.osmand.plus.quickaction.QuickActionListFragment;
import net.osmand.plus.routepreparationmenu.AvoidRoadsBottomSheetDialogFragment;
import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.settings.ExportImportSettingsAdapter.Type;
import java.util.List;
@ -99,7 +99,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment {
nightMode,
new ImportedSettingsItemsAdapter.OnItemClickListener() {
@Override
public void onItemClick(AdditionalDataWrapper.Type type) {
public void onItemClick(Type type) {
navigateTo(type);
}
});
@ -115,7 +115,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment {
}
}
private void navigateTo(AdditionalDataWrapper.Type type) {
private void navigateTo(Type type) {
FragmentManager fm = getFragmentManager();
Activity activity = requireActivity();
if (fm == null) {

View file

@ -1,9 +1,7 @@
package net.osmand.plus.settings;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
@ -42,16 +40,18 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.AdditionalDataWrapper;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.widgets.TextViewEx;
import net.osmand.plus.settings.ExportImportSettingsAdapter.Type;
import org.apache.commons.logging.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ImportSettingsFragment extends BaseOsmAndFragment
implements View.OnClickListener {
@ -137,12 +137,6 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
settingsHelper.importSettings(file, selectedItems, "", 1, getImportListener());
}
}
// else if (!fromPopBackStack) {
// FragmentManager fm = getFragmentManager();
// if (fm != null && file != null && selectedItems != null) {
// ImportDuplicatesFragment.showInstance(fm, duplicates, selectedItems, file);
// }
// }
}
adapter = new ExportImportSettingsAdapter(app, nightMode, true);
@ -300,8 +294,8 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
return settingsItems;
}
public static List<AdditionalDataWrapper> getSettingsToOperate(List<SettingsItem> settingsItems) {
List<AdditionalDataWrapper> settingsToOperate = new ArrayList<>();
public static Map<Type, List<?>> getSettingsToOperate(List<SettingsItem> settingsItems) {
Map<Type, List<?>> settingsToOperate = new HashMap<>();
List<ApplicationMode.ApplicationModeBean> profiles = new ArrayList<>();
List<QuickAction> quickActions = new ArrayList<>();
List<PoiUIFilter> poiUIFilters = new ArrayList<>();
@ -335,43 +329,25 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
}
if (!profiles.isEmpty()) {
settingsToOperate.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.PROFILE,
profiles));
settingsToOperate.put(Type.PROFILE, profiles);
}
if (!quickActions.isEmpty()) {
settingsToOperate.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.QUICK_ACTIONS,
quickActions));
settingsToOperate.put(Type.QUICK_ACTIONS, quickActions);
}
if (!poiUIFilters.isEmpty()) {
settingsToOperate.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.POI_TYPES,
poiUIFilters));
settingsToOperate.put(Type.POI_TYPES, poiUIFilters);
}
if (!tileSourceTemplates.isEmpty()) {
settingsToOperate.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.MAP_SOURCES,
tileSourceTemplates
));
settingsToOperate.put(Type.MAP_SOURCES, tileSourceTemplates);
}
if (!renderFilesList.isEmpty()) {
settingsToOperate.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.CUSTOM_RENDER_STYLE,
renderFilesList
));
settingsToOperate.put(Type.CUSTOM_RENDER_STYLE, renderFilesList);
}
if (!routingFilesList.isEmpty()) {
settingsToOperate.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.CUSTOM_ROUTING,
routingFilesList
));
settingsToOperate.put(Type.CUSTOM_ROUTING, routingFilesList);
}
if (!avoidRoads.isEmpty()) {
settingsToOperate.add(new AdditionalDataWrapper(
AdditionalDataWrapper.Type.AVOID_ROADS,
avoidRoads
));
settingsToOperate.put(Type.AVOID_ROADS, avoidRoads);
}
return settingsToOperate;
}

View file

@ -13,27 +13,31 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.profiles.AdditionalDataWrapper;
import net.osmand.plus.settings.ExportImportSettingsAdapter.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ImportedSettingsItemsAdapter extends
RecyclerView.Adapter<ImportedSettingsItemsAdapter.ItemViewHolder> {
private List<AdditionalDataWrapper> items;
private Map<Type, List<?>> itemsMap;
private List<Type> itemsTypes;
private UiUtilities uiUtils;
private OsmandApplication app;
private boolean nightMode;
private OnItemClickListener listener;
ImportedSettingsItemsAdapter(@NonNull OsmandApplication app, @NonNull List<AdditionalDataWrapper> items,
ImportedSettingsItemsAdapter(@NonNull OsmandApplication app, Map<Type, List<?>> itemsMap,
boolean nightMode, OnItemClickListener listener) {
this.app = app;
this.items = items;
this.itemsMap = itemsMap;
this.nightMode = nightMode;
this.listener = listener;
uiUtils = app.getUIUtilities();
itemsTypes = new ArrayList<>(itemsMap.keySet());
}
@NonNull
@ -46,8 +50,8 @@ public class ImportedSettingsItemsAdapter extends
@Override
public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
final AdditionalDataWrapper currentItem = items.get(position);
boolean isLastItem = items.size() - 1 == position;
final Type currentItemType = itemsTypes.get(position);
boolean isLastItem = itemsTypes.size() - 1 == position;
int activeColorRes = nightMode
? R.color.active_color_primary_dark
: R.color.active_color_primary_light;
@ -58,16 +62,16 @@ public class ImportedSettingsItemsAdapter extends
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listener.onItemClick(currentItem.getType());
listener.onItemClick(currentItemType);
}
});
holder.subTitle.setText(String.format(
app.getString(R.string.ltr_or_rtl_combine_via_colon),
app.getString(R.string.items_added),
String.valueOf(currentItem.getItems().size()))
String.valueOf(itemsMap.get(currentItemType).size()))
);
switch (currentItem.getType()) {
switch (currentItemType) {
case PROFILE:
holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.map_action_settings, activeColorRes));
holder.title.setText(R.string.shared_string_settings);
@ -101,7 +105,7 @@ public class ImportedSettingsItemsAdapter extends
@Override
public int getItemCount() {
return items.size();
return itemsMap.keySet().size();
}
public static class ItemViewHolder extends RecyclerView.ViewHolder {
@ -120,6 +124,6 @@ public class ImportedSettingsItemsAdapter extends
}
interface OnItemClickListener {
void onItemClick(AdditionalDataWrapper.Type type);
void onItemClick(Type type);
}
}