From 8ed7f54d46307177e4ef05721b3c6f15aa4fa9c4 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 13 Jun 2020 22:11:57 +0800 Subject: Add an option to move thumbnail in compact layout to the left. --- .../Adapter/PostRecyclerViewAdapter.java | 49 +++++++++++++++++++- ...howThumbnailOnTheRightInCompactLayoutEvent.java | 9 ++++ .../infinityforreddit/Fragment/PostFragment.java | 9 ++++ .../ImmersiveInterfacePreferenceFragment.java | 53 ++++++++++++++++++++++ .../Settings/InterfacePreferenceFragment.java | 45 ++++-------------- .../Utils/SharedPreferencesUtils.java | 1 + .../infinityforreddit/Utils/Utils.java | 5 ++ 7 files changed, 134 insertions(+), 37 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Event/ShowThumbnailOnTheRightInCompactLayoutEvent.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ImmersiveInterfacePreferenceFragment.java (limited to 'app/src/main/java') 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 7aaaa391..98355c69 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -22,6 +22,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; +import androidx.constraintlayout.widget.Barrier; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintSet; import androidx.core.graphics.drawable.DrawableCompat; @@ -72,10 +73,10 @@ import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewVideoActivity; import ml.docilealligator.infinityforreddit.AsyncTask.LoadSubredditIconAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.LoadUserDataAsyncTask; +import ml.docilealligator.infinityforreddit.BottomSheetFragment.ShareLinkBottomSheetFragment; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomView.AspectRatioGifImageView; import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToDetailActivity; -import ml.docilealligator.infinityforreddit.BottomSheetFragment.ShareLinkBottomSheetFragment; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.Post.Post; import ml.docilealligator.infinityforreddit.Post.PostDataSource; @@ -153,6 +154,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter= 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()) { + immersiveInterfaceIgnoreNavBarSwitch.setVisible(true); + } else { + immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); + } + + immersiveInterfaceIgnoreNavBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new RecreateActivityEvent()); + return true; + }); + } else { + immersiveInterfaceSwitch.setVisible(false); + immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); + } + } + } +} \ 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 c3c21c1c..85ba2a5e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java @@ -1,10 +1,8 @@ package ml.docilealligator.infinityforreddit.Settings; -import android.os.Build; import android.os.Bundle; -import androidx.fragment.app.Fragment; import androidx.preference.ListPreference; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.SwitchPreference; @@ -17,56 +15,24 @@ import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPreferenceEvent; +import ml.docilealligator.infinityforreddit.Event.ShowThumbnailOnTheRightInCompactLayoutEvent; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; -/** - * A simple {@link Fragment} subclass. - */ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { setPreferencesFromResource(R.xml.interface_preference, rootKey); - SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY); - SwitchPreference immersiveInterfaceIgnoreNavBarSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_IGNORE_NAV_BAR_KEY); SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY); SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY); SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY); ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY); SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT); + SwitchPreference showThumbnailOnTheRightInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_RIGHT_IN_COMPACT_LAYOUT); SwitchPreference showAbsoluteNumberOfVotes = findPreference(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES); - 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()) { - immersiveInterfaceIgnoreNavBarSwitch.setVisible(true); - } else { - immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); - } - - immersiveInterfaceIgnoreNavBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> { - EventBus.getDefault().post(new RecreateActivityEvent()); - return true; - }); - } else { - immersiveInterfaceSwitch.setVisible(false); - immersiveInterfaceIgnoreNavBarSwitch.setVisible(false); - } - } - if (bottomAppBarSwitch != null) { bottomAppBarSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new RecreateActivityEvent()); @@ -102,6 +68,13 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat { }); } + if (showThumbnailOnTheRightInCompactLayout != null) { + showThumbnailOnTheRightInCompactLayout.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ShowThumbnailOnTheRightInCompactLayoutEvent((Boolean) newValue)); + return true; + }); + } + if (showAbsoluteNumberOfVotes != null) { showAbsoluteNumberOfVotes.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeShowAbsoluteNumberOfVotesEvent((Boolean) newValue)); 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 b29ff3ed..a26571a9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -74,6 +74,7 @@ public class SharedPreferencesUtils { public static final String SHOW_ELAPSED_TIME_KEY = "show_elapsed_time"; public static final String DEFAULT_POST_LAYOUT_KEY = "default_post_layout"; public static final String SHOW_DIVIDER_IN_COMPACT_LAYOUT = "show_divider_in_compact_layout"; + public static final String SHOW_THUMBNAIL_ON_THE_RIGHT_IN_COMPACT_LAYOUT = "show_thumbnail_on_the_right_in_compact_layout"; public static final String SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL = "swipe_to_go_back_from_post_detail"; public static final String VOLUME_KEYS_NAVIGATE_COMMENTS = "volume_keys_navigate_comments"; public static final String VOLUME_KEYS_NAVIGATE_POSTS = "volume_keys_navigate_posts"; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java index 329371dc..52a1972a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java @@ -7,6 +7,7 @@ import android.net.Network; import android.net.NetworkInfo; import android.text.Html; import android.text.Spannable; +import android.util.DisplayMetrics; import android.view.inputmethod.InputMethodManager; import android.widget.TextView; @@ -126,4 +127,8 @@ public class Utils { inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0); } } + + public static float convertDpToPixel(float dp, Context context){ + return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT); + } } -- cgit v1.2.3