mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-02-05 22:24:45 +01:00
Use bottom toolbar in ViewImageOrGifActivity is available.
This commit is contained in:
parent
7987dd684a
commit
7fe451b7e1
@ -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,11 +165,41 @@ 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 {
|
||||
bottomAppBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mLoadErrorLinearLayout.setOnClickListener(view -> {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
@ -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,9 +337,24 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
|
||||
if (isDownloading) {
|
||||
return false;
|
||||
}
|
||||
|
||||
isDownloading = true;
|
||||
requestPermissionAndDownload();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_share_view_image_or_gif_activity) {
|
||||
if (isGif)
|
||||
shareGif();
|
||||
else
|
||||
shareImage();
|
||||
return true;
|
||||
} else if (itemId == R.id.action_set_wallpaper_view_image_or_gif_activity) {
|
||||
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)
|
||||
@ -306,38 +371,6 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
|
||||
} else {
|
||||
download();
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (itemId == R.id.action_share_view_image_or_gif_activity) {
|
||||
if (isGif)
|
||||
shareGif();
|
||||
else
|
||||
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();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void download() {
|
||||
@ -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) {
|
||||
|
@ -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";
|
||||
|
5
app/src/main/res/drawable/ic_wallpaper_white_24dp.xml
Normal file
5
app/src/main/res/drawable/ic_wallpaper_white_24dp.xml
Normal file
@ -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>
|
@ -194,6 +194,7 @@
|
||||
android:background="?attr/selectableItemBackgroundBorderless" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.bottomappbar.BottomAppBar>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user