Use bottom toolbar in ViewImgurImageFragment is available.

This commit is contained in:
Alex Ning 2021-08-04 11:58:48 +08:00
parent 7fe451b7e1
commit f0c275e9ad
6 changed files with 230 additions and 118 deletions

View File

@ -144,11 +144,6 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
ButterKnife.bind(this); 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)));
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_VERTICALLY_TO_GO_BACK_FROM_MEDIA, true)) { if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_VERTICALLY_TO_GO_BACK_FROM_MEDIA, true)) {
Slidr.attach(this, new SlidrConfig.Builder().position(SlidrPosition.VERTICAL).distanceThreshold(0.125f).build()); Slidr.attach(this, new SlidrConfig.Builder().position(SlidrPosition.VERTICAL).distanceThreshold(0.125f).build());
} }
@ -181,6 +176,7 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
if (useBottomAppBar) { if (useBottomAppBar) {
getSupportActionBar().hide(); getSupportActionBar().hide();
bottomAppBar.setVisibility(View.VISIBLE);
downloadImageView.setOnClickListener(view -> { downloadImageView.setOnClickListener(view -> {
if (isDownloading) { if (isDownloading) {
return; return;
@ -198,7 +194,10 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa
setWallpaper(); setWallpaper();
}); });
} else { } else {
bottomAppBar.setVisibility(View.GONE); 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)));
} }
mLoadErrorLinearLayout.setOnClickListener(view -> { mLoadErrorLinearLayout.setOnClickListener(view -> {

View File

@ -77,6 +77,7 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa
LinearLayout errorLinearLayout; LinearLayout errorLinearLayout;
private SectionsPagerAdapter sectionsPagerAdapter; private SectionsPagerAdapter sectionsPagerAdapter;
private ArrayList<ImgurMedia> images; private ArrayList<ImgurMedia> images;
private boolean useBottomAppBar;
@Inject @Inject
@Named("imgur") @Named("imgur")
Retrofit imgurRetrofit; Retrofit imgurRetrofit;
@ -116,12 +117,17 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa
ButterKnife.bind(this); ButterKnife.bind(this);
useBottomAppBar = sharedPreferences.getBoolean(SharedPreferencesUtils.USE_BOTTOM_TOOLBAR_IN_MEDIA_VIEWER, false);
if (!useBottomAppBar) {
ActionBar actionBar = getSupportActionBar(); ActionBar actionBar = getSupportActionBar();
Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp); Drawable upArrow = getResources().getDrawable(R.drawable.ic_arrow_back_white_24dp);
actionBar.setHomeAsUpIndicator(upArrow); actionBar.setHomeAsUpIndicator(upArrow);
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor))); actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparentActionBarAndExoPlayerControllerColor)));
setTitle(" "); setTitle(" ");
} else {
getSupportActionBar().hide();
}
String imgurId = getIntent().getStringExtra(EXTRA_IMGUR_ID); String imgurId = getIntent().getStringExtra(EXTRA_IMGUR_ID);
if (imgurId == null) { if (imgurId == null) {
@ -153,6 +159,10 @@ public class ViewImgurMediaActivity extends AppCompatActivity implements SetAsWa
errorLinearLayout.setOnClickListener(view -> fetchImgurMedia(imgurId)); errorLinearLayout.setOnClickListener(view -> fetchImgurMedia(imgurId));
} }
public boolean isUseBottomAppBar() {
return useBottomAppBar;
}
private void fetchImgurMedia(String imgurId) { private void fetchImgurMedia(String imgurId) {
errorLinearLayout.setVisibility(View.GONE); errorLinearLayout.setVisibility(View.GONE);
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);

View File

@ -16,8 +16,10 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -36,6 +38,7 @@ import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition; import com.bumptech.glide.request.transition.Transition;
import com.davemorrissey.labs.subscaleview.ImageSource; import com.davemorrissey.labs.subscaleview.ImageSource;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView; import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import com.google.android.material.bottomappbar.BottomAppBar;
import java.io.File; import java.io.File;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -65,6 +68,16 @@ public class ViewImgurImageFragment extends Fragment {
SubsamplingScaleImageView imageView; SubsamplingScaleImageView imageView;
@BindView(R.id.load_image_error_linear_layout_view_imgur_image_fragment) @BindView(R.id.load_image_error_linear_layout_view_imgur_image_fragment)
LinearLayout errorLinearLayout; LinearLayout errorLinearLayout;
@BindView(R.id.bottom_navigation_view_imgur_image_fragment)
BottomAppBar bottomAppBar;
@BindView(R.id.title_text_view_view_imgur_image_fragment)
TextView titleTextView;
@BindView(R.id.download_image_view_view_imgur_image_fragment)
ImageView downloadImageView;
@BindView(R.id.share_image_view_view_imgur_image_fragment)
ImageView shareImageView;
@BindView(R.id.wallpaper_image_view_view_imgur_image_fragment)
ImageView wallpaperImageView;
@Inject @Inject
Executor mExecutor; Executor mExecutor;
@ -81,7 +94,7 @@ public class ViewImgurImageFragment extends Fragment {
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_view_imgur_images, container, false); View rootView = inflater.inflate(R.layout.fragment_view_imgur_image, container, false);
((Infinity) activity.getApplication()).getAppComponent().inject(this); ((Infinity) activity.getApplication()).getAppComponent().inject(this);
@ -100,6 +113,9 @@ public class ViewImgurImageFragment extends Fragment {
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
isActionBarHidden = false; isActionBarHidden = false;
if (activity.isUseBottomAppBar()) {
bottomAppBar.setVisibility(View.VISIBLE);
}
} else { } else {
activity.getWindow().getDecorView().setSystemUiVisibility( activity.getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE View.SYSTEM_UI_FLAG_LAYOUT_STABLE
@ -109,6 +125,9 @@ public class ViewImgurImageFragment extends Fragment {
| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE); | View.SYSTEM_UI_FLAG_IMMERSIVE);
isActionBarHidden = true; isActionBarHidden = true;
if (activity.isUseBottomAppBar()) {
bottomAppBar.setVisibility(View.GONE);
}
} }
}); });
imageView.setMinimumDpi(80); imageView.setMinimumDpi(80);
@ -121,6 +140,23 @@ public class ViewImgurImageFragment extends Fragment {
loadImage(); loadImage();
}); });
if (activity.isUseBottomAppBar()) {
bottomAppBar.setVisibility(View.VISIBLE);
downloadImageView.setOnClickListener(view -> {
if (isDownloading) {
return;
}
isDownloading = true;
requestPermissionAndDownload();
});
shareImageView.setOnClickListener(view -> {
shareImage();
});
wallpaperImageView.setOnClickListener(view -> {
setWallpaper();
});
}
return rootView; return rootView;
} }
@ -164,9 +200,21 @@ public class ViewImgurImageFragment extends Fragment {
if (isDownloading) { if (isDownloading) {
return false; return false;
} }
isDownloading = true; isDownloading = true;
requestPermissionAndDownload();
return true;
} else if (itemId == R.id.action_share_view_imgur_image_fragment) {
shareImage();
return true;
} else if (itemId == R.id.action_set_wallpaper_view_imgur_image_fragment) {
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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
if (ContextCompat.checkSelfPermission(activity, if (ContextCompat.checkSelfPermission(activity,
Manifest.permission.WRITE_EXTERNAL_STORAGE) Manifest.permission.WRITE_EXTERNAL_STORAGE)
@ -183,9 +231,20 @@ public class ViewImgurImageFragment extends Fragment {
} else { } else {
download(); download();
} }
}
return true; private void download() {
} else if (itemId == R.id.action_share_view_imgur_image_fragment) { isDownloading = false;
Intent intent = new Intent(activity, DownloadMediaService.class);
intent.putExtra(DownloadMediaService.EXTRA_URL, imgurMedia.getLink());
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE);
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, imgurMedia.getFileName());
ContextCompat.startForegroundService(activity, intent);
Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
}
private void shareImage() {
glide.asBitmap().load(imgurMedia.getLink()).into(new CustomTarget<Bitmap>() { glide.asBitmap().load(imgurMedia.getLink()).into(new CustomTarget<Bitmap>() {
@Override @Override
@ -224,8 +283,9 @@ public class ViewImgurImageFragment extends Fragment {
} }
}); });
return true; }
} else if (itemId == R.id.action_set_wallpaper_view_imgur_image_fragment) {
private void setWallpaper() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment(); SetAsWallpaperBottomSheetFragment setAsWallpaperBottomSheetFragment = new SetAsWallpaperBottomSheetFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
@ -235,21 +295,6 @@ public class ViewImgurImageFragment extends Fragment {
} else { } else {
((SetAsWallpaperCallback) activity).setToBoth(activity.getCurrentPagePosition()); ((SetAsWallpaperCallback) activity).setToBoth(activity.getCurrentPagePosition());
} }
return true;
}
return false;
}
private void download() {
isDownloading = false;
Intent intent = new Intent(activity, DownloadMediaService.class);
intent.putExtra(DownloadMediaService.EXTRA_URL, imgurMedia.getLink());
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE);
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, imgurMedia.getFileName());
ContextCompat.startForegroundService(activity, intent);
Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();
} }
@Override @Override

View File

@ -46,6 +46,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:backgroundTint="#80000000" android:backgroundTint="#80000000"
android:visibility="gone"
style="@style/Widget.MaterialComponents.BottomAppBar"> style="@style/Widget.MaterialComponents.BottomAppBar">
<LinearLayout <LinearLayout

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.ViewImgurImageFragment">
<ProgressBar
android:id="@+id/progress_bar_view_imgur_image_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/image_view_view_imgur_image_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/load_image_error_linear_layout_view_imgur_image_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_error_outline_white_24dp"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@android:color/white"
android:text="@string/error_loading_image_tap_to_retry"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family" />
</LinearLayout>
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_navigation_view_imgur_image_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_imgur_image_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_imgur_image_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_imgur_image_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_imgur_image_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>

View File

@ -1,40 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.ViewImgurImageFragment">
<ProgressBar
android:id="@+id/progress_bar_view_imgur_image_fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
android:id="@+id/image_view_view_imgur_image_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/load_image_error_linear_layout_view_imgur_image_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_error_outline_white_24dp"
android:layout_gravity="center"
android:gravity="center"
android:textColor="@android:color/white"
android:text="@string/error_loading_image_tap_to_retry"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family" />
</LinearLayout>
</RelativeLayout>