pref: 优化主题
This commit is contained in:
parent
26733cf6c3
commit
6f72e2b373
|
|
@ -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<TintSwitch>(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
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<RecyclerView>(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) {}
|
||||
|
|
|
|||
|
|
@ -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<FrameLayout>(R.id.chat_bubble_custom_view)
|
||||
val customView = item.customViewBuilder?.invoke(context, item.position, customViewParent)
|
||||
if (customView != null) {
|
||||
viewHolder.getView<FrameLayout>(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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintTextView
|
||||
|
|
@ -18,14 +19,12 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxWidth="250dp"
|
||||
android:padding="16dp"
|
||||
android:textSize="15sp" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/chat_bubble_custom_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</com.huanchengfly.tieba.post.widgets.theme.TintLinearLayout>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.huanchengfly.tieba.post.widgets.theme.TintSwitch
|
||||
android:id="@+id/theme_toolbar_primary_color"
|
||||
style="@style/Widget.Switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/tip_toolbar_primary_color"
|
||||
app:switchPadding="8dp"
|
||||
app:textColor="@color/default_color_text" />
|
||||
</LinearLayout>
|
||||
|
|
@ -112,6 +112,7 @@
|
|||
<attr name="switchBackgroundTint" format="color" />
|
||||
<attr name="thumbTint" format="color" />
|
||||
<attr name="trackTintList" format="color" />
|
||||
<attr name="textColor" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="TintMaterialCardView">
|
||||
|
|
|
|||
Loading…
Reference in New Issue