Use bottom toolbar in ViewRedditGalleryVideoFragment is available.

This commit is contained in:
Alex Ning 2021-08-04 14:07:15 +08:00
parent 27173031a1
commit 085eaa8505

View File

@ -1,7 +1,6 @@
package ml.docilealligator.infinityforreddit.fragments; package ml.docilealligator.infinityforreddit.fragments;
import android.Manifest; import android.Manifest;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -18,7 +17,9 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -39,6 +40,7 @@ import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.android.material.bottomappbar.BottomAppBar;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
@ -46,8 +48,9 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity;
import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.services.DownloadMediaService;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
@ -62,7 +65,13 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
PlayerView videoPlayerView; PlayerView videoPlayerView;
@BindView(R.id.mute_exo_playback_control_view) @BindView(R.id.mute_exo_playback_control_view)
ImageButton muteButton; ImageButton muteButton;
private Activity activity; @BindView(R.id.bottom_navigation_exo_playback_control_view)
BottomAppBar bottomAppBar;
@BindView(R.id.title_text_view_exo_playback_control_view)
TextView titleTextView;
@BindView(R.id.download_image_view_exo_playback_control_view)
ImageView downloadImageView;
private ViewRedditGalleryActivity activity;
private Post.Gallery galleryVideo; private Post.Gallery galleryVideo;
private String subredditName; private String subredditName;
private SimpleExoPlayer player; private SimpleExoPlayer player;
@ -139,6 +148,17 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(galleryVideo.url))); player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(galleryVideo.url)));
preparePlayer(savedInstanceState); preparePlayer(savedInstanceState);
if (activity.isUseBottomAppBar()) {
bottomAppBar.setVisibility(View.VISIBLE);
downloadImageView.setOnClickListener(view -> {
if (isDownloading) {
return;
}
isDownloading = true;
requestPermissionAndDownload();
});
}
return rootView; return rootView;
} }
@ -152,6 +172,13 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
public boolean onOptionsItemSelected(@NonNull MenuItem item) { public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.action_download_view_reddit_gallery_video_fragment) { if (item.getItemId() == R.id.action_download_view_reddit_gallery_video_fragment) {
isDownloading = true; isDownloading = true;
requestPermissionAndDownload();
return true;
}
return false;
}
private void requestPermissionAndDownload() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
if (ContextCompat.checkSelfPermission(activity, if (ContextCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE) Manifest.permission.WRITE_EXTERNAL_STORAGE)
@ -168,9 +195,6 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
} else { } else {
download(); download();
} }
return true;
}
return false;
} }
@Override @Override
@ -286,6 +310,6 @@ public class ViewRedditGalleryVideoFragment extends Fragment {
@Override @Override
public void onAttach(@NonNull Context context) { public void onAttach(@NonNull Context context) {
super.onAttach(context); super.onAttach(context);
activity = (Activity) context; activity = (ViewRedditGalleryActivity) context;
} }
} }