aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-08-03 14:03:45 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-08-03 14:03:45 +0000
commit7fe451b7e15f97b486e61e4217178f5cf454accf (patch)
tree56e7da353f502dc84627fedb7473c78d2e9b7628
parent7987dd684a40d0817151d581c2071c7c88253ef3 (diff)
downloadinfinity-for-reddit-7fe451b7e15f97b486e61e4217178f5cf454accf.tar
infinity-for-reddit-7fe451b7e15f97b486e61e4217178f5cf454accf.tar.gz
infinity-for-reddit-7fe451b7e15f97b486e61e4217178f5cf454accf.tar.bz2
infinity-for-reddit-7fe451b7e15f97b486e61e4217178f5cf454accf.tar.lz
infinity-for-reddit-7fe451b7e15f97b486e61e4217178f5cf454accf.tar.xz
infinity-for-reddit-7fe451b7e15f97b486e61e4217178f5cf454accf.tar.zst
infinity-for-reddit-7fe451b7e15f97b486e61e4217178f5cf454accf.zip
Use bottom toolbar in ViewImageOrGifActivity is available.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java135
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/res/drawable/ic_wallpaper_white_24dp.xml5
-rw-r--r--app/src/main/res/layout/activity_theme_preview.xml1
-rw-r--r--app/src/main/res/layout/activity_view_image_or_gif.xml62
-rw-r--r--app/src/main/res/values/strings.xml1
-rw-r--r--app/src/main/res/xml/interface_preferences.xml5
7 files changed, 167 insertions, 43 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java
index f0227961..34fb586d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewImageOrGifActivity.java
@@ -12,11 +12,14 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.Html;
+import android.text.Spanned;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
+import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -42,6 +45,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 com.r0adkll.slidr.Slidr;
import com.r0adkll.slidr.model.SlidrConfig;
import com.r0adkll.slidr.model.SlidrPosition;
@@ -85,6 +89,16 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
BigImageView mImageView;
@BindView(R.id.load_image_error_linear_layout_view_image_or_gif_activity)
LinearLayout mLoadErrorLinearLayout;
+ @BindView(R.id.bottom_navigation_view_image_or_gif_activity)
+ BottomAppBar bottomAppBar;
+ @BindView(R.id.title_text_view_view_image_or_gif_activity)
+ TextView titleTextView;
+ @BindView(R.id.download_image_view_view_image_or_gif_activity)
+ ImageView downloadImageView;
+ @BindView(R.id.share_image_view_view_image_or_gif_activity)
+ ImageView shareImageView;
+ @BindView(R.id.wallpaper_image_view_view_image_or_gif_activity)
+ ImageView wallpaperImageView;
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
@@ -151,10 +165,40 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
String postTitle = intent.getStringExtra(EXTRA_POST_TITLE_KEY);
mSubredditName = intent.getStringExtra(EXTRA_SUBREDDIT_OR_USERNAME_KEY);
+ boolean useBottomAppBar = mSharedPreferences.getBoolean(SharedPreferencesUtils.USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER, false);
if (postTitle != null) {
- setTitle(Html.fromHtml(String.format("<small>%s</small>", postTitle)));
+ Spanned title = Html.fromHtml(String.format("<small>%s</small>", postTitle));
+ if (useBottomAppBar) {
+ titleTextView.setText(title);
+ } else {
+ setTitle(title);
+ }
+ } else {
+ if (!useBottomAppBar) {
+ setTitle("");
+ }
+ }
+
+ if (useBottomAppBar) {
+ getSupportActionBar().hide();
+ downloadImageView.setOnClickListener(view -> {
+ if (isDownloading) {
+ return;
+ }
+ isDownloading = true;
+ requestPermissionAndDownload();
+ });
+ shareImageView.setOnClickListener(view -> {
+ if (isGif)
+ shareGif();
+ else
+ shareImage();
+ });
+ wallpaperImageView.setOnClickListener(view -> {
+ setWallpaper();
+ });
} else {
- setTitle("");
+ bottomAppBar.setVisibility(View.GONE);
}
mLoadErrorLinearLayout.setOnClickListener(view -> {
@@ -170,6 +214,9 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
isActionBarHidden = false;
+ if (useBottomAppBar) {
+ bottomAppBar.setVisibility(View.VISIBLE);
+ }
} else {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
@@ -179,6 +226,9 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
isActionBarHidden = true;
+ if (useBottomAppBar) {
+ bottomAppBar.setVisibility(View.GONE);
+ }
}
});
@@ -287,26 +337,8 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
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(this,
- Manifest.permission.WRITE_EXTERNAL_STORAGE)
- != PackageManager.PERMISSION_GRANTED) {
-
- // Permission is not granted
- // No explanation needed; request the permission
- ActivityCompat.requestPermissions(this, 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_image_or_gif_activity) {
if (isGif)
@@ -315,31 +347,32 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
shareImage();
return true;
} else if (itemId == R.id.action_set_wallpaper_view_image_or_gif_activity) {
- if (!isGif) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment();
- setAsWallpaperBottomSheetFragment.show(getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag());
- } else {
- WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.BOTH_SCREENS, this,
- new WallpaperSetter.SetWallpaperListener() {
- @Override
- public void success() {
- Toast.makeText(ViewImageOrGifActivity.this, R.string.wallpaper_set, Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void failed() {
- Toast.makeText(ViewImageOrGifActivity.this, R.string.error_set_wallpaper, Toast.LENGTH_SHORT).show();
- }
- });
- }
- }
+ 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(this,
+ Manifest.permission.WRITE_EXTERNAL_STORAGE)
+ != PackageManager.PERMISSION_GRANTED) {
+
+ // Permission is not granted
+ // No explanation needed; request the permission
+ ActivityCompat.requestPermissions(this, 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;
@@ -433,6 +466,28 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
}).submit();
}
+ private void setWallpaper() {
+ if (!isGif) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment();
+ setAsWallpaperBottomSheetFragment.show(getSupportFragmentManager(), setAsWallpaperBottomSheetFragment.getTag());
+ } else {
+ WallpaperSetter.set(mExecutor, new Handler(), mImageUrl, WallpaperSetter.BOTH_SCREENS, this,
+ new WallpaperSetter.SetWallpaperListener() {
+ @Override
+ public void success() {
+ Toast.makeText(ViewImageOrGifActivity.this, R.string.wallpaper_set, Toast.LENGTH_SHORT).show();
+ }
+
+ @Override
+ public void failed() {
+ Toast.makeText(ViewImageOrGifActivity.this, R.string.error_set_wallpaper, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+ }
+ }
+
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE && grantResults.length > 0) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
index 69b5917b..47b1f109 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
@@ -185,6 +185,7 @@ public class SharedPreferencesUtils {
public static final String VIDEO_PLAYER_AUTOMATIC_LANDSCAPE_ORIENTATION = "video_player_automatic_landscape_orientation";
public static final String REMEMBER_MUTING_OPTION_IN_POST_FEED = "remember_muting_option_in_post_feed";
public static final String DEFAULT_LINK_POST_LAYOUT_KEY = "default_link_post_layout";
+ public static final String USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER = "use_bottom_toolbar_in_media_viewer";
public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences";
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";
diff --git a/app/src/main/res/drawable/ic_wallpaper_white_24dp.xml b/app/src/main/res/drawable/ic_wallpaper_white_24dp.xml
new file mode 100644
index 00000000..9db92d6f
--- /dev/null
+++ b/app/src/main/res/drawable/ic_wallpaper_white_24dp.xml
@@ -0,0 +1,5 @@
+<vector android:height="24dp"
+ android:viewportHeight="24" android:viewportWidth="24"
+ android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+ <path android:fillColor="@android:color/white" android:pathData="M4,4h7L11,2L4,2c-1.1,0 -2,0.9 -2,2v7h2L4,4zM10,13l-4,5h12l-3,-4 -2.03,2.71L10,13zM17,8.5c0,-0.83 -0.67,-1.5 -1.5,-1.5S14,7.67 14,8.5s0.67,1.5 1.5,1.5S17,9.33 17,8.5zM20,2h-7v2h7v7h2L22,4c0,-1.1 -0.9,-2 -2,-2zM20,20h-7v2h7c1.1,0 2,-0.9 2,-2v-7h-2v7zM4,13L2,13v7c0,1.1 0.9,2 2,2h7v-2L4,20v-7z"/>
+</vector>
diff --git a/app/src/main/res/layout/activity_theme_preview.xml b/app/src/main/res/layout/activity_theme_preview.xml
index 6ca8a0b0..67a75368 100644
--- a/app/src/main/res/layout/activity_theme_preview.xml
+++ b/app/src/main/res/layout/activity_theme_preview.xml
@@ -194,6 +194,7 @@
android:background="?attr/selectableItemBackgroundBorderless" />
</LinearLayout>
+
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
diff --git a/app/src/main/res/layout/activity_view_image_or_gif.xml b/app/src/main/res/layout/activity_view_image_or_gif.xml
index 4ecd9fda..e97a422a 100644
--- a/app/src/main/res/layout/activity_view_image_or_gif.xml
+++ b/app/src/main/res/layout/activity_view_image_or_gif.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/hauler_view_view_image_or_gif_activity"
@@ -12,7 +12,7 @@
android:id="@+id/progress_bar_view_image_or_gif_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_centerInParent="true" />
+ android:layout_gravity="center" />
<com.github.piasy.biv.view.BigImageView
android:id="@+id/image_view_view_image_or_gif_activity"
@@ -40,4 +40,60 @@
</LinearLayout>
-</RelativeLayout>
+ <com.google.android.material.bottomappbar.BottomAppBar
+ android:id="@+id/bottom_navigation_view_image_or_gif_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom"
+ android:backgroundTint="#80000000"
+ style="@style/Widget.MaterialComponents.BottomAppBar">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/title_text_view_view_image_or_gif_activity"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="center_vertical"
+ android:gravity="center_vertical"
+ android:paddingTop="8dp"
+ android:paddingBottom="8dp"
+ android:textColor="#FFFFFF"
+ android:textSize="?attr/font_20"
+ android:fontFamily="?attr/font_family"
+ android:maxLines="1"
+ android:ellipsize="end" />
+
+ <ImageView
+ android:id="@+id/download_image_view_view_image_or_gif_activity"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="16dp"
+ android:src="@drawable/ic_file_download_toolbar_white_24dp"
+ android:background="?attr/selectableItemBackgroundBorderless" />
+
+ <ImageView
+ android:id="@+id/share_image_view_view_image_or_gif_activity"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="16dp"
+ android:src="@drawable/ic_share_toolbar_white_24dp"
+ android:background="?attr/selectableItemBackgroundBorderless" />
+
+ <ImageView
+ android:id="@+id/wallpaper_image_view_view_image_or_gif_activity"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginEnd="16dp"
+ android:padding="16dp"
+ android:src="@drawable/ic_wallpaper_white_24dp"
+ android:background="?attr/selectableItemBackgroundBorderless" />
+
+ </LinearLayout>
+
+ </com.google.android.material.bottomappbar.BottomAppBar>
+
+</androidx.coordinatorlayout.widget.CoordinatorLayout>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 7d528f8e..30b81fd4 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -592,6 +592,7 @@
<string name="settings_post_details_title">Post Details</string>
<string name="settings_separate_post_and_comments_in_portrait_mode">Separate Post And Comments in Portrait Mode</string>
<string name="settings_separate_post_and_comments_in_landscape_mode">Separate Post And Comments in Landscape Mode</string>
+ <string name="settings_use_bottom_toolbar_in_media_viewer_title">Use Bottom Toolbar in Media Viewer</string>
<string name="no_link_available">Cannot get the link</string>
diff --git a/app/src/main/res/xml/interface_preferences.xml b/app/src/main/res/xml/interface_preferences.xml
index 47207d0a..1a4e0f86 100644
--- a/app/src/main/res/xml/interface_preferences.xml
+++ b/app/src/main/res/xml/interface_preferences.xml
@@ -37,6 +37,11 @@
app:key="hide_subreddit_description"
app:title="@string/settings_hide_subreddit_description_title" />
+ <SwitchPreference
+ app:defaultValue="false"
+ app:key="use_bottom_toolbar_in_media_viewer"
+ app:title="@string/settings_use_bottom_toolbar_in_media_viewer_title" />
+
<ListPreference
app:defaultValue="0"
app:entries="@array/settings_default_search_result_tab"