From d9626e216b741a2f71c229f03c745f1aa542794b Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 28 Feb 2020 17:52:49 +0200 Subject: [PATCH] prepare importing finish --- OsmAnd/res/layout/fragment_import.xml | 13 ----- .../res/layout/fragment_import_duplicates.xml | 15 +----- .../src/net/osmand/plus/SettingsHelper.java | 5 ++ .../plus/settings/ImportCompleteFragment.java | 21 +++++---- .../settings/ImportDuplicatesFragment.java | 8 +++- .../plus/settings/ImportSettingsFragment.java | 47 ++++--------------- 6 files changed, 33 insertions(+), 76 deletions(-) diff --git a/OsmAnd/res/layout/fragment_import.xml b/OsmAnd/res/layout/fragment_import.xml index e3a8e18bfa..b8fba79615 100644 --- a/OsmAnd/res/layout/fragment_import.xml +++ b/OsmAnd/res/layout/fragment_import.xml @@ -128,17 +128,6 @@ - - - - - - diff --git a/OsmAnd/res/layout/fragment_import_duplicates.xml b/OsmAnd/res/layout/fragment_import_duplicates.xml index 62e4d7d235..e60370892f 100644 --- a/OsmAnd/res/layout/fragment_import_duplicates.xml +++ b/OsmAnd/res/layout/fragment_import_duplicates.xml @@ -135,18 +135,7 @@ - - - - - - - diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index 3e4f18a166..606705d212 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -269,6 +269,11 @@ public class SettingsHelper { return items; } + @NonNull + public List getDuplicateItems() { + return duplicateItems; + } + @NonNull public List excludeDuplicateItems() { if (!items.isEmpty()) { diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java index 7f0971827a..db1b91c737 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java @@ -41,11 +41,11 @@ import static net.osmand.plus.settings.ImportSettingsFragment.getSettingsToOpera public class ImportCompleteFragment extends BaseOsmAndFragment { public static final String TAG = ImportCompleteFragment.class.getSimpleName(); private static final String FILE_NAME_KEY = "FILE_NAME_KEY"; + private OsmandApplication app; + private RecyclerView recyclerView; private List settingsItems; private String fileName; - private OsmandApplication app; private boolean nightMode; - private RecyclerView recyclerView; public static void showInstance(FragmentManager fm, @NonNull List settingsItems, @NonNull String fileName) { @@ -68,6 +68,9 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { nightMode = !app.getSettings().isLightContent(); if (settingsItems == null) { settingsItems = app.getSettingsHelper().getImportedItems(); + if (settingsItems == null) { + dismissFragment(); + } } } @@ -78,20 +81,19 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { inflater = UiUtilities.getInflater(app, nightMode); View root = inflater.inflate(R.layout.fragment_import_complete, container, false); TextView description = root.findViewById(R.id.description); + TextView btnClose = root.findViewById(R.id.button_close); + recyclerView = root.findViewById(R.id.list); description.setText(UiUtilities.createSpannableString( String.format(getString(R.string.import_complete_description), fileName), fileName, new StyleSpan(Typeface.BOLD) )); - - TextView btnClose = root.findViewById(R.id.button_close); btnClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dismissFragment(); } }); - recyclerView = root.findViewById(R.id.list); if (Build.VERSION.SDK_INT >= 21) { AndroidUtils.addStatusBarPadding21v(app, root); } @@ -128,6 +130,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { if (fm != null) { getFragmentManager().popBackStack(IMPORT_SETTINGS_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); } + app.getSettingsHelper().setImportedItems(null); } private void navigateTo(AdditionalDataWrapper.Type type) { @@ -135,6 +138,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { if (fm == null) { return; } + dismissFragment(); switch (type) { case CUSTOM_ROUTING: case PROFILE: @@ -152,7 +156,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { new QuickSearchDialogFragment().show(fm, QuickSearchDialogFragment.TAG); break; case MAP_SOURCES: - Activity activity = getActivity(); + Activity activity = requireActivity(); if (activity instanceof MapActivity) { ((MapActivity) activity).getDashboard() .setDashboardVisibility( @@ -169,10 +173,8 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { new AvoidRoadsBottomSheetDialogFragment().show(fm, AvoidRoadsBottomSheetDialogFragment.TAG); break; default: - return; + break; } -// dismissFragment(); - app.getSettingsHelper().setImportedItems(null); } @Override @@ -180,7 +182,6 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light; } - public void setSettingsItems(List settingsItems) { this.settingsItems = settingsItems; } diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java index 10e186096c..a1a56838ff 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java @@ -44,7 +44,6 @@ import java.util.ArrayList; import java.util.List; import static net.osmand.plus.settings.ImportSettingsFragment.IMPORT_SETTINGS_TAG; -import static net.osmand.plus.settings.ImportSettingsFragment.getDuplicatesData; public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View.OnClickListener { @@ -83,11 +82,16 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View if (settingsItems == null) { settingsItems = app.getSettingsHelper().getSettingsItems(); if (settingsItems != null) { - duplicatesList = getDuplicatesData(settingsItems); +// duplicatesList = getDuplicatesData(settingsItems); + } else { + dismissFragment(); } } if (file == null) { file = app.getSettingsHelper().getSettingsFile(); + if (file == null) { + dismissFragment(); + } } } diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index f130798ead..68e7404036 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -59,7 +59,6 @@ public class ImportSettingsFragment extends BaseOsmAndFragment private File file; private boolean allSelected; private boolean nightMode; - private String fileName; private LinearLayout buttonsContainer; private ProgressBar progressBar; private CollapsingToolbarLayout toolbarLayout; @@ -81,9 +80,15 @@ public class ImportSettingsFragment extends BaseOsmAndFragment nightMode = !app.getSettings().isLightContent(); if (settingsItems == null) { settingsItems = app.getSettingsHelper().getSettingsItems(); + if (settingsItems == null) { + dismissFragment(); + } } if (file == null) { file = app.getSettingsHelper().getSettingsFile(); + if (file == null) { + dismissFragment(); + } } } @@ -198,42 +203,6 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } } - public static List getDuplicatesData(List items) { - List duplicateItems = new ArrayList<>(); - for (SettingsItem item : items) { - if (item instanceof SettingsHelper.ProfileSettingsItem) { - if (item.exists()) { - duplicateItems.add(((SettingsHelper.ProfileSettingsItem) item).getModeBean()); - } - } else if (item instanceof SettingsHelper.QuickActionSettingsItem) { - List duplicates = ((SettingsHelper.QuickActionSettingsItem) item).excludeDuplicateItems(); - if (!duplicates.isEmpty()) { - duplicateItems.addAll(duplicates); - } - } else if (item instanceof SettingsHelper.PoiUiFilterSettingsItem) { - List duplicates = ((SettingsHelper.PoiUiFilterSettingsItem) item).excludeDuplicateItems(); - if (!duplicates.isEmpty()) { - duplicateItems.addAll(duplicates); - } - } else if (item instanceof SettingsHelper.MapSourcesSettingsItem) { - List duplicates = ((SettingsHelper.MapSourcesSettingsItem) item).excludeDuplicateItems(); - if (!duplicates.isEmpty()) { - duplicateItems.addAll(duplicates); - } - } else if (item instanceof SettingsHelper.FileSettingsItem) { - if (item.exists()) { - duplicateItems.add(((SettingsHelper.FileSettingsItem) item).getFile()); - } - } else if (item instanceof SettingsHelper.AvoidRoadsSettingsItem) { - List avoidRoads = ((SettingsHelper.AvoidRoadsSettingsItem) item).excludeDuplicateItems(); - if (!avoidRoads.isEmpty()) { - duplicateItems.addAll(avoidRoads); - } - } - } - return duplicateItems; - } - public void setSettingsItems(List settingsItems) { this.settingsItems = settingsItems; } @@ -291,10 +260,13 @@ public class ImportSettingsFragment extends BaseOsmAndFragment profiles.add(((SettingsHelper.ProfileSettingsItem) item).getModeBean()); } else if (item.getType().equals(SettingsHelper.SettingsItemType.QUICK_ACTION)) { quickActions.addAll(((SettingsHelper.QuickActionSettingsItem) item).getItems()); + quickActions.addAll(((SettingsHelper.QuickActionSettingsItem) item).getDuplicateItems()); } else if (item.getType().equals(SettingsHelper.SettingsItemType.POI_UI_FILTERS)) { poiUIFilters.addAll(((SettingsHelper.PoiUiFilterSettingsItem) item).getItems()); + poiUIFilters.addAll(((SettingsHelper.PoiUiFilterSettingsItem) item).getDuplicateItems()); } else if (item.getType().equals(SettingsHelper.SettingsItemType.MAP_SOURCES)) { tileSourceTemplates.addAll(((SettingsHelper.MapSourcesSettingsItem) item).getItems()); + tileSourceTemplates.addAll(((SettingsHelper.MapSourcesSettingsItem) item).getDuplicateItems()); } else if (item.getType().equals(SettingsHelper.SettingsItemType.FILE)) { if (item.getName().startsWith("/rendering/")) { renderFilesList.add(((SettingsHelper.FileSettingsItem) item).getFile()); @@ -303,6 +275,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } } else if (item.getType().equals(SettingsHelper.SettingsItemType.AVOID_ROADS)) { avoidRoads.addAll(((SettingsHelper.AvoidRoadsSettingsItem) item).getItems()); + avoidRoads.addAll(((SettingsHelper.AvoidRoadsSettingsItem) item).getDuplicateItems()); } }