From e3f9d31a3404eccee01b6deb53c8d166f1557892 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sat, 13 Aug 2022 12:25:04 +1000 Subject: Fix caption shown under the navbar in ViewRedditGalleryImageOrGifFragment. --- .../activities/ViewRedditGalleryActivity.java | 9 +++++ .../customviews/AspectRatioGifImageView.java | 2 +- .../ViewRedditGalleryImageOrGifFragment.java | 42 ++++++++++++---------- .../fragment_view_reddit_gallery_image_or_gif.xml | 7 ++-- 4 files changed, 37 insertions(+), 23 deletions(-) (limited to 'app/src/main') 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 67744239..1c52da84 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java @@ -76,6 +76,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA private String subredditName; private boolean isNsfw; private boolean useBottomAppBar; + private boolean isActionBarHidden = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -279,6 +280,14 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA this.typeface = typeface; } + public boolean isActionBarHidden() { + return isActionBarHidden; + } + + public void setActionBarHidden(boolean isActionBarHidden) { + this.isActionBarHidden = isActionBarHidden; + } + private class SectionsPagerAdapter extends FragmentStatePagerAdapter { SectionsPagerAdapter(@NonNull FragmentManager fm) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java index 6e6c1059..5097849f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/AspectRatioGifImageView.java @@ -25,7 +25,7 @@ public class AspectRatioGifImageView extends GifImageView { } public final void setRatio(float var1) { - if (this.ratio != var1) { + if (Math.abs(this.ratio - var1) > 0.0001) { this.ratio = var1; requestLayout(); 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 e90c277f..fe9dac8b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryImageOrGifFragment.java @@ -112,7 +112,6 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { private String subredditName; private boolean isNsfw; private boolean isDownloading = false; - private boolean isActionBarHidden = false; private boolean isUseBottomCaption = false; private boolean isFallback = false; @@ -215,20 +214,13 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { }); loadImage(); - activity.getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); imageView.setOnClickListener(view -> { - if (isActionBarHidden) { - activity.getWindow().getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); - isActionBarHidden = false; - if (activity.isUseBottomAppBar() || isUseBottomCaption) { - bottomAppBar.setVisibility(View.VISIBLE); + if (activity.isActionBarHidden()) { + activity.getWindow().getDecorView().setSystemUiVisibility(0); + activity.setActionBarHidden(false); + if (activity.isUseBottomAppBar()) { + bottomAppBarMenu.setVisibility(View.VISIBLE); } } else { hideAppBar(); @@ -244,7 +236,7 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { }); if (activity.isUseBottomAppBar()) { - bottomAppBar.setVisibility(View.VISIBLE); + bottomAppBarMenu.setVisibility(View.VISIBLE); if (media.mediaType == Post.Gallery.TYPE_GIF) { titleTextView.setText(getString(R.string.view_reddit_gallery_activity_gif_label, getArguments().getInt(EXTRA_INDEX) + 1, getArguments().getInt(EXTRA_MEDIA_COUNT))); @@ -279,7 +271,6 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { isUseBottomCaption = true; if (!activity.isUseBottomAppBar()) { - bottomAppBar.setVisibility(View.VISIBLE); bottomAppBarMenu.setVisibility(View.GONE); } @@ -339,9 +330,9 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE); - isActionBarHidden = true; - if (activity.isUseBottomAppBar() || isUseBottomCaption) { - bottomAppBar.setVisibility(View.GONE); + activity.setActionBarHidden(true); + if (activity.isUseBottomAppBar()) { + bottomAppBarMenu.setVisibility(View.GONE); } } @@ -382,7 +373,8 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { } return true; } else if (itemId == R.id.action_set_wallpaper_view_reddit_gallery_image_or_gif_fragment) { - setWallpaper(); + //setWallpaper(); + Toast.makeText(activity, Integer.toString(activity.getWindow().getDecorView().getSystemUiVisibility()), Toast.LENGTH_SHORT).show(); return true; } @@ -542,6 +534,18 @@ public class ViewRedditGalleryImageOrGifFragment extends Fragment { if (ssiv == null || !ssiv.hasImage()) { loadImage(); } + + if (activity.isActionBarHidden()) { + activity.getWindow().getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_IMMERSIVE); + } else { + activity.getWindow().getDecorView().setSystemUiVisibility(0); + } } @Override diff --git a/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml b/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml index c0aa4168..71e04ebf 100644 --- a/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml +++ b/app/src/main/res/layout/fragment_view_reddit_gallery_image_or_gif.xml @@ -45,8 +45,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" - android:backgroundTint="#80000000" - android:visibility="gone"> + app:paddingBottomSystemWindowInsets="false" + android:backgroundTint="#80000000"> + android:layout_height="wrap_content" + android:visibility="gone">