From cb9154369070fe3773c16da0d4e7b3c33b716a1f Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Sat, 11 Jan 2020 10:39:49 +0800 Subject: Setting default post layout is now available. Add an option to hide the divider in post compact layout. --- .../infinityforreddit/Activity/MainActivity.java | 5 --- .../Adapter/PostRecyclerViewAdapter.java | 16 ++++++++- .../Event/ChangePostLayoutEvent.java | 9 +++++ .../ShowDividerInCompactLayoutPreferenceEvent.java | 9 +++++ .../infinityforreddit/Fragment/PostFragment.java | 39 +++++++++++++++------- .../Settings/MainPreferenceFragment.java | 18 ++++++++++ .../Utils/SharedPreferencesUtils.java | 2 ++ 7 files changed, 80 insertions(+), 18 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Event/ChangePostLayoutEvent.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Event/ShowDividerInCompactLayoutPreferenceEvent.java (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index c5eb9ac2..70b38606 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -3,10 +3,8 @@ package ml.docilealligator.infinityforreddit.Activity; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; -import android.graphics.Color; import android.os.Build; import android.os.Bundle; import android.util.TypedValue; @@ -27,7 +25,6 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.core.content.ContextCompat; import androidx.core.view.GravityCompat; import androidx.core.widget.NestedScrollView; import androidx.drawerlayout.widget.DrawerLayout; @@ -464,8 +461,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb lp.setAnchorId(View.NO_ID); lp.gravity = Gravity.END | Gravity.BOTTOM; fab.setLayoutParams(lp); - fab.setImageTintList(ColorStateList.valueOf(Color.WHITE)); - fab.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(this, R.color.backgroundColorPrimary))); } fab.setVisibility(View.VISIBLE); 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 2a4e6fe1..ad9c215d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java @@ -102,6 +102,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter { + EventBus.getDefault().post(new ChangePostLayoutEvent(Integer.parseInt((String) newValue))); + return true; + }); + } + + if (showDividerInCompactLayout != null) { + showDividerInCompactLayout.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ShowDividerInCompactLayoutPreferenceEvent((Boolean) newValue)); + return true; + }); + } + if (nsfwSwitch != null) { nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeNSFWEvent((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 b0434d82..7154f06e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -62,6 +62,8 @@ public class SharedPreferencesUtils { public static final int POST_LAYOUT_COMPACT = 1; public static final String PULL_NOTIFICATION_TIME = "pull_notification_time"; 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 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"; -- cgit v1.2.3