From 129b9e7056d2e1c4b8e101967f0dffa04a66e4de Mon Sep 17 00:00:00 2001 From: HuanChengFly <609486518@qq.com> Date: Sat, 14 Nov 2020 15:48:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=80=8F=E6=98=8E?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/interfaces/BackgroundTintable.kt | 7 +++++++ .../huanchengfly/tieba/post/utils/ThemeUtil.java | 6 +++++- .../post/widgets/theme/TintConstraintLayout.java | 7 +++++-- .../widgets/theme/TintCoordinatorLayout.java | 16 ++++++++++++++-- .../post/widgets/theme/TintFrameLayout.java | 16 ++++++++++++++-- .../post/widgets/theme/TintLinearLayout.java | 16 ++++++++++++++-- .../post/widgets/theme/TintRelativeLayout.java | 14 +++++++++++++- 7 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/com/huanchengfly/tieba/post/interfaces/BackgroundTintable.kt diff --git a/app/src/main/java/com/huanchengfly/tieba/post/interfaces/BackgroundTintable.kt b/app/src/main/java/com/huanchengfly/tieba/post/interfaces/BackgroundTintable.kt new file mode 100644 index 00000000..7ed44b36 --- /dev/null +++ b/app/src/main/java/com/huanchengfly/tieba/post/interfaces/BackgroundTintable.kt @@ -0,0 +1,7 @@ +package com.huanchengfly.tieba.post.interfaces + +interface BackgroundTintable { + fun setBackgroundTintResId(resId: Int) + + fun getBackgroundTintResId(): Int +} \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/ThemeUtil.java b/app/src/main/java/com/huanchengfly/tieba/post/utils/ThemeUtil.java index e9d2a9f5..1411d2f0 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/ThemeUtil.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/ThemeUtil.java @@ -32,6 +32,7 @@ import com.google.android.material.appbar.AppBarLayout; import com.huanchengfly.tieba.post.BaseApplication; import com.huanchengfly.tieba.post.R; import com.huanchengfly.tieba.post.activities.BaseActivity; +import com.huanchengfly.tieba.post.interfaces.BackgroundTintable; import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils; import com.huanchengfly.tieba.post.widgets.theme.TintSwipeRefreshLayout; import com.scwang.smart.refresh.header.MaterialHeader; @@ -281,6 +282,9 @@ public class ThemeUtil { } } view.setBackgroundTintList(null); + if (view instanceof BackgroundTintable) { + ((BackgroundTintable) view).setBackgroundTintResId(0); + } String backgroundFilePath = SharedPreferencesUtil.get(BaseApplication.getInstance(), SharedPreferencesUtil.SP_SETTINGS) .getString(SP_TRANSLUCENT_THEME_BACKGROUND_PATH, null); if (backgroundFilePath == null) { @@ -329,7 +333,7 @@ public class ThemeUtil { } public static void setTranslucentThemeBackground(View view) { - setTranslucentThemeBackground(view, true, true); + setTranslucentThemeBackground(view, true, false); } @StyleRes diff --git a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintConstraintLayout.java b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintConstraintLayout.java index da91cb4d..123dcab3 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintConstraintLayout.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintConstraintLayout.java @@ -10,12 +10,13 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; +import com.huanchengfly.tieba.post.R; +import com.huanchengfly.tieba.post.interfaces.BackgroundTintable; import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable; import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils; -import com.huanchengfly.tieba.post.R; @SuppressLint("CustomViewStyleable") -public class TintConstraintLayout extends ConstraintLayout implements Tintable { +public class TintConstraintLayout extends ConstraintLayout implements Tintable, BackgroundTintable { private int mBackgroundTintResId; public TintConstraintLayout(@NonNull Context context) { @@ -57,10 +58,12 @@ public class TintConstraintLayout extends ConstraintLayout implements Tintable { } } + @Override public int getBackgroundTintResId() { return mBackgroundTintResId; } + @Override public void setBackgroundTintResId(int backgroundTintResId) { mBackgroundTintResId = backgroundTintResId; tint(); diff --git a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintCoordinatorLayout.java b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintCoordinatorLayout.java index c8161b50..caaf46d8 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintCoordinatorLayout.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintCoordinatorLayout.java @@ -10,12 +10,13 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.coordinatorlayout.widget.CoordinatorLayout; +import com.huanchengfly.tieba.post.R; +import com.huanchengfly.tieba.post.interfaces.BackgroundTintable; import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable; import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils; -import com.huanchengfly.tieba.post.R; @SuppressLint("CustomViewStyleable") -public class TintCoordinatorLayout extends CoordinatorLayout implements Tintable { +public class TintCoordinatorLayout extends CoordinatorLayout implements Tintable, BackgroundTintable { private int mBackgroundTintResId; public TintCoordinatorLayout(@NonNull Context context) { @@ -56,4 +57,15 @@ public class TintCoordinatorLayout extends CoordinatorLayout implements Tintable } } } + + @Override + public void setBackgroundTintResId(int resId) { + mBackgroundTintResId = resId; + tint(); + } + + @Override + public int getBackgroundTintResId() { + return mBackgroundTintResId; + } } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintFrameLayout.java b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintFrameLayout.java index f41356c7..342ff8ee 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintFrameLayout.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintFrameLayout.java @@ -10,12 +10,13 @@ import android.widget.FrameLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.huanchengfly.tieba.post.R; +import com.huanchengfly.tieba.post.interfaces.BackgroundTintable; import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable; import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils; -import com.huanchengfly.tieba.post.R; @SuppressLint("CustomViewStyleable") -public class TintFrameLayout extends FrameLayout implements Tintable { +public class TintFrameLayout extends FrameLayout implements Tintable, BackgroundTintable { private int mBackgroundTintResId; public TintFrameLayout(@NonNull Context context) { @@ -56,4 +57,15 @@ public class TintFrameLayout extends FrameLayout implements Tintable { } } } + + @Override + public void setBackgroundTintResId(int resId) { + mBackgroundTintResId = resId; + tint(); + } + + @Override + public int getBackgroundTintResId() { + return mBackgroundTintResId; + } } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintLinearLayout.java b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintLinearLayout.java index 5b019435..509e0371 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintLinearLayout.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintLinearLayout.java @@ -10,12 +10,13 @@ import android.widget.LinearLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.huanchengfly.tieba.post.R; +import com.huanchengfly.tieba.post.interfaces.BackgroundTintable; import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable; import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils; -import com.huanchengfly.tieba.post.R; @SuppressLint("CustomViewStyleable") -public class TintLinearLayout extends LinearLayout implements Tintable { +public class TintLinearLayout extends LinearLayout implements Tintable, BackgroundTintable { private int mBackgroundTintResId; public TintLinearLayout(@NonNull Context context) { @@ -56,4 +57,15 @@ public class TintLinearLayout extends LinearLayout implements Tintable { } } } + + @Override + public void setBackgroundTintResId(int resId) { + mBackgroundTintResId = resId; + tint(); + } + + @Override + public int getBackgroundTintResId() { + return mBackgroundTintResId; + } } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintRelativeLayout.java b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintRelativeLayout.java index 4f325bb2..17b8af03 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintRelativeLayout.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintRelativeLayout.java @@ -12,11 +12,12 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.huanchengfly.tieba.post.R; +import com.huanchengfly.tieba.post.interfaces.BackgroundTintable; import com.huanchengfly.tieba.post.ui.theme.interfaces.Tintable; import com.huanchengfly.tieba.post.ui.theme.utils.ThemeUtils; @SuppressLint("CustomViewStyleable") -public class TintRelativeLayout extends RelativeLayout implements Tintable { +public class TintRelativeLayout extends RelativeLayout implements Tintable, BackgroundTintable { private int mBackgroundTintResId; public TintRelativeLayout(@NonNull Context context) { @@ -63,4 +64,15 @@ public class TintRelativeLayout extends RelativeLayout implements Tintable { super.setBackground(background); applyTintColor(); } + + @Override + public void setBackgroundTintResId(int resId) { + mBackgroundTintResId = resId; + tint(); + } + + @Override + public int getBackgroundTintResId() { + return mBackgroundTintResId; + } }