mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-28 11:58:23 +01:00
Use bottom toolbar in ViewRedditGalleryVideoFragment is available.
This commit is contained in:
parent
27173031a1
commit
085eaa8505
@ -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,27 +172,31 @@ 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();
|
||||
}
|
||||
} else {
|
||||
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();
|
||||
}
|
||||
} else {
|
||||
download();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {
|
||||
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user