aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-02-20 07:10:50 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-02-20 07:10:50 +0000
commitd9b9a7c3c13303e2f61b2cb557ab96ec1a23a7ac (patch)
tree2aab31e5591df0378283fee51ce53f44690c3030 /app/src/main/java/ml/docilealligator/infinityforreddit
parent59465390a9e5ec06bfd8d3b46fbcaeedf560f563 (diff)
downloadinfinity-for-reddit-d9b9a7c3c13303e2f61b2cb557ab96ec1a23a7ac.tar
infinity-for-reddit-d9b9a7c3c13303e2f61b2cb557ab96ec1a23a7ac.tar.gz
infinity-for-reddit-d9b9a7c3c13303e2f61b2cb557ab96ec1a23a7ac.tar.bz2
infinity-for-reddit-d9b9a7c3c13303e2f61b2cb557ab96ec1a23a7ac.tar.lz
infinity-for-reddit-d9b9a7c3c13303e2f61b2cb557ab96ec1a23a7ac.tar.xz
infinity-for-reddit-d9b9a7c3c13303e2f61b2cb557ab96ec1a23a7ac.tar.zst
infinity-for-reddit-d9b9a7c3c13303e2f61b2cb557ab96ec1a23a7ac.zip
Add an option to show comment dividers. Put theme option to InterfacePreferenceFragment.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/InterfacePreferenceFragment.java59
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java50
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java1
7 files changed, 93 insertions, 56 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
index a3123182..65711954 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
@@ -176,6 +176,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
private boolean mLockFab;
private boolean mSwipeUpToHideFab;
private boolean mExpandChildren;
+ private boolean mShowCommentDivider;
private LinearLayoutManager mLinearLayoutManager;
private CommentAndPostRecyclerViewAdapter mAdapter;
private RecyclerView.SmoothScroller mSmoothScroller;
@@ -263,6 +264,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
mSwipeUpToHideFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_UP_TO_HIDE_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
+ mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
mGlide = Glide.with(this);
mLocale = getResources().getConfiguration().locale;
@@ -508,7 +510,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost,
mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler,
- mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren,
+ mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override
public void updatePost(Post post) {
@@ -631,7 +633,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide,
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler,
- mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren,
+ mVoteButtonsOnTheRight, mShowElapsedTime, mExpandChildren, mShowCommentDivider,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override
public void updatePost(Post post) {
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 80887700..82270285 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -123,6 +123,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime;
private boolean mExpandChildren;
+ private boolean mShowCommentDivider;
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
private boolean isInitiallyLoading;
private boolean isInitiallyLoadingFailed;
@@ -138,7 +139,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
String accessToken, String accountName, Post post, Locale locale,
String singleCommentId, boolean isSingleCommentThreadMode,
boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight,
- boolean showElapsedTime, boolean expandChildren,
+ boolean showElapsedTime, boolean expandChildren, boolean showCommentDivider,
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
mActivity = activity;
mRetrofit = retrofit;
@@ -229,6 +230,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime;
mExpandChildren = expandChildren;
+ mShowCommentDivider = showCommentDivider;
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
isInitiallyLoading = true;
isInitiallyLoadingFailed = false;
@@ -1940,6 +1942,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
ImageView replyButton;
@BindView(R.id.vertical_block_item_post_comment)
View verticalBlock;
+ @BindView(R.id.divider_item_comment)
+ View commentDivider;
CommentViewHolder(View itemView) {
super(itemView);
@@ -1964,6 +1968,10 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
constraintSet.setHorizontalBias(moreButton.getId(), 0);
constraintSet.applyTo(bottomConstraintLayout);
}
+
+ if (mShowCommentDivider) {
+ commentDivider.setVisibility(View.VISIBLE);
+ }
}
}
@@ -1972,10 +1980,16 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
View verticalBlock;
@BindView(R.id.placeholder_text_view_item_load_more_comments)
TextView placeholderTextView;
+ @BindView(R.id.divider_item_load_more_comments_placeholder)
+ View commentDivider;
LoadMoreChildCommentsViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
+
+ if (mShowCommentDivider) {
+ commentDivider.setVisibility(View.VISIBLE);
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
index a9ee3f9e..1221fff8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
@@ -70,13 +70,15 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
private int mColorAccent;
private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime;
+ private boolean mShowCommentDivider;
private NetworkState networkState;
private RetryLoadingMoreCallback mRetryLoadingMoreCallback;
public CommentsListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit,
String accessToken, String accountName,
- boolean voteButtonsOnTheRight,
- boolean showElapsedTime, RetryLoadingMoreCallback retryLoadingMoreCallback) {
+ boolean voteButtonsOnTheRight, boolean showElapsedTime,
+ boolean showCommentDivider,
+ RetryLoadingMoreCallback retryLoadingMoreCallback) {
super(DIFF_CALLBACK);
mContext = context;
mOauthRetrofit = oauthRetrofit;
@@ -109,6 +111,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
mAccountName = accountName;
mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime;
+ mShowCommentDivider = showCommentDivider;
mRetryLoadingMoreCallback = retryLoadingMoreCallback;
mTextColorPrimaryDark = mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme);
mColorAccent = mContext.getResources().getColor(R.color.colorAccent);
@@ -429,6 +432,8 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
ImageView expandButton;
@BindView(R.id.reply_button_item_post_comment)
ImageView replyButton;
+ @BindView(R.id.divider_item_comment)
+ View commentDivider;
DataViewHolder(View itemView) {
super(itemView);
@@ -452,6 +457,10 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
constraintSet.setHorizontalBias(moreButton.getId(), 0);
constraintSet.applyTo(bottomConstraintLayout);
}
+
+ if (mShowCommentDivider) {
+ commentDivider.setVisibility(View.VISIBLE);
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
index aa5edb94..11a80379 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
@@ -87,6 +87,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private Activity mActivity;
private CommentsListingRecyclerViewAdapter mAdapter;
private boolean mShowElapsedTime;
+ private boolean mShowCommentDivider;
public CommentsListingFragment() {
// Required empty public constructor
@@ -116,6 +117,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
}
mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
+ mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
if (savedInstanceState == null) {
getCurrentAccountAndBindView(resources);
@@ -150,7 +152,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit,
getArguments().getString(EXTRA_ACCESS_TOKEN), getArguments().getString(EXTRA_ACCOUNT_NAME),
- voteButtonsOnTheRight, mShowElapsedTime, () -> mCommentViewModel.retryLoadingMore());
+ voteButtonsOnTheRight, mShowElapsedTime, mShowCommentDivider, () -> mCommentViewModel.retryLoadingMore());
String username = getArguments().getString(EXTRA_USERNAME);
String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value);
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 3ce67392..4123f276 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,14 @@
package ml.docilealligator.infinityforreddit.Settings;
+import android.app.Activity;
+import android.content.Context;
+import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatDelegate;
import androidx.fragment.app.Fragment;
import androidx.preference.ListPreference;
import androidx.preference.PreferenceFragmentCompat;
@@ -19,15 +24,24 @@ import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPref
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
+import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
+
/**
* A simple {@link Fragment} subclass.
*/
public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
+ private Activity activity;
+
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.interface_preference, rootKey);
+ ListPreference themePreference = findPreference(SharedPreferencesUtils.THEME_KEY);
+ SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY);
SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY);
SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY);
SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY);
@@ -35,6 +49,45 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY);
SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT);
+ boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
+
+ if (themePreference != null) {
+ if (systemDefault) {
+ themePreference.setEntries(R.array.settings_theme_q);
+ } else {
+ themePreference.setEntries(R.array.settings_theme);
+ }
+
+ themePreference.setOnPreferenceChangeListener((preference, newValue) -> {
+ int option = Integer.parseInt((String) newValue);
+ switch (option) {
+ case 0:
+ AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
+ break;
+ case 1:
+ AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
+ break;
+ case 2:
+ if (systemDefault) {
+ AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
+ } else {
+ AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY);
+ }
+ }
+ return true;
+ });
+ }
+
+ if (amoledDarkSwitch != null) {
+ amoledDarkSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
+ if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_NO) {
+ EventBus.getDefault().post(new RecreateActivityEvent());
+ activity.recreate();
+ }
+ return true;
+ });
+ }
+
if (immersiveInterfaceSwitch != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
immersiveInterfaceSwitch.setVisible(true);
@@ -82,4 +135,10 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
});
}
}
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ activity = (Activity) context;
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java
index 58bd8cf1..5733c32e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java
@@ -4,13 +4,9 @@ package ml.docilealligator.infinityforreddit.Settings;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
-import android.content.res.Configuration;
-import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatDelegate;
-import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
@@ -27,11 +23,6 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
-import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
-
/**
* A simple {@link PreferenceFragmentCompat} subclass.
*/
@@ -46,22 +37,10 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
setPreferencesFromResource(R.xml.main_preferences, rootKey);
((Infinity) activity.getApplication()).getAppComponent().inject(this);
- SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY);
SwitchPreference confirmToExitSwitch = findPreference(SharedPreferencesUtils.CONFIRM_TO_EXIT);
SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY);
SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_KEY);
- ListPreference themePreference = findPreference(SharedPreferencesUtils.THEME_KEY);
-
- if (amoledDarkSwitch != null) {
- amoledDarkSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
- if ((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_NO) {
- EventBus.getDefault().post(new RecreateActivityEvent());
- activity.recreate();
- }
- return true;
- });
- }
if (confirmToExitSwitch != null) {
confirmToExitSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@@ -104,35 +83,6 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
return true;
});
}
-
- boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
-
- if (themePreference != null) {
- if (systemDefault) {
- themePreference.setEntries(R.array.settings_theme_q);
- } else {
- themePreference.setEntries(R.array.settings_theme);
- }
-
- themePreference.setOnPreferenceChangeListener((preference, newValue) -> {
- int option = Integer.parseInt((String) newValue);
- switch (option) {
- case 0:
- AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO);
- break;
- case 1:
- AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES);
- break;
- case 2:
- if (systemDefault) {
- AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_FOLLOW_SYSTEM);
- } else {
- AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_AUTO_BATTERY);
- }
- }
- return true;
- });
- }
}
@Override
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 3717a6cd..357ee2a5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -74,4 +74,5 @@ public class SharedPreferencesUtils {
public static final String SHOW_TOP_LEVEL_COMMENTS_FIRST = "show_top_level_comments_first";
public static final String CONFIRM_TO_EXIT = "confirm_to_exit";
public static final String LOCK_BOTTOM_APP_BAR = "lock_bottom_app_bar";
+ public static final String SHOW_COMMENT_DIVIDER = "show_comment_divider";
}