Merge pull request #5563 from Stypox/fix-tablayout-visibility
Fix tab layout visibility with age restricted videos
This commit is contained in:
commit
a26baa3061
1 changed files with 29 additions and 26 deletions
|
@ -33,7 +33,6 @@ import android.widget.FrameLayout;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
import androidx.annotation.AttrRes;
|
import androidx.annotation.AttrRes;
|
||||||
import androidx.annotation.DrawableRes;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
|
@ -580,6 +579,7 @@ public final class VideoDetailFragment
|
||||||
Player.DEFAULT_CONTROLS_DURATION, 0);
|
Player.DEFAULT_CONTROLS_DURATION, 0);
|
||||||
binding.detailSecondaryControlPanel.setVisibility(View.GONE);
|
binding.detailSecondaryControlPanel.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
// view pager height has changed, update the tab layout
|
||||||
updateTabLayoutVisibility();
|
updateTabLayoutVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -650,6 +650,7 @@ public final class VideoDetailFragment
|
||||||
// prevent useless updates to tab layout visibility if nothing changed
|
// prevent useless updates to tab layout visibility if nothing changed
|
||||||
if (verticalOffset != lastAppBarVerticalOffset) {
|
if (verticalOffset != lastAppBarVerticalOffset) {
|
||||||
lastAppBarVerticalOffset = verticalOffset;
|
lastAppBarVerticalOffset = verticalOffset;
|
||||||
|
// the view was scrolled
|
||||||
updateTabLayoutVisibility();
|
updateTabLayoutVisibility();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -952,6 +953,7 @@ public final class VideoDetailFragment
|
||||||
}
|
}
|
||||||
updateTabIconsAndContentDescriptions();
|
updateTabIconsAndContentDescriptions();
|
||||||
}
|
}
|
||||||
|
// the page adapter now contains tabs: show the tab layout
|
||||||
updateTabLayoutVisibility();
|
updateTabLayoutVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -974,12 +976,10 @@ public final class VideoDetailFragment
|
||||||
private void updateTabs(@NonNull final StreamInfo info) {
|
private void updateTabs(@NonNull final StreamInfo info) {
|
||||||
if (showRelatedStreams) {
|
if (showRelatedStreams) {
|
||||||
if (binding.relatedStreamsLayout == null) { // phone
|
if (binding.relatedStreamsLayout == null) { // phone
|
||||||
pageAdapter.updateItem(RELATED_TAB_TAG,
|
pageAdapter.updateItem(RELATED_TAB_TAG, RelatedVideosFragment.getInstance(info));
|
||||||
RelatedVideosFragment.getInstance(info));
|
|
||||||
} else { // tablet + TV
|
} else { // tablet + TV
|
||||||
getChildFragmentManager().beginTransaction()
|
getChildFragmentManager().beginTransaction()
|
||||||
.replace(R.id.relatedStreamsLayout,
|
.replace(R.id.relatedStreamsLayout, RelatedVideosFragment.getInstance(info))
|
||||||
RelatedVideosFragment.getInstance(info))
|
|
||||||
.commitAllowingStateLoss();
|
.commitAllowingStateLoss();
|
||||||
binding.relatedStreamsLayout.setVisibility(
|
binding.relatedStreamsLayout.setVisibility(
|
||||||
player != null && player.isFullscreen() ? View.GONE : View.VISIBLE);
|
player != null && player.isFullscreen() ? View.GONE : View.VISIBLE);
|
||||||
|
@ -987,10 +987,12 @@ public final class VideoDetailFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showDescription) {
|
if (showDescription) {
|
||||||
pageAdapter.updateItem(DESCRIPTION_TAB_TAG,
|
pageAdapter.updateItem(DESCRIPTION_TAB_TAG, new DescriptionFragment(info));
|
||||||
new DescriptionFragment(info));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
binding.viewPager.setVisibility(View.VISIBLE);
|
||||||
|
// make sure the tab layout is visible
|
||||||
|
updateTabLayoutVisibility();
|
||||||
pageAdapter.notifyDataSetUpdate();
|
pageAdapter.notifyDataSetUpdate();
|
||||||
updateTabIconsAndContentDescriptions();
|
updateTabIconsAndContentDescriptions();
|
||||||
}
|
}
|
||||||
|
@ -1007,9 +1009,12 @@ public final class VideoDetailFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTabLayoutVisibility() {
|
public void updateTabLayoutVisibility() {
|
||||||
if (pageAdapter.getCount() < 2) {
|
if (pageAdapter.getCount() < 2 || binding.viewPager.getVisibility() != View.VISIBLE) {
|
||||||
|
// hide tab layout if there is only one tab or if the view pager is also hidden
|
||||||
binding.tabLayout.setVisibility(View.GONE);
|
binding.tabLayout.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
|
// call `post()` to be sure `viewPager.getHitRect()`
|
||||||
|
// is up to date and not being currently recomputed
|
||||||
binding.tabLayout.post(() -> {
|
binding.tabLayout.post(() -> {
|
||||||
if (getContext() != null) {
|
if (getContext() != null) {
|
||||||
final Rect pagerHitRect = new Rect();
|
final Rect pagerHitRect = new Rect();
|
||||||
|
@ -1020,7 +1025,7 @@ public final class VideoDetailFragment
|
||||||
WindowManager.class)).getDefaultDisplay().getSize(displaySize);
|
WindowManager.class)).getDefaultDisplay().getSize(displaySize);
|
||||||
|
|
||||||
final int viewPagerVisibleHeight = displaySize.y - pagerHitRect.top;
|
final int viewPagerVisibleHeight = displaySize.y - pagerHitRect.top;
|
||||||
// see TabLayout.DEFAULT_HEIGHT
|
// see TabLayout.DEFAULT_HEIGHT, which is equal to 48dp
|
||||||
final float tabLayoutHeight = TypedValue.applyDimension(
|
final float tabLayoutHeight = TypedValue.applyDimension(
|
||||||
TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics());
|
TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics());
|
||||||
|
|
||||||
|
@ -1030,6 +1035,7 @@ public final class VideoDetailFragment
|
||||||
Math.max(0, tabLayoutHeight * 3 - viewPagerVisibleHeight));
|
Math.max(0, tabLayoutHeight * 3 - viewPagerVisibleHeight));
|
||||||
binding.tabLayout.setVisibility(View.VISIBLE);
|
binding.tabLayout.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
|
// view pager is not visible enough
|
||||||
binding.tabLayout.setVisibility(View.GONE);
|
binding.tabLayout.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1039,6 +1045,7 @@ public final class VideoDetailFragment
|
||||||
|
|
||||||
public void scrollToTop() {
|
public void scrollToTop() {
|
||||||
binding.appBarLayout.setExpanded(true, true);
|
binding.appBarLayout.setExpanded(true, true);
|
||||||
|
// notify tab layout of scrolling
|
||||||
updateTabLayoutVisibility();
|
updateTabLayoutVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1321,13 +1328,21 @@ public final class VideoDetailFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showError(final String message, final boolean showRetryButton) {
|
public void showError(final String message, final boolean showRetryButton) {
|
||||||
showError(message, showRetryButton, R.drawable.not_available_monkey);
|
super.showError(message, showRetryButton);
|
||||||
|
setErrorImage(R.drawable.not_available_monkey);
|
||||||
|
|
||||||
|
if (binding.relatedStreamsLayout != null) { // hide related streams for tablets
|
||||||
|
binding.relatedStreamsLayout.setVisibility(View.INVISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// hide comments / related streams / description tabs
|
||||||
|
binding.viewPager.setVisibility(View.GONE);
|
||||||
|
binding.tabLayout.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void showError(final String message, final boolean showRetryButton,
|
private void hideAgeRestrictedContent() {
|
||||||
@DrawableRes final int imageError) {
|
showError(getString(R.string.restricted_video,
|
||||||
super.showError(message, showRetryButton);
|
getString(R.string.show_age_restricted_content_title)), false);
|
||||||
setErrorImage(imageError);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupBroadcastReceiver() {
|
private void setupBroadcastReceiver() {
|
||||||
|
@ -1552,18 +1567,6 @@ public final class VideoDetailFragment
|
||||||
noVideoStreams ? R.drawable.ic_headset_shadow : R.drawable.ic_play_arrow_shadow);
|
noVideoStreams ? R.drawable.ic_headset_shadow : R.drawable.ic_play_arrow_shadow);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideAgeRestrictedContent() {
|
|
||||||
showError(getString(R.string.restricted_video,
|
|
||||||
getString(R.string.show_age_restricted_content_title)), false);
|
|
||||||
|
|
||||||
if (binding.relatedStreamsLayout != null) { // tablet
|
|
||||||
binding.relatedStreamsLayout.setVisibility(View.INVISIBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.viewPager.setVisibility(View.GONE);
|
|
||||||
binding.tabLayout.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void displayUploaderAsSubChannel(final StreamInfo info) {
|
private void displayUploaderAsSubChannel(final StreamInfo info) {
|
||||||
binding.detailSubChannelTextView.setText(info.getUploaderName());
|
binding.detailSubChannelTextView.setText(info.getUploaderName());
|
||||||
binding.detailSubChannelTextView.setVisibility(View.VISIBLE);
|
binding.detailSubChannelTextView.setVisibility(View.VISIBLE);
|
||||||
|
|
Loading…
Reference in a new issue