From 5b9c9245fd61969646d9a3f3c00427aa8fc7b00d Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 26 Feb 2020 18:31:06 +0200 Subject: [PATCH 01/30] initial commit --- .../res/layout/fragment_import_complete.xml | 130 ++++++++++++ OsmAnd/res/layout/list_item_import.xml | 72 ++++--- OsmAnd/res/values/strings.xml | 6 + .../src/net/osmand/plus/SettingsHelper.java | 11 + .../settings/DuplicatesSettingsAdapter.java | 4 +- .../settings/ExportImportSettingsAdapter.java | 6 +- .../plus/settings/ImportCompleteFragment.java | 188 ++++++++++++++++++ .../settings/ImportDuplicatesFragment.java | 14 +- .../plus/settings/ImportSettingsFragment.java | 12 +- .../ImportedSettingsItemsAdapter.java | 143 +++++++++++++ 10 files changed, 534 insertions(+), 52 deletions(-) create mode 100644 OsmAnd/res/layout/fragment_import_complete.xml create mode 100644 OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java create mode 100644 OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java diff --git a/OsmAnd/res/layout/fragment_import_complete.xml b/OsmAnd/res/layout/fragment_import_complete.xml new file mode 100644 index 0000000000..25069b6a0f --- /dev/null +++ b/OsmAnd/res/layout/fragment_import_complete.xml @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/list_item_import.xml b/OsmAnd/res/layout/list_item_import.xml index 25042fd505..9f489889b7 100644 --- a/OsmAnd/res/layout/list_item_import.xml +++ b/OsmAnd/res/layout/list_item_import.xml @@ -7,49 +7,57 @@ android:minHeight="@dimen/setting_list_item_small_height" android:orientation="vertical"> - - - + android:layout_width="match_parent" + android:layout_height="wrap_content"> + android:layout_height="match_parent" + android:background="?attr/selectableItemBackground" + android:gravity="center_vertical" + android:orientation="horizontal"> - + + + android:orientation="vertical" + android:paddingTop="@dimen/content_padding_small" + android:paddingBottom="@dimen/content_padding_small"> - + + + + + - + + Added: %1$s item + Added: %1$s items + Added: %1$s items + Quick action + Import complete + All data from the %1$s is imported, you can use buttons below to open needed part of the application to manage it. Custom profile Angle: %s° Angle diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index de63be3c15..e3d5e671e2 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -103,6 +103,7 @@ public class SettingsHelper { private boolean importSuspended; private boolean collectOnly; private ImportAsyncTask importTask; + private List importedItems; public interface SettingsImportListener { void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items); @@ -1937,6 +1938,15 @@ public class SettingsHelper { return this.importTask.getFile(); } + @Nullable + public List getImportedItems() { + return importedItems; + } + + public void setImportedItems(List importedItems) { + this.importedItems = importedItems; + } + @SuppressLint("StaticFieldLeak") private class ImportItemsAsyncTask extends AsyncTask { @@ -1980,6 +1990,7 @@ public class SettingsHelper { if (listener != null) { listener.onSettingsImportFinished(success, empty, items); } + importedItems = items; } @SuppressLint("StaticFieldLeak") diff --git a/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java index ff49348940..c952fb03a3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java @@ -115,8 +115,8 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter 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) { + ImportCompleteFragment fragment = new ImportCompleteFragment(); + fragment.setSettingsItems(settingsItems); + fragment.setFileName(fileName); + fm.beginTransaction().replace(R.id.fragmentContainer, fragment).addToBackStack(null).commit(); + } + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (savedInstanceState != null) { + fileName = savedInstanceState.getString(FILE_NAME_KEY); + } + app = requireMyApplication(); + nightMode = !app.getSettings().isLightContent(); + if (settingsItems == null) { + settingsItems = app.getSettingsHelper().getImportedItems(); + } + } + + @Nullable + @Override + 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_complete, container, false); + TextView description = root.findViewById(R.id.description); + setupDescription(description); + TextView btnClose = root.findViewById(R.id.button_close); + btnClose.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + FragmentManager fm = getFragmentManager(); + if (fm != null) { + fm.popBackStackImmediate(); + } + } + }); + recyclerView = root.findViewById(R.id.list); + if (Build.VERSION.SDK_INT >= 21) { + AndroidUtils.addStatusBarPadding21v(app, root); + } + return root; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + ImportedSettingsItemsAdapter adapter = new ImportedSettingsItemsAdapter( + app, + getSettingsToOperate(settingsItems), + nightMode, + new ImportedSettingsItemsAdapter.OnItemClickListener() { + @Override + public void onItemClick(AdditionalDataWrapper.Type type) { + navigateTo(type); + } + }); + recyclerView.setLayoutManager(new LinearLayoutManager(getMyApplication())); + recyclerView.setAdapter(adapter); + } + + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + outState.putString(FILE_NAME_KEY, fileName); + } + + private void navigateTo(AdditionalDataWrapper.Type type) { + FragmentManager fm = getFragmentManager(); + if (fm == null) { + return; + } + Fragment fragment; + String TAG; + switch (type) { + case PROFILE: + fragment = new GeneralProfileSettingsFragment(); + TAG = GeneralProfileSettingsFragment.TAG; + break; + case QUICK_ACTIONS: + fragment = new QuickActionListFragment(); + TAG = QuickActionListFragment.TAG; + break; + case POI_TYPES: + fragment = new QuickSearchDialogFragment(); + TAG = QuickSearchDialogFragment.TAG; + break; + case MAP_SOURCES: + fragment = new GeneralProfileSettingsFragment(); + TAG = QuickActionListFragment.TAG; + break; + case CUSTOM_RENDER_STYLE: + fragment = new SelectMapStyleBottomSheetDialogFragment(); + TAG = SelectMapStyleBottomSheetDialogFragment.TAG; + break; + case CUSTOM_ROUTING: + return; + case AVOID_ROADS: + fragment = new AvoidRoadsBottomSheetDialogFragment(); + TAG = AvoidRoadsBottomSheetDialogFragment.TAG; + break; + default: + return; + } + for (Fragment f : fm.getFragments()) { + if (f instanceof NavigationFragment) { + continue; + } else if (f != null) { + fm.beginTransaction().remove(fragment).commit(); + } + } + fm.beginTransaction() + .add(R.id.fragmentContainer, fragment, TAG) + .commitAllowingStateLoss(); + } + + @Override + public int getStatusBarColorId() { + return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light; + } + + private void setupDescription(TextView description) { + String descriptionText = String.format(getString( + R.string.import_complete_description), fileName); + int startIndex = descriptionText.indexOf(fileName); + SpannableString spannableDescription = new SpannableString(descriptionText); + spannableDescription.setSpan( + new StyleSpan(Typeface.BOLD), + startIndex, + startIndex + fileName.length(), + Spanned.SPAN_INCLUSIVE_INCLUSIVE); + description.setText(spannableDescription); + } + + public void setSettingsItems(List settingsItems) { + this.settingsItems = settingsItems; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } +} diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java index 2b4fe6990d..f9fe7769de 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java @@ -7,6 +7,7 @@ import android.support.annotation.Nullable; import android.support.design.widget.AppBarLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewCompat; import android.support.v4.widget.NestedScrollView; import android.support.v7.widget.LinearLayoutManager; @@ -225,20 +226,15 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View public void onRoutingFilesLoaded() { } }); + FragmentManager fm = getFragmentManager(); + 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))); } } }); - FragmentManager fm = getFragmentManager(); - if (fm != null) { - fm.popBackStackImmediate(); - Fragment fragment = fm.findFragmentByTag(ImportSettingsFragment.TAG); - if (fragment != null) { - fm.beginTransaction().remove(fragment).commit(); - fm.popBackStackImmediate(); - } - } } private void setupToolbar(Toolbar toolbar) { diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index 664cbcdbc1..57139a27f7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -97,7 +97,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - adapter = new ExportImportSettingsAdapter(app, getSettingsToOperate(), nightMode, true); + adapter = new ExportImportSettingsAdapter(app, getSettingsToOperate(settingsItems), nightMode, true); expandableList.setAdapter(adapter); } @@ -136,15 +136,15 @@ public class ImportSettingsFragment extends BaseOsmAndFragment public void onRoutingFilesLoaded() { } }); + FragmentManager fm = getFragmentManager(); + 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))); } } }); - FragmentManager fm = getFragmentManager(); - if (fm != null) { - fm.popBackStackImmediate(); - } } else { ImportDuplicatesFragment.showInstance(requireActivity().getSupportFragmentManager(), duplicateItems, settingsItems, file); } @@ -228,7 +228,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment return settingsItems; } - private List getSettingsToOperate() { + public static List getSettingsToOperate(List settingsItems) { List settingsToOperate = new ArrayList<>(); List profiles = new ArrayList<>(); List quickActions = new ArrayList<>(); diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java new file mode 100644 index 0000000000..f40aefff11 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java @@ -0,0 +1,143 @@ +package net.osmand.plus.settings; + +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +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 java.util.List; + + +public class ImportedSettingsItemsAdapter extends + RecyclerView.Adapter { + private List items; + private UiUtilities uiUtils; + private OsmandApplication app; + private boolean nightMode; + private OnItemClickListener listener; + + ImportedSettingsItemsAdapter(@NonNull OsmandApplication app, @NonNull List items, + boolean nightMode, OnItemClickListener listener) { + this.app = app; + this.items = items; + this.nightMode = nightMode; + this.listener = listener; + uiUtils = app.getUIUtilities(); + } + + @NonNull + @Override + public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + LayoutInflater inflater = UiUtilities.getInflater(app, nightMode); + View view = inflater.inflate(R.layout.list_item_import, parent, false); + return new ItemViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) { + final AdditionalDataWrapper currentItem = items.get(position); + boolean isLastItem = items.size() - 1 == position; + int activeColorRes = nightMode + ? R.color.active_color_primary_dark + : R.color.active_color_primary_light; + + holder.icon.setPadding(0, 0, AndroidUtils.dpToPx(app, 16), 0); + holder.title.setTextColor(app.getResources().getColor(activeColorRes)); + holder.divider.setVisibility(isLastItem ? View.VISIBLE : View.GONE); + holder.itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + listener.onItemClick(currentItem.getType()); + } + }); + setupSubTitle(holder.subTitle, currentItem.getItems().size()); + + switch (currentItem.getType()) { + case PROFILE: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.map_action_settings, activeColorRes)); + holder.title.setText(R.string.shared_string_settings); + break; + case QUICK_ACTIONS: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.map_quick_action, activeColorRes)); + holder.title.setText(R.string.shared_string_quick_action); + break; + case POI_TYPES: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_search_dark, activeColorRes)); + holder.title.setText(R.string.search_activity); + break; + case MAP_SOURCES: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_layers, activeColorRes)); + holder.title.setText(R.string.configure_map); + break; + case CUSTOM_RENDER_STYLE: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_map_style, activeColorRes)); + holder.title.setText(R.string.shared_string_rendering_style); + break; + case CUSTOM_ROUTING: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_route_distance, activeColorRes)); + holder.title.setText(R.string.shared_string_routing); + break; + case AVOID_ROADS: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_alert, activeColorRes)); + holder.title.setText(R.string.avoid_road); + break; + } + } + + private void setupSubTitle(TextView subTitle, int count) { + int stringRes; + if (count > 100) + count %= 100; + if (count > 20) + count %= 10; + switch (count) { + case 1: + stringRes = R.string.added_one_item; + break; + case 2: + case 3: + case 4: + stringRes = R.string.added_two_items; + break; + default: + stringRes = R.string.added_five_items; + break; + } + subTitle.setText(String.format(app.getString(stringRes), String.valueOf(count))); + } + + + @Override + public int getItemCount() { + return items.size(); + } + + public static class ItemViewHolder extends RecyclerView.ViewHolder { + ImageView icon; + TextView title; + TextView subTitle; + View divider; + + ItemViewHolder(View itemView) { + super(itemView); + title = itemView.findViewById(R.id.title); + subTitle = itemView.findViewById(R.id.sub_title); + icon = itemView.findViewById(R.id.icon); + divider = itemView.findViewById(R.id.bottom_divider); + } + } + + interface OnItemClickListener { + void onItemClick(AdditionalDataWrapper.Type type); + } +} From 72971f3e139152d26b9ca9c687df2fb0a70b9ff1 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Thu, 27 Feb 2020 13:11:18 +0200 Subject: [PATCH 02/30] import complete screen --- OsmAnd/res/layout/fragment_import.xml | 16 +++++++ .../res/layout/fragment_import_duplicates.xml | 28 ++++++++++--- OsmAnd/res/values/strings.xml | 2 + .../osmand/plus/activities/MapActivity.java | 10 +++++ .../settings/DuplicatesSettingsAdapter.java | 2 +- .../plus/settings/ImportCompleteFragment.java | 36 +++++++++------- .../settings/ImportDuplicatesFragment.java | 26 ++++++++++-- .../plus/settings/ImportSettingsFragment.java | 42 +++++++++++++++---- 8 files changed, 130 insertions(+), 32 deletions(-) diff --git a/OsmAnd/res/layout/fragment_import.xml b/OsmAnd/res/layout/fragment_import.xml index 29d43b823e..9c52c5d1ee 100644 --- a/OsmAnd/res/layout/fragment_import.xml +++ b/OsmAnd/res/layout/fragment_import.xml @@ -127,6 +127,10 @@ + + + + + + diff --git a/OsmAnd/res/layout/fragment_import_duplicates.xml b/OsmAnd/res/layout/fragment_import_duplicates.xml index a12f52d4b6..c72a37309e 100644 --- a/OsmAnd/res/layout/fragment_import_duplicates.xml +++ b/OsmAnd/res/layout/fragment_import_duplicates.xml @@ -124,18 +124,34 @@ android:minHeight="@dimen/toolbar_height" osmand:layout_collapseMode="pin" osmand:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed" - osmand:title="@string/import_duplicates_title"> + tools:title="@string/import_duplicates_title"> - + android:layout_height="wrap_content"> + + + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 0c21b2f5bc..f5146a39c4 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,8 @@ Thx - Hardy --> + Importing + OsmAnd check %1$s for duplicates with existing items in the application. It may take some time. Added: %1$s item Added: %1$s items Added: %1$s items diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 4025e127d5..a8da9b64a4 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -140,6 +140,7 @@ import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.settings.BaseSettingsFragment.SettingsScreenType; import net.osmand.plus.settings.ConfigureProfileFragment; import net.osmand.plus.settings.DataStorageFragment; +import net.osmand.plus.settings.ImportCompleteFragment; import net.osmand.plus.settings.ImportSettingsFragment; import net.osmand.plus.settings.ProfileAppearanceFragment; import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; @@ -738,6 +739,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven importSettingsFragment.showExitDialog(); return; } + ImportCompleteFragment importCompleteFragment = getImportCompleteFragment(); + if (importCompleteFragment != null) { + importCompleteFragment.dismissFragment(); + return; + } super.onBackPressed(); } @@ -2457,6 +2463,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return getFragment(ImportSettingsFragment.TAG); } + public ImportCompleteFragment getImportCompleteFragment() { + return getFragment(ImportCompleteFragment.TAG); + } + public void backToConfigureProfileFragment() { FragmentManager fragmentManager = getSupportFragmentManager(); int backStackEntryCount = fragmentManager.getBackStackEntryCount(); diff --git a/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java index c952fb03a3..99c9f83e95 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java @@ -114,7 +114,7 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter settingsItems; private File file; private boolean nightMode; + private ProgressBar progressBar; + private Toolbar toolbar; public static void showInstance(@NonNull FragmentManager fm, List duplicatesList, List settingsItems, File file) { @@ -59,7 +63,10 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View fragment.setDuplicatesList(duplicatesList); fragment.setSettingsItems(settingsItems); fragment.setFile(file); - fm.beginTransaction().replace(R.id.fragmentContainer, fragment, TAG).addToBackStack(null).commit(); + fm.beginTransaction() + .replace(R.id.fragmentContainer, fragment, TAG) + .addToBackStack(IMPORT_SETTINGS_TAG) + .commit(); } @Override @@ -81,11 +88,13 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View 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_duplicates, container, false); - setupToolbar((Toolbar) root.findViewById(R.id.toolbar)); + toolbar = root.findViewById(R.id.toolbar); + setupToolbar(toolbar); ComplexButton replaceAllBtn = root.findViewById(R.id.replace_all_btn); ComplexButton keepBothBtn = root.findViewById(R.id.keep_both_btn); buttonsContainer = root.findViewById(R.id.buttons_container); nestedScroll = root.findViewById(R.id.nested_scroll); + progressBar = root.findViewById(R.id.progress_bar); keepBothBtn.setIcon(getPaintedContentIcon(R.drawable.ic_action_keep_both, nightMode ? getResources().getColor(R.color.icon_color_active_dark) @@ -211,7 +220,18 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light; } + private void dismissFragment() { + FragmentManager fm = getFragmentManager(); + if (fm != null) { + fm.popBackStack(IMPORT_SETTINGS_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); + } + } + private void importItems(boolean shouldReplace) { + progressBar.setVisibility(View.VISIBLE); + list.setVisibility(View.GONE); + buttonsContainer.setVisibility(View.GONE); + toolbar.setTitle(getString(R.string.shared_string_importing)); for (SettingsItem item : settingsItems) { item.setShouldReplace(shouldReplace); } @@ -238,6 +258,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View } private void setupToolbar(Toolbar toolbar) { + toolbar.setTitle(R.string.import_duplicates_title); toolbar.setNavigationIcon(getPaintedContentIcon(R.drawable.ic_arrow_back, nightMode ? getResources().getColor(R.color.active_buttons_and_links_text_dark) @@ -249,7 +270,6 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View FragmentManager fm = getFragmentManager(); if (fm != null) { fm.popBackStackImmediate(); - ImportSettingsFragment.showInstance(fm, null, file); } } }); diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index 57139a27f7..d0144ecaeb 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -2,15 +2,16 @@ package net.osmand.plus.settings; import android.content.Context; import android.content.DialogInterface; +import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.design.widget.AppBarLayout; import android.support.v4.app.FragmentManager; import android.support.v4.view.ViewCompat; import android.support.v7.app.AlertDialog; import android.support.v7.widget.Toolbar; +import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -35,6 +36,8 @@ import net.osmand.plus.profiles.AdditionalDataWrapper; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.widgets.TextViewEx; +import org.w3c.dom.Text; + import java.io.File; import java.util.ArrayList; import java.util.List; @@ -43,6 +46,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment implements View.OnClickListener { public static final String TAG = ImportSettingsFragment.class.getSimpleName(); + public static final String IMPORT_SETTINGS_TAG = "import_settings_tag"; private OsmandApplication app; private ExportImportSettingsAdapter adapter; private ExpandableListView expandableList; @@ -51,12 +55,17 @@ public class ImportSettingsFragment extends BaseOsmAndFragment private File file; private boolean allSelected; private boolean nightMode; + private Toolbar toolbar; + private TextView description; public static void showInstance(@NonNull FragmentManager fm, List settingsItems, @NonNull File file) { ImportSettingsFragment fragment = new ImportSettingsFragment(); fragment.setSettingsItems(settingsItems); fragment.setFile(file); - fm.beginTransaction().replace(R.id.fragmentContainer, fragment, TAG).addToBackStack(null).commit(); + fm.beginTransaction(). + replace(R.id.fragmentContainer, fragment, TAG) + .addToBackStack(IMPORT_SETTINGS_TAG) + .commit(); } @Override @@ -77,13 +86,14 @@ 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); - setupToolbar((Toolbar) root.findViewById(R.id.toolbar)); + toolbar = root.findViewById(R.id.toolbar); + setupToolbar(toolbar); TextViewEx continueBtn = root.findViewById(R.id.continue_button); selectBtn = root.findViewById(R.id.select_button); expandableList = root.findViewById(R.id.list); ViewCompat.setNestedScrollingEnabled(expandableList, true); View header = inflater.inflate(R.layout.list_item_description_header, container, false); - 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); @@ -122,6 +132,13 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } private void importItems() { + description.setText(AndroidUtils.getStyledString( + String.format(getString(R.string.checking_for_duplicate_description), file.getName()), + file.getName(), + new StyleSpan(Typeface.BOLD), + null)); + + final FragmentManager fm = getFragmentManager(); List settingsItems = getSettingsItemsFromData(adapter.getDataToOperate()); List duplicateItems = getDuplicatesData(settingsItems); if (duplicateItems.isEmpty()) { @@ -129,24 +146,32 @@ public class ImportSettingsFragment extends BaseOsmAndFragment @Override public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { if (succeed) { - app.showShortToastMessage(app.getString(R.string.file_imported_successfully, file.getName())); app.getRendererRegistry().updateExternalRenderers(); AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() { @Override public void onRoutingFilesLoaded() { } }); - FragmentManager fm = getFragmentManager(); 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 { - ImportDuplicatesFragment.showInstance(requireActivity().getSupportFragmentManager(), duplicateItems, settingsItems, file); + if (fm != null) { + ImportDuplicatesFragment.showInstance(fm, duplicateItems, settingsItems, file); + } + } + } + + private void dismissFragment() { + FragmentManager fm = getFragmentManager(); + if (fm != null) { + getFragmentManager().popBackStack(IMPORT_SETTINGS_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); } } @@ -316,7 +341,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment public void onClick(DialogInterface dialog, int which) { FragmentManager fm = getFragmentManager(); if (fm != null) { - fm.popBackStackImmediate(); + fm.popBackStack(IMPORT_SETTINGS_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); } } }); @@ -334,6 +359,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment showExitDialog(); } }); + toolbar.setTitle(R.string.shared_string_import); } public void setFile(File file) { From 6afde41f1950bb2b9501ccd6279054a66685de37 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 28 Feb 2020 11:14:57 +0200 Subject: [PATCH 03/30] complete settings screen --- OsmAnd/res/layout/fragment_import.xml | 4 +- .../layout/list_item_description_header.xml | 2 +- OsmAnd/res/values/strings.xml | 3 +- OsmAnd/src/net/osmand/plus/UiUtilities.java | 15 ++++ .../plus/settings/ImportCompleteFragment.java | 71 ++++++++----------- .../settings/ImportDuplicatesFragment.java | 22 +++++- .../plus/settings/ImportSettingsFragment.java | 31 ++++++-- 7 files changed, 95 insertions(+), 53 deletions(-) diff --git a/OsmAnd/res/layout/fragment_import.xml b/OsmAnd/res/layout/fragment_import.xml index 9c52c5d1ee..92926c3ec1 100644 --- a/OsmAnd/res/layout/fragment_import.xml +++ b/OsmAnd/res/layout/fragment_import.xml @@ -112,6 +112,7 @@ osmand:collapsedTitleTextAppearance="@style/AppBarTitle" osmand:expandedTitleGravity="start|bottom" osmand:expandedTitleTextAppearance="@style/AppBarTitle" + tools:title="@string/shared_string_import" osmand:layout_scrollFlags="scroll|exitUntilCollapsed"> + osmand:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed"> diff --git a/OsmAnd/res/layout/list_item_description_header.xml b/OsmAnd/res/layout/list_item_description_header.xml index 7d0a15d436..1a8c777b87 100644 --- a/OsmAnd/res/layout/list_item_description_header.xml +++ b/OsmAnd/res/layout/list_item_description_header.xml @@ -2,7 +2,7 @@ + Importing data from %1$s Importing - OsmAnd check %1$s for duplicates with existing items in the application. It may take some time. + OsmAnd check %1$s for duplicates with existing items in the application.\n\nIt may take some time. Added: %1$s item Added: %1$s items Added: %1$s items diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index fde5357591..67a26c0bfd 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.PorterDuff; +import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.LayerDrawable; @@ -23,6 +24,9 @@ import android.support.v4.view.ViewCompat; import android.support.v4.widget.TintableCompoundButton; import android.support.v7.view.ContextThemeWrapper; import android.support.v7.widget.SwitchCompat; +import android.text.SpannableString; +import android.text.Spanned; +import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -559,4 +563,15 @@ public class UiUtilities { v.requestLayout(); } } + + public static SpannableString createSpannableString(String text, String textToStyle, StyleSpan styleSpan) { + int startIndex = text.indexOf(textToStyle); + SpannableString spannable = new SpannableString(text); + spannable.setSpan( + styleSpan, + startIndex, + startIndex + textToStyle.length(), + Spanned.SPAN_INCLUSIVE_INCLUSIVE); + return spannable; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java index 5d004b1a4c..300c2f1ca1 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java @@ -74,13 +74,12 @@ 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); - description.setText(AndroidUtils.getStyledString( - String.format(getString(R.string.checking_for_duplicate_description), fileName), + description.setText(UiUtilities.createSpannableString( + String.format(getString(R.string.import_complete_description), fileName), fileName, - new StyleSpan(Typeface.BOLD), - null)); + new StyleSpan(Typeface.BOLD) + )); - setupDescription(description); TextView btnClose = root.findViewById(R.id.button_close); btnClose.setOnClickListener(new View.OnClickListener() { @Override @@ -98,18 +97,20 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - ImportedSettingsItemsAdapter adapter = new ImportedSettingsItemsAdapter( - app, - getSettingsToOperate(settingsItems), - nightMode, - new ImportedSettingsItemsAdapter.OnItemClickListener() { - @Override - public void onItemClick(AdditionalDataWrapper.Type type) { - navigateTo(type); - } - }); - recyclerView.setLayoutManager(new LinearLayoutManager(getMyApplication())); - recyclerView.setAdapter(adapter); + if (settingsItems != null) { + ImportedSettingsItemsAdapter adapter = new ImportedSettingsItemsAdapter( + app, + getSettingsToOperate(settingsItems), + nightMode, + new ImportedSettingsItemsAdapter.OnItemClickListener() { + @Override + public void onItemClick(AdditionalDataWrapper.Type type) { + navigateTo(type); + } + }); + recyclerView.setLayoutManager(new LinearLayoutManager(getMyApplication())); + recyclerView.setAdapter(adapter); + } } @Override @@ -134,26 +135,30 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { String TAG; switch (type) { case PROFILE: - fragment = new GeneralProfileSettingsFragment(); - TAG = GeneralProfileSettingsFragment.TAG; + BaseSettingsFragment.showInstance( + getActivity(), + BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS + ); break; case QUICK_ACTIONS: - fragment = new QuickActionListFragment(); - TAG = QuickActionListFragment.TAG; + fm.beginTransaction() + .add(R.id.fragmentContainer, new QuickActionListFragment(), QuickActionListFragment.TAG) + .addToBackStack(QuickActionListFragment.TAG).commitAllowingStateLoss(); break; case POI_TYPES: - fragment = new QuickSearchDialogFragment(); - TAG = QuickSearchDialogFragment.TAG; + QuickSearchDialogFragment quickSearchDialogFragment = new QuickSearchDialogFragment(); + quickSearchDialogFragment.show(fm, QuickSearchDialogFragment.TAG); break; case MAP_SOURCES: - fragment = new GeneralProfileSettingsFragment(); - TAG = QuickActionListFragment.TAG; + break; case CUSTOM_RENDER_STYLE: + fragment = new SelectMapStyleBottomSheetDialogFragment(); TAG = SelectMapStyleBottomSheetDialogFragment.TAG; break; case CUSTOM_ROUTING: + return; case AVOID_ROADS: fragment = new AvoidRoadsBottomSheetDialogFragment(); @@ -163,9 +168,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { return; } dismissFragment(); - fm.beginTransaction() - .replace(R.id.fragmentContainer, fragment, TAG) - .commit(); + app.getSettingsHelper().setImportedItems(null); } @Override @@ -173,18 +176,6 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light; } - private void setupDescription(TextView description) { - String descriptionText = String.format(getString( - R.string.import_complete_description), fileName); - int startIndex = descriptionText.indexOf(fileName); - SpannableString spannableDescription = new SpannableString(descriptionText); - spannableDescription.setSpan( - new StyleSpan(Typeface.BOLD), - startIndex, - startIndex + fileName.length(), - Spanned.SPAN_INCLUSIVE_INCLUSIVE); - description.setText(spannableDescription); - } 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 c634665adb..10e186096c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java @@ -1,10 +1,12 @@ package net.osmand.plus.settings; +import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.AppBarLayout; +import android.support.design.widget.CollapsingToolbarLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; @@ -13,12 +15,14 @@ import android.support.v4.widget.NestedScrollView; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; +import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.widget.LinearLayout; import android.widget.ProgressBar; +import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.map.ITileSource; @@ -56,6 +60,8 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View private boolean nightMode; private ProgressBar progressBar; private Toolbar toolbar; + private CollapsingToolbarLayout toolbarLayout; + private TextView description; public static void showInstance(@NonNull FragmentManager fm, List duplicatesList, List settingsItems, File file) { @@ -76,7 +82,9 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View nightMode = !app.getSettings().isLightContent(); if (settingsItems == null) { settingsItems = app.getSettingsHelper().getSettingsItems(); - duplicatesList = getDuplicatesData(settingsItems); + if (settingsItems != null) { + duplicatesList = getDuplicatesData(settingsItems); + } } if (file == null) { file = app.getSettingsHelper().getSettingsFile(); @@ -94,7 +102,9 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View ComplexButton keepBothBtn = root.findViewById(R.id.keep_both_btn); buttonsContainer = root.findViewById(R.id.buttons_container); nestedScroll = root.findViewById(R.id.nested_scroll); + description = root.findViewById(R.id.description); progressBar = root.findViewById(R.id.progress_bar); + toolbarLayout = root.findViewById(R.id.toolbar_layout); keepBothBtn.setIcon(getPaintedContentIcon(R.drawable.ic_action_keep_both, nightMode ? getResources().getColor(R.color.icon_color_active_dark) @@ -138,6 +148,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View DuplicatesSettingsAdapter adapter = new DuplicatesSettingsAdapter(app, prepareDuplicates(), nightMode); list.setLayoutManager(new LinearLayoutManager(getMyApplication())); list.setAdapter(adapter); + toolbarLayout.setTitle(getString(R.string.import_duplicates_title)); } private List prepareDuplicates() { @@ -228,10 +239,15 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View } private void importItems(boolean shouldReplace) { + 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) + )); progressBar.setVisibility(View.VISIBLE); list.setVisibility(View.GONE); buttonsContainer.setVisibility(View.GONE); - toolbar.setTitle(getString(R.string.shared_string_importing)); for (SettingsItem item : settingsItems) { item.setShouldReplace(shouldReplace); } @@ -239,7 +255,6 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View @Override public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { if (succeed) { - app.showShortToastMessage(app.getString(R.string.file_imported_successfully, file.getName())); app.getRendererRegistry().updateExternalRenderers(); AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() { @Override @@ -251,6 +266,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View ImportCompleteFragment.showInstance(fm, items, file.getName()); } } else if (empty) { + dismissFragment(); app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error))); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index d0144ecaeb..d53eb2bbab 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -7,6 +7,7 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.design.widget.CollapsingToolbarLayout; import android.support.v4.app.FragmentManager; import android.support.v4.view.ViewCompat; import android.support.v7.app.AlertDialog; @@ -16,6 +17,8 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ExpandableListView; +import android.widget.LinearLayout; +import android.widget.ProgressBar; import android.widget.TextView; import net.osmand.AndroidUtils; @@ -57,6 +60,10 @@ public class ImportSettingsFragment extends BaseOsmAndFragment private boolean nightMode; private Toolbar toolbar; private TextView description; + private String fileName; + private LinearLayout buttonsContainer; + private ProgressBar progressBar; + private CollapsingToolbarLayout toolbarLayout; public static void showInstance(@NonNull FragmentManager fm, List settingsItems, @NonNull File file) { ImportSettingsFragment fragment = new ImportSettingsFragment(); @@ -87,17 +94,20 @@ public class ImportSettingsFragment extends BaseOsmAndFragment inflater = UiUtilities.getInflater(app, nightMode); View root = inflater.inflate(R.layout.fragment_import, container, false); toolbar = root.findViewById(R.id.toolbar); + toolbarLayout = root.findViewById(R.id.toolbar_layout); setupToolbar(toolbar); TextViewEx continueBtn = root.findViewById(R.id.continue_button); selectBtn = root.findViewById(R.id.select_button); expandableList = root.findViewById(R.id.list); ViewCompat.setNestedScrollingEnabled(expandableList, true); - View header = inflater.inflate(R.layout.list_item_description_header, container, false); + View header = inflater.inflate(R.layout.list_item_description_header, null); description = header.findViewById(R.id.description); description.setText(R.string.select_data_to_import); expandableList.addHeaderView(header); continueBtn.setOnClickListener(this); selectBtn.setOnClickListener(this); + buttonsContainer = root.findViewById(R.id.buttons_container); + progressBar = root.findViewById(R.id.progress_bar); if (Build.VERSION.SDK_INT >= 21) { AndroidUtils.addStatusBarPadding21v(app, root); } @@ -109,6 +119,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment super.onViewCreated(view, savedInstanceState); adapter = new ExportImportSettingsAdapter(app, getSettingsToOperate(settingsItems), nightMode, true); expandableList.setAdapter(adapter); + toolbarLayout.setTitle(getString(R.string.shared_string_import)); } @Override @@ -132,16 +143,25 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } private void importItems() { - description.setText(AndroidUtils.getStyledString( + toolbarLayout.setTitle(getString(R.string.shared_string_preparing)); + description.setText(UiUtilities.createSpannableString( String.format(getString(R.string.checking_for_duplicate_description), file.getName()), file.getName(), - new StyleSpan(Typeface.BOLD), - null)); - + new StyleSpan(Typeface.BOLD) + )); + buttonsContainer.setVisibility(View.GONE); + progressBar.setVisibility(View.VISIBLE); + 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) { @@ -359,7 +379,6 @@ public class ImportSettingsFragment extends BaseOsmAndFragment showExitDialog(); } }); - toolbar.setTitle(R.string.shared_string_import); } public void setFile(File file) { From 9a6c9d111d48564915210db85392d149a8daf02e Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 28 Feb 2020 15:21:18 +0200 Subject: [PATCH 04/30] complete settings screen --- OsmAnd/res/layout/fragment_import.xml | 7 +- OsmAnd/res/values/sizes.xml | 2 +- .../src/net/osmand/plus/SettingsHelper.java | 87 +++++++++++++++++++ .../plus/settings/ImportCompleteFragment.java | 36 ++++---- .../plus/settings/ImportSettingsFragment.java | 65 +++++++------- 5 files changed, 147 insertions(+), 50 deletions(-) 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() { From d9626e216b741a2f71c229f03c745f1aa542794b Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 28 Feb 2020 17:52:49 +0200 Subject: [PATCH 05/30] 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()); } } From 3a869940b2e3408148712135a29ee51eba62f2ff Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Mon, 2 Mar 2020 16:56:17 +0200 Subject: [PATCH 06/30] change screen orientation support --- .../src/net/osmand/plus/SQLiteTileSource.java | 6 +- .../src/net/osmand/plus/SettingsHelper.java | 81 +++++++++--- .../settings/ExportImportSettingsAdapter.java | 10 +- .../settings/ExportProfileBottomSheet.java | 2 +- .../plus/settings/ImportCompleteFragment.java | 8 +- .../settings/ImportDuplicatesFragment.java | 67 ++++++---- .../plus/settings/ImportSettingsFragment.java | 123 +++++++++++------- 7 files changed, 191 insertions(+), 106 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java index fde2f7f9b0..82e4df2762 100644 --- a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java +++ b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java @@ -126,9 +126,9 @@ public class SQLiteTileSource implements ITileSource { db = ctx.getSQLiteAPI().getOrCreateDatabase( ctx.getAppPath(TILES_INDEX_DIR).getAbsolutePath() + "/" + name + SQLITE_EXT, true); - db.execSQL("CREATE TABLE tiles (x int, y int, z int, s int, image blob, time long, PRIMARY KEY (x,y,z,s))"); - db.execSQL("CREATE INDEX IND on tiles (x,y,z,s)"); - db.execSQL("CREATE TABLE info(tilenumbering,minzoom,maxzoom)"); + db.execSQL("CREATE TABLE IF NOT EXISTS tiles (x int, y int, z int, s int, image blob, time long, PRIMARY KEY (x,y,z,s))"); + db.execSQL("CREATE INDEX IF NOT EXISTS IND on tiles (x,y,z,s)"); + db.execSQL("CREATE TABLE IF NOT EXISTS info(tilenumbering,minzoom,maxzoom)"); db.execSQL("INSERT INTO info (tilenumbering,minzoom,maxzoom) VALUES ('simple','" + minZoom + "','" + maxZoom + "');"); addInfoColumn(URL, urlTemplate); diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index 606705d212..25c0d97184 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -8,7 +8,6 @@ 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; @@ -51,7 +50,6 @@ import java.io.OutputStream; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -103,8 +101,11 @@ public class SettingsHelper { private boolean importing; private boolean importSuspended; private boolean collectOnly; + private boolean checkingDuplicates; private ImportAsyncTask importTask; + private CheckDuplicatesTask checkDuplicatesTask; private List importedItems; + private List selectedItems; public interface SettingsImportListener { void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items); @@ -147,6 +148,14 @@ public class SettingsHelper { return importing; } + public boolean isCheckingDuplicates() { + return checkingDuplicates; + } + + public boolean isCollectOnly() { + return collectOnly; + } + public enum SettingsItemType { GLOBAL, PROFILE, @@ -1812,7 +1821,7 @@ public class SettingsHelper { } @SuppressLint("StaticFieldLeak") - private class ImportAsyncTask extends AsyncTask> { + public class ImportAsyncTask extends AsyncTask> { private File file; private String latestChanges; @@ -1936,16 +1945,20 @@ public class SettingsHelper { public File getFile() { return this.file; } + + public void setListener(SettingsImportListener listener) { + this.listener = listener; + } } @Nullable public List getSettingsItems() { - return this.importTask.getItems(); + return importTask != null ? importTask.getItems() : null; } @Nullable public File getSettingsFile() { - return this.importTask.getFile(); + return importTask != null ? importTask.getFile() : null; } @Nullable @@ -1953,10 +1966,30 @@ public class SettingsHelper { return importedItems; } + @Nullable + public List getDuplicatesItems() { + return checkDuplicatesTask != null ? checkDuplicatesTask.getDuplicates() : null; + } + public void setImportedItems(List importedItems) { this.importedItems = importedItems; } + @Nullable + public CheckDuplicatesTask getCheckDuplicatesTask() { + return checkDuplicatesTask; + } + + @Nullable + public ImportAsyncTask getImportTask() { + return importTask; + } + + @Nullable + public List getSelectedItems() { + return selectedItems; + } + @SuppressLint("StaticFieldLeak") private class ImportItemsAsyncTask extends AsyncTask { @@ -1997,6 +2030,7 @@ public class SettingsHelper { importing = false; importSuspended = false; importTask = null; + checkDuplicatesTask = null; if (listener != null) { listener.onSettingsImportFinished(success, empty, items); } @@ -2055,43 +2089,48 @@ public class SettingsHelper { } @SuppressLint("StaticFieldLeak") - public class CheckDuplicateTask extends AsyncTask> { + public class CheckDuplicatesTask extends AsyncTask> { private List items; private List duplicates; private CheckDuplicatesListener listener; private long startTime; - CheckDuplicateTask(@NonNull List items, CheckDuplicatesListener listener) { + CheckDuplicatesTask(@NonNull List items, CheckDuplicatesListener listener) { this.items = items; this.listener = listener; } @Override protected void onPreExecute() { + selectedItems = this.items; + checkingDuplicates = true; + checkDuplicatesTask = this; startTime = System.currentTimeMillis(); super.onPreExecute(); } @Override protected List doInBackground(Void... voids) { - return getDuplicatesData(this.items); + long currentTime = System.currentTimeMillis(); + List duplicateItems = getDuplicatesData(this.items); + if (currentTime - startTime < 700) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + LOG.error("Error on check duplicates delay" + e); + } + } + return duplicateItems; } @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); } + checkingDuplicates = false; super.onPostExecute(objects); } @@ -2130,10 +2169,18 @@ public class SettingsHelper { } return duplicateItems; } + + public void setListener(CheckDuplicatesListener listener) { + this.listener = listener; + } + + List getDuplicates() { + return duplicates; + } } public void checkDuplicates(@NonNull List items, CheckDuplicatesListener listener) { - new CheckDuplicateTask(items, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new CheckDuplicatesTask(items, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } public void importSettings(@NonNull File settingsFile, String latestChanges, int version, diff --git a/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java index b8d479c2cd..1fb6796a71 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java @@ -44,18 +44,10 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { private boolean importState; private int profileColor; - ExportImportSettingsAdapter(OsmandApplication app, List dataList, boolean nightMode, boolean importState) { + ExportImportSettingsAdapter(OsmandApplication app, boolean nightMode, boolean importState) { this.app = app; - this.dataList = dataList; this.nightMode = nightMode; this.importState = importState; - this.dataToOperate = new ArrayList<>(); - this.profileColor = app.getSettings().getApplicationMode().getIconColorInfo().getColor(nightMode); - } - - ExportImportSettingsAdapter(OsmandApplication app, boolean nightMode) { - this.app = app; - this.nightMode = nightMode; this.dataList = new ArrayList<>(); this.dataToOperate = new ArrayList<>(); this.profileColor = app.getSettings().getApplicationMode().getIconColorInfo().getColor(nightMode); diff --git a/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java index 2c58ee66a6..c05816417f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java @@ -109,7 +109,7 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet { if (!dataList.isEmpty()) { final View additionalDataView = inflater.inflate(R.layout.bottom_sheet_item_additional_data, null); ExpandableListView listView = additionalDataView.findViewById(R.id.list); - adapter = new ExportImportSettingsAdapter(app, nightMode); + adapter = new ExportImportSettingsAdapter(app, nightMode, false); View listHeader = inflater.inflate(R.layout.item_header_export_expand_list, null); final View topSwitchDivider = listHeader.findViewById(R.id.topSwitchDivider); final View bottomSwitchDivider = listHeader.findViewById(R.id.bottomSwitchDivider); diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java index db1b91c737..764447edd7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java @@ -6,12 +6,9 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.text.SpannableString; -import android.text.Spanned; import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; @@ -26,7 +23,6 @@ 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; @@ -35,6 +31,7 @@ import net.osmand.plus.search.QuickSearchDialogFragment; import java.util.List; +import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID; import static net.osmand.plus.settings.ImportSettingsFragment.IMPORT_SETTINGS_TAG; import static net.osmand.plus.settings.ImportSettingsFragment.getSettingsToOperate; @@ -128,7 +125,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { public void dismissFragment() { FragmentManager fm = getFragmentManager(); if (fm != null) { - getFragmentManager().popBackStack(IMPORT_SETTINGS_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); + fm.popBackStack(IMPORT_SETTINGS_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); } app.getSettingsHelper().setImportedItems(null); } @@ -139,6 +136,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { return; } dismissFragment(); + fm.popBackStack(DRAWER_SETTINGS_ID + ".new", FragmentManager.POP_BACK_STACK_INCLUSIVE); switch (type) { case CUSTOM_ROUTING: case PROFILE: diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java index a1a56838ff..cf0b2cceea 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java @@ -5,12 +5,8 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.design.widget.AppBarLayout; import android.support.design.widget.CollapsingToolbarLayout; -import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentTransaction; -import android.support.v4.view.ViewCompat; import android.support.v4.widget.NestedScrollView; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -58,7 +54,6 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View private File file; private boolean nightMode; private ProgressBar progressBar; - private Toolbar toolbar; private CollapsingToolbarLayout toolbarLayout; private TextView description; @@ -71,7 +66,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View fm.beginTransaction() .replace(R.id.fragmentContainer, fragment, TAG) .addToBackStack(IMPORT_SETTINGS_TAG) - .commit(); + .commitAllowingStateLoss(); } @Override @@ -80,17 +75,21 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View app = requireMyApplication(); nightMode = !app.getSettings().isLightContent(); if (settingsItems == null) { - settingsItems = app.getSettingsHelper().getSettingsItems(); - if (settingsItems != null) { -// duplicatesList = getDuplicatesData(settingsItems); - } else { - dismissFragment(); - } + settingsItems = app.getSettingsHelper().getSelectedItems(); + } + if (duplicatesList == null) { + duplicatesList = app.getSettingsHelper().getDuplicatesItems(); } if (file == null) { file = app.getSettingsHelper().getSettingsFile(); - if (file == null) { - dismissFragment(); + } + SettingsHelper.ImportAsyncTask importAsyncTask = app.getSettingsHelper().getImportTask(); + if (importAsyncTask != null) { + importAsyncTask.setListener(getImportListener()); + } else if (app.getSettingsHelper().getImportedItems() != null) { + FragmentManager fm = getFragmentManager(); + if (fm != null) { + ImportCompleteFragment.showInstance(fm, app.getSettingsHelper().getImportedItems(), file.getName()); } } } @@ -100,7 +99,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View 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_duplicates, container, false); - toolbar = root.findViewById(R.id.toolbar); + Toolbar toolbar = root.findViewById(R.id.toolbar); setupToolbar(toolbar); ComplexButton replaceAllBtn = root.findViewById(R.id.replace_all_btn); ComplexButton keepBothBtn = root.findViewById(R.id.keep_both_btn); @@ -149,13 +148,19 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - DuplicatesSettingsAdapter adapter = new DuplicatesSettingsAdapter(app, prepareDuplicates(), nightMode); - list.setLayoutManager(new LinearLayoutManager(getMyApplication())); - list.setAdapter(adapter); - toolbarLayout.setTitle(getString(R.string.import_duplicates_title)); + if (duplicatesList != null) { + DuplicatesSettingsAdapter adapter = new DuplicatesSettingsAdapter(app, prepareDuplicates(duplicatesList), nightMode); + list.setLayoutManager(new LinearLayoutManager(getMyApplication())); + list.setAdapter(adapter); + } + if (app.getSettingsHelper().isImporting() && !app.getSettingsHelper().isCollectOnly()) { + setupImportingUi(); + } else { + toolbarLayout.setTitle(getString(R.string.import_duplicates_title)); + } } - private List prepareDuplicates() { + private List prepareDuplicates(List duplicatesList) { List duplicates = new ArrayList<>(); List profiles = new ArrayList<>(); List actions = new ArrayList<>(); @@ -243,6 +248,16 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View } private void importItems(boolean shouldReplace) { + if (settingsItems != null && file != null) { + setupImportingUi(); + for (SettingsItem item : settingsItems) { + item.setShouldReplace(shouldReplace); + } + app.getSettingsHelper().importSettings(file, settingsItems, "", 1, getImportListener()); + } + } + + private void setupImportingUi() { toolbarLayout.setTitle(getString(R.string.shared_string_importing)); description.setText(UiUtilities.createSpannableString( String.format(getString(R.string.importing_from), file.getName()), @@ -252,12 +267,12 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View progressBar.setVisibility(View.VISIBLE); list.setVisibility(View.GONE); buttonsContainer.setVisibility(View.GONE); - for (SettingsItem item : settingsItems) { - item.setShouldReplace(shouldReplace); - } - app.getSettingsHelper().importSettings(file, settingsItems, "", 1, new SettingsHelper.SettingsImportListener() { + } + + private SettingsHelper.SettingsImportListener getImportListener() { + return new SettingsHelper.SettingsImportListener() { @Override - public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { + public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { if (succeed) { app.getRendererRegistry().updateExternalRenderers(); AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() { @@ -274,7 +289,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error))); } } - }); + }; } private void setupToolbar(Toolbar toolbar) { diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index 68e7404036..b8d1175c4f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -39,7 +39,6 @@ import net.osmand.plus.profiles.AdditionalDataWrapper; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.widgets.TextViewEx; -import org.w3c.dom.Text; import java.io.File; import java.util.ArrayList; @@ -62,32 +61,44 @@ public class ImportSettingsFragment extends BaseOsmAndFragment private LinearLayout buttonsContainer; private ProgressBar progressBar; private CollapsingToolbarLayout toolbarLayout; + private SettingsHelper settingsHelper; - public static void showInstance(@NonNull FragmentManager fm, List settingsItems, @NonNull File file) { + public static void showInstance(@NonNull FragmentManager fm, @NonNull List settingsItems, @NonNull File file) { ImportSettingsFragment fragment = new ImportSettingsFragment(); fragment.setSettingsItems(settingsItems); fragment.setFile(file); fm.beginTransaction(). replace(R.id.fragmentContainer, fragment, TAG) .addToBackStack(IMPORT_SETTINGS_TAG) - .commit(); + .commitAllowingStateLoss(); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); app = requireMyApplication(); + settingsHelper = app.getSettingsHelper(); 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(); + } + List duplicates = settingsHelper.getDuplicatesItems(); + if (duplicates == null) { + SettingsHelper.CheckDuplicatesTask checkDuplicatesTask = settingsHelper.getCheckDuplicatesTask(); + if (checkDuplicatesTask != null) { + settingsHelper.getCheckDuplicatesTask().setListener(getDuplicatesListener()); + } + } else { + FragmentManager fm = getFragmentManager(); + if (duplicates.isEmpty()) { + app.getSettingsHelper().importSettings(file, settingsItems, "", 1, getImportListener()); + } else { + if (fm != null) { + ImportDuplicatesFragment.showInstance(fm, duplicates, settingsItems, file); + } } } } @@ -98,11 +109,13 @@ public class ImportSettingsFragment extends BaseOsmAndFragment inflater = UiUtilities.getInflater(app, nightMode); View root = inflater.inflate(R.layout.fragment_import, container, false); Toolbar toolbar = root.findViewById(R.id.toolbar); - toolbarLayout = root.findViewById(R.id.toolbar_layout); - setupToolbar(toolbar); TextViewEx continueBtn = root.findViewById(R.id.continue_button); + toolbarLayout = root.findViewById(R.id.toolbar_layout); selectBtn = root.findViewById(R.id.select_button); expandableList = root.findViewById(R.id.list); + buttonsContainer = root.findViewById(R.id.buttons_container); + progressBar = root.findViewById(R.id.progress_bar); + setupToolbar(toolbar); ViewCompat.setNestedScrollingEnabled(expandableList, true); View header = inflater.inflate(R.layout.list_item_description_header, null); description = header.findViewById(R.id.description); @@ -110,8 +123,6 @@ public class ImportSettingsFragment extends BaseOsmAndFragment expandableList.addHeaderView(header); continueBtn.setOnClickListener(this); selectBtn.setOnClickListener(this); - buttonsContainer = root.findViewById(R.id.buttons_container); - progressBar = root.findViewById(R.id.progress_bar); if (Build.VERSION.SDK_INT >= 21) { AndroidUtils.addStatusBarPadding21v(app, root); } @@ -121,9 +132,19 @@ public class ImportSettingsFragment extends BaseOsmAndFragment @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - adapter = new ExportImportSettingsAdapter(app, getSettingsToOperate(settingsItems), nightMode, true); + adapter = new ExportImportSettingsAdapter(app, nightMode, true); + if (settingsItems != null) { + adapter.updateSettingsList(getSettingsToOperate(settingsItems)); + } expandableList.setAdapter(adapter); - toolbarLayout.setTitle(getString(R.string.shared_string_import)); + + if (settingsHelper.isCheckingDuplicates()) { + updateUi(R.string.shared_string_preparing, R.string.checking_for_duplicate_description); + } else if (settingsHelper.isImporting() && !settingsHelper.isCollectOnly()) { + updateUi(R.string.shared_string_importing, R.string.importing_from); + } else { + toolbarLayout.setTitle(getString(R.string.shared_string_import)); + } } @Override @@ -146,54 +167,66 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } } - private void importItems() { - toolbarLayout.setTitle(getString(R.string.shared_string_preparing)); + private void updateUi(int toolbarTitleRes, int descriptionRes) { + toolbarLayout.setTitle(getString(toolbarTitleRes)); description.setText(UiUtilities.createSpannableString( - String.format(getString(R.string.checking_for_duplicate_description), file.getName()), + String.format(getString(descriptionRes), file.getName()), file.getName(), new StyleSpan(Typeface.BOLD) )); buttonsContainer.setVisibility(View.GONE); progressBar.setVisibility(View.VISIBLE); adapter.clearSettingsList(); - final FragmentManager fm = getFragmentManager(); + } + + private void importItems() { + updateUi(R.string.shared_string_preparing, R.string.checking_for_duplicate_description); List settingsItems = getSettingsItemsFromData(adapter.getDataToOperate()); - app.getSettingsHelper().checkDuplicates(settingsItems, new SettingsHelper.CheckDuplicatesListener() { + settingsHelper.checkDuplicates(settingsItems, getDuplicatesListener()); + } + + private SettingsHelper.SettingsImportListener getImportListener() { + return new SettingsHelper.SettingsImportListener() { @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() { + public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { + FragmentManager fm = getFragmentManager(); + if (succeed) { + app.getRendererRegistry().updateExternalRenderers(); + AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() { @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(); - } + 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(); + } + } + }; + } + + private SettingsHelper.CheckDuplicatesListener getDuplicatesListener() { + return new SettingsHelper.CheckDuplicatesListener() { + @Override + public void onDuplicatesChecked(@NonNull List duplicates, List items) { + FragmentManager fm = getFragmentManager(); + if (duplicates.isEmpty()) { + if (isAdded()) { + updateUi(R.string.shared_string_importing, R.string.importing_from); + } + settingsHelper.importSettings(file, items, "", 1, getImportListener()); } else { if (fm != null) { - ImportDuplicatesFragment.showInstance(fm, duplicates, items, file); + if (!isStateSaved()) { + ImportDuplicatesFragment.showInstance(fm, duplicates, items, file); + } } } } - }); + }; } private void dismissFragment() { From ec6386628c0e987602ba894379af6f32d1ec6b01 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Mon, 2 Mar 2020 17:22:00 +0200 Subject: [PATCH 07/30] refactor --- .../src/net/osmand/plus/SettingsHelper.java | 2 +- OsmAnd/src/net/osmand/plus/UiUtilities.java | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index 25c0d97184..9cb01a743e 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -1971,7 +1971,7 @@ public class SettingsHelper { return checkDuplicatesTask != null ? checkDuplicatesTask.getDuplicates() : null; } - public void setImportedItems(List importedItems) { + public void setImportedItems(@Nullable List importedItems) { this.importedItems = importedItems; } diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 67a26c0bfd..e03651ef35 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -38,16 +38,21 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.Location; +import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.plus.views.DirectionDrawable; import net.osmand.plus.widgets.TextViewEx; +import org.apache.commons.logging.Log; + import java.util.Locale; import gnu.trove.map.hash.TLongObjectHashMap; public class UiUtilities { + private static final Log LOG = PlatformUtil.getLog(UiUtilities.class); + private TLongObjectHashMap drawableCache = new TLongObjectHashMap<>(); private OsmandApplication app; private static final int ORIENTATION_0 = 0; @@ -564,14 +569,21 @@ public class UiUtilities { } } - public static SpannableString createSpannableString(String text, String textToStyle, StyleSpan styleSpan) { - int startIndex = text.indexOf(textToStyle); + public static SpannableString createSpannableString(@NonNull String text, + @NonNull String textToStyle, + @NonNull StyleSpan styleSpan) { SpannableString spannable = new SpannableString(text); - spannable.setSpan( - styleSpan, - startIndex, - startIndex + textToStyle.length(), - Spanned.SPAN_INCLUSIVE_INCLUSIVE); - return spannable; + try { + int startIndex = text.indexOf(textToStyle); + spannable.setSpan( + styleSpan, + startIndex, + startIndex + textToStyle.length(), + Spanned.SPAN_INCLUSIVE_INCLUSIVE); + return spannable; + } catch (RuntimeException e) { + LOG.error("Error trying to find index of " + textToStyle + " " + e); + return spannable; + } } } \ No newline at end of file From 67655b7496baec4877594da9d6c24b0fedf1c970 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Mon, 2 Mar 2020 17:38:06 +0200 Subject: [PATCH 08/30] refactor --- .../settings/ImportDuplicatesFragment.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java index cf0b2cceea..f8c97dd82a 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java @@ -56,6 +56,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View private ProgressBar progressBar; private CollapsingToolbarLayout toolbarLayout; private TextView description; + private SettingsHelper settingsHelper; public static void showInstance(@NonNull FragmentManager fm, List duplicatesList, List settingsItems, File file) { @@ -73,23 +74,25 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); app = requireMyApplication(); + settingsHelper = app.getSettingsHelper(); nightMode = !app.getSettings().isLightContent(); if (settingsItems == null) { - settingsItems = app.getSettingsHelper().getSelectedItems(); + settingsItems = settingsHelper.getSelectedItems(); } if (duplicatesList == null) { - duplicatesList = app.getSettingsHelper().getDuplicatesItems(); + duplicatesList = settingsHelper.getDuplicatesItems(); } if (file == null) { - file = app.getSettingsHelper().getSettingsFile(); + file = settingsHelper.getSettingsFile(); } - SettingsHelper.ImportAsyncTask importAsyncTask = app.getSettingsHelper().getImportTask(); + SettingsHelper.ImportAsyncTask importAsyncTask = settingsHelper.getImportTask(); + List importedItems = settingsHelper.getImportedItems(); if (importAsyncTask != null) { importAsyncTask.setListener(getImportListener()); - } else if (app.getSettingsHelper().getImportedItems() != null) { + } else if (importedItems != null) { FragmentManager fm = getFragmentManager(); if (fm != null) { - ImportCompleteFragment.showInstance(fm, app.getSettingsHelper().getImportedItems(), file.getName()); + ImportCompleteFragment.showInstance(fm, importedItems, file.getName()); } } } @@ -153,7 +156,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View list.setLayoutManager(new LinearLayoutManager(getMyApplication())); list.setAdapter(adapter); } - if (app.getSettingsHelper().isImporting() && !app.getSettingsHelper().isCollectOnly()) { + if (settingsHelper.isImporting() && !settingsHelper.isCollectOnly()) { setupImportingUi(); } else { toolbarLayout.setTitle(getString(R.string.import_duplicates_title)); @@ -253,7 +256,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View for (SettingsItem item : settingsItems) { item.setShouldReplace(shouldReplace); } - app.getSettingsHelper().importSettings(file, settingsItems, "", 1, getImportListener()); + settingsHelper.importSettings(file, settingsItems, "", 1, getImportListener()); } } From 59352429ac7d135e234b2221fb4beee37277ef45 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Mon, 2 Mar 2020 17:45:29 +0200 Subject: [PATCH 09/30] refactor --- OsmAnd/src/net/osmand/plus/SettingsHelper.java | 4 ++++ .../net/osmand/plus/settings/ImportCompleteFragment.java | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index 9cb01a743e..5abfe17f24 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -1990,6 +1990,10 @@ public class SettingsHelper { return selectedItems; } + public void setSelectedItems(@Nullable List selectedItems) { + this.selectedItems = selectedItems; + } + @SuppressLint("StaticFieldLeak") private class ImportItemsAsyncTask extends AsyncTask { diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java index 764447edd7..82563cfdfe 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java @@ -18,6 +18,7 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.SettingsHelper; import net.osmand.plus.SettingsHelper.SettingsItem; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -43,6 +44,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { private List settingsItems; private String fileName; private boolean nightMode; + private SettingsHelper settingsHelper; public static void showInstance(FragmentManager fm, @NonNull List settingsItems, @NonNull String fileName) { @@ -62,9 +64,10 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { fileName = savedInstanceState.getString(FILE_NAME_KEY); } app = requireMyApplication(); + settingsHelper = app.getSettingsHelper(); nightMode = !app.getSettings().isLightContent(); if (settingsItems == null) { - settingsItems = app.getSettingsHelper().getImportedItems(); + settingsItems = settingsHelper.getImportedItems(); if (settingsItems == null) { dismissFragment(); } @@ -127,7 +130,8 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { if (fm != null) { fm.popBackStack(IMPORT_SETTINGS_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); } - app.getSettingsHelper().setImportedItems(null); + settingsHelper.setImportedItems(null); + settingsHelper.setSelectedItems(null); } private void navigateTo(AdditionalDataWrapper.Type type) { From 50a4cb244d8cffbe476fc34299222972533b5c52 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Mon, 2 Mar 2020 18:36:11 +0200 Subject: [PATCH 10/30] refactor / corrections --- .../src/net/osmand/plus/SettingsHelper.java | 21 ++----------------- .../settings/DuplicatesSettingsAdapter.java | 5 +++-- .../settings/ExportImportSettingsAdapter.java | 3 ++- .../plus/settings/ImportSettingsFragment.java | 5 +++-- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index 5abfe17f24..ad649b6e89 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -2111,7 +2111,6 @@ public class SettingsHelper { checkingDuplicates = true; checkDuplicatesTask = this; startTime = System.currentTimeMillis(); - super.onPreExecute(); } @Override @@ -2135,7 +2134,6 @@ public class SettingsHelper { listener.onDuplicatesChecked(objects, this.items); } checkingDuplicates = false; - super.onPostExecute(objects); } private List getDuplicatesData(List items) { @@ -2145,18 +2143,8 @@ public class SettingsHelper { 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(); + } else if (item instanceof SettingsHelper.CollectionSettingsItem) { + List duplicates = ((CollectionSettingsItem) item).excludeDuplicateItems(); if (!duplicates.isEmpty()) { duplicateItems.addAll(duplicates); } @@ -2164,11 +2152,6 @@ public class SettingsHelper { 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; diff --git a/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java index 99c9f83e95..3bb9f9ee51 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java @@ -9,6 +9,7 @@ import android.widget.ImageView; import android.widget.TextView; import net.osmand.AndroidUtils; +import net.osmand.IndexConstants; import net.osmand.map.ITileSource; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode.ApplicationModeBean; @@ -111,10 +112,10 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter Date: Mon, 2 Mar 2020 18:50:51 +0200 Subject: [PATCH 11/30] poi types opens categories tab --- .../plus/settings/ImportCompleteFragment.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java index 82563cfdfe..7a67f6707f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java @@ -136,6 +136,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { private void navigateTo(AdditionalDataWrapper.Type type) { FragmentManager fm = getFragmentManager(); + Activity activity = requireActivity(); if (fm == null) { return; } @@ -155,10 +156,18 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { .addToBackStack(QuickActionListFragment.TAG).commit(); break; case POI_TYPES: - new QuickSearchDialogFragment().show(fm, QuickSearchDialogFragment.TAG); + if (activity instanceof MapActivity) { + QuickSearchDialogFragment.showInstance( + (MapActivity) activity, + "", + null, + QuickSearchDialogFragment.QuickSearchType.REGULAR, + QuickSearchDialogFragment.QuickSearchTab.CATEGORIES, + null + ); + } break; case MAP_SOURCES: - Activity activity = requireActivity(); if (activity instanceof MapActivity) { ((MapActivity) activity).getDashboard() .setDashboardVisibility( From 0849d736b955f580780d5d56f72e9298262d8cb3 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Tue, 3 Mar 2020 10:49:56 +0200 Subject: [PATCH 12/30] change subtitle "items added:" --- OsmAnd/res/values/strings.xml | 4 +-- .../ImportedSettingsItemsAdapter.java | 25 +------------------ 2 files changed, 2 insertions(+), 27 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 33981d82e2..395ffd501d 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -14,9 +14,7 @@ Importing data from %1$s Importing OsmAnd check %1$s for duplicates with existing items in the application.\n\nIt may take some time. - Added: %1$s item - Added: %1$s items - Added: %1$s items + Items added: %1$s Quick action Import complete All data from the %1$s is imported, you can use buttons below to open needed part of the application to manage it. diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java index f40aefff11..ed7681c891 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java @@ -60,7 +60,7 @@ public class ImportedSettingsItemsAdapter extends listener.onItemClick(currentItem.getType()); } }); - setupSubTitle(holder.subTitle, currentItem.getItems().size()); + holder.subTitle.setText(String.format(app.getString(R.string.items_added), String.valueOf(currentItem.getItems().size()))); switch (currentItem.getType()) { case PROFILE: @@ -94,29 +94,6 @@ public class ImportedSettingsItemsAdapter extends } } - private void setupSubTitle(TextView subTitle, int count) { - int stringRes; - if (count > 100) - count %= 100; - if (count > 20) - count %= 10; - switch (count) { - case 1: - stringRes = R.string.added_one_item; - break; - case 2: - case 3: - case 4: - stringRes = R.string.added_two_items; - break; - default: - stringRes = R.string.added_five_items; - break; - } - subTitle.setText(String.format(app.getString(stringRes), String.valueOf(count))); - } - - @Override public int getItemCount() { return items.size(); From 39513938349f674a07f0a1fda649416aa21cc1ab Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 4 Mar 2020 10:20:55 +0200 Subject: [PATCH 13/30] refactor --- OsmAnd/res/values/strings.xml | 2 +- .../osmand/plus/settings/ImportedSettingsItemsAdapter.java | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 395ffd501d..2b102f4e55 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -14,7 +14,7 @@ Importing data from %1$s Importing OsmAnd check %1$s for duplicates with existing items in the application.\n\nIt may take some time. - Items added: %1$s + Items added Quick action Import complete All data from the %1$s is imported, you can use buttons below to open needed part of the application to manage it. diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java index ed7681c891..c0d37ca935 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java @@ -60,7 +60,11 @@ public class ImportedSettingsItemsAdapter extends listener.onItemClick(currentItem.getType()); } }); - holder.subTitle.setText(String.format(app.getString(R.string.items_added), String.valueOf(currentItem.getItems().size()))); + 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())) + ); switch (currentItem.getType()) { case PROFILE: From fb2643b98a09b2bcbc5ca6eb2448a472c349ccaf Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 4 Mar 2020 10:30:05 +0200 Subject: [PATCH 14/30] refactor --- OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java index 7a67f6707f..7c7840c3e9 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java @@ -54,7 +54,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { fm.beginTransaction() .replace(R.id.fragmentContainer, fragment, TAG) .addToBackStack(IMPORT_SETTINGS_TAG) - .commit(); + .commitAllowingStateLoss(); } @Override From 3f9dc403809743e4bf58d1cd339fa9e5218665e9 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Thu, 5 Mar 2020 11:34:06 +0200 Subject: [PATCH 15/30] imports conflicts --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 3 +++ .../osmand/plus/settings/ImportCompleteFragment.java | 11 ++++++----- .../plus/settings/ImportDuplicatesFragment.java | 2 ++ .../osmand/plus/settings/ImportSettingsFragment.java | 3 +++ .../plus/settings/ImportedSettingsItemsAdapter.java | 5 +++-- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index c3bad834a2..4608b6dfec 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -12,6 +12,9 @@ import android.graphics.drawable.RippleDrawable; import android.hardware.Sensor; import android.hardware.SensorManager; import android.os.Build; +import android.text.SpannableString; +import android.text.Spanned; +import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java index 7c7840c3e9..edb68f68e9 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java @@ -4,17 +4,18 @@ import android.app.Activity; import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.FragmentManager; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.FragmentManager; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java index 83928b3059..b4039b1870 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java @@ -21,6 +21,8 @@ import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.google.android.material.appbar.CollapsingToolbarLayout; + import net.osmand.AndroidUtils; import net.osmand.map.ITileSource; import net.osmand.plus.AppInitializer; diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index 1296b338f8..56f58d0275 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -5,6 +5,7 @@ import android.content.DialogInterface; import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; +import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -20,6 +21,8 @@ import androidx.appcompat.widget.Toolbar; import androidx.core.view.ViewCompat; import androidx.fragment.app.FragmentManager; +import com.google.android.material.appbar.CollapsingToolbarLayout; + import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.map.ITileSource; diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java index c0d37ca935..8ce32751f3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java @@ -1,13 +1,14 @@ package net.osmand.plus.settings; -import android.support.annotation.NonNull; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; From 6e70a32756ecbdae4b06e1960bcb8948a099ef30 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Thu, 5 Mar 2020 13:46:36 +0200 Subject: [PATCH 16/30] androidx refactor --- .../res/layout/fragment_import_complete.xml | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/OsmAnd/res/layout/fragment_import_complete.xml b/OsmAnd/res/layout/fragment_import_complete.xml index 25069b6a0f..b0af290996 100644 --- a/OsmAnd/res/layout/fragment_import_complete.xml +++ b/OsmAnd/res/layout/fragment_import_complete.xml @@ -1,12 +1,12 @@ - - - - + - - - + osmand:title="@string/shared_string_import_complete"/> - - - + - + - + From adb9464de5df3136d045e7c4f7b10e373107ab6c Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 11 Mar 2020 13:29:28 +0200 Subject: [PATCH 17/30] refactor / three state importTask --- .../src/net/osmand/plus/SettingsHelper.java | 252 ++++++++---------- .../plus/settings/ImportCompleteFragment.java | 22 +- .../settings/ImportDuplicatesFragment.java | 39 ++- .../plus/settings/ImportSettingsFragment.java | 101 ++++--- 4 files changed, 192 insertions(+), 222 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index e6de24fcea..f9c67faf8b 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -104,9 +104,6 @@ public class SettingsHelper { private boolean checkingDuplicates; private ImportAsyncTask importTask; private Map exportAsyncTasks = new HashMap<>(); - private CheckDuplicatesTask checkDuplicatesTask; - private List importedItems; - private List selectedItems; public interface SettingsImportListener { void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items); @@ -1828,36 +1825,52 @@ public class SettingsHelper { private String latestChanges; private int version; - private SettingsImportListener listener; + private SettingsImportListener importListener; + private CheckDuplicatesListener duplicatesListener; private SettingsImporter importer; private List items = new ArrayList<>(); + private List selectedItems = new ArrayList<>(); private List processedItems = new ArrayList<>(); private SettingsItem currentItem; private AlertDialog dialog; + private State state; + private List duplicates; - ImportAsyncTask(@NonNull File settingsFile, String latestChanges, int version, @Nullable SettingsImportListener listener) { - this.file = settingsFile; - this.listener = listener; + ImportAsyncTask(@NonNull File file, String latestChanges, int version, @Nullable SettingsImportListener importListener) { + this.file = file; + this.importListener = importListener; this.latestChanges = latestChanges; this.version = version; importer = new SettingsImporter(app); collectOnly = true; + state = State.COLLECT; } - ImportAsyncTask(@NonNull File settingsFile, @NonNull List items, String latestChanges, int version, @Nullable SettingsImportListener listener) { - this.file = settingsFile; - this.listener = listener; + ImportAsyncTask(@NonNull File file, @NonNull List items, String latestChanges, int version, @Nullable SettingsImportListener importListener) { + this.file = file; + this.importListener = importListener; this.items = items; this.latestChanges = latestChanges; this.version = version; importer = new SettingsImporter(app); collectOnly = false; + state = State.IMPORT; + } + + ImportAsyncTask(@NonNull File file, @NonNull List items, @NonNull List selectedItems, @Nullable CheckDuplicatesListener duplicatesListener) { + this.file = file; + this.items = items; + this.duplicatesListener = duplicatesListener; + this.selectedItems = selectedItems; + importer = new SettingsImporter(app); + collectOnly = true; + state = State.CHECK_DUPLICATES; } @Override protected void onPreExecute() { if (importing) { - finishImport(listener, false, false, items); + finishImport(importListener, false, false, items); } importing = true; importSuspended = false; @@ -1866,29 +1879,58 @@ public class SettingsHelper { @Override protected List doInBackground(Void... voids) { - if (collectOnly) { - try { - return importer.collectItems(file); - } catch (IllegalArgumentException e) { - LOG.error("Failed to collect items from: " + file.getName(), e); - } catch (IOException e) { - LOG.error("Failed to collect items from: " + file.getName(), e); - } - } else { - return this.items; + switch (state) { + case COLLECT: + try { + return importer.collectItems(file); + } catch (IllegalArgumentException e) { + LOG.error("Failed to collect items from: " + file.getName(), e); + } catch (IOException e) { + LOG.error("Failed to collect items from: " + file.getName(), e); + } + break; + case CHECK_DUPLICATES: + checkingDuplicates = true; + long startTime = System.currentTimeMillis(); + List duplicatesData = getDuplicatesData(this.selectedItems); + long diffTime = System.currentTimeMillis() - startTime; + if (diffTime < 500 && diffTime >= 0) { + try { + Thread.sleep(500 - diffTime); + } catch (InterruptedException e) { + LOG.error("Error on check duplicates delay" + e); + } + } + this.duplicates = duplicatesData; + return selectedItems; + case IMPORT: + return this.items; } return null; } @Override protected void onPostExecute(@Nullable List items) { - if (items != null) { + if (items != null && !State.CHECK_DUPLICATES.equals(state)) { this.items = items; + } else { + selectedItems = items; } - if (collectOnly) { - listener.onSettingsImportFinished(true, false, this.items); - } else if (items != null && items.size() > 0) { - processNextItem(); + switch (state) { + case COLLECT: + importListener.onSettingsImportFinished(true, false, this.items); + break; + case CHECK_DUPLICATES: + checkingDuplicates = false; + if (duplicatesListener != null) { + duplicatesListener.onDuplicatesChecked(duplicates, this.selectedItems); + } + break; + case IMPORT: + if (items != null && items.size() > 0) { + processNextItem(); + } + break; } } @@ -1898,9 +1940,9 @@ public class SettingsHelper { } if (items.size() == 0 && !importSuspended) { if (processedItems.size() > 0) { - new ImportItemsAsyncTask(file, listener, processedItems).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new ImportItemsAsyncTask(file, importListener, processedItems).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } else { - finishImport(listener, false, true, items); + finishImport(importListener, false, true, items); } return; } @@ -1942,38 +1984,46 @@ public class SettingsHelper { return this.file; } - public void setListener(SettingsImportListener listener) { - this.listener = listener; + public void setImportListener(SettingsImportListener importListener) { + this.importListener = importListener; } - } - @Nullable - public List getSettingsItems() { - return importTask != null ? importTask.getItems() : null; - } + public void setDuplicatesListener(CheckDuplicatesListener duplicatesListener) { + this.duplicatesListener = duplicatesListener; + } - @Nullable - public File getSettingsFile() { - return importTask != null ? importTask.getFile() : null; - } + public State getState() { + return this.state; + } - @Nullable - public List getImportedItems() { - return importedItems; - } + public List getDuplicates() { + return this.duplicates; + } - @Nullable - public List getDuplicatesItems() { - return checkDuplicatesTask != null ? checkDuplicatesTask.getDuplicates() : null; - } + public List getSelectedItems() { + return this.selectedItems; + } - public void setImportedItems(@Nullable List importedItems) { - this.importedItems = importedItems; - } - - @Nullable - public CheckDuplicatesTask getCheckDuplicatesTask() { - return checkDuplicatesTask; + 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.CollectionSettingsItem) { + List duplicates = ((CollectionSettingsItem) item).excludeDuplicateItems(); + if (!duplicates.isEmpty()) { + duplicateItems.addAll(duplicates); + } + } else if (item instanceof SettingsHelper.FileSettingsItem) { + if (item.exists()) { + duplicateItems.add(((SettingsHelper.FileSettingsItem) item).getFile()); + } + } + } + return duplicateItems; + } } @Nullable @@ -1982,12 +2032,8 @@ public class SettingsHelper { } @Nullable - public List getSelectedItems() { - return selectedItems; - } - - public void setSelectedItems(@Nullable List selectedItems) { - this.selectedItems = selectedItems; + public State getImportTaskState() { + return importTask != null ? importTask.getState() : null; } public boolean isFileExporting(File file) { @@ -2041,11 +2087,9 @@ public class SettingsHelper { importing = false; importSuspended = false; importTask = null; - checkDuplicatesTask = null; if (listener != null) { listener.onSettingsImportFinished(success, empty, items); } - importedItems = items; } @SuppressLint("StaticFieldLeak") @@ -2088,82 +2132,8 @@ public class SettingsHelper { } } - @SuppressLint("StaticFieldLeak") - public class CheckDuplicatesTask extends AsyncTask> { - - private List items; - private List duplicates; - private CheckDuplicatesListener listener; - private long startTime; - - CheckDuplicatesTask(@NonNull List items, CheckDuplicatesListener listener) { - this.items = items; - this.listener = listener; - } - - @Override - protected void onPreExecute() { - selectedItems = this.items; - checkingDuplicates = true; - checkDuplicatesTask = this; - startTime = System.currentTimeMillis(); - } - - @Override - protected List doInBackground(Void... voids) { - long currentTime = System.currentTimeMillis(); - List duplicateItems = getDuplicatesData(this.items); - if (currentTime - startTime < 700) { - try { - Thread.sleep(500); - } catch (InterruptedException e) { - LOG.error("Error on check duplicates delay" + e); - } - } - return duplicateItems; - } - - @Override - protected void onPostExecute(List objects) { - duplicates = objects; - if (listener != null) { - listener.onDuplicatesChecked(objects, this.items); - } - checkingDuplicates = false; - } - - 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.CollectionSettingsItem) { - List duplicates = ((CollectionSettingsItem) item).excludeDuplicateItems(); - if (!duplicates.isEmpty()) { - duplicateItems.addAll(duplicates); - } - } else if (item instanceof SettingsHelper.FileSettingsItem) { - if (item.exists()) { - duplicateItems.add(((SettingsHelper.FileSettingsItem) item).getFile()); - } - } - } - return duplicateItems; - } - - public void setListener(CheckDuplicatesListener listener) { - this.listener = listener; - } - - List getDuplicates() { - return duplicates; - } - } - - public void checkDuplicates(@NonNull List items, CheckDuplicatesListener listener) { - new CheckDuplicatesTask(items, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + public void checkDuplicates(@NonNull File file, @NonNull List items, @NonNull List selectedItems, CheckDuplicatesListener listener) { + new ImportAsyncTask(file, items, selectedItems, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } public void importSettings(@NonNull File settingsFile, String latestChanges, int version, @@ -2186,4 +2156,10 @@ public class SettingsHelper { @NonNull SettingsItem... items) { exportSettings(fileDir, fileName, listener, new ArrayList<>(Arrays.asList(items))); } + + public enum State { + COLLECT, + CHECK_DUPLICATES, + IMPORT + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java index edb68f68e9..56f8cb6015 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java @@ -19,7 +19,6 @@ import androidx.recyclerview.widget.RecyclerView; import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.SettingsHelper; import net.osmand.plus.SettingsHelper.SettingsItem; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; @@ -39,19 +38,18 @@ 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 boolean nightMode; - private SettingsHelper settingsHelper; public static void showInstance(FragmentManager fm, @NonNull List settingsItems, @NonNull String fileName) { ImportCompleteFragment fragment = new ImportCompleteFragment(); fragment.setSettingsItems(settingsItems); fragment.setFileName(fileName); + fragment.setRetainInstance(true); fm.beginTransaction() .replace(R.id.fragmentContainer, fragment, TAG) .addToBackStack(IMPORT_SETTINGS_TAG) @@ -61,18 +59,8 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (savedInstanceState != null) { - fileName = savedInstanceState.getString(FILE_NAME_KEY); - } app = requireMyApplication(); - settingsHelper = app.getSettingsHelper(); nightMode = !app.getSettings().isLightContent(); - if (settingsItems == null) { - settingsItems = settingsHelper.getImportedItems(); - if (settingsItems == null) { - dismissFragment(); - } - } } @Nullable @@ -120,19 +108,11 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { } } - @Override - public void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - outState.putString(FILE_NAME_KEY, fileName); - } - public void dismissFragment() { FragmentManager fm = getFragmentManager(); if (fm != null) { fm.popBackStack(IMPORT_SETTINGS_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); } - settingsHelper.setImportedItems(null); - settingsHelper.setSelectedItems(null); } private void navigateTo(AdditionalDataWrapper.Type type) { diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java index b4039b1870..5a5286851f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java @@ -79,24 +79,18 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View app = requireMyApplication(); settingsHelper = app.getSettingsHelper(); nightMode = !app.getSettings().isLightContent(); - if (settingsItems == null) { - settingsItems = settingsHelper.getSelectedItems(); - } - if (duplicatesList == null) { - duplicatesList = settingsHelper.getDuplicatesItems(); - } - if (file == null) { - file = settingsHelper.getSettingsFile(); - } - SettingsHelper.ImportAsyncTask importAsyncTask = settingsHelper.getImportTask(); - List importedItems = settingsHelper.getImportedItems(); - if (importAsyncTask != null) { - importAsyncTask.setListener(getImportListener()); - } else if (importedItems != null) { - FragmentManager fm = getFragmentManager(); - if (fm != null) { - ImportCompleteFragment.showInstance(fm, importedItems, file.getName()); + SettingsHelper.ImportAsyncTask importTask = settingsHelper.getImportTask(); + if (importTask != null) { + if (settingsItems == null) { + settingsItems = importTask.getSelectedItems(); } + if (duplicatesList == null) { + duplicatesList = importTask.getDuplicates(); + } + if (file == null) { + file = importTask.getFile(); + } + importTask.setImportListener(getImportListener()); } } @@ -150,20 +144,21 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View return root; } - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); if (duplicatesList != null) { DuplicatesSettingsAdapter adapter = new DuplicatesSettingsAdapter(app, prepareDuplicates(duplicatesList), nightMode); list.setLayoutManager(new LinearLayoutManager(getMyApplication())); list.setAdapter(adapter); } - if (settingsHelper.isImporting() && !settingsHelper.isCollectOnly()) { + SettingsHelper.State state = settingsHelper.getImportTaskState(); + if (settingsHelper.isImporting() && !settingsHelper.isCollectOnly() && state != null && state.equals(SettingsHelper.State.IMPORT)) { setupImportingUi(); } else { toolbarLayout.setTitle(getString(R.string.import_duplicates_title)); } + toolbarLayout.setTitle(getString(R.string.import_duplicates_title)); } private List prepareDuplicates(List duplicatesList) { @@ -287,7 +282,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View } }); FragmentManager fm = getFragmentManager(); - if (fm != null) { + if (fm != null && file != null) { ImportCompleteFragment.showInstance(fm, items, file.getName()); } } else if (empty) { diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index 56f58d0275..20b1365f27 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -1,7 +1,9 @@ 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; @@ -25,6 +27,7 @@ import com.google.android.material.appbar.CollapsingToolbarLayout; import net.osmand.AndroidUtils; import net.osmand.IndexConstants; +import net.osmand.PlatformUtil; import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager; import net.osmand.plus.AppInitializer; @@ -33,6 +36,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.SettingsHelper; +import net.osmand.plus.SettingsHelper.ImportAsyncTask; import net.osmand.plus.SettingsHelper.SettingsItem; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.BaseOsmAndFragment; @@ -43,6 +47,8 @@ import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.widgets.TextViewEx; +import org.apache.commons.logging.Log; + import java.io.File; import java.util.ArrayList; import java.util.List; @@ -51,7 +57,8 @@ public class ImportSettingsFragment extends BaseOsmAndFragment implements View.OnClickListener { public static final String TAG = ImportSettingsFragment.class.getSimpleName(); - public static final String IMPORT_SETTINGS_TAG = "import_settings_tag"; + public static final Log LOG = PlatformUtil.getLog(ImportSettingsFragment.class.getSimpleName()); + static final String IMPORT_SETTINGS_TAG = "import_settings_tag"; private OsmandApplication app; private ExportImportSettingsAdapter adapter; private ExpandableListView expandableList; @@ -77,33 +84,11 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } @Override - public void onCreate(Bundle savedInstanceState) { + public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); app = requireMyApplication(); settingsHelper = app.getSettingsHelper(); nightMode = !app.getSettings().isLightContent(); - if (settingsItems == null) { - settingsItems = app.getSettingsHelper().getSettingsItems(); - } - if (file == null) { - file = app.getSettingsHelper().getSettingsFile(); - } - List duplicates = settingsHelper.getDuplicatesItems(); - if (duplicates == null) { - SettingsHelper.CheckDuplicatesTask checkDuplicatesTask = settingsHelper.getCheckDuplicatesTask(); - if (checkDuplicatesTask != null) { - settingsHelper.getCheckDuplicatesTask().setListener(getDuplicatesListener()); - } - } else { - FragmentManager fm = getFragmentManager(); - if (duplicates.isEmpty()) { - app.getSettingsHelper().importSettings(file, settingsItems, "", 1, getImportListener()); - } else { - if (fm != null) { - ImportDuplicatesFragment.showInstance(fm, duplicates, settingsItems, file); - } - } - } } @Nullable @@ -133,17 +118,44 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); + public void onActivityCreated(@Nullable Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + ImportAsyncTask importAsyncTask = settingsHelper.getImportTask(); + if (importAsyncTask != null) { + if (settingsItems == null) { + settingsItems = importAsyncTask.getItems(); + } + if (file == null) { + file = importAsyncTask.getFile(); + } + List duplicates = importAsyncTask.getDuplicates(); + List selectedItems = importAsyncTask.getSelectedItems(); + if (duplicates == null) { + importAsyncTask.setDuplicatesListener(getDuplicatesListener()); + } else if (duplicates.isEmpty()) { + if (selectedItems != null && file != null) { + 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); if (settingsItems != null) { adapter.updateSettingsList(getSettingsToOperate(settingsItems)); } expandableList.setAdapter(adapter); + toolbarLayout.setTitle(getString(R.string.shared_string_import)); + SettingsHelper.State state = settingsHelper.getImportTaskState(); if (settingsHelper.isCheckingDuplicates()) { updateUi(R.string.shared_string_preparing, R.string.checking_for_duplicate_description); - } else if (settingsHelper.isImporting() && !settingsHelper.isCollectOnly()) { + } else if (settingsHelper.isImporting() && !settingsHelper.isCollectOnly() && state != null && state.equals(SettingsHelper.State.IMPORT)) { updateUi(R.string.shared_string_importing, R.string.importing_from); } else { toolbarLayout.setTitle(getString(R.string.shared_string_import)); @@ -171,21 +183,26 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } private void updateUi(int toolbarTitleRes, int descriptionRes) { - toolbarLayout.setTitle(getString(toolbarTitleRes)); - description.setText(UiUtilities.createSpannableString( - String.format(getString(descriptionRes), file.getName()), - file.getName(), - new StyleSpan(Typeface.BOLD) - )); - buttonsContainer.setVisibility(View.GONE); - progressBar.setVisibility(View.VISIBLE); - adapter.clearSettingsList(); + if (file != null) { + String fileName = file.getName(); + toolbarLayout.setTitle(getString(toolbarTitleRes)); + description.setText(UiUtilities.createSpannableString( + String.format(getString(descriptionRes), fileName), + fileName, + new StyleSpan(Typeface.BOLD) + )); + buttonsContainer.setVisibility(View.GONE); + progressBar.setVisibility(View.VISIBLE); + adapter.clearSettingsList(); + } } private void importItems() { updateUi(R.string.shared_string_preparing, R.string.checking_for_duplicate_description); - List settingsItems = getSettingsItemsFromData(adapter.getDataToOperate()); - settingsHelper.checkDuplicates(settingsItems, getDuplicatesListener()); + List selectedItems = getSettingsItemsFromData(adapter.getDataToOperate()); + if (file != null && settingsItems != null) { + settingsHelper.checkDuplicates(file, settingsItems, selectedItems, getDuplicatesListener()); + } } private SettingsHelper.SettingsImportListener getImportListener() { @@ -200,7 +217,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment public void onRoutingFilesLoaded() { } }); - if (fm != null) { + if (fm != null && file != null) { ImportCompleteFragment.showInstance(fm, items, file.getName()); } } else if (empty) { @@ -220,9 +237,11 @@ public class ImportSettingsFragment extends BaseOsmAndFragment if (isAdded()) { updateUi(R.string.shared_string_importing, R.string.importing_from); } - settingsHelper.importSettings(file, items, "", 1, getImportListener()); + if (file != null) { + settingsHelper.importSettings(file, items, "", 1, getImportListener()); + } } else { - if (fm != null) { + if (fm != null && file != null) { if (!isStateSaved()) { ImportDuplicatesFragment.showInstance(fm, duplicates, items, file); } From c89450c694ac30041857bbf51dfd6eeca0282d1b Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 11 Mar 2020 16:08:57 +0200 Subject: [PATCH 18/30] remove AdditionalDataWrapper --- .../plus/profiles/AdditionalDataWrapper.java | 37 -------------- .../settings/ExportImportSettingsAdapter.java | 49 ++++++++++++------- .../settings/ExportProfileBottomSheet.java | 37 +++++--------- .../plus/settings/ImportCompleteFragment.java | 6 +-- .../plus/settings/ImportSettingsFragment.java | 48 +++++------------- .../ImportedSettingsItemsAdapter.java | 26 +++++----- 6 files changed, 73 insertions(+), 130 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/profiles/AdditionalDataWrapper.java diff --git a/OsmAnd/src/net/osmand/plus/profiles/AdditionalDataWrapper.java b/OsmAnd/src/net/osmand/plus/profiles/AdditionalDataWrapper.java deleted file mode 100644 index c0300b6e9b..0000000000 --- a/OsmAnd/src/net/osmand/plus/profiles/AdditionalDataWrapper.java +++ /dev/null @@ -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 - } -} diff --git a/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java index 7ed3dc2654..f67887ea4d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java @@ -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 dataToOperate; - private List dataList; + private Map> itemsMap; + private List 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 settingsList) { - this.dataList = settingsList; + public void updateSettingsList(Map> 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> map : itemsMap.entrySet()) { + dataToOperate.addAll(map.getValue()); } } notifyDataSetChanged(); @@ -308,4 +313,14 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { List getDataToOperate() { return this.dataToOperate; } + + public enum Type { + PROFILE, + QUICK_ACTIONS, + POI_TYPES, + MAP_SOURCES, + CUSTOM_RENDER_STYLE, + CUSTOM_ROUTING, + AVOID_ROADS + } } diff --git a/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java index 50e64c838f..b6ac83cf9f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java @@ -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 dataList = new ArrayList<>(); + private Map> dataList = new HashMap<>(); private ExportImportSettingsAdapter adapter; private SettingsHelper.SettingsExportListener exportListener; @@ -214,22 +215,18 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet { } } - private List getAdditionalData() { - List dataList = new ArrayList<>(); + private Map> getAdditionalData() { + Map> dataList = new HashMap<>(); QuickActionFactory factory = new QuickActionFactory(); List 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 poiList = app.getPoiFilters().getUserDefinedPoiFilters(false); if (!poiList.isEmpty()) { - dataList.add(new AdditionalDataWrapper( - AdditionalDataWrapper.Type.POI_TYPES, - poiList - )); + dataList.put(Type.POI_TYPES, poiList); } List 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 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 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; } diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java index 56f8cb6015..9b52bf23ee 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java @@ -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) { diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index 20b1365f27..6eb1aa5014 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -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 getSettingsToOperate(List settingsItems) { - List settingsToOperate = new ArrayList<>(); + public static Map> getSettingsToOperate(List settingsItems) { + Map> settingsToOperate = new HashMap<>(); List profiles = new ArrayList<>(); List quickActions = new ArrayList<>(); List 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; } diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java index 8ce32751f3..b2f074cab2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java @@ -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 { - private List items; + private Map> itemsMap; + private List itemsTypes; private UiUtilities uiUtils; private OsmandApplication app; private boolean nightMode; private OnItemClickListener listener; - ImportedSettingsItemsAdapter(@NonNull OsmandApplication app, @NonNull List items, + ImportedSettingsItemsAdapter(@NonNull OsmandApplication app, Map> 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); } } From a375f5a6da8615a927c8ebd01bce8dceed95b6f8 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 11 Mar 2020 16:15:47 +0200 Subject: [PATCH 19/30] resolve conflict --- .../src/net/osmand/plus/settings/ImportDuplicatesFragment.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java index 5b78cba73d..c202a1625a 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java @@ -1,6 +1,5 @@ package net.osmand.plus.settings; -import android.graphics.drawable.Drawable; import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; @@ -17,7 +16,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.core.widget.NestedScrollView; -import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; From 94594b81c21e051af5f1a8b7959559a95b254436 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Wed, 11 Mar 2020 18:13:53 +0200 Subject: [PATCH 20/30] remove duplicate string --- OsmAnd/res/values-ar/strings.xml | 1 - OsmAnd/res/values-b+ast/strings.xml | 1 - OsmAnd/res/values-be/strings.xml | 1 - OsmAnd/res/values-bg/strings.xml | 1 - OsmAnd/res/values-ca/strings.xml | 1 - OsmAnd/res/values-da/strings.xml | 1 - OsmAnd/res/values-de/strings.xml | 1 - OsmAnd/res/values-el/strings.xml | 1 - OsmAnd/res/values-eo/strings.xml | 1 - OsmAnd/res/values-es-rAR/strings.xml | 1 - OsmAnd/res/values-es-rUS/strings.xml | 1 - OsmAnd/res/values-eu/strings.xml | 1 - OsmAnd/res/values-fa/strings.xml | 1 - OsmAnd/res/values-fi/strings.xml | 1 - OsmAnd/res/values-fr/strings.xml | 1 - OsmAnd/res/values-gl/strings.xml | 1 - OsmAnd/res/values-he/strings.xml | 1 - OsmAnd/res/values-hr/strings.xml | 1 - OsmAnd/res/values-is/strings.xml | 1 - OsmAnd/res/values-it/strings.xml | 1 - OsmAnd/res/values-nl/strings.xml | 1 - OsmAnd/res/values-pl/strings.xml | 1 - OsmAnd/res/values-pt-rBR/strings.xml | 1 - OsmAnd/res/values-ru/strings.xml | 1 - OsmAnd/res/values-sc/strings.xml | 1 - OsmAnd/res/values-sk/strings.xml | 1 - OsmAnd/res/values-sl/strings.xml | 1 - OsmAnd/res/values-sr/strings.xml | 1 - OsmAnd/res/values-tr/strings.xml | 1 - OsmAnd/res/values-uk/strings.xml | 1 - OsmAnd/res/values-zh-rTW/strings.xml | 1 - OsmAnd/res/values/strings.xml | 2 -- .../net/osmand/plus/settings/ImportedSettingsItemsAdapter.java | 2 +- 33 files changed, 1 insertion(+), 34 deletions(-) diff --git a/OsmAnd/res/values-ar/strings.xml b/OsmAnd/res/values-ar/strings.xml index 9b5344c2f8..1b52eed72f 100644 --- a/OsmAnd/res/values-ar/strings.xml +++ b/OsmAnd/res/values-ar/strings.xml @@ -3509,7 +3509,6 @@ تحضير أنواع النقاط لا شيء محدد - إجراءات سريعة الأوضاع سيتم استبدال العناصر الحالية بعناصر من الملف استبدال الكل diff --git a/OsmAnd/res/values-b+ast/strings.xml b/OsmAnd/res/values-b+ast/strings.xml index 09bf00052f..2fc1ec8a61 100644 --- a/OsmAnd/res/values-b+ast/strings.xml +++ b/OsmAnd/res/values-b+ast/strings.xml @@ -1452,7 +1452,6 @@ Preparando Tipos de PDI Nun hai nada seleicionao - Aiciones rápides Perfiles %1$s llistáu, yá existe n\'OsmAnd. Los elementos actuales sustituiránse por elementos del ficheru diff --git a/OsmAnd/res/values-be/strings.xml b/OsmAnd/res/values-be/strings.xml index 3d4c353fab..df3dcdc871 100644 --- a/OsmAnd/res/values-be/strings.xml +++ b/OsmAnd/res/values-be/strings.xml @@ -3514,7 +3514,6 @@ Падрыхтоўка Тыпы POI Нічога не абрана - Хуткія дзеянні Профілі Дадзеныя %1$s ужо ёсць у OsmAnd. Бягучыя элементы заменяцца элементамі з файла diff --git a/OsmAnd/res/values-bg/strings.xml b/OsmAnd/res/values-bg/strings.xml index 427b1ecddd..9c49dff48d 100644 --- a/OsmAnd/res/values-bg/strings.xml +++ b/OsmAnd/res/values-bg/strings.xml @@ -2012,7 +2012,6 @@ Подготовка Тип POI Нищо не е избрано - Бързи действия Профили Изброените %1$s, вече съществуват в OsmAnd. Текущите елементи ще бъдат заменени с елементи от файлът diff --git a/OsmAnd/res/values-ca/strings.xml b/OsmAnd/res/values-ca/strings.xml index 3cc40cb5f5..22080bba05 100644 --- a/OsmAnd/res/values-ca/strings.xml +++ b/OsmAnd/res/values-ca/strings.xml @@ -3515,7 +3515,6 @@ Abasta l\'àrea: %1$s x %2$s Preparant Tipus de PDI No hi ha res seleccionat - Accions directes Perfils Els llistats %1$s ja existeixen a OsmAnd. Els elements actuals es substituiran amb elements de l\'arxiu diff --git a/OsmAnd/res/values-da/strings.xml b/OsmAnd/res/values-da/strings.xml index af7830d80e..c05874fc3e 100644 --- a/OsmAnd/res/values-da/strings.xml +++ b/OsmAnd/res/values-da/strings.xml @@ -3507,7 +3507,6 @@ Repræsenterer område: %1$s x %2$s Forbereder IP typer Intet valgt - Genveje Profiler Aktuelle poster erstattes med poster fra filen Erstat alle diff --git a/OsmAnd/res/values-de/strings.xml b/OsmAnd/res/values-de/strings.xml index 10c76ff843..ea20cd8769 100644 --- a/OsmAnd/res/values-de/strings.xml +++ b/OsmAnd/res/values-de/strings.xml @@ -3553,7 +3553,6 @@ Lon %2$s Winkel Zusätzliches gerades Segment zwischen meinem Standort und berechneter Route wird angezeigt, bis die Route neu berechnet wird Minimaler Winkel zwischen meinem Standort und der Route - Schnellaktionen Profile Die aufgelisteten %1$s sind in OsmAnd bereits vorhanden. Vorbereitung diff --git a/OsmAnd/res/values-el/strings.xml b/OsmAnd/res/values-el/strings.xml index 2762145c25..98a8c07e02 100644 --- a/OsmAnd/res/values-el/strings.xml +++ b/OsmAnd/res/values-el/strings.xml @@ -3515,7 +3515,6 @@ Προετοιμασία Είδη Σημείων Ενδιαφέροντος Τίποτα δεν επιλέχτηκε - Ταχείες ενέργειες Κατανομές Το εισηγμένο %1$s, υπάρχει ήδη στο OsmAnd. Τα τρέχοντα αντικείμενα θα αντικατασταθούν με αντικείμενα από το αρχείο diff --git a/OsmAnd/res/values-eo/strings.xml b/OsmAnd/res/values-eo/strings.xml index dfde0288ce..e2ee15aa1e 100644 --- a/OsmAnd/res/values-eo/strings.xml +++ b/OsmAnd/res/values-eo/strings.xml @@ -3532,7 +3532,6 @@ Indikas lokon: %1$s x %2$s" Preparado Specoj de interesejoj Nenio elektita - Rapidaj agoj Profiloj Listigitaj %1$s jam ekzistas en OsmAnd. La nunaj elementoj estos anstataŭigitaj per elementoj el la dosiero diff --git a/OsmAnd/res/values-es-rAR/strings.xml b/OsmAnd/res/values-es-rAR/strings.xml index 6525182f91..4db4faf562 100644 --- a/OsmAnd/res/values-es-rAR/strings.xml +++ b/OsmAnd/res/values-es-rAR/strings.xml @@ -3551,7 +3551,6 @@ Lon %2$s Preparando Tipos de PDI Nada marcado - Acciones rápidas Perfiles El listado «%1$s», ya existe en OsmAnd. Los elementos actuales serán reemplazados por elementos del archivo diff --git a/OsmAnd/res/values-es-rUS/strings.xml b/OsmAnd/res/values-es-rUS/strings.xml index 99da136cb7..179c5080b4 100644 --- a/OsmAnd/res/values-es-rUS/strings.xml +++ b/OsmAnd/res/values-es-rUS/strings.xml @@ -3551,7 +3551,6 @@ Lon %2$s Preparando Tipos de PDI Nada marcado - Acciones rápidas Perfiles El listado «%1$s», ya existe en OsmAnd. Los elementos actuales serán reemplazados por elementos del archivo diff --git a/OsmAnd/res/values-eu/strings.xml b/OsmAnd/res/values-eu/strings.xml index 80bdd0c360..97547af5c5 100644 --- a/OsmAnd/res/values-eu/strings.xml +++ b/OsmAnd/res/values-eu/strings.xml @@ -3559,7 +3559,6 @@ Area honi dagokio: %1$s x %2$s Prestatzen POI motak Ez da ezer hautatu - Ekintza azkarrak Profilak Zerrendatutako %1$s, badago dagoeneko OsmAnd-en. Uneko elementuak fitxategiko elementuekin ordeztuko dira diff --git a/OsmAnd/res/values-fa/strings.xml b/OsmAnd/res/values-fa/strings.xml index cc460f5237..0c3f670f8b 100644 --- a/OsmAnd/res/values-fa/strings.xml +++ b/OsmAnd/res/values-fa/strings.xml @@ -3577,7 +3577,6 @@ کمترین زاویه میان موقعیت من و مسیر آماده‌سازی چیزی انتخاب نشده - کنش‌های فوری پروفایل‌ها موارد موجود در فایل، جانشین موارد کنونی می‌شود جانشانی همه diff --git a/OsmAnd/res/values-fi/strings.xml b/OsmAnd/res/values-fi/strings.xml index c8df578184..fee2c9dbb5 100644 --- a/OsmAnd/res/values-fi/strings.xml +++ b/OsmAnd/res/values-fi/strings.xml @@ -2524,7 +2524,6 @@ Jos pidät OsmAndista ja OSMsta ja haluat tukea niitä, on tämä täydellinen t Kulma Valmistellaan KP-tyypit - Pikatoiminnot Profiilit Korvaa kaikki Pidä molemmat diff --git a/OsmAnd/res/values-fr/strings.xml b/OsmAnd/res/values-fr/strings.xml index fd15a0938f..a54ad96b59 100644 --- a/OsmAnd/res/values-fr/strings.xml +++ b/OsmAnd/res/values-fr/strings.xml @@ -3521,7 +3521,6 @@ représentant la zone : %1$s x %2$s Préparation en cours Types de PI Aucun élément sélectionné - Actions rapides Profils Les %1$s listés existent déjà dans OsmAnd. Les éléments actuels seront remplacés par les éléments du fichier diff --git a/OsmAnd/res/values-gl/strings.xml b/OsmAnd/res/values-gl/strings.xml index 57389d2426..eac7283aca 100644 --- a/OsmAnd/res/values-gl/strings.xml +++ b/OsmAnd/res/values-gl/strings.xml @@ -3603,7 +3603,6 @@ Lon %2$s Estase a preparar Tipos de PDI Ren selecionado - Accións rápidas Perfís %1$s listado, xa existe no OsmAnd. Os elementos actuais serán substituídos polos elementos do ficheiro diff --git a/OsmAnd/res/values-he/strings.xml b/OsmAnd/res/values-he/strings.xml index c044afc97e..8e81f2dabc 100644 --- a/OsmAnd/res/values-he/strings.xml +++ b/OsmAnd/res/values-he/strings.xml @@ -3509,7 +3509,6 @@ בהכנה סוגי נקודות עניין שום דבר לא נבחר - פעולות מהירות פרופילים הפריטים הנוכחיים יוחלפו בפריטים מהקובץ להחליף הכול diff --git a/OsmAnd/res/values-hr/strings.xml b/OsmAnd/res/values-hr/strings.xml index f388d5da82..b6ae2df8d1 100644 --- a/OsmAnd/res/values-hr/strings.xml +++ b/OsmAnd/res/values-hr/strings.xml @@ -1423,7 +1423,6 @@ Kut Priprema Ništa nije odabrano - Brze akcije Profili Navedene %1$s, već postoje u OsmAnd. Trenutne stavke bit će zamijenjene stavkama iz datoteke diff --git a/OsmAnd/res/values-is/strings.xml b/OsmAnd/res/values-is/strings.xml index 4efe86c52c..52de80cf25 100644 --- a/OsmAnd/res/values-is/strings.xml +++ b/OsmAnd/res/values-is/strings.xml @@ -3560,7 +3560,6 @@ Stendur fyrir svæði: %1$s x %2$s Undirbý Gerðir POI-merkisstaða Ekkert valið - Flýtiaðgerðir Notandasnið Taldi upp %1$s, er þegar til staðar í OsmAnd. Fyrirliggjandi atriðum verður skipt út með atriðum úr skránni diff --git a/OsmAnd/res/values-it/strings.xml b/OsmAnd/res/values-it/strings.xml index f12655e74a..4239c8a359 100644 --- a/OsmAnd/res/values-it/strings.xml +++ b/OsmAnd/res/values-it/strings.xml @@ -3551,7 +3551,6 @@ Rappresenta l\'area: %1$s x %2$s Preparando Tipi di PDI Nessuna selezione - Azioni veloci Profili Gli elencati %1$s, esistono già in OsmAnd. Gli oggetti attuali verranno sostituiti con gli oggetti dal file diff --git a/OsmAnd/res/values-nl/strings.xml b/OsmAnd/res/values-nl/strings.xml index ec361b541a..2029a71fb7 100644 --- a/OsmAnd/res/values-nl/strings.xml +++ b/OsmAnd/res/values-nl/strings.xml @@ -3391,7 +3391,6 @@ voor Gebied: %1$s x %2$s Voorbereiding POI types Niets geselecteerd - Snelle acties Profielen De getoonde %1$s zijn in OsmAnd reeds beschikbaar. Huidige elementen worden vervangen door elementen uit het bestand diff --git a/OsmAnd/res/values-pl/strings.xml b/OsmAnd/res/values-pl/strings.xml index 7dfe770a65..99b2b2f6ae 100644 --- a/OsmAnd/res/values-pl/strings.xml +++ b/OsmAnd/res/values-pl/strings.xml @@ -3561,7 +3561,6 @@ Reprezentuje obszar: %1$s x %2$s Wybierz dane, które mają zostać zaimportowane. Importuj plik routingu Jest to filtr odcięcia niskiej prędkości, który nie rejestruje punktów poniżej określonej prędkości. Może to sprawić, że zarejestrowane ślady będą wyglądać na bardziej płynne podczas przeglądania na mapie. - Szybka czynność Zatrzymaj oba Styl renderowania Zobacz swoje zmiany lub błędy OSM, które nie zostały jeszcze przesłane w %1$s. Przesłane punkty nie będą już wyświetlane. diff --git a/OsmAnd/res/values-pt-rBR/strings.xml b/OsmAnd/res/values-pt-rBR/strings.xml index 27a06c1da1..5f34034430 100644 --- a/OsmAnd/res/values-pt-rBR/strings.xml +++ b/OsmAnd/res/values-pt-rBR/strings.xml @@ -3538,7 +3538,6 @@ Pôr do Sol: %2$s Preparando Tipos de POI Nada selecionado - Ações rápidas Perfis Listado %1$s já existe no OsmAnd. Os itens atuais serão substituídos pelos itens do arquivo diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index d81e2d307a..e6ce2e9f52 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -3482,7 +3482,6 @@ Подготовка Типы POI Ничего не выбрано - Быстрые действия Профили Текущие элементы будут заменены элементами из файла Заменить все diff --git a/OsmAnd/res/values-sc/strings.xml b/OsmAnd/res/values-sc/strings.xml index 8b4da7cf0c..716dbda924 100644 --- a/OsmAnd/res/values-sc/strings.xml +++ b/OsmAnd/res/values-sc/strings.xml @@ -3550,7 +3550,6 @@ Pro praghere iscrie su còdighe intreu Ammaniende Castas de PDI Nudda de ischertadu - Atziones lestras Profilos Sos %1$s allistados esistint giai in OsmAnd. Sos elementos atuales ant a èssere remplasados cun elementos dae su documentu diff --git a/OsmAnd/res/values-sk/strings.xml b/OsmAnd/res/values-sk/strings.xml index 80cd603483..4ce4c0248a 100644 --- a/OsmAnd/res/values-sk/strings.xml +++ b/OsmAnd/res/values-sk/strings.xml @@ -3485,7 +3485,6 @@ Zodpovedá oblasti: %1$s x %2$s Pripravujem Typy bodov záujmu Nič nie je zvolené - Rýchle akcie Profily Poznámka: kontrola na nenulovú rýchlosť: Väčšina čipov GPS hlási hodnotu rýchlosti len ak algoritmus usúdi, že sa pohybujete, inak nevráti žiadnu rýchlosť. Preto použitie nenulového nastavenia v tomto filtri vlastne použije detekciu pohybu v GPS čipe. Ale aj keď nebude rýchlosť filtrovaná tu pri zázname, použijeme túto funkciu pri analýze GPX pre zistenie Opravenej vzdialenosti, teda hodnoty zobrazenej v tomto poli je vzdialenosť zaznamenaná počas pohybu. Toto zaznamená len body zmerané pri indikovanej minimálnej presnosti (v metroch/stopách, ako ju hlási Android pre vaše zariadenie). Presnosť znamená rozptyl opakovaných meraní a nesúvisí priamo s presnosťou, ktorá určuje ako blízko je vaše meranie k skutočnej polohe. diff --git a/OsmAnd/res/values-sl/strings.xml b/OsmAnd/res/values-sl/strings.xml index 597b48a557..7a6f1dc154 100644 --- a/OsmAnd/res/values-sl/strings.xml +++ b/OsmAnd/res/values-sl/strings.xml @@ -3299,6 +3299,5 @@ Koda predstavlja območje: %1$s x %2$s Poteka priprava ... Vrste točk POI Ni izbranih predmetov - Hitra dejanja Profili \ No newline at end of file diff --git a/OsmAnd/res/values-sr/strings.xml b/OsmAnd/res/values-sr/strings.xml index 0ff7e17fc8..c97ab01e70 100644 --- a/OsmAnd/res/values-sr/strings.xml +++ b/OsmAnd/res/values-sr/strings.xml @@ -3548,7 +3548,6 @@ Препремам Типови тачака од интереса Ништа није означено - Брзе радње Профили Излистан %1$s, већ постоји у OsmAnd-у. Тренутне ставке ће бити замењене ставкама из фајла diff --git a/OsmAnd/res/values-tr/strings.xml b/OsmAnd/res/values-tr/strings.xml index ca8b82b19d..80fb0b9e48 100644 --- a/OsmAnd/res/values-tr/strings.xml +++ b/OsmAnd/res/values-tr/strings.xml @@ -3506,7 +3506,6 @@ Hazırlama POI türleri Hiçbir şey seçilmedi - Hızlı eylemler Profiller Listelenen %1$s, OsmAnd\'da zaten var. Geçerli ögeler, dosyadaki ögelerle değiştirilecek diff --git a/OsmAnd/res/values-uk/strings.xml b/OsmAnd/res/values-uk/strings.xml index 11ed908675..be69253d16 100644 --- a/OsmAnd/res/values-uk/strings.xml +++ b/OsmAnd/res/values-uk/strings.xml @@ -3540,7 +3540,6 @@ Підготування Види POI Нічого не вибрано - Швидкі дії Профілі Перелічені %1$s вже існують у OsmAnd. Поточні елементи будуть замінені на елементи з файлу diff --git a/OsmAnd/res/values-zh-rTW/strings.xml b/OsmAnd/res/values-zh-rTW/strings.xml index afecd84102..5759ce2a61 100644 --- a/OsmAnd/res/values-zh-rTW/strings.xml +++ b/OsmAnd/res/values-zh-rTW/strings.xml @@ -3541,7 +3541,6 @@ 正在準備 POI 類型 未選取 - 快速動作 設定檔 列出的 %1$s 已存在於 OsmAnd 中。 目前的項目將會被從檔案而來的項目所取代 diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index f6da069fb8..a8f3e65c78 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -20,7 +20,6 @@ Importing OsmAnd check %1$s for duplicates with existing items in the application.\n\nIt may take some time. Items added - Quick action Import complete All data from the %1$s is imported, you can use buttons below to open needed part of the application to manage it. Import rendering file @@ -33,7 +32,6 @@ Preparing POI types Nothing selected - Quick actions Profiles Listed %1$s, already exist in OsmAnd. Current items will be replaced with items from the file diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java index b2f074cab2..f22e43faf7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java @@ -78,7 +78,7 @@ public class ImportedSettingsItemsAdapter extends break; case QUICK_ACTIONS: holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.map_quick_action, activeColorRes)); - holder.title.setText(R.string.shared_string_quick_action); + holder.title.setText(R.string.configure_screen_quick_action); break; case POI_TYPES: holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_search_dark, activeColorRes)); From 6cdc6a8fb892b2c303aed49e008784d680eec79a Mon Sep 17 00:00:00 2001 From: max-klaus Date: Wed, 11 Mar 2020 21:47:16 +0300 Subject: [PATCH 21/30] Revert "remove duplicate string" This reverts commit 94594b81c21e051af5f1a8b7959559a95b254436. --- OsmAnd/res/values-ar/strings.xml | 1 + OsmAnd/res/values-b+ast/strings.xml | 1 + OsmAnd/res/values-be/strings.xml | 1 + OsmAnd/res/values-bg/strings.xml | 1 + OsmAnd/res/values-ca/strings.xml | 1 + OsmAnd/res/values-da/strings.xml | 1 + OsmAnd/res/values-de/strings.xml | 1 + OsmAnd/res/values-el/strings.xml | 1 + OsmAnd/res/values-eo/strings.xml | 1 + OsmAnd/res/values-es-rAR/strings.xml | 1 + OsmAnd/res/values-es-rUS/strings.xml | 1 + OsmAnd/res/values-eu/strings.xml | 1 + OsmAnd/res/values-fa/strings.xml | 1 + OsmAnd/res/values-fi/strings.xml | 1 + OsmAnd/res/values-fr/strings.xml | 1 + OsmAnd/res/values-gl/strings.xml | 1 + OsmAnd/res/values-he/strings.xml | 1 + OsmAnd/res/values-hr/strings.xml | 1 + OsmAnd/res/values-is/strings.xml | 1 + OsmAnd/res/values-it/strings.xml | 1 + OsmAnd/res/values-nl/strings.xml | 1 + OsmAnd/res/values-pl/strings.xml | 1 + OsmAnd/res/values-pt-rBR/strings.xml | 1 + OsmAnd/res/values-ru/strings.xml | 1 + OsmAnd/res/values-sc/strings.xml | 1 + OsmAnd/res/values-sk/strings.xml | 1 + OsmAnd/res/values-sl/strings.xml | 1 + OsmAnd/res/values-sr/strings.xml | 1 + OsmAnd/res/values-tr/strings.xml | 1 + OsmAnd/res/values-uk/strings.xml | 1 + OsmAnd/res/values-zh-rTW/strings.xml | 1 + OsmAnd/res/values/strings.xml | 2 ++ .../net/osmand/plus/settings/ImportedSettingsItemsAdapter.java | 2 +- 33 files changed, 34 insertions(+), 1 deletion(-) diff --git a/OsmAnd/res/values-ar/strings.xml b/OsmAnd/res/values-ar/strings.xml index 1b52eed72f..9b5344c2f8 100644 --- a/OsmAnd/res/values-ar/strings.xml +++ b/OsmAnd/res/values-ar/strings.xml @@ -3509,6 +3509,7 @@ تحضير أنواع النقاط لا شيء محدد + إجراءات سريعة الأوضاع سيتم استبدال العناصر الحالية بعناصر من الملف استبدال الكل diff --git a/OsmAnd/res/values-b+ast/strings.xml b/OsmAnd/res/values-b+ast/strings.xml index 2fc1ec8a61..09bf00052f 100644 --- a/OsmAnd/res/values-b+ast/strings.xml +++ b/OsmAnd/res/values-b+ast/strings.xml @@ -1452,6 +1452,7 @@ Preparando Tipos de PDI Nun hai nada seleicionao + Aiciones rápides Perfiles %1$s llistáu, yá existe n\'OsmAnd. Los elementos actuales sustituiránse por elementos del ficheru diff --git a/OsmAnd/res/values-be/strings.xml b/OsmAnd/res/values-be/strings.xml index df3dcdc871..3d4c353fab 100644 --- a/OsmAnd/res/values-be/strings.xml +++ b/OsmAnd/res/values-be/strings.xml @@ -3514,6 +3514,7 @@ Падрыхтоўка Тыпы POI Нічога не абрана + Хуткія дзеянні Профілі Дадзеныя %1$s ужо ёсць у OsmAnd. Бягучыя элементы заменяцца элементамі з файла diff --git a/OsmAnd/res/values-bg/strings.xml b/OsmAnd/res/values-bg/strings.xml index 9c49dff48d..427b1ecddd 100644 --- a/OsmAnd/res/values-bg/strings.xml +++ b/OsmAnd/res/values-bg/strings.xml @@ -2012,6 +2012,7 @@ Подготовка Тип POI Нищо не е избрано + Бързи действия Профили Изброените %1$s, вече съществуват в OsmAnd. Текущите елементи ще бъдат заменени с елементи от файлът diff --git a/OsmAnd/res/values-ca/strings.xml b/OsmAnd/res/values-ca/strings.xml index 22080bba05..3cc40cb5f5 100644 --- a/OsmAnd/res/values-ca/strings.xml +++ b/OsmAnd/res/values-ca/strings.xml @@ -3515,6 +3515,7 @@ Abasta l\'àrea: %1$s x %2$s Preparant Tipus de PDI No hi ha res seleccionat + Accions directes Perfils Els llistats %1$s ja existeixen a OsmAnd. Els elements actuals es substituiran amb elements de l\'arxiu diff --git a/OsmAnd/res/values-da/strings.xml b/OsmAnd/res/values-da/strings.xml index c05874fc3e..af7830d80e 100644 --- a/OsmAnd/res/values-da/strings.xml +++ b/OsmAnd/res/values-da/strings.xml @@ -3507,6 +3507,7 @@ Repræsenterer område: %1$s x %2$s Forbereder IP typer Intet valgt + Genveje Profiler Aktuelle poster erstattes med poster fra filen Erstat alle diff --git a/OsmAnd/res/values-de/strings.xml b/OsmAnd/res/values-de/strings.xml index ea20cd8769..10c76ff843 100644 --- a/OsmAnd/res/values-de/strings.xml +++ b/OsmAnd/res/values-de/strings.xml @@ -3553,6 +3553,7 @@ Lon %2$s Winkel Zusätzliches gerades Segment zwischen meinem Standort und berechneter Route wird angezeigt, bis die Route neu berechnet wird Minimaler Winkel zwischen meinem Standort und der Route + Schnellaktionen Profile Die aufgelisteten %1$s sind in OsmAnd bereits vorhanden. Vorbereitung diff --git a/OsmAnd/res/values-el/strings.xml b/OsmAnd/res/values-el/strings.xml index 98a8c07e02..2762145c25 100644 --- a/OsmAnd/res/values-el/strings.xml +++ b/OsmAnd/res/values-el/strings.xml @@ -3515,6 +3515,7 @@ Προετοιμασία Είδη Σημείων Ενδιαφέροντος Τίποτα δεν επιλέχτηκε + Ταχείες ενέργειες Κατανομές Το εισηγμένο %1$s, υπάρχει ήδη στο OsmAnd. Τα τρέχοντα αντικείμενα θα αντικατασταθούν με αντικείμενα από το αρχείο diff --git a/OsmAnd/res/values-eo/strings.xml b/OsmAnd/res/values-eo/strings.xml index e2ee15aa1e..dfde0288ce 100644 --- a/OsmAnd/res/values-eo/strings.xml +++ b/OsmAnd/res/values-eo/strings.xml @@ -3532,6 +3532,7 @@ Indikas lokon: %1$s x %2$s" Preparado Specoj de interesejoj Nenio elektita + Rapidaj agoj Profiloj Listigitaj %1$s jam ekzistas en OsmAnd. La nunaj elementoj estos anstataŭigitaj per elementoj el la dosiero diff --git a/OsmAnd/res/values-es-rAR/strings.xml b/OsmAnd/res/values-es-rAR/strings.xml index 4db4faf562..6525182f91 100644 --- a/OsmAnd/res/values-es-rAR/strings.xml +++ b/OsmAnd/res/values-es-rAR/strings.xml @@ -3551,6 +3551,7 @@ Lon %2$s Preparando Tipos de PDI Nada marcado + Acciones rápidas Perfiles El listado «%1$s», ya existe en OsmAnd. Los elementos actuales serán reemplazados por elementos del archivo diff --git a/OsmAnd/res/values-es-rUS/strings.xml b/OsmAnd/res/values-es-rUS/strings.xml index 179c5080b4..99da136cb7 100644 --- a/OsmAnd/res/values-es-rUS/strings.xml +++ b/OsmAnd/res/values-es-rUS/strings.xml @@ -3551,6 +3551,7 @@ Lon %2$s Preparando Tipos de PDI Nada marcado + Acciones rápidas Perfiles El listado «%1$s», ya existe en OsmAnd. Los elementos actuales serán reemplazados por elementos del archivo diff --git a/OsmAnd/res/values-eu/strings.xml b/OsmAnd/res/values-eu/strings.xml index 97547af5c5..80bdd0c360 100644 --- a/OsmAnd/res/values-eu/strings.xml +++ b/OsmAnd/res/values-eu/strings.xml @@ -3559,6 +3559,7 @@ Area honi dagokio: %1$s x %2$s Prestatzen POI motak Ez da ezer hautatu + Ekintza azkarrak Profilak Zerrendatutako %1$s, badago dagoeneko OsmAnd-en. Uneko elementuak fitxategiko elementuekin ordeztuko dira diff --git a/OsmAnd/res/values-fa/strings.xml b/OsmAnd/res/values-fa/strings.xml index 0c3f670f8b..cc460f5237 100644 --- a/OsmAnd/res/values-fa/strings.xml +++ b/OsmAnd/res/values-fa/strings.xml @@ -3577,6 +3577,7 @@ کمترین زاویه میان موقعیت من و مسیر آماده‌سازی چیزی انتخاب نشده + کنش‌های فوری پروفایل‌ها موارد موجود در فایل، جانشین موارد کنونی می‌شود جانشانی همه diff --git a/OsmAnd/res/values-fi/strings.xml b/OsmAnd/res/values-fi/strings.xml index fee2c9dbb5..c8df578184 100644 --- a/OsmAnd/res/values-fi/strings.xml +++ b/OsmAnd/res/values-fi/strings.xml @@ -2524,6 +2524,7 @@ Jos pidät OsmAndista ja OSMsta ja haluat tukea niitä, on tämä täydellinen t Kulma Valmistellaan KP-tyypit + Pikatoiminnot Profiilit Korvaa kaikki Pidä molemmat diff --git a/OsmAnd/res/values-fr/strings.xml b/OsmAnd/res/values-fr/strings.xml index a54ad96b59..fd15a0938f 100644 --- a/OsmAnd/res/values-fr/strings.xml +++ b/OsmAnd/res/values-fr/strings.xml @@ -3521,6 +3521,7 @@ représentant la zone : %1$s x %2$s Préparation en cours Types de PI Aucun élément sélectionné + Actions rapides Profils Les %1$s listés existent déjà dans OsmAnd. Les éléments actuels seront remplacés par les éléments du fichier diff --git a/OsmAnd/res/values-gl/strings.xml b/OsmAnd/res/values-gl/strings.xml index eac7283aca..57389d2426 100644 --- a/OsmAnd/res/values-gl/strings.xml +++ b/OsmAnd/res/values-gl/strings.xml @@ -3603,6 +3603,7 @@ Lon %2$s Estase a preparar Tipos de PDI Ren selecionado + Accións rápidas Perfís %1$s listado, xa existe no OsmAnd. Os elementos actuais serán substituídos polos elementos do ficheiro diff --git a/OsmAnd/res/values-he/strings.xml b/OsmAnd/res/values-he/strings.xml index 8e81f2dabc..c044afc97e 100644 --- a/OsmAnd/res/values-he/strings.xml +++ b/OsmAnd/res/values-he/strings.xml @@ -3509,6 +3509,7 @@ בהכנה סוגי נקודות עניין שום דבר לא נבחר + פעולות מהירות פרופילים הפריטים הנוכחיים יוחלפו בפריטים מהקובץ להחליף הכול diff --git a/OsmAnd/res/values-hr/strings.xml b/OsmAnd/res/values-hr/strings.xml index b6ae2df8d1..f388d5da82 100644 --- a/OsmAnd/res/values-hr/strings.xml +++ b/OsmAnd/res/values-hr/strings.xml @@ -1423,6 +1423,7 @@ Kut Priprema Ništa nije odabrano + Brze akcije Profili Navedene %1$s, već postoje u OsmAnd. Trenutne stavke bit će zamijenjene stavkama iz datoteke diff --git a/OsmAnd/res/values-is/strings.xml b/OsmAnd/res/values-is/strings.xml index 52de80cf25..4efe86c52c 100644 --- a/OsmAnd/res/values-is/strings.xml +++ b/OsmAnd/res/values-is/strings.xml @@ -3560,6 +3560,7 @@ Stendur fyrir svæði: %1$s x %2$s Undirbý Gerðir POI-merkisstaða Ekkert valið + Flýtiaðgerðir Notandasnið Taldi upp %1$s, er þegar til staðar í OsmAnd. Fyrirliggjandi atriðum verður skipt út með atriðum úr skránni diff --git a/OsmAnd/res/values-it/strings.xml b/OsmAnd/res/values-it/strings.xml index 4239c8a359..f12655e74a 100644 --- a/OsmAnd/res/values-it/strings.xml +++ b/OsmAnd/res/values-it/strings.xml @@ -3551,6 +3551,7 @@ Rappresenta l\'area: %1$s x %2$s Preparando Tipi di PDI Nessuna selezione + Azioni veloci Profili Gli elencati %1$s, esistono già in OsmAnd. Gli oggetti attuali verranno sostituiti con gli oggetti dal file diff --git a/OsmAnd/res/values-nl/strings.xml b/OsmAnd/res/values-nl/strings.xml index 2029a71fb7..ec361b541a 100644 --- a/OsmAnd/res/values-nl/strings.xml +++ b/OsmAnd/res/values-nl/strings.xml @@ -3391,6 +3391,7 @@ voor Gebied: %1$s x %2$s Voorbereiding POI types Niets geselecteerd + Snelle acties Profielen De getoonde %1$s zijn in OsmAnd reeds beschikbaar. Huidige elementen worden vervangen door elementen uit het bestand diff --git a/OsmAnd/res/values-pl/strings.xml b/OsmAnd/res/values-pl/strings.xml index 99b2b2f6ae..7dfe770a65 100644 --- a/OsmAnd/res/values-pl/strings.xml +++ b/OsmAnd/res/values-pl/strings.xml @@ -3561,6 +3561,7 @@ Reprezentuje obszar: %1$s x %2$s Wybierz dane, które mają zostać zaimportowane. Importuj plik routingu Jest to filtr odcięcia niskiej prędkości, który nie rejestruje punktów poniżej określonej prędkości. Może to sprawić, że zarejestrowane ślady będą wyglądać na bardziej płynne podczas przeglądania na mapie. + Szybka czynność Zatrzymaj oba Styl renderowania Zobacz swoje zmiany lub błędy OSM, które nie zostały jeszcze przesłane w %1$s. Przesłane punkty nie będą już wyświetlane. diff --git a/OsmAnd/res/values-pt-rBR/strings.xml b/OsmAnd/res/values-pt-rBR/strings.xml index 5f34034430..27a06c1da1 100644 --- a/OsmAnd/res/values-pt-rBR/strings.xml +++ b/OsmAnd/res/values-pt-rBR/strings.xml @@ -3538,6 +3538,7 @@ Pôr do Sol: %2$s Preparando Tipos de POI Nada selecionado + Ações rápidas Perfis Listado %1$s já existe no OsmAnd. Os itens atuais serão substituídos pelos itens do arquivo diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index e6ce2e9f52..d81e2d307a 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -3482,6 +3482,7 @@ Подготовка Типы POI Ничего не выбрано + Быстрые действия Профили Текущие элементы будут заменены элементами из файла Заменить все diff --git a/OsmAnd/res/values-sc/strings.xml b/OsmAnd/res/values-sc/strings.xml index 716dbda924..8b4da7cf0c 100644 --- a/OsmAnd/res/values-sc/strings.xml +++ b/OsmAnd/res/values-sc/strings.xml @@ -3550,6 +3550,7 @@ Pro praghere iscrie su còdighe intreu Ammaniende Castas de PDI Nudda de ischertadu + Atziones lestras Profilos Sos %1$s allistados esistint giai in OsmAnd. Sos elementos atuales ant a èssere remplasados cun elementos dae su documentu diff --git a/OsmAnd/res/values-sk/strings.xml b/OsmAnd/res/values-sk/strings.xml index 4ce4c0248a..80cd603483 100644 --- a/OsmAnd/res/values-sk/strings.xml +++ b/OsmAnd/res/values-sk/strings.xml @@ -3485,6 +3485,7 @@ Zodpovedá oblasti: %1$s x %2$s Pripravujem Typy bodov záujmu Nič nie je zvolené + Rýchle akcie Profily Poznámka: kontrola na nenulovú rýchlosť: Väčšina čipov GPS hlási hodnotu rýchlosti len ak algoritmus usúdi, že sa pohybujete, inak nevráti žiadnu rýchlosť. Preto použitie nenulového nastavenia v tomto filtri vlastne použije detekciu pohybu v GPS čipe. Ale aj keď nebude rýchlosť filtrovaná tu pri zázname, použijeme túto funkciu pri analýze GPX pre zistenie Opravenej vzdialenosti, teda hodnoty zobrazenej v tomto poli je vzdialenosť zaznamenaná počas pohybu. Toto zaznamená len body zmerané pri indikovanej minimálnej presnosti (v metroch/stopách, ako ju hlási Android pre vaše zariadenie). Presnosť znamená rozptyl opakovaných meraní a nesúvisí priamo s presnosťou, ktorá určuje ako blízko je vaše meranie k skutočnej polohe. diff --git a/OsmAnd/res/values-sl/strings.xml b/OsmAnd/res/values-sl/strings.xml index 7a6f1dc154..597b48a557 100644 --- a/OsmAnd/res/values-sl/strings.xml +++ b/OsmAnd/res/values-sl/strings.xml @@ -3299,5 +3299,6 @@ Koda predstavlja območje: %1$s x %2$s Poteka priprava ... Vrste točk POI Ni izbranih predmetov + Hitra dejanja Profili \ No newline at end of file diff --git a/OsmAnd/res/values-sr/strings.xml b/OsmAnd/res/values-sr/strings.xml index c97ab01e70..0ff7e17fc8 100644 --- a/OsmAnd/res/values-sr/strings.xml +++ b/OsmAnd/res/values-sr/strings.xml @@ -3548,6 +3548,7 @@ Препремам Типови тачака од интереса Ништа није означено + Брзе радње Профили Излистан %1$s, већ постоји у OsmAnd-у. Тренутне ставке ће бити замењене ставкама из фајла diff --git a/OsmAnd/res/values-tr/strings.xml b/OsmAnd/res/values-tr/strings.xml index 80fb0b9e48..ca8b82b19d 100644 --- a/OsmAnd/res/values-tr/strings.xml +++ b/OsmAnd/res/values-tr/strings.xml @@ -3506,6 +3506,7 @@ Hazırlama POI türleri Hiçbir şey seçilmedi + Hızlı eylemler Profiller Listelenen %1$s, OsmAnd\'da zaten var. Geçerli ögeler, dosyadaki ögelerle değiştirilecek diff --git a/OsmAnd/res/values-uk/strings.xml b/OsmAnd/res/values-uk/strings.xml index be69253d16..11ed908675 100644 --- a/OsmAnd/res/values-uk/strings.xml +++ b/OsmAnd/res/values-uk/strings.xml @@ -3540,6 +3540,7 @@ Підготування Види POI Нічого не вибрано + Швидкі дії Профілі Перелічені %1$s вже існують у OsmAnd. Поточні елементи будуть замінені на елементи з файлу diff --git a/OsmAnd/res/values-zh-rTW/strings.xml b/OsmAnd/res/values-zh-rTW/strings.xml index 5759ce2a61..afecd84102 100644 --- a/OsmAnd/res/values-zh-rTW/strings.xml +++ b/OsmAnd/res/values-zh-rTW/strings.xml @@ -3541,6 +3541,7 @@ 正在準備 POI 類型 未選取 + 快速動作 設定檔 列出的 %1$s 已存在於 OsmAnd 中。 目前的項目將會被從檔案而來的項目所取代 diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a8f3e65c78..f6da069fb8 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -20,6 +20,7 @@ Importing OsmAnd check %1$s for duplicates with existing items in the application.\n\nIt may take some time. Items added + Quick action Import complete All data from the %1$s is imported, you can use buttons below to open needed part of the application to manage it. Import rendering file @@ -32,6 +33,7 @@ Preparing POI types Nothing selected + Quick actions Profiles Listed %1$s, already exist in OsmAnd. Current items will be replaced with items from the file diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java index f22e43faf7..b2f074cab2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java @@ -78,7 +78,7 @@ public class ImportedSettingsItemsAdapter extends break; case QUICK_ACTIONS: holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.map_quick_action, activeColorRes)); - holder.title.setText(R.string.configure_screen_quick_action); + holder.title.setText(R.string.shared_string_quick_action); break; case POI_TYPES: holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_search_dark, activeColorRes)); From 4e7687371cd690a9b9d95aea352d67cc941f4556 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Wed, 11 Mar 2020 21:49:40 +0300 Subject: [PATCH 22/30] Remove duplicate string --- OsmAnd/res/values/strings.xml | 1 - .../net/osmand/plus/settings/ImportedSettingsItemsAdapter.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index f6da069fb8..eb98de459c 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -20,7 +20,6 @@ Importing OsmAnd check %1$s for duplicates with existing items in the application.\n\nIt may take some time. Items added - Quick action Import complete All data from the %1$s is imported, you can use buttons below to open needed part of the application to manage it. Import rendering file diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java index b2f074cab2..f22e43faf7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java @@ -78,7 +78,7 @@ public class ImportedSettingsItemsAdapter extends break; case QUICK_ACTIONS: holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.map_quick_action, activeColorRes)); - holder.title.setText(R.string.shared_string_quick_action); + holder.title.setText(R.string.configure_screen_quick_action); break; case POI_TYPES: holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_search_dark, activeColorRes)); From 63e2ba3493e17017fc9c0dda0585ed598dd068fc Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 12 Mar 2020 12:15:45 +0200 Subject: [PATCH 23/30] Fix several possible crashes with fragment manager and import dialogs --- .../activities/FavoritesSearchFragment.java | 6 +++- .../osmand/plus/activities/MapActivity.java | 16 ++++------ ...eoNoteRecordingMenuFullScreenFragment.java | 9 +++++- .../osmand/plus/base/ContextMenuFragment.java | 8 ++--- .../net/osmand/plus/helpers/ImportHelper.java | 32 +++++++++++-------- .../MapContextMenuFragment.java | 6 ++-- .../ContextMenuCardDialogFragment.java | 8 ++--- .../search/QuickSearchDialogFragment.java | 5 ++- .../plus/settings/BaseSettingsFragment.java | 5 ++- 9 files changed, 56 insertions(+), 39 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java index 2bdd750655..34265a37b2 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java @@ -33,6 +33,7 @@ import androidx.core.content.ContextCompat; import androidx.core.view.ViewCompat; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; import net.osmand.access.AccessibilityAssistant; @@ -221,7 +222,10 @@ public class FavoritesSearchFragment extends DialogFragment { public void onDismiss(DialogInterface dialog) { Activity activity = getActivity(); if (activity != null) { - getChildFragmentManager().popBackStack(); + FragmentManager fragmentManager = getChildFragmentManager(); + if (!fragmentManager.isStateSaved()) { + fragmentManager.popBackStack(); + } } super.onDismiss(dialog); } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 48726c6d7c..65eda804c7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1128,10 +1128,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } public void dismissCardDialog() { - try { - getSupportFragmentManager().popBackStack(ContextMenuCardDialogFragment.TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); - } catch (Exception e) { - e.printStackTrace(); + FragmentManager fragmentManager = getSupportFragmentManager(); + if (!fragmentManager.isStateSaved()) { + fragmentManager.popBackStack(ContextMenuCardDialogFragment.TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); } } @@ -2166,10 +2165,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } public void dismissSettingsScreens() { - try { - getSupportFragmentManager().popBackStack(DRAWER_SETTINGS_ID + ".new", FragmentManager.POP_BACK_STACK_INCLUSIVE); - } catch (Exception e) { - e.printStackTrace(); + FragmentManager fragmentManager = getSupportFragmentManager(); + if (!fragmentManager.isStateSaved()) { + fragmentManager.popBackStack(DRAWER_SETTINGS_ID + ".new", FragmentManager.POP_BACK_STACK_INCLUSIVE); } } @@ -2456,7 +2454,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven public void backToConfigureProfileFragment() { FragmentManager fragmentManager = getSupportFragmentManager(); int backStackEntryCount = fragmentManager.getBackStackEntryCount(); - if (backStackEntryCount > 0) { + if (backStackEntryCount > 0 && !fragmentManager.isStateSaved()) { BackStackEntry entry = fragmentManager.getBackStackEntryAt(backStackEntryCount - 1); if (ConfigureProfileFragment.TAG.equals(entry.getName())) { fragmentManager.popBackStack(); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteRecordingMenuFullScreenFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteRecordingMenuFullScreenFragment.java index e38ecfa892..a594c9ec72 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteRecordingMenuFullScreenFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteRecordingMenuFullScreenFragment.java @@ -8,6 +8,7 @@ import android.view.WindowManager; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import net.osmand.plus.R; @@ -59,6 +60,12 @@ public class AudioVideoNoteRecordingMenuFullScreenFragment extends Fragment { public void dismiss() { dismissing = true; - getActivity().getSupportFragmentManager().popBackStack(); + FragmentActivity activity = getActivity(); + if (activity != null) { + FragmentManager fragmentManager = activity.getSupportFragmentManager(); + if (!fragmentManager.isStateSaved()) { + fragmentManager.popBackStack(); + } + } } } diff --git a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java index 64b0d8b4a0..1e0b10ee31 100644 --- a/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/ContextMenuFragment.java @@ -937,11 +937,9 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment { if (isSingleFragment()) { FragmentActivity activity = getActivity(); if (activity != null) { - try { - activity.getSupportFragmentManager().popBackStack(getFragmentTag(), - FragmentManager.POP_BACK_STACK_INCLUSIVE); - } catch (Exception e) { - // + FragmentManager fragmentManager = activity.getSupportFragmentManager(); + if (!fragmentManager.isStateSaved()) { + fragmentManager.popBackStack(getFragmentTag(), FragmentManager.POP_BACK_STACK_INCLUSIVE); } } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index 4411ef4551..36df3fdb64 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -1,7 +1,6 @@ package net.osmand.plus.helpers; import android.annotation.SuppressLint; -import android.app.Activity; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; @@ -341,9 +340,10 @@ public class ImportHelper { @Override protected void onPreExecute() { - progress = ProgressDialog - .show(activity, app.getString(R.string.loading_smth, ""), - app.getString(R.string.loading_data)); + if (AndroidUtils.isActivityNotDestroyed(activity)) { + progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), + app.getString(R.string.loading_data)); + } } @Override @@ -362,7 +362,7 @@ public class ImportHelper { @Override protected void onPostExecute(GPXFile result) { - if (AndroidUtils.isActivityNotDestroyed(activity)) { + if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) { progress.dismiss(); } Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG) @@ -679,7 +679,9 @@ public class ImportHelper { @Override protected void onPreExecute() { - progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data)); + if (AndroidUtils.isActivityNotDestroyed(activity)) { + progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data)); + } mFileName = fileName; } @@ -705,7 +707,7 @@ public class ImportHelper { loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() { @Override public void onRoutingFilesLoaded() { - if (AndroidUtils.isActivityNotDestroyed(activity)) { + if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) { progress.dismiss(); } RoutingConfiguration.Builder builder = app.getCustomRoutingConfig(mFileName); @@ -720,7 +722,7 @@ public class ImportHelper { } }); } else { - if (AndroidUtils.isActivityNotDestroyed(activity)) { + if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) { progress.dismiss(); } app.showShortToastMessage(app.getString(R.string.file_import_error, mFileName, error)); @@ -762,7 +764,9 @@ public class ImportHelper { @Override protected void onPreExecute() { - progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data)); + if (AndroidUtils.isActivityNotDestroyed(activity)) { + progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data)); + } } @Override @@ -783,7 +787,7 @@ public class ImportHelper { app.getSettingsHelper().importSettings(file, latestChanges, version, new SettingsImportListener() { @Override public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { - if (AndroidUtils.isActivityNotDestroyed(activity)) { + if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) { progress.dismiss(); } if (succeed) { @@ -797,7 +801,7 @@ public class ImportHelper { } }); } else { - if (AndroidUtils.isActivityNotDestroyed(activity)) { + if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) { progress.dismiss(); } app.showShortToastMessage(app.getString(R.string.file_import_error, name, error)); @@ -889,7 +893,9 @@ public class ImportHelper { @Override protected void onPreExecute() { - progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data)); + if (AndroidUtils.isActivityNotDestroyed(activity)) { + progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data)); + } mFileName = fileName; } @@ -916,7 +922,7 @@ public class ImportHelper { } else { app.showShortToastMessage(app.getString(R.string.file_import_error, mFileName, error)); } - if (AndroidUtils.isActivityNotDestroyed(activity)) { + if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) { progress.dismiss(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 5153698081..dbb14182d7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -2120,9 +2120,9 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo public void dismissMenu() { FragmentActivity activity = getActivity(); if (activity != null) { - try { - activity.getSupportFragmentManager().popBackStack(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); - } catch (Exception e) { + FragmentManager fragmentManager = activity.getSupportFragmentManager(); + if (!fragmentManager.isStateSaved()) { + fragmentManager.popBackStack(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); } } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialogFragment.java index 8b2934241b..541bbef145 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/dialogs/ContextMenuCardDialogFragment.java @@ -134,11 +134,9 @@ public class ContextMenuCardDialogFragment extends BaseOsmAndFragment { public void dismiss() { MapActivity activity = dialog.getMapActivity(); if (activity != null) { - try { - activity.getSupportFragmentManager().popBackStack(TAG, - FragmentManager.POP_BACK_STACK_INCLUSIVE); - } catch (Exception e) { - e.printStackTrace(); + FragmentManager fragmentManager = activity.getSupportFragmentManager(); + if (!fragmentManager.isStateSaved()) { + fragmentManager.popBackStack(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); } } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 68544590f4..9d25e244cd 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -1023,7 +1023,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC hideToolbar(); mapActivity.updateStatusBarColor(); mapActivity.refreshMap(); - getChildFragmentManager().popBackStack(); + FragmentManager fragmentManager = getChildFragmentManager(); + if (!fragmentManager.isStateSaved()) { + fragmentManager.popBackStack(); + } } super.onDismiss(dialog); } diff --git a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java index 27758dc6e2..f07bf164ec 100644 --- a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java @@ -585,7 +585,10 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl public void dismiss() { FragmentActivity activity = getActivity(); if (activity != null) { - activity.getSupportFragmentManager().popBackStack(); + FragmentManager fragmentManager = activity.getSupportFragmentManager(); + if (!fragmentManager.isStateSaved()) { + fragmentManager.popBackStack(); + } } } From 79c59cab42f2a403b4583a614c87f4b3d81bd20b Mon Sep 17 00:00:00 2001 From: max-klaus Date: Fri, 13 Mar 2020 11:38:53 +0300 Subject: [PATCH 24/30] SettingsHelper refactoring done --- .../src/net/osmand/plus/SettingsHelper.java | 212 ++++++------------ .../osmand/plus/activities/MapActivity.java | 2 - .../net/osmand/plus/helpers/ImportHelper.java | 11 +- .../settings/ConfigureProfileFragment.java | 7 +- .../settings/ImportDuplicatesFragment.java | 12 +- .../plus/settings/ImportSettingsFragment.java | 26 +-- 6 files changed, 91 insertions(+), 179 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index f9c67faf8b..a3abaa1b10 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -1,13 +1,11 @@ package net.osmand.plus; import android.annotation.SuppressLint; -import android.app.Activity; import android.content.Context; import android.os.AsyncTask; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -96,64 +94,30 @@ public class SettingsHelper { private static final int BUFFER = 1024; private OsmandApplication app; - private Activity activity; - private boolean importing; - private boolean importSuspended; - private boolean collectOnly; - private boolean checkingDuplicates; private ImportAsyncTask importTask; private Map exportAsyncTasks = new HashMap<>(); public interface SettingsImportListener { - void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items); + void onSettingsImportFinished(boolean succeed, @NonNull List items); } - public interface SettingsExportListener { - void onSettingsExportFinished(@NonNull File file, boolean succeed); + public interface SettingsCollectListener { + void onSettingsCollectFinished(boolean succeed, boolean empty, @NonNull List items); } public interface CheckDuplicatesListener { void onDuplicatesChecked(@NonNull List duplicates, List items); } + public interface SettingsExportListener { + void onSettingsExportFinished(@NonNull File file, boolean succeed); + } + public SettingsHelper(OsmandApplication app) { this.app = app; } - public Activity getActivity() { - return activity; - } - - public void setActivity(Activity activity) { - this.activity = activity; - if (importing && !collectOnly) { - importTask.processNextItem(); - } - } - - public void resetActivity(Activity activity) { - if (this.activity == activity) { - if (importing) { - importTask.suspendImport(); - importSuspended = true; - } - this.activity = null; - } - } - - public boolean isImporting() { - return importing; - } - - public boolean isCheckingDuplicates() { - return checkingDuplicates; - } - - public boolean isCollectOnly() { - return collectOnly; - } - public enum SettingsItemType { GLOBAL, PROFILE, @@ -1826,24 +1790,24 @@ public class SettingsHelper { private int version; private SettingsImportListener importListener; + private SettingsCollectListener collectListener; private CheckDuplicatesListener duplicatesListener; private SettingsImporter importer; + private List items = new ArrayList<>(); private List selectedItems = new ArrayList<>(); - private List processedItems = new ArrayList<>(); - private SettingsItem currentItem; - private AlertDialog dialog; - private State state; private List duplicates; - ImportAsyncTask(@NonNull File file, String latestChanges, int version, @Nullable SettingsImportListener importListener) { + private ImportType importType; + private boolean importDone; + + ImportAsyncTask(@NonNull File file, String latestChanges, int version, @Nullable SettingsCollectListener collectListener) { this.file = file; - this.importListener = importListener; + this.collectListener = collectListener; this.latestChanges = latestChanges; this.version = version; importer = new SettingsImporter(app); - collectOnly = true; - state = State.COLLECT; + importType = ImportType.COLLECT; } ImportAsyncTask(@NonNull File file, @NonNull List items, String latestChanges, int version, @Nullable SettingsImportListener importListener) { @@ -1853,8 +1817,7 @@ public class SettingsHelper { this.latestChanges = latestChanges; this.version = version; importer = new SettingsImporter(app); - collectOnly = false; - state = State.IMPORT; + importType = ImportType.IMPORT; } ImportAsyncTask(@NonNull File file, @NonNull List items, @NonNull List selectedItems, @Nullable CheckDuplicatesListener duplicatesListener) { @@ -1863,23 +1826,21 @@ public class SettingsHelper { this.duplicatesListener = duplicatesListener; this.selectedItems = selectedItems; importer = new SettingsImporter(app); - collectOnly = true; - state = State.CHECK_DUPLICATES; + importType = ImportType.CHECK_DUPLICATES; } @Override protected void onPreExecute() { - if (importing) { - finishImport(importListener, false, false, items); + ImportAsyncTask importTask = SettingsHelper.this.importTask; + if (importTask != null && !importTask.importDone) { + finishImport(importListener, false, items); } - importing = true; - importSuspended = false; - importTask = this; + SettingsHelper.this.importTask = this; } @Override protected List doInBackground(Void... voids) { - switch (state) { + switch (importType) { case COLLECT: try { return importer.collectItems(file); @@ -1890,98 +1851,49 @@ public class SettingsHelper { } break; case CHECK_DUPLICATES: - checkingDuplicates = true; - long startTime = System.currentTimeMillis(); - List duplicatesData = getDuplicatesData(this.selectedItems); - long diffTime = System.currentTimeMillis() - startTime; - if (diffTime < 500 && diffTime >= 0) { - try { - Thread.sleep(500 - diffTime); - } catch (InterruptedException e) { - LOG.error("Error on check duplicates delay" + e); - } - } - this.duplicates = duplicatesData; + this.duplicates = getDuplicatesData(selectedItems); return selectedItems; case IMPORT: - return this.items; + return items; } return null; } @Override protected void onPostExecute(@Nullable List items) { - if (items != null && !State.CHECK_DUPLICATES.equals(state)) { + if (items != null && importType != ImportType.CHECK_DUPLICATES) { this.items = items; } else { selectedItems = items; } - switch (state) { + switch (importType) { case COLLECT: - importListener.onSettingsImportFinished(true, false, this.items); + importDone = true; + collectListener.onSettingsCollectFinished(true, false, this.items); break; case CHECK_DUPLICATES: - checkingDuplicates = false; + importDone = true; if (duplicatesListener != null) { - duplicatesListener.onDuplicatesChecked(duplicates, this.selectedItems); + duplicatesListener.onDuplicatesChecked(duplicates, selectedItems); } break; case IMPORT: if (items != null && items.size() > 0) { - processNextItem(); + for (SettingsItem item : items) { + item.apply(); + } + new ImportItemsAsyncTask(file, importListener, items).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } break; } } - private void processNextItem() { - if (activity == null) { - return; - } - if (items.size() == 0 && !importSuspended) { - if (processedItems.size() > 0) { - new ImportItemsAsyncTask(file, importListener, processedItems).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } else { - finishImport(importListener, false, true, items); - } - return; - } - final SettingsItem item; - if (importSuspended && currentItem != null) { - item = currentItem; - } else if (items.size() > 0) { - item = items.remove(0); - currentItem = item; - } else { - item = null; - } - importSuspended = false; - if (item != null) { - acceptItem(item); - } else { - processNextItem(); - } - } - - private void suspendImport() { - if (dialog != null) { - dialog.dismiss(); - dialog = null; - } - } - - private void acceptItem(SettingsItem item) { - item.apply(); - processedItems.add(item); - processNextItem(); - } - public List getItems() { - return this.items; + return items; } public File getFile() { - return this.file; + return file; } public void setImportListener(SettingsImportListener importListener) { @@ -1992,33 +1904,37 @@ public class SettingsHelper { this.duplicatesListener = duplicatesListener; } - public State getState() { - return this.state; + ImportType getImportType() { + return importType; + } + + boolean isImportDone() { + return importDone; } public List getDuplicates() { - return this.duplicates; + return duplicates; } public List getSelectedItems() { - return this.selectedItems; + return selectedItems; } private List getDuplicatesData(List items) { List duplicateItems = new ArrayList<>(); for (SettingsItem item : items) { - if (item instanceof SettingsHelper.ProfileSettingsItem) { + if (item instanceof ProfileSettingsItem) { if (item.exists()) { - duplicateItems.add(((SettingsHelper.ProfileSettingsItem) item).getModeBean()); + duplicateItems.add(((ProfileSettingsItem) item).getModeBean()); } - } else if (item instanceof SettingsHelper.CollectionSettingsItem) { + } else if (item instanceof CollectionSettingsItem) { List duplicates = ((CollectionSettingsItem) item).excludeDuplicateItems(); if (!duplicates.isEmpty()) { duplicateItems.addAll(duplicates); } - } else if (item instanceof SettingsHelper.FileSettingsItem) { + } else if (item instanceof FileSettingsItem) { if (item.exists()) { - duplicateItems.add(((SettingsHelper.FileSettingsItem) item).getFile()); + duplicateItems.add(((FileSettingsItem) item).getFile()); } } } @@ -2032,8 +1948,14 @@ public class SettingsHelper { } @Nullable - public State getImportTaskState() { - return importTask != null ? importTask.getState() : null; + public ImportType getImportTaskType() { + ImportAsyncTask importTask = this.importTask; + return importTask != null ? importTask.getImportType() : null; + } + + public boolean isImportDone() { + ImportAsyncTask importTask = this.importTask; + return importTask == null || importTask.isImportDone(); } public boolean isFileExporting(File file) { @@ -2079,16 +2001,14 @@ public class SettingsHelper { @Override protected void onPostExecute(Boolean success) { - finishImport(listener, success, false, items); + finishImport(listener, success, items); } } - private void finishImport(@Nullable SettingsImportListener listener, boolean success, boolean empty, @NonNull List items) { - importing = false; - importSuspended = false; + private void finishImport(@Nullable SettingsImportListener listener, boolean success, @NonNull List items) { importTask = null; if (listener != null) { - listener.onSettingsImportFinished(success, empty, items); + listener.onSettingsImportFinished(success, items); } } @@ -2132,13 +2052,13 @@ public class SettingsHelper { } } - public void checkDuplicates(@NonNull File file, @NonNull List items, @NonNull List selectedItems, CheckDuplicatesListener listener) { - new ImportAsyncTask(file, items, selectedItems, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + public void collectSettings(@NonNull File settingsFile, String latestChanges, int version, + @Nullable SettingsCollectListener listener) { + new ImportAsyncTask(settingsFile, latestChanges, version, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } - public void importSettings(@NonNull File settingsFile, String latestChanges, int version, - @Nullable SettingsImportListener listener) { - new ImportAsyncTask(settingsFile, latestChanges, version, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + public void checkDuplicates(@NonNull File file, @NonNull List items, @NonNull List selectedItems, CheckDuplicatesListener listener) { + new ImportAsyncTask(file, items, selectedItems, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } public void importSettings(@NonNull File settingsFile, @NonNull List items, String latestChanges, int version, @Nullable SettingsImportListener listener) { @@ -2157,7 +2077,7 @@ public class SettingsHelper { exportSettings(fileDir, fileName, listener, new ArrayList<>(Arrays.asList(items))); } - public enum State { + public enum ImportType { COLLECT, CHECK_DUPLICATES, IMPORT diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 4f86cb8445..c086cca099 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -909,7 +909,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } app.getDownloadThread().setUiActivity(this); - app.getSettingsHelper().setActivity(this); boolean routeWasFinished = routingHelper.isRouteWasFinished(); if (routeWasFinished && !DestinationReachedMenu.wasShown()) { @@ -1510,7 +1509,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven app.getMapMarkersHelper().removeListener(this); app.getRoutingHelper().removeListener(this); app.getDownloadThread().resetUiActivity(this); - app.getSettingsHelper().resetActivity(this); if (atlasMapRendererView != null) { atlasMapRendererView.handleOnPause(); } diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index 4411ef4551..978d42c74f 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -1,7 +1,6 @@ package net.osmand.plus.helpers; import android.annotation.SuppressLint; -import android.app.Activity; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; @@ -48,6 +47,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.SettingsHelper; +import net.osmand.plus.SettingsHelper.SettingsCollectListener; import net.osmand.plus.SettingsHelper.SettingsImportListener; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.ActivityResultListener; @@ -780,17 +780,14 @@ public class ImportHelper { File tempDir = app.getAppPath(IndexConstants.TEMP_DIR); final File file = new File(tempDir, name); if (error == null && file.exists()) { - app.getSettingsHelper().importSettings(file, latestChanges, version, new SettingsImportListener() { + app.getSettingsHelper().collectSettings(file, latestChanges, version, new SettingsCollectListener() { @Override - public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { + public void onSettingsCollectFinished(boolean succeed, boolean empty, @NonNull List items) { if (AndroidUtils.isActivityNotDestroyed(activity)) { progress.dismiss(); } if (succeed) { - FragmentManager fragmentManager = activity.getSupportFragmentManager(); - if (fragmentManager != null) { - ImportSettingsFragment.showInstance(fragmentManager, items, file); - } + ImportSettingsFragment.showInstance(activity.getSupportFragmentManager(), items, file); } else if (empty) { app.showShortToastMessage(app.getString(R.string.file_import_error, name, app.getString(R.string.shared_string_unexpected_error))); } diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java index c139c607e7..7238fde88f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java @@ -36,6 +36,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.SettingsHelper; +import net.osmand.plus.SettingsHelper.SettingsCollectListener; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; @@ -182,9 +183,9 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co } private void restoreCustomModeFromFile(final File file) { - app.getSettingsHelper().importSettings(file, "", 1, new SettingsHelper.SettingsImportListener() { + app.getSettingsHelper().collectSettings(file, "", 1, new SettingsCollectListener() { @Override - public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { + public void onSettingsCollectFinished(boolean succeed, boolean empty, @NonNull List items) { if (succeed) { for (SettingsHelper.SettingsItem item : items) { item.setShouldReplace(true); @@ -198,7 +199,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co private void importBackupSettingsItems(File file, List items) { app.getSettingsHelper().importSettings(file, items, "", 1, new SettingsHelper.SettingsImportListener() { @Override - public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { + public void onSettingsImportFinished(boolean succeed, @NonNull List items) { app.showToastMessage(R.string.profile_prefs_reset_successful); updateCopiedOrResetPrefs(); } diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java index c202a1625a..fa13b9d6a6 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java @@ -29,6 +29,8 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.SettingsHelper; +import net.osmand.plus.SettingsHelper.ImportAsyncTask; +import net.osmand.plus.SettingsHelper.ImportType; import net.osmand.plus.SettingsHelper.SettingsItem; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.BaseOsmAndFragment; @@ -78,7 +80,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View app = requireMyApplication(); settingsHelper = app.getSettingsHelper(); nightMode = !app.getSettings().isLightContent(); - SettingsHelper.ImportAsyncTask importTask = settingsHelper.getImportTask(); + ImportAsyncTask importTask = settingsHelper.getImportTask(); if (importTask != null) { if (settingsItems == null) { settingsItems = importTask.getSelectedItems(); @@ -151,8 +153,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View list.setLayoutManager(new LinearLayoutManager(getMyApplication())); list.setAdapter(adapter); } - SettingsHelper.State state = settingsHelper.getImportTaskState(); - if (settingsHelper.isImporting() && !settingsHelper.isCollectOnly() && state != null && state.equals(SettingsHelper.State.IMPORT)) { + if (settingsHelper.getImportTaskType() == ImportType.IMPORT) { setupImportingUi(); } else { toolbarLayout.setTitle(getString(R.string.import_duplicates_title)); @@ -272,7 +273,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View private SettingsHelper.SettingsImportListener getImportListener() { return new SettingsHelper.SettingsImportListener() { @Override - public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { + public void onSettingsImportFinished(boolean succeed, @NonNull List items) { if (succeed) { app.getRendererRegistry().updateExternalRenderers(); AppInitializer.loadRoutingFiles(app, new AppInitializer.LoadRoutingFilesCallback() { @@ -284,9 +285,6 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View if (fm != null && file != null) { ImportCompleteFragment.showInstance(fm, items, file.getName()); } - } else if (empty) { - dismissFragment(); - app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error))); } } }; diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index 6eb1aa5014..9687ab4e34 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -35,6 +35,7 @@ import net.osmand.plus.R; import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.SettingsHelper; import net.osmand.plus.SettingsHelper.ImportAsyncTask; +import net.osmand.plus.SettingsHelper.ImportType; import net.osmand.plus.SettingsHelper.SettingsItem; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.BaseOsmAndFragment; @@ -120,18 +121,18 @@ public class ImportSettingsFragment extends BaseOsmAndFragment @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - ImportAsyncTask importAsyncTask = settingsHelper.getImportTask(); - if (importAsyncTask != null) { + ImportAsyncTask importTask = settingsHelper.getImportTask(); + if (importTask != null) { if (settingsItems == null) { - settingsItems = importAsyncTask.getItems(); + settingsItems = importTask.getItems(); } if (file == null) { - file = importAsyncTask.getFile(); + file = importTask.getFile(); } - List duplicates = importAsyncTask.getDuplicates(); - List selectedItems = importAsyncTask.getSelectedItems(); + List duplicates = importTask.getDuplicates(); + List selectedItems = importTask.getSelectedItems(); if (duplicates == null) { - importAsyncTask.setDuplicatesListener(getDuplicatesListener()); + importTask.setDuplicatesListener(getDuplicatesListener()); } else if (duplicates.isEmpty()) { if (selectedItems != null && file != null) { settingsHelper.importSettings(file, selectedItems, "", 1, getImportListener()); @@ -146,10 +147,10 @@ public class ImportSettingsFragment extends BaseOsmAndFragment expandableList.setAdapter(adapter); toolbarLayout.setTitle(getString(R.string.shared_string_import)); - SettingsHelper.State state = settingsHelper.getImportTaskState(); - if (settingsHelper.isCheckingDuplicates()) { + ImportType importTaskType = settingsHelper.getImportTaskType(); + if (importTaskType == ImportType.CHECK_DUPLICATES && !settingsHelper.isImportDone()) { updateUi(R.string.shared_string_preparing, R.string.checking_for_duplicate_description); - } else if (settingsHelper.isImporting() && !settingsHelper.isCollectOnly() && state != null && state.equals(SettingsHelper.State.IMPORT)) { + } else if (importTaskType == ImportType.IMPORT) { updateUi(R.string.shared_string_importing, R.string.importing_from); } else { toolbarLayout.setTitle(getString(R.string.shared_string_import)); @@ -202,7 +203,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment private SettingsHelper.SettingsImportListener getImportListener() { return new SettingsHelper.SettingsImportListener() { @Override - public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List items) { + public void onSettingsImportFinished(boolean succeed, @NonNull List items) { FragmentManager fm = getFragmentManager(); if (succeed) { app.getRendererRegistry().updateExternalRenderers(); @@ -214,9 +215,6 @@ public class ImportSettingsFragment extends BaseOsmAndFragment if (fm != null && file != 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(); } } }; From 16b3f81ac85ba59c5d08d295671b0075ce55d973 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 13 Mar 2020 13:11:54 +0200 Subject: [PATCH 25/30] duplicates delay --- .../plus/settings/ImportSettingsFragment.java | 55 ++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index 9687ab4e34..e6fa0a91a7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -59,6 +59,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment public static final String TAG = ImportSettingsFragment.class.getSimpleName(); public static final Log LOG = PlatformUtil.getLog(ImportSettingsFragment.class.getSimpleName()); + private static final String DUPLICATES_START_TIME_KEY = "duplicates_start_time"; static final String IMPORT_SETTINGS_TAG = "import_settings_tag"; private OsmandApplication app; private ExportImportSettingsAdapter adapter; @@ -73,6 +74,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment private ProgressBar progressBar; private CollapsingToolbarLayout toolbarLayout; private SettingsHelper settingsHelper; + private long duplicateStartTime; public static void showInstance(@NonNull FragmentManager fm, @NonNull List settingsItems, @NonNull File file) { ImportSettingsFragment fragment = new ImportSettingsFragment(); @@ -87,6 +89,9 @@ public class ImportSettingsFragment extends BaseOsmAndFragment @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + if (savedInstanceState != null) { + duplicateStartTime = savedInstanceState.getLong(DUPLICATES_START_TIME_KEY); + } app = requireMyApplication(); settingsHelper = app.getSettingsHelper(); nightMode = !app.getSettings().isLightContent(); @@ -157,6 +162,12 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } } + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + outState.putLong(DUPLICATES_START_TIME_KEY, duplicateStartTime); + } + @Override public void onClick(View view) { switch (view.getId()) { @@ -196,6 +207,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment updateUi(R.string.shared_string_preparing, R.string.checking_for_duplicate_description); List selectedItems = getSettingsItemsFromData(adapter.getDataToOperate()); if (file != null && settingsItems != null) { + duplicateStartTime = System.currentTimeMillis(); settingsHelper.checkDuplicates(file, settingsItems, selectedItems, getDuplicatesListener()); } } @@ -223,26 +235,41 @@ public class ImportSettingsFragment extends BaseOsmAndFragment private SettingsHelper.CheckDuplicatesListener getDuplicatesListener() { return new SettingsHelper.CheckDuplicatesListener() { @Override - public void onDuplicatesChecked(@NonNull List duplicates, List items) { - FragmentManager fm = getFragmentManager(); - if (duplicates.isEmpty()) { - if (isAdded()) { - updateUi(R.string.shared_string_importing, R.string.importing_from); - } - if (file != null) { - settingsHelper.importSettings(file, items, "", 1, getImportListener()); - } - } else { - if (fm != null && file != null) { - if (!isStateSaved()) { - ImportDuplicatesFragment.showInstance(fm, duplicates, items, file); + public void onDuplicatesChecked(@NonNull final List duplicates, final List items) { + long delay = System.currentTimeMillis() - duplicateStartTime; + delay = delay < 500 ? 500 - delay : 0; + if (delay != 0) { + app.runInUIThread(new Runnable() { + @Override + public void run() { + processDuplicates(duplicates, items); } - } + }, delay); + } else { + processDuplicates(duplicates, items); } } }; } + private void processDuplicates(List duplicates, List items) { + FragmentManager fm = getFragmentManager(); + if (duplicates.isEmpty()) { + if (isAdded()) { + updateUi(R.string.shared_string_importing, R.string.importing_from); + } + if (file != null) { + settingsHelper.importSettings(file, items, "", 1, getImportListener()); + } + } else { + if (fm != null && file != null) { + if (!isStateSaved()) { + ImportDuplicatesFragment.showInstance(fm, duplicates, items, file); + } + } + } + } + private void dismissFragment() { FragmentManager fm = getFragmentManager(); if (fm != null) { From caaa7bb3fd0401a00b1819e446f5234392331aed Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 13 Mar 2020 13:46:57 +0200 Subject: [PATCH 26/30] refactor delay --- .../plus/settings/ImportSettingsFragment.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index e6fa0a91a7..1314d117d2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -60,6 +60,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment public static final String TAG = ImportSettingsFragment.class.getSimpleName(); public static final Log LOG = PlatformUtil.getLog(ImportSettingsFragment.class.getSimpleName()); private static final String DUPLICATES_START_TIME_KEY = "duplicates_start_time"; + private static final long MIN_DELAY_TIME = 500; static final String IMPORT_SETTINGS_TAG = "import_settings_tag"; private OsmandApplication app; private ExportImportSettingsAdapter adapter; @@ -236,9 +237,9 @@ public class ImportSettingsFragment extends BaseOsmAndFragment return new SettingsHelper.CheckDuplicatesListener() { @Override public void onDuplicatesChecked(@NonNull final List duplicates, final List items) { - long delay = System.currentTimeMillis() - duplicateStartTime; - delay = delay < 500 ? 500 - delay : 0; - if (delay != 0) { + long spentTime = System.currentTimeMillis() - duplicateStartTime; + if (spentTime < MIN_DELAY_TIME) { + long delay = MIN_DELAY_TIME - spentTime; app.runInUIThread(new Runnable() { @Override public void run() { @@ -254,19 +255,13 @@ public class ImportSettingsFragment extends BaseOsmAndFragment private void processDuplicates(List duplicates, List items) { FragmentManager fm = getFragmentManager(); - if (duplicates.isEmpty()) { + if (duplicates.isEmpty() && file != null) { if (isAdded()) { updateUi(R.string.shared_string_importing, R.string.importing_from); } - if (file != null) { - settingsHelper.importSettings(file, items, "", 1, getImportListener()); - } - } else { - if (fm != null && file != null) { - if (!isStateSaved()) { - ImportDuplicatesFragment.showInstance(fm, duplicates, items, file); - } - } + settingsHelper.importSettings(file, items, "", 1, getImportListener()); + } else if (fm != null && file != null && !isStateSaved()) { + ImportDuplicatesFragment.showInstance(fm, duplicates, items, file); } } From 1920bf7b9aca022dfa4357b7bfc8069dd938f3e5 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 13 Mar 2020 14:09:27 +0200 Subject: [PATCH 27/30] resolve conflicts / refactor --- .../plus/settings/ImportCompleteFragment.java | 4 +-- .../settings/ImportDuplicatesFragment.java | 9 +------ .../plus/settings/ImportSettingsFragment.java | 27 +++++++++---------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java index 9b52bf23ee..725281c31f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportCompleteFragment.java @@ -110,7 +110,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { public void dismissFragment() { FragmentManager fm = getFragmentManager(); - if (fm != null) { + if (fm != null && !fm.isStateSaved()) { fm.popBackStack(IMPORT_SETTINGS_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); } } @@ -118,7 +118,7 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { private void navigateTo(Type type) { FragmentManager fm = getFragmentManager(); Activity activity = requireActivity(); - if (fm == null) { + if (fm == null || fm.isStateSaved()) { return; } dismissFragment(); diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java index fa13b9d6a6..fa702f252d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportDuplicatesFragment.java @@ -241,13 +241,6 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light; } - private void dismissFragment() { - FragmentManager fm = getFragmentManager(); - if (fm != null) { - fm.popBackStack(IMPORT_SETTINGS_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); - } - } - private void importItems(boolean shouldReplace) { if (settingsItems != null && file != null) { setupImportingUi(); @@ -301,7 +294,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment implements View @Override public void onClick(View v) { FragmentManager fm = getFragmentManager(); - if (fm != null) { + if (fm != null && !fm.isStateSaved()) { fm.popBackStackImmediate(); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index 1314d117d2..8598964dcd 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -60,7 +60,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment public static final String TAG = ImportSettingsFragment.class.getSimpleName(); public static final Log LOG = PlatformUtil.getLog(ImportSettingsFragment.class.getSimpleName()); private static final String DUPLICATES_START_TIME_KEY = "duplicates_start_time"; - private static final long MIN_DELAY_TIME = 500; + private static final long MIN_DELAY_TIME_MS = 500; static final String IMPORT_SETTINGS_TAG = "import_settings_tag"; private OsmandApplication app; private ExportImportSettingsAdapter adapter; @@ -238,8 +238,8 @@ public class ImportSettingsFragment extends BaseOsmAndFragment @Override public void onDuplicatesChecked(@NonNull final List duplicates, final List items) { long spentTime = System.currentTimeMillis() - duplicateStartTime; - if (spentTime < MIN_DELAY_TIME) { - long delay = MIN_DELAY_TIME - spentTime; + if (spentTime < MIN_DELAY_TIME_MS) { + long delay = MIN_DELAY_TIME_MS - spentTime; app.runInUIThread(new Runnable() { @Override public void run() { @@ -255,19 +255,21 @@ public class ImportSettingsFragment extends BaseOsmAndFragment private void processDuplicates(List duplicates, List items) { FragmentManager fm = getFragmentManager(); - if (duplicates.isEmpty() && file != null) { - if (isAdded()) { - updateUi(R.string.shared_string_importing, R.string.importing_from); + if (file != null) { + if (duplicates.isEmpty()) { + if (isAdded()) { + updateUi(R.string.shared_string_importing, R.string.importing_from); + } + settingsHelper.importSettings(file, items, "", 1, getImportListener()); + } else if (fm != null && !isStateSaved()) { + ImportDuplicatesFragment.showInstance(fm, duplicates, items, file); } - settingsHelper.importSettings(file, items, "", 1, getImportListener()); - } else if (fm != null && file != null && !isStateSaved()) { - ImportDuplicatesFragment.showInstance(fm, duplicates, items, file); } } private void dismissFragment() { FragmentManager fm = getFragmentManager(); - if (fm != null) { + if (fm != null && !fm.isStateSaved()) { getFragmentManager().popBackStack(IMPORT_SETTINGS_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); } } @@ -386,10 +388,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment dismissDialog.setPositiveButton(R.string.shared_string_exit, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - FragmentManager fm = getFragmentManager(); - if (fm != null) { - fm.popBackStack(IMPORT_SETTINGS_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE); - } + dismissFragment(); } }); dismissDialog.show(); From b704f92d37aa4e2053bbccc5070c4b69acda5bd7 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 13 Mar 2020 16:19:32 +0200 Subject: [PATCH 28/30] refactor --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 4 +- .../settings/ExportImportSettingsAdapter.java | 10 +++-- .../plus/settings/ImportSettingsFragment.java | 40 +++++++++---------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 6fa7095d21..c7c8cbc447 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -566,9 +566,7 @@ public class UiUtilities { } } - public static SpannableString createSpannableString(@NonNull String text, - @NonNull String textToStyle, - @NonNull StyleSpan styleSpan) { + public static SpannableString createSpannableString(@NonNull String text, @NonNull String textToStyle, @NonNull StyleSpan styleSpan) { SpannableString spannable = new SpannableString(text); try { int startIndex = text.indexOf(textToStyle); diff --git a/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java index f67887ea4d..17e3acafb3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java @@ -30,6 +30,7 @@ import net.osmand.view.ThreeStateCheckbox; import java.io.File; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -115,7 +116,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { notifyDataSetChanged(); } }); - adjustIndicator(app, groupPosition, isExpanded, group, true); + adjustIndicator(app, groupPosition, isExpanded, group, nightMode); return group; } @@ -229,7 +230,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { @Override public int getGroupCount() { - return itemsMap.keySet().size(); + return itemsTypes.size(); } @Override @@ -291,6 +292,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { public void updateSettingsList(Map> itemsMap) { this.itemsMap = itemsMap; this.itemsTypes = new ArrayList<>(itemsMap.keySet()); + Collections.sort(itemsTypes); notifyDataSetChanged(); } @@ -303,8 +305,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { public void selectAll(boolean selectAll) { dataToOperate.clear(); if (selectAll) { - for (Map.Entry> map : itemsMap.entrySet()) { - dataToOperate.addAll(map.getValue()); + for (List values : itemsMap.values()) { + dataToOperate.addAll(values); } } notifyDataSetChanged(); diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index 8598964dcd..2ba4a77817 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -34,9 +34,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.SettingsHelper; -import net.osmand.plus.SettingsHelper.ImportAsyncTask; -import net.osmand.plus.SettingsHelper.ImportType; -import net.osmand.plus.SettingsHelper.SettingsItem; +import net.osmand.plus.SettingsHelper.*; import net.osmand.plus.UiUtilities; import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; @@ -326,27 +324,27 @@ public class ImportSettingsFragment extends BaseOsmAndFragment List renderFilesList = new ArrayList<>(); List avoidRoads = new ArrayList<>(); - for (SettingsHelper.SettingsItem item : settingsItems) { - if (item.getType().equals(SettingsHelper.SettingsItemType.PROFILE)) { - 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)) { + for (SettingsItem item : settingsItems) { + if (item.getType().equals(SettingsItemType.PROFILE)) { + profiles.add(((ProfileSettingsItem) item).getModeBean()); + } else if (item.getType().equals(SettingsItemType.QUICK_ACTION)) { + quickActions.addAll(((QuickActionSettingsItem) item).getItems()); + quickActions.addAll(((QuickActionSettingsItem) item).getDuplicateItems()); + } else if (item.getType().equals(SettingsItemType.POI_UI_FILTERS)) { + poiUIFilters.addAll(((PoiUiFilterSettingsItem) item).getItems()); + poiUIFilters.addAll(((PoiUiFilterSettingsItem) item).getDuplicateItems()); + } else if (item.getType().equals(SettingsItemType.MAP_SOURCES)) { + tileSourceTemplates.addAll(((MapSourcesSettingsItem) item).getItems()); + tileSourceTemplates.addAll(((MapSourcesSettingsItem) item).getDuplicateItems()); + } else if (item.getType().equals(SettingsItemType.FILE)) { if (item.getName().contains(IndexConstants.RENDERERS_DIR)) { - renderFilesList.add(((SettingsHelper.FileSettingsItem) item).getFile()); + renderFilesList.add(((FileSettingsItem) item).getFile()); } else if (item.getName().contains(IndexConstants.ROUTING_PROFILES_DIR)) { - routingFilesList.add(((SettingsHelper.FileSettingsItem) item).getFile()); + routingFilesList.add(((FileSettingsItem) item).getFile()); } - } else if (item.getType().equals(SettingsHelper.SettingsItemType.AVOID_ROADS)) { - avoidRoads.addAll(((SettingsHelper.AvoidRoadsSettingsItem) item).getItems()); - avoidRoads.addAll(((SettingsHelper.AvoidRoadsSettingsItem) item).getDuplicateItems()); + } else if (item.getType().equals(SettingsItemType.AVOID_ROADS)) { + avoidRoads.addAll(((AvoidRoadsSettingsItem) item).getItems()); + avoidRoads.addAll(((AvoidRoadsSettingsItem) item).getDuplicateItems()); } } From 63cdd079f51533e3dadd2d4d020348ef3b068c57 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 13 Mar 2020 16:24:06 +0200 Subject: [PATCH 29/30] itemsType sort --- .../net/osmand/plus/settings/ImportedSettingsItemsAdapter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java index f22e43faf7..bdd66578a7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java @@ -17,6 +17,7 @@ import net.osmand.plus.settings.ExportImportSettingsAdapter.Type; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -38,6 +39,7 @@ public class ImportedSettingsItemsAdapter extends this.listener = listener; uiUtils = app.getUIUtilities(); itemsTypes = new ArrayList<>(itemsMap.keySet()); + Collections.sort(itemsTypes); } @NonNull From 972380f53767c0b43c5128d284ba54615684b783 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 13 Mar 2020 18:01:51 +0200 Subject: [PATCH 30/30] Add slope legend image --- OsmAnd/res/drawable/img_legend_slope.xml | 102 +++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 OsmAnd/res/drawable/img_legend_slope.xml diff --git a/OsmAnd/res/drawable/img_legend_slope.xml b/OsmAnd/res/drawable/img_legend_slope.xml new file mode 100644 index 0000000000..e3a8566e45 --- /dev/null +++ b/OsmAnd/res/drawable/img_legend_slope.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +