diff --git a/OsmAnd/res/layout/fragment_import.xml b/OsmAnd/res/layout/fragment_import.xml index 92926c3ec1..c04a748780 100644 --- a/OsmAnd/res/layout/fragment_import.xml +++ b/OsmAnd/res/layout/fragment_import.xml @@ -80,7 +80,7 @@ android:layout_height="match_parent" android:background="?attr/selectableItemBackground" android:ellipsize="end" - android:gravity="end|center_vertical" + android:gravity="start|center_vertical" android:maxLines="1" android:paddingLeft="@dimen/content_padding_small" android:paddingTop="@dimen/content_padding_half" @@ -110,6 +110,8 @@ android:layout_height="@dimen/toolbar_height_expanded" android:background="?attr/colorPrimary" osmand:collapsedTitleTextAppearance="@style/AppBarTitle" + osmand:expandedTitleMarginStart="16dp" + osmand:expandedTitleMarginBottom="12dp" osmand:expandedTitleGravity="start|bottom" osmand:expandedTitleTextAppearance="@style/AppBarTitle" tools:title="@string/shared_string_import" @@ -121,7 +123,8 @@ android:layout_height="@dimen/toolbar_height" android:minHeight="@dimen/toolbar_height" osmand:layout_collapseMode="pin" - osmand:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed"> + osmand:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed" + android:layout_marginLeft="0dp"> diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index fcd589b5d8..ad201fa4c5 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -319,7 +319,7 @@ 56dp 56dp - 112dp + 96dp 36dp 80dp diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index e3d5e671e2..3e4f18a166 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -8,6 +8,7 @@ import android.os.AsyncTask; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.AlertDialog; +import android.text.style.AlignmentSpan; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -113,6 +114,10 @@ public class SettingsHelper { void onSettingsExportFinished(@NonNull File file, boolean succeed); } + public interface CheckDuplicatesListener { + void onDuplicatesChecked(@NonNull List duplicates, List items); + } + public SettingsHelper(OsmandApplication app) { this.app = app; } @@ -2044,6 +2049,88 @@ public class SettingsHelper { } } + @SuppressLint("StaticFieldLeak") + public class CheckDuplicateTask extends AsyncTask> { + + private List items; + private List duplicates; + private CheckDuplicatesListener listener; + private long startTime; + + CheckDuplicateTask(@NonNull List items, CheckDuplicatesListener listener) { + this.items = items; + this.listener = listener; + } + + @Override + protected void onPreExecute() { + startTime = System.currentTimeMillis(); + super.onPreExecute(); + } + + @Override + protected List doInBackground(Void... voids) { + return getDuplicatesData(this.items); + } + + @Override + protected void onPostExecute(List objects) { + duplicates = objects; + long currentTime = System.currentTimeMillis(); + if (currentTime - startTime < 700) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + if (listener != null) { + listener.onDuplicatesChecked(objects, this.items); + } + super.onPostExecute(objects); + } + + private 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 checkDuplicates(@NonNull List items, CheckDuplicatesListener listener) { + new CheckDuplicateTask(items, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + public void importSettings(@NonNull File settingsFile, String latestChanges, int version, boolean askBeforeImport, @Nullable SettingsImportListener listener) { new ImportAsyncTask(settingsFile, latestChanges, version, askBeforeImport, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java index 300c2f1ca1..7f0971827a 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.settings; +import android.app.Activity; import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; @@ -22,7 +23,10 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.SettingsHelper.SettingsItem; import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BaseOsmAndFragment; +import net.osmand.plus.dashboard.DashboardOnMap; +import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.dialogs.SelectMapStyleBottomSheetDialogFragment; import net.osmand.plus.profiles.AdditionalDataWrapper; import net.osmand.plus.quickaction.QuickActionListFragment; @@ -131,43 +135,43 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { if (fm == null) { return; } - Fragment fragment; - String TAG; switch (type) { + case CUSTOM_ROUTING: case PROFILE: BaseSettingsFragment.showInstance( - getActivity(), + requireActivity(), BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS ); break; case QUICK_ACTIONS: fm.beginTransaction() .add(R.id.fragmentContainer, new QuickActionListFragment(), QuickActionListFragment.TAG) - .addToBackStack(QuickActionListFragment.TAG).commitAllowingStateLoss(); + .addToBackStack(QuickActionListFragment.TAG).commit(); break; case POI_TYPES: - QuickSearchDialogFragment quickSearchDialogFragment = new QuickSearchDialogFragment(); - quickSearchDialogFragment.show(fm, QuickSearchDialogFragment.TAG); + new QuickSearchDialogFragment().show(fm, QuickSearchDialogFragment.TAG); break; case MAP_SOURCES: - + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + ((MapActivity) activity).getDashboard() + .setDashboardVisibility( + true, + DashboardOnMap.DashboardType.CONFIGURE_MAP, + null + ); + } break; case CUSTOM_RENDER_STYLE: - - fragment = new SelectMapStyleBottomSheetDialogFragment(); - TAG = SelectMapStyleBottomSheetDialogFragment.TAG; + new SelectMapStyleBottomSheetDialogFragment().show(fm, SelectMapStyleBottomSheetDialogFragment.TAG); break; - case CUSTOM_ROUTING: - - return; case AVOID_ROADS: - fragment = new AvoidRoadsBottomSheetDialogFragment(); - TAG = AvoidRoadsBottomSheetDialogFragment.TAG; + new AvoidRoadsBottomSheetDialogFragment().show(fm, AvoidRoadsBottomSheetDialogFragment.TAG); break; default: return; } - dismissFragment(); +// dismissFragment(); app.getSettingsHelper().setImportedItems(null); } diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index a8b41b666c..f130798ead 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -54,12 +54,11 @@ public class ImportSettingsFragment extends BaseOsmAndFragment private ExportImportSettingsAdapter adapter; private ExpandableListView expandableList; private TextViewEx selectBtn; + private TextView description; private List settingsItems; private File file; private boolean allSelected; private boolean nightMode; - private Toolbar toolbar; - private TextView description; private String fileName; private LinearLayout buttonsContainer; private ProgressBar progressBar; @@ -93,7 +92,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { inflater = UiUtilities.getInflater(app, nightMode); View root = inflater.inflate(R.layout.fragment_import, container, false); - toolbar = root.findViewById(R.id.toolbar); + Toolbar toolbar = root.findViewById(R.id.toolbar); toolbarLayout = root.findViewById(R.id.toolbar_layout); setupToolbar(toolbar); TextViewEx continueBtn = root.findViewById(R.id.continue_button); @@ -101,7 +100,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment expandableList = root.findViewById(R.id.list); ViewCompat.setNestedScrollingEnabled(expandableList, true); View header = inflater.inflate(R.layout.list_item_description_header, null); - TextView description = header.findViewById(R.id.description); + description = header.findViewById(R.id.description); description.setText(R.string.select_data_to_import); expandableList.addHeaderView(header); continueBtn.setOnClickListener(this); @@ -154,38 +153,42 @@ public class ImportSettingsFragment extends BaseOsmAndFragment adapter.clearSettingsList(); final FragmentManager fm = getFragmentManager(); List settingsItems = getSettingsItemsFromData(adapter.getDataToOperate()); - List duplicateItems = getDuplicatesData(settingsItems); - if (duplicateItems.isEmpty()) { - toolbarLayout.setTitle(getString(R.string.shared_string_importing)); - description.setText(UiUtilities.createSpannableString( - String.format(getString(R.string.importing_from), file.getName()), - file.getName(), - new StyleSpan(Typeface.BOLD) - )); - app.getSettingsHelper().importSettings(file, settingsItems, "", 1, new SettingsHelper.SettingsImportListener() { - @Override - public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { - if (succeed) { - app.getRendererRegistry().updateExternalRenderers(); - AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() { - @Override - public void onRoutingFilesLoaded() { + app.getSettingsHelper().checkDuplicates(settingsItems, new SettingsHelper.CheckDuplicatesListener() { + @Override + public void onDuplicatesChecked(@NonNull List duplicates, List items) { + if (duplicates.isEmpty()) { + toolbarLayout.setTitle(getString(R.string.shared_string_importing)); + description.setText(UiUtilities.createSpannableString( + String.format(getString(R.string.importing_from), file.getName()), + file.getName(), + new StyleSpan(Typeface.BOLD) + )); + app.getSettingsHelper().importSettings(file, items, "", 1, new SettingsHelper.SettingsImportListener() { + @Override + public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { + if (succeed) { + app.getRendererRegistry().updateExternalRenderers(); + AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() { + @Override + public void onRoutingFilesLoaded() { + } + }); + if (fm != null) { + ImportCompleteFragment.showInstance(fm, items, file.getName()); + } + } else if (empty) { + app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error))); + dismissFragment(); } - }); - if (fm != null) { - ImportCompleteFragment.showInstance(fm, items, file.getName()); } - } else if (empty) { - app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error))); - dismissFragment(); + }); + } else { + if (fm != null) { + ImportDuplicatesFragment.showInstance(fm, duplicates, items, file); } } - }); - } else { - if (fm != null) { - ImportDuplicatesFragment.showInstance(fm, duplicateItems, settingsItems, file); } - } + }); } private void dismissFragment() {