From e840d42fb9395abc8b5655c593d4d6b0317a3436 Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 14 Jan 2021 11:06:37 +0100 Subject: [PATCH] Add content description to detail fragment tabs --- .../fragments/detail/VideoDetailFragment.java | 18 +++++++++++++----- app/src/main/res/values/strings.xml | 3 +++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 375fb0918..cb34fc189 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -33,6 +33,7 @@ import androidx.annotation.AttrRes; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.content.res.AppCompatResources; @@ -154,6 +155,7 @@ public final class VideoDetailFragment private boolean showDescription; private String selectedTabTag; @AttrRes @NonNull final List tabIcons = new ArrayList<>(); + @StringRes @NonNull final List tabContentDescriptions = new ArrayList<>(); private boolean tabSettingsChanged = false; @State @@ -905,23 +907,27 @@ public final class VideoDetailFragment } pageAdapter.clearAllItems(); tabIcons.clear(); + tabContentDescriptions.clear(); if (shouldShowComments()) { pageAdapter.addFragment( CommentsFragment.getInstance(serviceId, url, title), COMMENTS_TAB_TAG); tabIcons.add(R.drawable.ic_comment_white_24dp); + tabContentDescriptions.add(R.string.comments_tab_description); } if (showRelatedStreams && binding.relatedStreamsLayout == null) { //temp empty fragment. will be updated in handleResult pageAdapter.addFragment(new Fragment(), RELATED_TAB_TAG); tabIcons.add(R.drawable.ic_art_track_white_24dp); + tabContentDescriptions.add(R.string.related_streams_tab_description); } if (showDescription) { // temp empty fragment. will be updated in handleResult pageAdapter.addFragment(new Fragment(), DESCRIPTION_TAB_TAG); tabIcons.add(R.drawable.ic_description_white_24dp); + tabContentDescriptions.add(R.string.description_tab_description); } pageAdapter.notifyDataSetUpdate(); @@ -933,20 +939,22 @@ public final class VideoDetailFragment binding.viewPager.setCurrentItem(position); } binding.tabLayout.setVisibility(View.VISIBLE); - updateTabIcons(); + updateTabIconsAndContentDescriptions(); } } /** * To be called whenever {@link #pageAdapter} is modified, since that triggers a refresh in - * {@link FragmentVideoDetailBinding#tabLayout} resetting all tab's icons. This reads icons from - * {@link #tabIcons}, which are set in {@link #initTabs()} + * {@link FragmentVideoDetailBinding#tabLayout} resetting all tab's icons and content + * descriptions. This reads icons from {@link #tabIcons} and content descriptions from + * {@link #tabContentDescriptions}, which are all set in {@link #initTabs()}. */ - private void updateTabIcons() { + private void updateTabIconsAndContentDescriptions() { for (int i = 0; i < tabIcons.size(); ++i) { final TabLayout.Tab tab = binding.tabLayout.getTabAt(i); if (tab != null) { tab.setIcon(tabIcons.get(i)); + tab.setContentDescription(tabContentDescriptions.get(i)); } } } @@ -972,7 +980,7 @@ public final class VideoDetailFragment } pageAdapter.notifyDataSetUpdate(); - updateTabIcons(); + updateTabIconsAndContentDescriptions(); } private boolean shouldShowComments() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 207680fef..702dcafbf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -281,6 +281,9 @@ Uploader\'s avatar thumbnail Likes Dislikes + Comments + Related streams + Description Use Tor (Experimental) Force download traffic through Tor for increased privacy (streaming videos not yet supported). Report error