From 085eaa8505a7ef64c3342219e8a7b7c484e22435 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 4 Aug 2021 14:07:15 +0800 Subject: Use bottom toolbar in ViewRedditGalleryVideoFragment is available. --- .../fragments/ViewRedditGalleryVideoFragment.java | 62 +++++++++++++++------- 1 file changed, 43 insertions(+), 19 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java index 386601fa..bceee6d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java @@ -1,7 +1,6 @@ package ml.docilealligator.infinityforreddit.fragments; import android.Manifest; -import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; @@ -18,7 +17,9 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.TextView; import android.widget.Toast; 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.DefaultDataSourceFactory; import com.google.android.exoplayer2.util.Util; +import com.google.android.material.bottomappbar.BottomAppBar; import javax.inject.Inject; import javax.inject.Named; @@ -46,8 +48,9 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.post.Post; 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.utils.SharedPreferencesUtils; @@ -62,7 +65,13 @@ public class ViewRedditGalleryVideoFragment extends Fragment { PlayerView videoPlayerView; @BindView(R.id.mute_exo_playback_control_view) 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 String subredditName; private SimpleExoPlayer player; @@ -139,6 +148,17 @@ public class ViewRedditGalleryVideoFragment extends Fragment { player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(galleryVideo.url))); preparePlayer(savedInstanceState); + if (activity.isUseBottomAppBar()) { + bottomAppBar.setVisibility(View.VISIBLE); + downloadImageView.setOnClickListener(view -> { + if (isDownloading) { + return; + } + isDownloading = true; + requestPermissionAndDownload(); + }); + } + return rootView; } @@ -152,25 +172,29 @@ public class ViewRedditGalleryVideoFragment extends Fragment { public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.action_download_view_reddit_gallery_video_fragment) { isDownloading = true; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { - if (ContextCompat.checkSelfPermission(activity, - Manifest.permission.WRITE_EXTERNAL_STORAGE) - != PackageManager.PERMISSION_GRANTED) { - - // Permission is not granted - // No explanation needed; request the permission - requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, - PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE); - } else { - // Permission has already been granted - download(); - } + 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 (ContextCompat.checkSelfPermission(activity, + Manifest.permission.WRITE_EXTERNAL_STORAGE) + != PackageManager.PERMISSION_GRANTED) { + + // Permission is not granted + // No explanation needed; request the permission + requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, + PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE); } else { + // Permission has already been granted download(); } - return true; + } else { + download(); } - return false; } @Override @@ -286,6 +310,6 @@ public class ViewRedditGalleryVideoFragment extends Fragment { @Override public void onAttach(@NonNull Context context) { super.onAttach(context); - activity = (Activity) context; + activity = (ViewRedditGalleryActivity) context; } } \ No newline at end of file -- cgit v1.2.3