From bc1d385fef235669cd528b6717f97ade6a0b166f Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 9 Apr 2020 10:04:57 +0300 Subject: [PATCH] Fix #8693 Profile appearance: Strange scroll appear after select different icon/color. Hide keyboard on scroll --- .../settings/ProfileAppearanceFragment.java | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index b872ca8148..8af4450a62 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -33,6 +33,7 @@ import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; +import androidx.recyclerview.widget.RecyclerView; import net.osmand.AndroidUtils; import net.osmand.IndexConstants; @@ -261,6 +262,15 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } } }); + getListView().addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { + super.onScrollStateChanged(recyclerView, newState); + if (newState != RecyclerView.SCROLL_STATE_IDLE) { + hideKeyboard(); + } + } + }); } return view; } @@ -402,7 +412,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { View iconItem = createIconItemView(iconRes, iconItems); iconItems.addView(iconItem, new FlowLayout.LayoutParams(0, 0)); } - setIconNewColor(changedProfile.iconRes); + setIconColor(changedProfile.iconRes); } else if (LOCATION_ICON_ITEMS.equals(preference.getKey())) { locationIconItems = (FlowLayout) holder.findViewById(R.id.color_items); locationIconItems.removeAllViews(); @@ -452,9 +462,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { public void onClick(View v) { if (colorRes != changedProfile.color) { updateColorSelector(colorRes); + setVerticalScrollBarEnabled(false); updatePreference(findPreference(MASTER_PROFILE)); updatePreference(findPreference(LOCATION_ICON_ITEMS)); updatePreference(findPreference(NAV_ICON_ITEMS)); + setVerticalScrollBarEnabled(true); } } }); @@ -482,7 +494,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { colorItem.findViewById(R.id.checkMark).setVisibility(View.VISIBLE); changedProfile.color = color; if (iconItems != null) { - setIconNewColor(changedProfile.iconRes); + updateIconColor(changedProfile.iconRes); } updateProfileNameAppearance(); updateProfileButton(); @@ -521,7 +533,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } private void updateIconSelector(int iconRes) { - setIconNewColor(iconRes); + updateIconColor(iconRes); View iconItem = iconItems.findViewWithTag(changedProfile.iconRes); iconItem.findViewById(R.id.outline).setVisibility(View.GONE); ImageView checkMark = iconItem.findViewById(R.id.checkMark); @@ -552,7 +564,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { @Override public void onClick(View v) { if (locationIcon != changedProfile.locationIcon) { + setVerticalScrollBarEnabled(false); updateLocationIconSelector(locationIcon); + setVerticalScrollBarEnabled(true); } } }); @@ -596,7 +610,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { @Override public void onClick(View v) { if (navigationIcon != changedProfile.navigationIcon) { + setVerticalScrollBarEnabled(false); updateNavigationIconSelector(navigationIcon); + setVerticalScrollBarEnabled(true); } } }); @@ -621,7 +637,13 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { changedProfile.navigationIcon = navigationIcon; } - private void setIconNewColor(int iconRes) { + private void updateIconColor(int iconRes) { + setVerticalScrollBarEnabled(false); + setIconColor(iconRes); + setVerticalScrollBarEnabled(true); + } + + private void setIconColor(int iconRes) { int changedProfileColor = ContextCompat.getColor(app, changedProfile.color.getColor( app.getDaynightHelper().isNightModeForMapControls())); View iconItem = iconItems.findViewWithTag(iconRes); @@ -641,6 +663,20 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } } + private void setVerticalScrollBarEnabled(boolean enabled) { + final RecyclerView preferenceListView = getListView(); + if (enabled) { + preferenceListView.post(new Runnable() { + @Override + public void run() { + preferenceListView.setVerticalScrollBarEnabled(true); + } + }); + } else { + preferenceListView.setVerticalScrollBarEnabled(false); + } + } + private void hideKeyboard() { Activity activity = getActivity(); if (activity != null) {