diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-04-10 14:13:29 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-04-10 14:13:29 +0000 |
commit | 16014a8807dd22bb64d583d97ef6e315c9e56d5b (patch) | |
tree | 77192466092384b1f417ad5e3bcf4c149b140f28 /app/src/main/java/ml/docilealligator | |
parent | ad78aebf679af89f54ae537186f89907851ff963 (diff) | |
download | infinity-for-reddit-16014a8807dd22bb64d583d97ef6e315c9e56d5b.tar infinity-for-reddit-16014a8807dd22bb64d583d97ef6e315c9e56d5b.tar.gz infinity-for-reddit-16014a8807dd22bb64d583d97ef6e315c9e56d5b.tar.bz2 infinity-for-reddit-16014a8807dd22bb64d583d97ef6e315c9e56d5b.tar.lz infinity-for-reddit-16014a8807dd22bb64d583d97ef6e315c9e56d5b.tar.xz infinity-for-reddit-16014a8807dd22bb64d583d97ef6e315c9e56d5b.tar.zst infinity-for-reddit-16014a8807dd22bb64d583d97ef6e315c9e56d5b.zip |
Fix CommentIndentationView losing state.
Diffstat (limited to '')
3 files changed, 71 insertions, 15 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java index 306b607a..f463ed31 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java @@ -238,7 +238,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy private int mCommentIconAndInfoColor; private int mFullyCollapsedCommentBackgroundColor; private int mAwardedCommentBackgroundColor; - private int[] verticalBlockColors; + private Integer[] verticalBlockColors; private Drawable mCommentIcon; private float mScale; @@ -572,7 +572,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy mFullyCollapsedCommentBackgroundColor = customThemeWrapper.getFullyCollapsedCommentBackgroundColor(); mAwardedCommentBackgroundColor = customThemeWrapper.getAwardedCommentBackgroundColor(); - verticalBlockColors = new int[] { + verticalBlockColors = new Integer[] { customThemeWrapper.getCommentVerticalBarColor1(), customThemeWrapper.getCommentVerticalBarColor2(), customThemeWrapper.getCommentVerticalBarColor3(), @@ -1896,9 +1896,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy ((CommentViewHolder) holder).downvoteButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); ((CommentViewHolder) holder).replyButton.setColorFilter(mCommentIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); ((CommentViewHolder) holder).itemView.setBackgroundColor(mCommentBackgroundColor); - } else if (holder instanceof CommentFullyCollapsedViewHolder) { - } else if (holder instanceof LoadMoreChildCommentsViewHolder) { - } else if (holder instanceof PostDetailBaseViewHolder) { + } else if (holder instanceof PostDetailBaseViewHolder) { ((PostDetailBaseViewHolder) holder).mUpvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); ((PostDetailBaseViewHolder) holder).mScoreTextView.setTextColor(mPostIconAndInfoColor); ((PostDetailBaseViewHolder) holder).mDownvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomThemeWrapper.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomThemeWrapper.java index 84c8f326..f5e9c6bd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomThemeWrapper.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomThemeWrapper.java @@ -357,37 +357,37 @@ public class CustomThemeWrapper { getDefaultColor("#F0F0F0", "#3C3C3C", "#3C3C3C")); } - public int getCommentVerticalBarColor1() { + public Integer getCommentVerticalBarColor1() { return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_1, getDefaultColor("#1565C0", "#1565C0", "#1565C0")); } - public int getCommentVerticalBarColor2() { + public Integer getCommentVerticalBarColor2() { return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_2, getDefaultColor("#EE02BE", "#C300B3", "#C300B3")); } - public int getCommentVerticalBarColor3() { + public Integer getCommentVerticalBarColor3() { return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_3, getDefaultColor("#02DFEE", "#00B8DA", "#00B8DA")); } - public int getCommentVerticalBarColor4() { + public Integer getCommentVerticalBarColor4() { return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_4, getDefaultColor("#EED502", "#EDCA00", "#EDCA00")); } - public int getCommentVerticalBarColor5() { + public Integer getCommentVerticalBarColor5() { return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_5, getDefaultColor("#EE0220", "#EE0219", "#EE0219")); } - public int getCommentVerticalBarColor6() { + public Integer getCommentVerticalBarColor6() { return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_6, getDefaultColor("#02EE6E", "#00B925", "#00B925")); } - public int getCommentVerticalBarColor7() { + public Integer getCommentVerticalBarColor7() { return getThemeSharedPreferences().getInt(CustomThemeSharedPreferencesUtils.COMMENT_VERTICAL_BAR_COLOR_7, getDefaultColor("#EE4602", "#EE4602", "#EE4602")); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CommentIndentationView.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CommentIndentationView.java index 9d504b34..07697075 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CommentIndentationView.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customviews/CommentIndentationView.java @@ -3,6 +3,8 @@ package ml.docilealligator.infinityforreddit.customviews; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; +import android.os.Parcel; +import android.os.Parcelable; import android.util.AttributeSet; import android.widget.LinearLayout; @@ -16,13 +18,14 @@ public class CommentIndentationView extends LinearLayout { private final Paint paint; private int level; - private int[] colors; + private Integer[] colors; private ArrayList<Integer> startXs; private final int spacing; private final int pathWidth; public CommentIndentationView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); + setSaveEnabled(true); setWillNotDraw(false); paint = new Paint(Paint.ANTI_ALIAS_FLAG); pathWidth = (int) Utils.convertDpToPixel(2, context); @@ -36,6 +39,7 @@ public class CommentIndentationView extends LinearLayout { protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); + startXs.clear(); for (int i = 0; i < level; i++) { startXs.add(spacing * (i + 1) + pathWidth); } @@ -49,13 +53,67 @@ public class CommentIndentationView extends LinearLayout { paint.setColor(colors[i % 7]); canvas.drawLine(startXs.get(i), 0, startXs.get(i), getHeight(), paint); } - startXs.clear(); } - public void setLevelAndColors(int level, int[] colors) { + @Nullable + @Override + protected Parcelable onSaveInstanceState() { + Parcelable parcelable = super.onSaveInstanceState(); + SavedState myState = new SavedState(parcelable); + myState.startXs = this.startXs; + myState.colors = this.colors; + return parcelable; + } + + @Override + protected void onRestoreInstanceState(Parcelable state) { + SavedState savedState = (SavedState) state; + + super.onRestoreInstanceState(savedState.getSuperState()); + + this.startXs = savedState.startXs; + this.colors = savedState.colors; + + invalidate(); + } + + public void setLevelAndColors(int level, Integer[] colors) { this.colors = colors; this.level = level; int indentationSpacing = (level * spacing + pathWidth); setPaddingRelative(indentationSpacing, 0, pathWidth, 0); + invalidate(); + } + + private static class SavedState extends BaseSavedState { + ArrayList<Integer> startXs; + Integer[] colors; + + SavedState(Parcelable superState) { + super(superState); + } + + private SavedState(Parcel in) { + super(in); + startXs = in.readArrayList(SavedState.class.getClassLoader()); + colors = (Integer[]) in.readArray(SavedState.class.getClassLoader()); + } + + @Override + public void writeToParcel(Parcel out, int flags) { + super.writeToParcel(out, flags); + out.writeList(startXs); + out.writeArray(colors); + } + + public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.Creator<SavedState>() { + public SavedState createFromParcel(Parcel in) { + return new SavedState(in); + } + + public SavedState[] newArray(int size) { + return new SavedState[size]; + } + }; } } |