From efb1615151d3ce19406bae605c16489b60f92aad Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 20 Mar 2020 15:39:36 +0200 Subject: [PATCH 1/8] navigation type appearance fix --- .../settings/ExportImportSettingsAdapter.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java index 34b00a5d2b..fcfb6ae424 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java @@ -14,7 +14,9 @@ import androidx.core.widget.CompoundButtonCompat; import net.osmand.AndroidUtils; import net.osmand.IndexConstants; +import net.osmand.PlatformUtil; import net.osmand.map.ITileSource; +import net.osmand.plus.ApplicationMode.ApplicationModeBean; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -23,11 +25,14 @@ import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; 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 net.osmand.view.ThreeStateCheckbox; +import org.apache.commons.logging.Log; + import java.io.File; import java.util.ArrayList; import java.util.Collections; @@ -41,6 +46,7 @@ import static net.osmand.view.ThreeStateCheckbox.State.UNCHECKED; class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { + private static final Log LOG = PlatformUtil.getLog(ExportImportSettingsAdapter.class.getName()); private OsmandApplication app; private UiUtilities uiUtilities; private List dataToOperate; @@ -165,13 +171,23 @@ 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()); + } catch (IllegalArgumentException e) { + routingProfile = routingProfileValue.substring(0, 1).toUpperCase() + routingProfileValue.substring(1); + LOG.error("Error trying to get routing resource for " + routingProfileValue + "\n" + e); + } + } if (Algorithms.isEmpty(routingProfile)) { subText.setVisibility(View.GONE); } else { @@ -181,8 +197,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: From db2fa7f99b1358c6aacb2897d026fc66e4187a07 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Fri, 20 Mar 2020 18:55:36 +0200 Subject: [PATCH 2/8] ui fixes / fix import duplicates profiles --- .../res/layout/fragment_import_complete.xml | 1 + .../res/layout/fragment_import_duplicates.xml | 1 + .../layout/list_item_description_header.xml | 1 + OsmAnd/res/values/dimens.xml | 2 ++ OsmAnd/res/values/strings.xml | 1 + .../src/net/osmand/plus/SettingsHelper.java | 23 +++++++++++++++++-- .../settings/DuplicatesSettingsAdapter.java | 16 ++++++++++++- .../settings/ExportImportSettingsAdapter.java | 12 +++++++++- .../plus/settings/ImportSettingsFragment.java | 7 +++++- .../ImportedSettingsItemsAdapter.java | 6 +++++ 10 files changed, 65 insertions(+), 5 deletions(-) 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..e8e00b7401 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" /> 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..5c5a2eabc5 100644 --- a/OsmAnd/res/values/dimens.xml +++ b/OsmAnd/res/values/dimens.xml @@ -14,4 +14,6 @@ 280dp 160dp + 1.5 + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 917b17a8a6..7d64347954 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + %1$s of %2$s Are you sure you want to clear recorded data? All profile settings will be restored to their original state after creating/importing this profile. Restore all profile settings? diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index a3abaa1b10..3bf154c3c1 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -534,18 +534,37 @@ public class SettingsHelper { } private void renameProfile() { + List values = ApplicationMode.allPossibleValues(); + if (modeBean.userProfileName.isEmpty()) { + for (ApplicationMode mode : values) { + if (modeBean.stringKey.equals(mode.getStringKey())) { + modeBean.userProfileName = app.getString(mode.getNameKeyResource()); + break; + } + } + } 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/settings/DuplicatesSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java index f1ee92137e..c19f09abaa 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; 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,16 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter listItems = itemsMap.get(type); - subTextTv.setText(String.valueOf(listItems.size())); + subTextTv.setText(getSelectedItemsAmount(listItems)); if (dataToOperate.containsAll(listItems)) { checkBox.setState(CHECKED); @@ -283,6 +283,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 String.format(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 e3cc3226e9..c34f6981fa 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ImportSettingsFragment.java @@ -164,8 +164,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)); @@ -178,6 +180,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 From 958d9e24df250719f2c0bb2eab619ce2a4a84ce3 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Mon, 23 Mar 2020 16:15:15 +0200 Subject: [PATCH 3/8] decrease line spacing multiplier --- OsmAnd/res/values/dimens.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/res/values/dimens.xml b/OsmAnd/res/values/dimens.xml index 5c5a2eabc5..d31963861a 100644 --- a/OsmAnd/res/values/dimens.xml +++ b/OsmAnd/res/values/dimens.xml @@ -14,6 +14,6 @@ 280dp 160dp - 1.5 + 1.2 \ No newline at end of file From 76d5af9cc7bb46d9ef8b9debeb82012cd664ecce Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Mon, 23 Mar 2020 17:38:49 +0200 Subject: [PATCH 4/8] fix progress bar --- OsmAnd/res/layout/fragment_import.xml | 5 +++-- OsmAnd/res/layout/fragment_import_duplicates.xml | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/layout/fragment_import.xml b/OsmAnd/res/layout/fragment_import.xml index 5706475468..20356c24ed 100644 --- a/OsmAnd/res/layout/fragment_import.xml +++ b/OsmAnd/res/layout/fragment_import.xml @@ -129,11 +129,12 @@ diff --git a/OsmAnd/res/layout/fragment_import_duplicates.xml b/OsmAnd/res/layout/fragment_import_duplicates.xml index e8e00b7401..bd943c0583 100644 --- a/OsmAnd/res/layout/fragment_import_duplicates.xml +++ b/OsmAnd/res/layout/fragment_import_duplicates.xml @@ -138,10 +138,11 @@ From 197de55fc5ca826faab9322686766ec080fa4c22 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Mon, 23 Mar 2020 18:18:08 +0200 Subject: [PATCH 5/8] fix progress bar --- OsmAnd/res/layout/fragment_import.xml | 13 +++++++------ OsmAnd/res/layout/fragment_import_duplicates.xml | 13 +++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/OsmAnd/res/layout/fragment_import.xml b/OsmAnd/res/layout/fragment_import.xml index 20356c24ed..ffc6165836 100644 --- a/OsmAnd/res/layout/fragment_import.xml +++ b/OsmAnd/res/layout/fragment_import.xml @@ -127,15 +127,16 @@ - diff --git a/OsmAnd/res/layout/fragment_import_duplicates.xml b/OsmAnd/res/layout/fragment_import_duplicates.xml index bd943c0583..8e5cbc2a61 100644 --- a/OsmAnd/res/layout/fragment_import_duplicates.xml +++ b/OsmAnd/res/layout/fragment_import_duplicates.xml @@ -136,15 +136,16 @@ - From d0c3bc3bd6f79eb1aa4de0fc6465a74b1bf87f7e Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Thu, 26 Mar 2020 11:22:33 +0200 Subject: [PATCH 6/8] fix capitalizeFirstLetter of routing profile --- .../osmand/plus/settings/DuplicatesSettingsAdapter.java | 7 ++++--- .../osmand/plus/settings/ExportImportSettingsAdapter.java | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java index c19f09abaa..0d4338c690 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/DuplicatesSettingsAdapter.java @@ -21,7 +21,7 @@ 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; +import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.render.RenderingIcons; import net.osmand.util.Algorithms; @@ -90,9 +90,10 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter Date: Thu, 26 Mar 2020 12:12:05 +0200 Subject: [PATCH 7/8] refactor renameProfile() --- OsmAnd/src/net/osmand/plus/SettingsHelper.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index 82d9c4d591..494696c861 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -536,12 +536,10 @@ public class SettingsHelper { private void renameProfile() { List values = ApplicationMode.allPossibleValues(); - if (modeBean.userProfileName.isEmpty()) { - for (ApplicationMode mode : values) { - if (modeBean.stringKey.equals(mode.getStringKey())) { - modeBean.userProfileName = app.getString(mode.getNameKeyResource()); - break; - } + if (Algorithms.isEmpty(modeBean.userProfileName)) { + ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null); + if (appMode != null) { + modeBean.userProfileName = app.getString(appMode.getNameKeyResource()); } } int number = 0; From 23b5e868ec8fef64aebb5c9743b5f7016ff20d6d Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Thu, 26 Mar 2020 13:52:11 +0200 Subject: [PATCH 8/8] refactor ExportImportAdapter --- .../net/osmand/plus/settings/ExportImportSettingsAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java index 5ca1a62437..c90b9cb990 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/ExportImportSettingsAdapter.java @@ -291,7 +291,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { amount++; } } - return String.format(app.getString(R.string.n_items_of_z), String.valueOf(amount), String.valueOf(listItems.size())); + return app.getString(R.string.n_items_of_z, String.valueOf(amount), String.valueOf(listItems.size())); } private int getGroupTitle(Type type) {