Fix ImportCompleteFragment and remove duplicated code

This commit is contained in:
Vitaliy 2021-01-08 00:34:09 +02:00
parent fa4aa8fde5
commit d0d95e92cc
13 changed files with 38 additions and 70 deletions

View file

@ -92,11 +92,6 @@ public class AvoidRoadsSettingsItem extends CollectionSettingsItem<AvoidRoadInfo
return false;
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
@Override
public boolean shouldShowDuplicates() {
return false;

View file

@ -72,6 +72,11 @@ public abstract class CollectionSettingsItem<T> extends SettingsItem {
return true;
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
public abstract boolean isDuplicate(@NonNull T item);
@NonNull

View file

@ -109,11 +109,6 @@ public class FavoritesSettingsItem extends CollectionSettingsItem<FavoriteGroup>
return false;
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
@NonNull
@Override
public FavoriteGroup renameItem(@NonNull FavoriteGroup item) {

View file

@ -103,11 +103,6 @@ public class HistoryMarkersSettingsItem extends CollectionSettingsItem<MapMarker
return false;
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
@NonNull
@Override
public MapMarker renameItem(@NonNull MapMarker item) {

View file

@ -130,11 +130,6 @@ public class MapSourcesSettingsItem extends CollectionSettingsItem<ITileSource>
return "map_sources";
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
@Override
void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException {
try {

View file

@ -103,11 +103,6 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarker> {
return false;
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
@NonNull
@Override
public MapMarker renameItem(@NonNull MapMarker item) {

View file

@ -87,11 +87,6 @@ public class OnlineRoutingSettingsItem extends CollectionSettingsItem<OnlineRout
return false;
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
@NonNull
@Override
public OnlineRoutingEngine renameItem(@NonNull OnlineRoutingEngine item) {

View file

@ -113,11 +113,6 @@ public class OsmEditsSettingsItem extends CollectionSettingsItem<OpenstreetmapPo
return ctx.getString(R.string.osm_edits);
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
@Override
public boolean shouldShowDuplicates() {
return false;

View file

@ -106,11 +106,6 @@ public class OsmNotesSettingsItem extends CollectionSettingsItem<OsmNotesPoint>
return ctx.getString(R.string.osm_notes);
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
@Override
public boolean shouldShowDuplicates() {
return false;

View file

@ -105,11 +105,6 @@ public class PoiUiFiltersSettingsItem extends CollectionSettingsItem<PoiUIFilter
return "poi_ui_filters";
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
@Override
void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException {
try {

View file

@ -89,11 +89,6 @@ public class QuickActionsSettingsItem extends CollectionSettingsItem<QuickAction
}
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
@NonNull
@Override
public String getName() {

View file

@ -148,11 +148,6 @@ public class SearchHistorySettingsItem extends CollectionSettingsItem<HistoryEnt
return false;
}
@Override
public boolean shouldReadOnCollecting() {
return true;
}
@NonNull
@Override
public HistoryEntry renameItem(@NonNull HistoryEntry item) {

View file

@ -24,6 +24,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dialogs.SelectMapStyleBottomSheetDialogFragment;
@ -36,6 +37,7 @@ import net.osmand.plus.settings.backend.ExportSettingsType;
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
import net.osmand.plus.settings.backend.backup.SettingsHelper;
import net.osmand.plus.settings.backend.backup.SettingsItem;
import net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType;
import java.util.List;
@ -150,12 +152,11 @@ public class ImportCompleteFragment extends BaseOsmAndFragment {
dismissFragment();
fm.popBackStack(DRAWER_SETTINGS_ID + ".new", FragmentManager.POP_BACK_STACK_INCLUSIVE);
switch (type) {
case CUSTOM_ROUTING:
case GLOBAL:
case PROFILE:
BaseSettingsFragment.showInstance(
requireActivity(),
BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS
);
case CUSTOM_ROUTING:
case ONLINE_ROUTING_ENGINES:
BaseSettingsFragment.showInstance(requireActivity(), SettingsScreenType.MAIN_SETTINGS);
break;
case QUICK_ACTIONS:
fm.beginTransaction()
@ -190,19 +191,13 @@ public class ImportCompleteFragment extends BaseOsmAndFragment {
case AVOID_ROADS:
new AvoidRoadsBottomSheetDialogFragment().show(fm, AvoidRoadsBottomSheetDialogFragment.TAG);
break;
case TRACKS:
case OSM_NOTES:
case OSM_EDITS:
OsmAndAppCustomization appCustomization = app.getAppCustomization();
final Intent favorites = new Intent(activity, appCustomization.getFavoritesActivity());
favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
app.getSettings().FAVORITES_TAB.set(OsmEditingPlugin.OSM_EDIT_TAB);
startActivity(favorites);
break;
case FAVORITES:
Intent favoritesActivity = new Intent(activity, app.getAppCustomization().getFavoritesActivity());
favoritesActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
app.getSettings().FAVORITES_TAB.set(FavoritesActivity.FAV_TAB);
startActivity(favoritesActivity);
case MULTIMEDIA_NOTES:
int tabId = getFavoritesTabId(type);
openFavouritesActivity(activity, tabId);
break;
case SEARCH_HISTORY:
if (activity instanceof MapActivity) {
@ -221,6 +216,29 @@ public class ImportCompleteFragment extends BaseOsmAndFragment {
}
}
private void openFavouritesActivity(Activity activity, int tabType) {
OsmAndAppCustomization appCustomization = app.getAppCustomization();
Intent favoritesActivity = new Intent(activity, appCustomization.getFavoritesActivity());
favoritesActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
app.getSettings().FAVORITES_TAB.set(tabType);
startActivity(favoritesActivity);
}
private int getFavoritesTabId(ExportSettingsType type) {
switch (type) {
case OSM_NOTES:
case OSM_EDITS:
return OsmEditingPlugin.OSM_EDIT_TAB;
case MULTIMEDIA_NOTES:
return AudioVideoNotesPlugin.NOTES_TAB;
case TRACKS:
return FavoritesActivity.GPX_TAB;
case FAVORITES:
default:
return FavoritesActivity.FAV_TAB;
}
}
@Override
public int getStatusBarColorId() {
return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light;