aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/ml')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java103
2 files changed, 91 insertions, 32 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java
index 52a02e44..15737bbf 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java
@@ -55,6 +55,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
private SectionsPagerAdapter sectionsPagerAdapter;
private ArrayList<Post.Gallery> gallery;
private String subredditName;
+ private boolean useBottomAppBar;
@Inject
@Named("default")
SharedPreferences sharedPreferences;
@@ -91,10 +92,17 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
ButterKnife.bind(this);
- ActionBar actionBar = getSupportActionBar();
- Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
- actionBar.setHomeAsUpIndicator(upArrow);
- actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
+ useBottomAppBar = sharedPreferences.getBoolean(SharedPreferencesUtils.USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER, false);
+
+ if (!useBottomAppBar) {
+ ActionBar actionBar = getSupportActionBar();
+ Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
+ actionBar.setHomeAsUpIndicator(upArrow);
+ actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
+ setTitle(" ");
+ } else {
+ getSupportActionBar().hide();
+ }
setTitle(" ");
@@ -118,6 +126,10 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
setupViewPager();
}
+ public boolean isUseBottomAppBar() {
+ return useBottomAppBar;
+ }
+
private void setupViewPager() {
setToolbarTitle(0);
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java
index e3e06399..a0aa1476 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java
@@ -16,8 +16,10 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -41,6 +43,7 @@ import com.github.piasy.biv.loader.ImageLoader;
import com.github.piasy.biv.loader.glide.GlideImageLoader;
import com.github.piasy.biv.view.BigImageView;
import com.github.piasy.biv.view.GlideImageViewFactory;
+import com.google.android.material.bottomappbar.BottomAppBar;
import java.io.File;
import java.util.concurrent.Executor;
@@ -72,6 +75,16 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
BigImageView imageView;
@BindView(R.id.load_image_error_linear_layout_view_reddit_gallery_image_or_gif_fragment)
LinearLayout errorLinearLayout;
+ @BindView(R.id.bottom_navigation_view_reddit_gallery_image_or_gif_fragment)
+ BottomAppBar bottomAppBar;
+ @BindView(R.id.title_text_view_view_reddit_gallery_image_or_gif_fragment)
+ TextView titleTextView;
+ @BindView(R.id.download_image_view_view_reddit_gallery_image_or_gif_fragment)
+ ImageView downloadImageView;
+ @BindView(R.id.share_image_view_view_reddit_gallery_image_or_gif_fragment)
+ ImageView shareImageView;
+ @BindView(R.id.wallpaper_image_view_view_reddit_gallery_image_or_gif_fragment)
+ ImageView wallpaperImageView;
@Inject
Executor mExecutor;
@@ -192,6 +205,9 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
isActionBarHidden = false;
+ if (activity.isUseBottomAppBar()) {
+ bottomAppBar.setVisibility(View.VISIBLE);
+ }
} else {
activity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
@@ -201,6 +217,9 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
isActionBarHidden = true;
+ if (activity.isUseBottomAppBar()) {
+ bottomAppBar.setVisibility(View.GONE);
+ }
}
});
@@ -210,6 +229,27 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
loadImage();
});
+ if (activity.isUseBottomAppBar()) {
+ bottomAppBar.setVisibility(View.VISIBLE);
+ downloadImageView.setOnClickListener(view -> {
+ if (isDownloading) {
+ return;
+ }
+ isDownloading = true;
+ requestPermissionAndDownload();
+ });
+ shareImageView.setOnClickListener(view -> {
+ if (media.mediaType == Post.Gallery.TYPE_GIF) {
+ shareGif();
+ } else {
+ shareImage();
+ }
+ });
+ wallpaperImageView.setOnClickListener(view -> {
+ setWallpaper();
+ });
+ }
+
return rootView;
}
@@ -230,26 +270,8 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
if (isDownloading) {
return false;
}
-
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;
} else if (itemId == R.id.action_share_view_reddit_gallery_image_or_gif_fragment) {
if (media.mediaType == Post.Gallery.TYPE_GIF) {
@@ -259,21 +281,32 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
}
return true;
} else if (itemId == R.id.action_set_wallpaper_view_reddit_gallery_image_or_gif_fragment) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment();
- Bundle bundle = new Bundle();
- bundle.putInt(SetAsWallpaperBottomSheetFragment.EXTRA_VIEW_PAGER_POSITION, activity.getCurrentPagePosition());
- setAsWallpaperBottomSheetFragment.setArguments(bundle);
- setAsWallpaperBottomSheetFragment.show(activity.getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag());
- } else {
- ((SetAsWallpaperCallback) activity).setToBoth(activity.getCurrentPagePosition());
- }
+ setWallpaper();
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();
+ }
+ }
+
private void download() {
isDownloading = false;
@@ -366,6 +399,20 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment {
}).submit();
}
+ private void setWallpaper() {
+ if (media.mediaType != Post.Gallery.TYPE_GIF) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment();
+ Bundle bundle = new Bundle();
+ bundle.putInt(SetAsWallpaperBottomSheetFragment.EXTRA_VIEW_PAGER_POSITION, activity.getCurrentPagePosition());
+ setAsWallpaperBottomSheetFragment.setArguments(bundle);
+ setAsWallpaperBottomSheetFragment.show(activity.getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag());
+ } else {
+ ((SetAsWallpaperCallback) activity).setToBoth(activity.getCurrentPagePosition());
+ }
+ }
+ }
+
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {