diff options
author | ByteHamster <info@bytehamster.com> | 2021-03-05 11:18:01 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2021-03-05 11:18:01 +0100 |
commit | d1d5974cea24e90d2a6c7f211f8f0851b134bf34 (patch) | |
tree | eec1bb81f780eb51025526e4f4d1932013ecfaee /app/src | |
parent | 627bd35500f49373881b44ad52cd48899ea09e97 (diff) | |
download | AntennaPod-d1d5974cea24e90d2a6c7f211f8f0851b134bf34.zip |
Fix selection highlighting
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java | 6 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java | 52 |
2 files changed, 20 insertions, 38 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java index d7ebfff98..c37eb958a 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -215,7 +215,7 @@ public class NavListAdapter extends RecyclerView.Adapter<NavListAdapter.Holder> if (viewType != VIEW_TYPE_SECTION_DIVIDER) { TypedValue typedValue = new TypedValue(); - if (position == itemAccess.getSelectedItemIndex()) { + if (itemAccess.isSelected(position)) { activity.get().getTheme().resolveAttribute(R.attr.drawer_activated_color, typedValue, true); holder.itemView.setBackgroundResource(typedValue.resourceId); } else { @@ -399,7 +399,7 @@ public class NavListAdapter extends RecyclerView.Adapter<NavListAdapter.Holder> NavDrawerData.DrawerItem getItem(int position); - int getSelectedItemIndex(); + boolean isSelected(int position); int getQueueSize(); @@ -409,8 +409,6 @@ public class NavListAdapter extends RecyclerView.Adapter<NavListAdapter.Holder> int getReclaimableItems(); - int getFeedCounter(long feedId); - int getFeedCounterSum(); void onItemClick(int position); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java index 404b31d5c..bec459bed 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java @@ -72,7 +72,6 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS private NavDrawerData navDrawerData; private List<NavDrawerData.DrawerItem> flatItemList; - private int selectedNavListIndex = -1; private NavDrawerData.DrawerItem contextPressedItem = null; private NavListAdapter navAdapter; private Disposable disposable; @@ -91,7 +90,6 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS navAdapter.setHasStableIds(true); navList.setAdapter(navAdapter); navList.setLayoutManager(new LinearLayoutManager(getContext())); - updateSelection(); root.findViewById(R.id.nav_settings).setOnClickListener(v -> startActivity(new Intent(getActivity(), PreferenceActivity.class))); @@ -100,27 +98,6 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS return root; } - private void updateSelection() { - String lastNavFragment = getLastNavFragment(getContext()); - int tagIndex = navAdapter.getTags().indexOf(lastNavFragment); - if (tagIndex >= 0) { - selectedNavListIndex = tagIndex; - } else if (StringUtils.isNumeric(lastNavFragment)) { // last fragment was not a list, but a feed - long feedId = Long.parseLong(lastNavFragment); - if (navDrawerData != null) { - List<NavDrawerData.DrawerItem> items = flatItemList; - for (int i = 0; i < items.size(); i++) { - if (items.get(i).type == NavDrawerData.DrawerItem.Type.FEED - && ((NavDrawerData.FeedDrawerItem) items.get(i)).feed.getId() == feedId) { - selectedNavListIndex = navAdapter.getSubscriptionOffset() + i; - break; - } - } - } - } - navAdapter.notifyDataSetChanged(); - } - @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -256,7 +233,7 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS }); builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> { UserPreferences.setHiddenDrawerItems(hiddenDrawerItems); - updateSelection(); + navAdapter.notifyDataSetChanged(); // Update selection }); builder.setNegativeButton(R.string.cancel_label, null); builder.create().show(); @@ -282,8 +259,22 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS } @Override - public int getSelectedItemIndex() { - return selectedNavListIndex; + public boolean isSelected(int position) { + String lastNavFragment = getLastNavFragment(getContext()); + if (position < navAdapter.getSubscriptionOffset()) { + return navAdapter.getTags().get(position).equals(lastNavFragment); + } else if (StringUtils.isNumeric(lastNavFragment)) { // last fragment was not a list, but a feed + long feedId = Long.parseLong(lastNavFragment); + if (navDrawerData != null) { + NavDrawerData.DrawerItem itemToCheck = flatItemList.get( + position - navAdapter.getSubscriptionOffset()); + if (itemToCheck.type == NavDrawerData.DrawerItem.Type.FEED) { + // When the same feed is displayed multiple times, it should be highlighted multiple times. + return ((NavDrawerData.FeedDrawerItem) itemToCheck).feed.getId() == feedId; + } + } + } + return false; } @Override @@ -307,11 +298,6 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS } @Override - public int getFeedCounter(long feedId) { - return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0; - } - - @Override public int getFeedCounterSum() { if (navDrawerData == null) { return 0; @@ -404,7 +390,6 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS result -> { navDrawerData = result.first; flatItemList = result.second; - updateSelection(); // Selected item might be a feed navAdapter.notifyDataSetChanged(); progressBar.setVisibility(View.GONE); // Stays hidden once there is something in the list }, error -> { @@ -451,8 +436,7 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (PREF_LAST_FRAGMENT_TAG.equals(key)) { - updateSelection(); - navAdapter.notifyDataSetChanged(); + navAdapter.notifyDataSetChanged(); // Update selection } } } |