mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 17:58:34 +00:00
Make media overview view pager scrollable for long translations.
This commit is contained in:
parent
3e041befc8
commit
5782c8a58b
@ -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>
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user