Make media overview view pager scrollable for long translations.

This commit is contained in:
Alan Evans 2019-12-06 08:43:04 -05:00 committed by Greyson Parrelli
parent 3e041befc8
commit 5782c8a58b
2 changed files with 23 additions and 2 deletions

View File

@ -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" />
</com.google.android.material.appbar.AppBarLayout>

View File

@ -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<Pair<MediaLoader.MediaType, CharSequence>> pages;