From 5782c8a58bcdf8992e3ff0ad9ee815cfa6ecc4d3 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Fri, 6 Dec 2019 08:43:04 -0500 Subject: [PATCH] Make media overview view pager scrollable for long translations. --- res/layout/media_overview_activity.xml | 3 +-- .../mediaoverview/MediaOverviewActivity.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/res/layout/media_overview_activity.xml b/res/layout/media_overview_activity.xml index 2e57534c1b..b6b13cb9b3 100644 --- a/res/layout/media_overview_activity.xml +++ b/res/layout/media_overview_activity.xml @@ -25,10 +25,9 @@ android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_gravity="top" android:background="?attr/media_overview_toolbar_background" - app:tabBackground="?attr/media_overview_toolbar_background" app:tabIndicatorColor="@color/textsecure_primary" + app:tabMode="scrollable" app:tabSelectedTextColor="@color/textsecure_primary" /> diff --git a/src/org/thoughtcrime/securesms/mediaoverview/MediaOverviewActivity.java b/src/org/thoughtcrime/securesms/mediaoverview/MediaOverviewActivity.java index b23e47f986..ee61b59aab 100644 --- a/src/org/thoughtcrime/securesms/mediaoverview/MediaOverviewActivity.java +++ b/src/org/thoughtcrime/securesms/mediaoverview/MediaOverviewActivity.java @@ -21,6 +21,7 @@ import android.content.Intent; import android.os.Bundle; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; @@ -95,6 +96,8 @@ public final class MediaOverviewActivity extends PassphraseRequiredActionBarActi boolean allThreads = threadId == MediaDatabase.ALL_THREADS; + fillTabLayoutIfFits(tabLayout); + tabLayout.setupWithViewPager(viewPager); viewPager.setAdapter(new MediaOverviewPagerAdapter(getSupportFragmentManager())); @@ -228,6 +231,25 @@ public final class MediaOverviewActivity extends PassphraseRequiredActionBarActi .show(); } + private static void fillTabLayoutIfFits(@NonNull TabLayout tabLayout) { + tabLayout.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { + int totalWidth = 0; + int maxWidth = 0; + ViewGroup tabs = (ViewGroup) tabLayout.getChildAt(0); + + for (int i = 0; i < tabLayout.getTabCount(); i++) { + int tabWidth = tabs.getChildAt(i).getWidth(); + totalWidth += tabWidth; + maxWidth = Math.max(maxWidth, tabWidth); + } + + int viewWidth = right - left; + if (totalWidth < viewWidth) { + tabLayout.setTabMode(TabLayout.MODE_FIXED); + } + }); + } + private class MediaOverviewPagerAdapter extends FragmentStatePagerAdapter { private final List> pages;