mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 03:07:26 +01:00
Use bottom toolbar in ViewRedditGalleryImageOrGifFragment is available.
This commit is contained in:
parent
f0c275e9ad
commit
123898c946
@ -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());
|
||||
|
@ -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) {
|
||||
|
@ -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:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/constraintLayout"
|
||||
@ -11,7 +11,7 @@
|
||||
android:id="@+id/progress_bar_view_reddit_gallery_image_or_gif_fragment"
|
||||
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_reddit_gallery_image_or_gif_fragment"
|
||||
@ -39,4 +39,61 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
<com.google.android.material.bottomappbar.BottomAppBar
|
||||
android:id="@+id/bottom_navigation_view_reddit_gallery_image_or_gif_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:backgroundTint="#80000000"
|
||||
android:visibility="gone"
|
||||
style="@style/Widget.MaterialComponents.BottomAppBar">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title_text_view_view_reddit_gallery_image_or_gif_fragment"
|
||||
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_reddit_gallery_image_or_gif_fragment"
|
||||
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_reddit_gallery_image_or_gif_fragment"
|
||||
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_reddit_gallery_image_or_gif_fragment"
|
||||
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>
|
Loading…
Reference in New Issue
Block a user