Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.documentfile:documentfile:1.0.1'
implementation 'androidx.fragment:fragment-ktx:1.3.4'
implementation "androidx.lifecycle:lifecycle-livedata:${androidxLifecycleVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.content.pm.ActivityInfo;
import android.database.ContentObserver;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
Expand Down Expand Up @@ -41,6 +40,7 @@
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import androidx.core.view.DisplayCompat;
import androidx.preference.PreferenceManager;

import com.google.android.exoplayer2.ExoPlaybackException;
Expand Down Expand Up @@ -91,13 +91,13 @@
import org.schabi.newpipe.util.DeviceUtils;
import org.schabi.newpipe.util.ExtractorHelper;
import org.schabi.newpipe.util.ImageDisplayConstants;
import org.schabi.newpipe.util.external_communication.KoreUtils;
import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.external_communication.ShareUtils;
import org.schabi.newpipe.util.ThemeHelper;
import org.schabi.newpipe.util.external_communication.KoreUtils;
import org.schabi.newpipe.util.external_communication.ShareUtils;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -1022,15 +1022,17 @@ public void updateTabLayoutVisibility() {
// call `post()` to be sure `viewPager.getHitRect()`
// is up to date and not being currently recomputed
binding.tabLayout.post(() -> {
if (getContext() != null) {
final Context context = getContext();
if (context != null) {
final Rect pagerHitRect = new Rect();
binding.viewPager.getHitRect(pagerHitRect);

final Point displaySize = new Point();
Objects.requireNonNull(ContextCompat.getSystemService(getContext(),
WindowManager.class)).getDefaultDisplay().getSize(displaySize);
final WindowManager windowManager = Objects.requireNonNull(ContextCompat
.getSystemService(context, WindowManager.class));
final DisplayCompat.ModeCompat mode = DisplayCompat.getMode(context,
windowManager.getDefaultDisplay());

final int viewPagerVisibleHeight = displaySize.y - pagerHitRect.top;
final int viewPagerVisibleHeight = mode.getPhysicalHeight() - pagerHitRect.top;
Copy link
Member

@Stypox Stypox Jul 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct. viewPagerVisibleHeight should represent the height of the view pager that is visible on the screen, but here the size of Android's bottom bar is also summed, since getPhysicalHeight() is used. But now that I see it, it seems like it was also wrong before, since getDefaultDisplay().getSize() returned the height of the app and the above difference was also wrong. What viewPagerVisibleHeight should be equal to is "y_of_the_bottom_of_the_activity (i.e. just above Android's bottom bar) - y_of_the_top_of_viewPager". Is there a way to do this with the compat library? I saw that getDefaultDisplay().getSize() was deprecated in API 30 in favour of WindowMetrics, and WindowMetrics#getBounds() would provide us with "y_of_the_bottom_of_the_activity", but that method has not yet been backported in the compat library.

Copy link
Member Author

@Isira-Seneviratne Isira-Seneviratne Jul 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a Window Manager library which backports WindowMetrics, but it's still in alpha.

// see TabLayout.DEFAULT_HEIGHT, which is equal to 48dp
final float tabLayoutHeight = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics());
Expand Down