From a9ba807cf42632b1744b5af5b9e1081575fecae5 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 15 Jul 2020 10:42:46 +0800 Subject: [PATCH] Fix gif too small in ViewImageOrGifActivity. Hide immersive interface entry if the device has Android version lower than 8.0. --- .../Activity/ViewImageOrGifActivity.java | 52 ------------------- .../CommentAndPostRecyclerViewAdapter.java | 2 +- .../Adapter/PostRecyclerViewAdapter.java | 2 +- .../ImmersiveInterfacePreferenceFragment.java | 31 +++++------ .../Settings/InterfacePreferenceFragment.java | 7 +++ .../Utils/SharedPreferencesUtils.java | 1 + .../res/layout/activity_view_image_or_gif.xml | 3 +- app/src/main/res/values/strings.xml | 3 +- .../xml/immersive_interface_preferences.xml | 5 +- app/src/main/res/xml/interface_preference.xml | 4 +- 10 files changed, 30 insertions(+), 80 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java index dd2b0d1c..ad5e4fcc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageOrGifActivity.java @@ -77,8 +77,6 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa public static final String FILE_NAME_KEY = "FNK"; public static final String POST_TITLE_KEY = "PTK"; private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0; - /*@BindView(R.id.hauler_view_view_image_or_gif_activity) - HaulerView mHaulerView;*/ @BindView(R.id.progress_bar_view_image_or_gif_activity) ProgressBar mProgressBar; @BindView(R.id.image_view_view_image_or_gif_activity) @@ -259,61 +257,11 @@ public class ViewImageOrGifActivity extends AppCompatActivity implements SetAsWa } }); - /*if (isGif) { - gestureLayout.setVisibility(View.VISIBLE); - gestureLayout.getController().getSettings().setMaxZoom(10f).setDoubleTapZoom(2f).setPanEnabled(true); - mGifView.setOnClickListener(imageViewOnClickListener); - } else { - mImageView.setVisibility(View.VISIBLE); - mImageView.setOnClickListener(imageViewOnClickListener); - }*/ - loadImage(); } private void loadImage() { mImageView.showImage(Uri.parse(mImageUrl)); - /*if (isGif) { - glide.load(mImageUrl).listener(new RequestListener() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - mProgressBar.setVisibility(View.GONE); - mLoadErrorLinearLayout.setVisibility(View.VISIBLE); - return false; - } - - @Override - public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - mProgressBar.setVisibility(View.GONE); - return false; - } - }).override(Target.SIZE_ORIGINAL).into(mGifView); - } else { - glide.asBitmap().load(mImageUrl).listener(new RequestListener() { - @Override - public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) { - mProgressBar.setVisibility(View.GONE); - mLoadErrorLinearLayout.setVisibility(View.VISIBLE); - return false; - } - - @Override - public boolean onResourceReady(Bitmap resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) { - mProgressBar.setVisibility(View.GONE); - return false; - } - }).override(Target.SIZE_ORIGINAL).into(new CustomTarget() { - @Override - public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { - mImageView.setImage(ImageSource.bitmap(resource)); - } - - @Override - public void onLoadCleared(@Nullable Drawable placeholder) { - - } - }); - }*/ } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index a7975e47..bbf36110 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -1248,7 +1248,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter mPost.getPreviewWidth() && mPost.getPostType() == Post.IMAGE_TYPE) { + if (mImageViewWidth > mPost.getPreviewWidth()) { imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView); } else { imageRequestBuilder.into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java index d630f12a..835d8af1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -875,7 +875,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter post.getPreviewWidth() && post.getPostType() == Post.IMAGE_TYPE) { + if (mImageViewWidth > post.getPreviewWidth()) { imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostImageAndGifAutoplayViewHolder) holder).imageView); } else { imageRequestBuilder.into(((PostImageAndGifAutoplayViewHolder) holder).imageView); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ImmersiveInterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ImmersiveInterfacePreferenceFragment.java index c9f95e98..019f3593 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ImmersiveInterfacePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ImmersiveInterfacePreferenceFragment.java @@ -1,6 +1,5 @@ package ml.docilealligator.infinityforreddit.Settings; -import android.os.Build; import android.os.Bundle; import androidx.preference.PreferenceFragmentCompat; @@ -22,32 +21,26 @@ public class ImmersiveInterfacePreferenceFragment extends PreferenceFragmentComp SwitchPreference immersiveInterfaceIgnoreNavBarSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY); if (immersiveInterfaceSwitch != null && immersiveInterfaceIgnoreNavBarSwitch != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - immersiveInterfaceSwitch.setVisible(true); - immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> { - if ((Boolean) newValue) { - immersiveInterfaceIgnoreNavBarSwitch.setVisible(true); - } else { - immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); - } - EventBus.getDefault().post(new RecreateActivityEvent()); - return true; - }); - - if (immersiveInterfaceSwitch.isChecked()) { + immersiveInterfaceSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + if ((Boolean) newValue) { immersiveInterfaceIgnoreNavBarSwitch.setVisible(true); } else { immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); } + EventBus.getDefault().post(new RecreateActivityEvent()); + return true; + }); - immersiveInterfaceIgnoreNavBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new RecreateActivityEvent()); - return true; - }); + if (immersiveInterfaceSwitch.isChecked()) { + immersiveInterfaceIgnoreNavBarSwitch.setVisible(true); } else { - immersiveInterfaceSwitch.setVisible(false); immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); } + + immersiveInterfaceIgnoreNavBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new RecreateActivityEvent()); + return true; + }); } } } \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java index c665478a..bec9cad8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java @@ -1,9 +1,11 @@ package ml.docilealligator.infinityforreddit.Settings; +import android.os.Build; import android.os.Bundle; import androidx.preference.ListPreference; +import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; @@ -24,6 +26,7 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.interface_preference, rootKey); + Preference immersiveInterfaceEntryPreference = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_ENTRY_KEY); SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY); SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY); ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY); @@ -31,6 +34,10 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { SwitchPreference showThumbnailOnTheRightInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_LEFT_IN_COMPACT_LAYOUT); SwitchPreference showAbsoluteNumberOfVotes = findPreference(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES); + if (immersiveInterfaceEntryPreference != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + immersiveInterfaceEntryPreference.setVisible(true); + } + if (bottomAppBarSwitch != null) { bottomAppBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new RecreateActivityEvent()); 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 c4eba6f8..b473bc34 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -35,6 +35,7 @@ public class SharedPreferencesUtils { public static final String TITLE_FONT_FAMILY_KEY = "title_font_family"; public static final String CONTENT_FONT_FAMILY_KEY = "content_font_family"; public static final String AMOLED_DARK_KEY = "amoled_dark"; + public static final String IMMERSIVE_INTERFACE_ENTRY_KEY = "immersive_interface_entry"; public static final String IMMERSIVE_INTERFACE_KEY = "immersive_interface"; public static final String IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY = "immersive_interface_ignore_nav_bar"; public static final String BOTTOM_APP_BAR_KEY = "bottom_app_bar"; 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 21dd1f4b..9d3a0b58 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 @@ -19,8 +19,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" app:optimizeDisplay="true" - app:tapToRetry="false" - app:initScaleType="centerInside" /> + app:tapToRetry="false"/> Autoplay Videos Visible Area Offset (Landscape) Start autoplaying videos when %1$d%% of them are visible Immersive Interface + Does Not Apply to All Pages Ignore Navigation Bar in Immersive Interface Prevent the Bottom Navigation Bar Having Extra Padding Customize Tabs in Main Page @@ -378,7 +379,7 @@ Show Thumbnail on the Left in Compact Layout Swap Tap and Long Press in Comments Swipe Right to Go Back - Does not apply to all pages + Does Not Apply to All Pages Lock Jump to Next Top-level Comment Button Lock Bottom Navigation Bar Swipe Up to Hide Jump to Next Top-level Comment Button diff --git a/app/src/main/res/xml/immersive_interface_preferences.xml b/app/src/main/res/xml/immersive_interface_preferences.xml index 962faa10..6cd31d84 100644 --- a/app/src/main/res/xml/immersive_interface_preferences.xml +++ b/app/src/main/res/xml/immersive_interface_preferences.xml @@ -5,13 +5,12 @@ app:defaultValue="true" app:key="immersive_interface" app:title="@string/settings_immersive_interface_title" - app:isPreferenceVisible="false" /> + app:summary="@string/settings_immersive_interface_summary" /> + app:summary="@string/settings_immersive_interface_ignore_nav_bar_summary" /> \ No newline at end of file diff --git a/app/src/main/res/xml/interface_preference.xml b/app/src/main/res/xml/interface_preference.xml index e391a21c..8ad53611 100644 --- a/app/src/main/res/xml/interface_preference.xml +++ b/app/src/main/res/xml/interface_preference.xml @@ -8,8 +8,10 @@ app:fragment="ml.docilealligator.infinityforreddit.Settings.FontPreferenceFragment" /> + app:fragment="ml.docilealligator.infinityforreddit.Settings.ImmersiveInterfacePreferenceFragment" + app:isPreferenceVisible="false" />