Skip to content

Commit

Permalink
Add content description to detail fragment tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Jan 17, 2021
1 parent 750c4ff commit e840d42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;
Expand Down Expand Up @@ -154,6 +155,7 @@ public final class VideoDetailFragment
private boolean showDescription;
private String selectedTabTag;
@AttrRes @NonNull final List<Integer> tabIcons = new ArrayList<>();
@StringRes @NonNull final List<Integer> tabContentDescriptions = new ArrayList<>();
private boolean tabSettingsChanged = false;

@State
Expand Down Expand Up @@ -905,23 +907,27 @@ private void initTabs() {
}
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();

Expand All @@ -933,20 +939,22 @@ private void initTabs() {
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));
}
}
}
Expand All @@ -972,7 +980,7 @@ private void updateTabs(@NonNull final StreamInfo info) {
}

pageAdapter.notifyDataSetUpdate();
updateTabIcons();
updateTabIconsAndContentDescriptions();
}

private boolean shouldShowComments() {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@
<string name="detail_uploader_thumbnail_view_description">Uploader\'s avatar thumbnail</string>
<string name="detail_likes_img_view_description">Likes</string>
<string name="detail_dislikes_img_view_description">Dislikes</string>
<string name="comments_tab_description">Comments</string>
<string name="related_streams_tab_description">Related streams</string>
<string name="description_tab_description">Description</string>
<string name="use_tor_title">Use Tor</string>
<string name="use_tor_summary">(Experimental) Force download traffic through Tor for increased privacy (streaming videos not yet supported).</string>
<string name="report_error">Report error</string>
Expand Down

0 comments on commit e840d42

Please sign in to comment.