From 47832e1e91db7e355b8122e1b533966c8df5ddba Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 27 Sep 2019 16:58:57 +0800 Subject: Blurring spoiler post images is now available. Change spoiler and flair text background colors. Fixed collapsed comments shown after orientation change. --- .../main/java/Settings/MainPreferenceFragment.java | 9 +++++++ .../infinityforreddit/ChangeSpoilerBlurEvent.java | 8 ++++++ .../CommentAndPostRecyclerViewAdapter.java | 27 ++++++++++++------- .../infinityforreddit/PostFragment.java | 22 +++++++++++++--- .../infinityforreddit/PostRecyclerViewAdapter.java | 14 +++++++--- .../infinityforreddit/SharedPreferencesUtils.java | 1 + .../infinityforreddit/ViewPostDetailActivity.java | 30 ++++++++++++++++------ 7 files changed, 86 insertions(+), 25 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/ChangeSpoilerBlurEvent.java (limited to 'app/src/main/java') diff --git a/app/src/main/java/Settings/MainPreferenceFragment.java b/app/src/main/java/Settings/MainPreferenceFragment.java index af498294..8e3b7d99 100644 --- a/app/src/main/java/Settings/MainPreferenceFragment.java +++ b/app/src/main/java/Settings/MainPreferenceFragment.java @@ -17,6 +17,7 @@ import javax.inject.Inject; import ml.docilealligator.infinityforreddit.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.ChangeNSFWEvent; +import ml.docilealligator.infinityforreddit.ChangeSpoilerBlurEvent; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SharedPreferencesUtils; @@ -44,6 +45,7 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { 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(nsfwSwitch != null) { @@ -71,6 +73,13 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { }); } + if(blurSpoilerSwitch != null) { + blurSpoilerSwitch.setOnPreferenceChangeListener((preference, newValue) -> { + EventBus.getDefault().post(new ChangeSpoilerBlurEvent((Boolean) newValue)); + return true; + }); + } + boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; if(themePreference != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ChangeSpoilerBlurEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ChangeSpoilerBlurEvent.java new file mode 100644 index 00000000..f8c22224 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ChangeSpoilerBlurEvent.java @@ -0,0 +1,8 @@ +package ml.docilealligator.infinityforreddit; + +public class ChangeSpoilerBlurEvent { + public boolean needBlurSpoiler; + public ChangeSpoilerBlurEvent(boolean needBlurSpoiler) { + this.needBlurSpoiler = needBlurSpoiler; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index f2fb4545..897b2e86 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -52,6 +52,8 @@ import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import retrofit2.Retrofit; +import static ml.docilealligator.infinityforreddit.CommentActivity.WRITE_COMMENT_REQUEST_CODE; + class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { private static final int VIEW_TYPE_POST_DETAIL = 0; private static final int VIEW_TYPE_FIRST_LOADING = 1; @@ -78,6 +80,7 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter getVisibleComments() { + return mVisibleComments; + } + void initiallyLoading() { if(mVisibleComments.size() != 0) { int previousSize = mVisibleComments.size(); @@ -1162,6 +1167,10 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter= 0) { + mAdapter.addChildComment(comment, parentFullname, parentPosition); + } } } else { Toast.makeText(this, R.string.send_comment_failed, Toast.LENGTH_SHORT).show(); @@ -1219,7 +1232,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo } } else if(requestCode == EDIT_COMMENT_REQUEST_CODE) { if(resultCode == RESULT_OK) { - mAdapter.editComment(data.getExtras().getString(EditCommentActivity.EXTRA_EDITED_COMMENT_CONTENT), + mAdapter.editComment(data.getStringExtra(EditCommentActivity.EXTRA_EDITED_COMMENT_CONTENT), data.getExtras().getInt(EditCommentActivity.EXTRA_EDITED_COMMENT_POSITION)); } } @@ -1228,6 +1241,7 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); + comments = mAdapter.getVisibleComments(); Bridge.saveInstanceState(this, outState); } -- cgit v1.2.3