Set title to bottom app bar in other media fragments and activities.

This commit is contained in:
Alex Ning 2021-08-04 14:49:33 +08:00
parent eca3d91c8b
commit d0341f9be1
6 changed files with 47 additions and 16 deletions

View File

@ -274,14 +274,16 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa
}
private void setupViewPager() {
if (!useBottomAppBar) {
setToolbarTitle(0);
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
setToolbarTitle(position);
}
});
}
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOffscreenPageLimit(3);
}
@ -389,12 +391,16 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa
ViewImgurVideoFragment fragment = new ViewImgurVideoFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(ViewImgurVideoFragment.EXTRA_IMGUR_VIDEO, imgurMedia);
bundle.putInt(ViewImgurVideoFragment.EXTRA_INDEX, position);
bundle.putInt(ViewImgurVideoFragment.EXTRA_MEDIA_COUNT, images.size());
fragment.setArguments(bundle);
return fragment;
} else {
ViewImgurImageFragment fragment = new ViewImgurImageFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(ViewImgurImageFragment.EXTRA_IMGUR_IMAGES, imgurMedia);
bundle.putInt(ViewImgurImageFragment.EXTRA_INDEX, position);
bundle.putInt(ViewImgurImageFragment.EXTRA_MEDIA_COUNT, images.size());
fragment.setArguments(bundle);
return fragment;
}

View File

@ -104,8 +104,6 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
getSupportActionBar().hide();
}
setTitle(" ");
gallery = getIntent().getParcelableArrayListExtra(EXTRA_REDDIT_GALLERY);
if (gallery == null || gallery.isEmpty()) {
finish();
@ -131,14 +129,16 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
}
private void setupViewPager() {
if (!useBottomAppBar) {
setToolbarTitle(0);
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
setToolbarTitle(position);
}
});
}
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOffscreenPageLimit(3);
}
@ -243,6 +243,8 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
Bundle bundle = new Bundle();
bundle.putParcelable(ViewRedditGalleryVideoFragment.EXTRA_REDDIT_GALLERY_VIDEO, media);
bundle.putString(ViewRedditGalleryVideoFragment.EXTRA_SUBREDDIT_NAME, subredditName);
bundle.putInt(ViewRedditGalleryVideoFragment.EXTRA_INDEX, position);
bundle.putInt(ViewRedditGalleryVideoFragment.EXTRA_MEDIA_COUNT, gallery.size());
fragment.setArguments(bundle);
return fragment;
} else {
@ -250,6 +252,8 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
Bundle bundle = new Bundle();
bundle.putParcelable(ViewRedditGalleryImageOrGifFragment.EXTRA_REDDIT_GALLERY_MEDIA, media);
bundle.putString(ViewRedditGalleryImageOrGifFragment.EXTRA_SUBREDDIT_NAME, subredditName);
bundle.putInt(ViewRedditGalleryImageOrGifFragment.EXTRA_INDEX, position);
bundle.putInt(ViewRedditGalleryImageOrGifFragment.EXTRA_MEDIA_COUNT, gallery.size());
fragment.setArguments(bundle);
return fragment;
}

View File

@ -60,6 +60,8 @@ import ml.docilealligator.infinityforreddit.services.DownloadMediaService;
public class ViewImgurImageFragment extends Fragment {
public static final String EXTRA_IMGUR_IMAGES = "EII";
public static final String EXTRA_INDEX = "EI";
public static final String EXTRA_MEDIA_COUNT = "EMC";
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
@BindView(R.id.progress_bar_view_imgur_image_fragment)
@ -142,6 +144,8 @@ public class ViewImgurImageFragment extends Fragment {
if (activity.isUseBottomAppBar()) {
bottomAppBar.setVisibility(View.VISIBLE);
titleTextView.setText(getString(R.string.view_imgur_media_activity_image_label,
getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
downloadImageView.setOnClickListener(view -> {
if (isDownloading) {
return;

View File

@ -59,6 +59,8 @@ public class ViewImgurVideoFragment extends Fragment {
public static final String EXTRA_IMGUR_VIDEO = "EIV";
private static final String IS_MUTE_STATE = "IMS";
private static final String POSITION_STATE = "PS";
public static final String EXTRA_INDEX = "EI";
public static final String EXTRA_MEDIA_COUNT = "EMC";
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
@BindView(R.id.player_view_view_imgur_video_fragment)
PlayerView videoPlayerView;
@ -147,6 +149,8 @@ public class ViewImgurVideoFragment extends Fragment {
if (activity.isUseBottomAppBar()) {
bottomAppBar.setVisibility(View.VISIBLE);
titleTextView.setText(getString(R.string.view_imgur_media_activity_video_label,
getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
downloadImageView.setOnClickListener(view -> {
if (isDownloading) {
return;

View File

@ -67,6 +67,8 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
public static final String EXTRA_REDDIT_GALLERY_MEDIA = "ERGM";
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
public static final String EXTRA_INDEX = "EI";
public static final String EXTRA_MEDIA_COUNT = "EMC";
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
@BindView(R.id.progress_bar_view_reddit_gallery_image_or_gif_fragment)
@ -231,6 +233,13 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
if (activity.isUseBottomAppBar()) {
bottomAppBar.setVisibility(View.VISIBLE);
if (media.mediaType == Post.Gallery.TYPE_GIF) {
titleTextView.setText(getString(R.string.view_reddit_gallery_activity_gif_label,
getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
} else {
titleTextView.setText(getString(R.string.view_reddit_gallery_activity_image_label,
getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
}
downloadImageView.setOnClickListener(view -> {
if (isDownloading) {
return;

View File

@ -60,6 +60,8 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
private static final String IS_MUTE_STATE = "IMS";
private static final String POSITION_STATE = "PS";
public static final String EXTRA_INDEX = "EI";
public static final String EXTRA_MEDIA_COUNT = "EMC";
private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0;
@BindView(R.id.player_view_view_reddit_gallery_video_fragment)
PlayerView videoPlayerView;
@ -150,6 +152,8 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
if (activity.isUseBottomAppBar()) {
bottomAppBar.setVisibility(View.VISIBLE);
titleTextView.setText(getString(R.string.view_reddit_gallery_activity_video_label,
getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT)));
downloadImageView.setOnClickListener(view -> {
if (isDownloading) {
return;