diff --git a/OsmAnd/res/layout/fragment_import.xml b/OsmAnd/res/layout/fragment_import.xml index 5706475468..ffc6165836 100644 --- a/OsmAnd/res/layout/fragment_import.xml +++ b/OsmAnd/res/layout/fragment_import.xml @@ -127,14 +127,16 @@ - diff --git a/OsmAnd/res/layout/fragment_import_complete.xml b/OsmAnd/res/layout/fragment_import_complete.xml index 7983465d43..cb99048206 100644 --- a/OsmAnd/res/layout/fragment_import_complete.xml +++ b/OsmAnd/res/layout/fragment_import_complete.xml @@ -31,6 +31,7 @@ android:paddingTop="@dimen/list_header_settings_top_margin" android:paddingEnd="@dimen/content_padding" android:paddingBottom="@dimen/list_header_settings_top_margin" + android:lineSpacingMultiplier="@dimen/line_spacing_multiplier_description" android:textColor="?android:textColorPrimary" android:textSize="@dimen/default_list_text_size" tools:text="@string/import_complete_description" /> diff --git a/OsmAnd/res/layout/fragment_import_duplicates.xml b/OsmAnd/res/layout/fragment_import_duplicates.xml index d5f25eb5af..8e5cbc2a61 100644 --- a/OsmAnd/res/layout/fragment_import_duplicates.xml +++ b/OsmAnd/res/layout/fragment_import_duplicates.xml @@ -26,6 +26,7 @@ android:paddingTop="@dimen/list_header_settings_top_margin" android:paddingEnd="@dimen/content_padding" android:paddingBottom="@dimen/list_header_settings_top_margin" + android:lineSpacingMultiplier="@dimen/line_spacing_multiplier_description" android:text="@string/import_duplicates_description" android:textColor="?android:textColorPrimary" android:textSize="@dimen/default_list_text_size" /> @@ -135,14 +136,16 @@ - diff --git a/OsmAnd/res/layout/list_item_description_header.xml b/OsmAnd/res/layout/list_item_description_header.xml index 1a8c777b87..f27db51731 100644 --- a/OsmAnd/res/layout/list_item_description_header.xml +++ b/OsmAnd/res/layout/list_item_description_header.xml @@ -13,6 +13,7 @@ android:paddingStart="@dimen/content_padding" android:paddingTop="@dimen/list_header_settings_top_margin" android:paddingEnd="@dimen/content_padding" + android:lineSpacingMultiplier="@dimen/line_spacing_multiplier_description" android:paddingBottom="@dimen/list_header_settings_top_margin" android:textColor="?android:textColorPrimary" android:textSize="@dimen/default_list_text_size" diff --git a/OsmAnd/res/values/dimens.xml b/OsmAnd/res/values/dimens.xml index 509f5371fa..d31963861a 100644 --- a/OsmAnd/res/values/dimens.xml +++ b/OsmAnd/res/values/dimens.xml @@ -14,4 +14,6 @@ 280dp 160dp + 1.2 + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index f632d64851..fa17acd6fb 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -24,6 +24,7 @@ Hide terrain Show/hide terrain Slopes + %1$s of %2$s The route will be recalculated if the distance from the route to the current location is more than selected value. Select the distance after which the route will be recalculated. Recalculate route in case of deviation diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index 63476b4f7d..35cd7d471a 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -735,18 +735,35 @@ public class SettingsHelper { } private void renameProfile() { + List values = ApplicationMode.allPossibleValues(); + if (Algorithms.isEmpty(modeBean.userProfileName)) { + ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null); + if (appMode != null) { + modeBean.userProfileName = app.getString(appMode.getNameKeyResource()); + } + } int number = 0; while (true) { number++; String key = modeBean.stringKey + "_" + number; - if (ApplicationMode.valueOfStringKey(key, null) == null) { + String name = modeBean.userProfileName + '_' + number; + if (ApplicationMode.valueOfStringKey(key, null) == null && isNameUnique(values, name)) { + modeBean.userProfileName = name; modeBean.stringKey = key; - modeBean.userProfileName = modeBean.userProfileName + "_" + number; break; } } } + private boolean isNameUnique(List values, String name) { + for (ApplicationMode mode : values) { + if (mode.getUserProfileName().equals(name)) { + return false; + } + } + return true; + } + @Override public void apply() { if (!appMode.isCustomProfile() && !shouldReplace) { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java index 051152cd60..714abee320 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java @@ -34,6 +34,7 @@ import net.osmand.plus.quickaction.actions.NewAction; import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction; import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction; import net.osmand.plus.quickaction.actions.ShowHidePoiAction; +import net.osmand.util.Algorithms; import java.lang.reflect.Type; import java.util.ArrayList; @@ -190,19 +191,24 @@ public class QuickActionRegistry { private List parseActiveActionsList(String json) { - Type type = new TypeToken>() { - }.getType(); - List quickActions = gson.fromJson(json, type); - List rquickActions = new ArrayList<>(); - if (quickActions != null) { - for (QuickAction qa : quickActions) { - if (qa != null) { - rquickActions.add(qa); + List resQuickActions; + if (!Algorithms.isEmpty(json)) { + Type type = new TypeToken>() { + }.getType(); + List quickActions = gson.fromJson(json, type); + resQuickActions = new ArrayList<>(quickActions.size()); + if (quickActions != null) { + for (QuickAction qa : quickActions) { + if (qa != null) { + resQuickActions.add(qa); + } } } + } else { + resQuickActions = new ArrayList<>(); } - this.quickActions = rquickActions; - return rquickActions; + this.quickActions = resQuickActions; + return resQuickActions; } public List updateActionTypes() { diff --git a/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java index f1ee92137e..0d4338c690 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView; import net.osmand.AndroidUtils; import net.osmand.IndexConstants; +import net.osmand.PlatformUtil; import net.osmand.map.ITileSource; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode.ApplicationModeBean; @@ -20,15 +21,19 @@ import net.osmand.plus.UiUtilities; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.profiles.ProfileIconColors; +import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.render.RenderingIcons; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; + import java.io.File; import java.util.List; public class DuplicatesSettingsAdapter extends RecyclerView.Adapter { + private static final Log LOG = PlatformUtil.getLog(DuplicatesSettingsAdapter.class.getName()); private static final int HEADER_TYPE = 0; private static final int ITEM_TYPE = 1; @@ -81,7 +86,17 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter dataToOperate; @@ -91,7 +97,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, activeColorRes))); final List listItems = itemsMap.get(type); - subTextTv.setText(String.valueOf(listItems.size())); + subTextTv.setText(getSelectedItemsAmount(listItems)); if (dataToOperate.containsAll(listItems)) { checkBox.setState(CHECKED); @@ -165,13 +171,24 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { switch (type) { case PROFILE: - String profileName = ((ApplicationMode.ApplicationModeBean) currentItem).userProfileName; + ApplicationModeBean modeBean = (ApplicationModeBean) currentItem; + String profileName = modeBean.userProfileName; if (Algorithms.isEmpty(profileName)) { - ApplicationMode appMode = ApplicationMode.valueOfStringKey(((ApplicationMode.ApplicationModeBean) currentItem).stringKey, null); + ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null); profileName = app.getString(appMode.getNameKeyResource()); } title.setText(profileName); - String routingProfile = (((ApplicationMode.ApplicationModeBean) currentItem).routingProfile); + String routingProfile = ""; + String routingProfileValue = modeBean.routingProfile; + if (!routingProfileValue.isEmpty()) { + try { + routingProfile = app.getString(RoutingProfilesResources.valueOf(routingProfileValue.toUpperCase()).getStringRes()); + routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfile); + } catch (IllegalArgumentException e) { + routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfileValue); + LOG.error("Error trying to get routing resource for " + routingProfileValue + "\n" + e); + } + } if (Algorithms.isEmpty(routingProfile)) { subText.setVisibility(View.GONE); } else { @@ -181,8 +198,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { routingProfile)); subText.setVisibility(View.VISIBLE); } - int profileIconRes = AndroidUtils.getDrawableId(app, ((ApplicationMode.ApplicationModeBean) currentItem).iconName); - ProfileIconColors iconColor = ((ApplicationMode.ApplicationModeBean) currentItem).iconColor; + int profileIconRes = AndroidUtils.getDrawableId(app, modeBean.iconName); + ProfileIconColors iconColor = modeBean.iconColor; icon.setImageDrawable(uiUtilities.getIcon(profileIconRes, iconColor.getColor(nightMode))); break; case QUICK_ACTIONS: @@ -267,6 +284,16 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { return true; } + private String getSelectedItemsAmount(List listItems) { + int amount = 0; + for (Object item : listItems) { + if (dataToOperate.contains(item)) { + amount++; + } + } + return app.getString(R.string.n_items_of_z, String.valueOf(amount), String.valueOf(listItems.size())); + } + private int getGroupTitle(Type type) { switch (type) { case PROFILE: diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java index f3e53c7d91..d2e52adc47 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -172,8 +172,10 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } adapter = new ExportImportSettingsAdapter(app, nightMode, true); + Map> itemsMap = new HashMap<>(); if (settingsItems != null) { - adapter.updateSettingsList(getSettingsToOperate(settingsItems)); + itemsMap = getSettingsToOperate(settingsItems); + adapter.updateSettingsList(itemsMap); } expandableList.setAdapter(adapter); toolbarLayout.setTitle(getString(R.string.shared_string_import)); @@ -186,6 +188,9 @@ public class ImportSettingsFragment extends BaseOsmAndFragment } else { toolbarLayout.setTitle(getString(R.string.shared_string_import)); } + if (itemsMap.size() == 1 && itemsMap.containsKey(Type.PROFILE)) { + expandableList.expandGroup(0); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java index bdd66578a7..3dd0e4102c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportedSettingsItemsAdapter.java @@ -1,5 +1,6 @@ package net.osmand.plus.settings; +import android.graphics.Typeface; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -13,6 +14,7 @@ import net.osmand.AndroidUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; +import net.osmand.plus.helpers.FontCache; import net.osmand.plus.settings.ExportImportSettingsAdapter.Type; @@ -60,6 +62,10 @@ public class ImportedSettingsItemsAdapter extends holder.icon.setPadding(0, 0, AndroidUtils.dpToPx(app, 16), 0); holder.title.setTextColor(app.getResources().getColor(activeColorRes)); + Typeface typeface = FontCache.getFont(app, app.getString(R.string.font_roboto_medium)); + if (typeface != null) { + holder.title.setTypeface(typeface); + } holder.divider.setVisibility(isLastItem ? View.VISIBLE : View.GONE); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override