From 6f72e2b373b58619477e2001c76a412e5ea05b3a Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Sun, 7 Aug 2022 17:21:51 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E4=BC=98=E5=8C=96=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/activities/AppThemeActivity.kt | 22 ++++++++++++++++++- .../activities/TranslucentThemeActivity.kt | 4 ++-- .../post/adapters/ChatBubbleStyleAdapter.kt | 14 ++++++++---- .../tieba/post/utils/AppPreferencesUtils.kt | 1 + .../tieba/post/widgets/theme/TintSwitch.java | 5 +++++ app/src/main/res/layout/item_chat_bubble.xml | 3 +-- .../layout_bubble_toolbar_primary_color.xml | 17 ++++++++++++++ app/src/main/res/values/attrs.xml | 1 + 8 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 app/src/main/res/layout/layout_bubble_toolbar_primary_color.xml diff --git a/app/src/main/java/com/huanchengfly/tieba/post/activities/AppThemeActivity.kt b/app/src/main/java/com/huanchengfly/tieba/post/activities/AppThemeActivity.kt index 69f6a319..a9f544e3 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/activities/AppThemeActivity.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/activities/AppThemeActivity.kt @@ -2,6 +2,7 @@ package com.huanchengfly.tieba.post.activities import android.os.Build import android.os.Bundle +import android.view.LayoutInflater import android.view.View import android.widget.ImageView import androidx.appcompat.widget.Toolbar @@ -23,10 +24,12 @@ import com.huanchengfly.tieba.post.components.dividers.HorizontalSpacesDecoratio import com.huanchengfly.tieba.post.ui.common.animation.addMaskAnimation import com.huanchengfly.tieba.post.ui.common.animation.addZoomAnimation import com.huanchengfly.tieba.post.ui.common.animation.buildPressAnimator +import com.huanchengfly.tieba.post.ui.common.theme.utils.ThemeUtils import com.huanchengfly.tieba.post.utils.DialogUtil import com.huanchengfly.tieba.post.utils.ThemeUtil import com.huanchengfly.tieba.post.utils.ThemeUtil.THEME_CUSTOM import com.huanchengfly.tieba.post.utils.ThemeUtil.THEME_TRANSLUCENT +import com.huanchengfly.tieba.post.widgets.theme.TintSwitch import java.io.File class AppThemeActivity : BaseActivity() { @@ -138,7 +141,24 @@ class AppThemeActivity : BaseActivity() { getString(R.string.bubble_want_colored_toolbar), POSITION_RIGHT ), - ChatBubbleStyleAdapter.Bubble(getString(R.string.bubble_not_completed)) + ChatBubbleStyleAdapter.Bubble { context, _, parent -> + val view = LayoutInflater.from(context) + .inflate(R.layout.layout_bubble_toolbar_primary_color, parent, false) + view.findViewById(R.id.theme_toolbar_primary_color).apply { + setOnCheckedChangeListener(null) + isChecked = appPreferences.toolbarPrimaryColor + setOnCheckedChangeListener { _, isChecked -> + appPreferences.toolbarPrimaryColor = isChecked + postDelayed({ + ThemeUtils.refreshUI( + this@AppThemeActivity, + this@AppThemeActivity + ) + }, 10) + } + } + view + } ) ) } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/activities/TranslucentThemeActivity.kt b/app/src/main/java/com/huanchengfly/tieba/post/activities/TranslucentThemeActivity.kt index 80f3e814..d47d4b9f 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/activities/TranslucentThemeActivity.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/activities/TranslucentThemeActivity.kt @@ -295,7 +295,7 @@ class TranslucentThemeActivity : BaseActivity(), View.OnClickListener, OnSeekBar mTranslucentThemeColorAdapter.onItemClickListener = OnItemClickListener { _: View?, themeColor: Int, _: Int, _: Int -> appPreferences.translucentPrimaryColor = toString(themeColor) - maskView.post { ThemeUtils.refreshUI(this) } + maskView.post { ThemeUtils.refreshUI(this, this) } } (findViewById(R.id.select_color_recycler_view)).apply { addItemDecoration(HorizontalSpacesDecoration(0, 0, 12.dpToPx(), 12.dpToPx(), false)) @@ -360,7 +360,7 @@ class TranslucentThemeActivity : BaseActivity(), View.OnClickListener, OnSeekBar override fun onColorSelected(dialogId: Int, color: Int) { appPreferences.translucentPrimaryColor = toString(color) - ThemeUtils.refreshUI(this) + ThemeUtils.refreshUI(this, this) } override fun onDialogDismissed(dialogId: Int) {} diff --git a/app/src/main/java/com/huanchengfly/tieba/post/adapters/ChatBubbleStyleAdapter.kt b/app/src/main/java/com/huanchengfly/tieba/post/adapters/ChatBubbleStyleAdapter.kt index f9d6c529..87d26af4 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/adapters/ChatBubbleStyleAdapter.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/adapters/ChatBubbleStyleAdapter.kt @@ -5,6 +5,7 @@ import android.content.Context import android.util.TypedValue import android.view.Gravity import android.view.View +import android.view.ViewGroup import android.view.ViewGroup.LayoutParams.WRAP_CONTENT import android.widget.FrameLayout import com.huanchengfly.tieba.post.R @@ -55,17 +56,22 @@ class ChatBubbleStyleAdapter( } } viewHolder.setText(R.id.chat_bubble_text, item.text) - val customView = item.customViewBuilder?.invoke(context, item.position) + viewHolder.setVisibility(R.id.chat_bubble_text, item.text != null) + val customViewParent = viewHolder.getView(R.id.chat_bubble_custom_view) + val customView = item.customViewBuilder?.invoke(context, item.position, customViewParent) if (customView != null) { - viewHolder.getView(R.id.chat_bubble_custom_view) + customViewParent .addView(customView, FrameLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)) + customViewParent.visibility = View.VISIBLE + } else { + customViewParent.visibility = View.GONE } } data class Bubble( - val text: CharSequence, + val text: CharSequence? = null, val position: Int = POSITION_LEFT, - val customViewBuilder: ((context: Context, position: Int) -> View)? = null + val customViewBuilder: ((context: Context, position: Int, parent: ViewGroup) -> View)? = null ) { companion object { const val POSITION_LEFT = 0 diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt index a38d5646..cc2a9dd2 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt @@ -253,6 +253,7 @@ open class AppPreferencesUtils(context: Context) { ) { state = value MainScope().launch(Dispatchers.IO) { + state = value thisRef.preferencesDataStore.edit { it[booleanPreferencesKey(key ?: property.name)] = value } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintSwitch.java b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintSwitch.java index 8fce876d..5e4fe516 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintSwitch.java +++ b/app/src/main/java/com/huanchengfly/tieba/post/widgets/theme/TintSwitch.java @@ -16,6 +16,7 @@ public class TintSwitch extends SwitchCompat implements Tintable { private int mBackgroundTintResId; private int mThumbTintResId; private int mTrackTintListResId; + private int mTextColorResId; public TintSwitch(Context context) { this(context, null); @@ -41,6 +42,7 @@ public class TintSwitch extends SwitchCompat implements Tintable { mBackgroundTintResId = array.getResourceId(R.styleable.TintSwitch_switchBackgroundTint, R.color.transparent); mThumbTintResId = array.getResourceId(R.styleable.TintSwitch_thumbTint, R.color.white); mTrackTintListResId = array.getResourceId(R.styleable.TintSwitch_trackTintList, R.color.selector_switch_track); + mTextColorResId = array.getResourceId(R.styleable.TintSwitch_textColor, 0); array.recycle(); applyTintColor(); } @@ -54,6 +56,9 @@ public class TintSwitch extends SwitchCompat implements Tintable { } setThumbTintList(ColorStateList.valueOf(ThemeUtils.getColorById(getContext(), mThumbTintResId))); setTrackTintList(ColorStateListUtils.createColorStateList(getContext(), mTrackTintListResId)); + if (mTextColorResId != 0) { + setTextColor(ColorStateListUtils.createColorStateList(getContext(), mTextColorResId)); + } } private void fixColor() { diff --git a/app/src/main/res/layout/item_chat_bubble.xml b/app/src/main/res/layout/item_chat_bubble.xml index 1fdcd0ff..62a3fbc9 100644 --- a/app/src/main/res/layout/item_chat_bubble.xml +++ b/app/src/main/res/layout/item_chat_bubble.xml @@ -11,6 +11,7 @@ android:layout_height="wrap_content" android:background="@drawable/bg_radius_10dp" android:orientation="vertical" + android:padding="16dp" app:backgroundTint="@color/default_color_card"> diff --git a/app/src/main/res/layout/layout_bubble_toolbar_primary_color.xml b/app/src/main/res/layout/layout_bubble_toolbar_primary_color.xml new file mode 100644 index 00000000..110a7c72 --- /dev/null +++ b/app/src/main/res/layout/layout_bubble_toolbar_primary_color.xml @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 841afb7d..b04e9ca9 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -112,6 +112,7 @@ +