revert: "pref(AppPreferenceUtils): 单例"

This reverts commit 355650b17b.
This commit is contained in:
HuanCheng65 2023-07-17 15:44:49 +08:00
parent 355650b17b
commit 82d19358c7
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
27 changed files with 71 additions and 76 deletions

View File

@ -302,12 +302,12 @@ class App : Application(), IApp, SketchFactory {
when (attrId) { when (attrId) {
R.attr.colorPrimary -> { R.attr.colorPrimary -> {
if (ThemeUtil.THEME_CUSTOM == theme) { if (ThemeUtil.THEME_CUSTOM == theme) {
val customPrimaryColorStr = appPreferences.customPrimaryColor val customPrimaryColorStr = context.appPreferences.customPrimaryColor
return if (customPrimaryColorStr != null) { return if (customPrimaryColorStr != null) {
Color.parseColor(customPrimaryColorStr) Color.parseColor(customPrimaryColorStr)
} else getColorByAttr(context, attrId, ThemeUtil.THEME_BLUE) } else getColorByAttr(context, attrId, ThemeUtil.THEME_BLUE)
} else if (ThemeUtil.isTranslucentTheme(theme)) { } else if (ThemeUtil.isTranslucentTheme(theme)) {
val primaryColorStr = appPreferences.translucentPrimaryColor val primaryColorStr = context.appPreferences.translucentPrimaryColor
return if (primaryColorStr != null) { return if (primaryColorStr != null) {
Color.parseColor(primaryColorStr) Color.parseColor(primaryColorStr)
} else getColorByAttr(context, attrId, ThemeUtil.THEME_BLUE) } else getColorByAttr(context, attrId, ThemeUtil.THEME_BLUE)
@ -363,7 +363,7 @@ class App : Application(), IApp, SketchFactory {
) )
) )
} else { } else {
val isPrimaryColor = appPreferences.toolbarPrimaryColor val isPrimaryColor = context.appPreferences.toolbarPrimaryColor
if (isPrimaryColor) { if (isPrimaryColor) {
getColorByAttr(context, R.attr.colorPrimary, theme) getColorByAttr(context, R.attr.colorPrimary, theme)
} else { } else {

View File

@ -37,16 +37,8 @@ import com.huanchengfly.tieba.post.ui.common.theme.interfaces.ExtraRefreshable
import com.huanchengfly.tieba.post.ui.common.theme.utils.ThemeUtils import com.huanchengfly.tieba.post.ui.common.theme.utils.ThemeUtils
import com.huanchengfly.tieba.post.ui.widgets.VoicePlayerView import com.huanchengfly.tieba.post.ui.widgets.VoicePlayerView
import com.huanchengfly.tieba.post.ui.widgets.theme.TintToolbar import com.huanchengfly.tieba.post.ui.widgets.theme.TintToolbar
import com.huanchengfly.tieba.post.utils.AppPreferencesUtils import com.huanchengfly.tieba.post.utils.*
import com.huanchengfly.tieba.post.utils.DialogUtil import kotlinx.coroutines.*
import com.huanchengfly.tieba.post.utils.HandleBackUtil
import com.huanchengfly.tieba.post.utils.ThemeUtil
import com.huanchengfly.tieba.post.utils.calcStatusBarColorInt
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
abstract class BaseActivity : AppCompatActivity(), ExtraRefreshable, CoroutineScope { abstract class BaseActivity : AppCompatActivity(), ExtraRefreshable, CoroutineScope {
@ -62,7 +54,7 @@ abstract class BaseActivity : AppCompatActivity(), ExtraRefreshable, CoroutineSc
private var customStatusColor = -1 private var customStatusColor = -1
private var statusBarTinted = false private var statusBarTinted = false
val appPreferences: AppPreferencesUtils by lazy { AppPreferencesUtils } val appPreferences: AppPreferencesUtils by lazy { AppPreferencesUtils(this) }
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()

View File

@ -11,12 +11,7 @@ import com.huanchengfly.tieba.post.api.models.ForumRecommend
import com.huanchengfly.tieba.post.components.MyViewHolder import com.huanchengfly.tieba.post.components.MyViewHolder
import com.huanchengfly.tieba.post.dpToPx import com.huanchengfly.tieba.post.dpToPx
import com.huanchengfly.tieba.post.ui.common.theme.utils.ColorStateListUtils import com.huanchengfly.tieba.post.ui.common.theme.utils.ColorStateListUtils
import com.huanchengfly.tieba.post.utils.ImageUtil import com.huanchengfly.tieba.post.utils.*
import com.huanchengfly.tieba.post.utils.ThemeUtil
import com.huanchengfly.tieba.post.utils.Util
import com.huanchengfly.tieba.post.utils.appPreferences
import com.huanchengfly.tieba.post.utils.getRadiusDrawable
import com.huanchengfly.tieba.post.utils.wrapRipple
class MainForumListAdapter( class MainForumListAdapter(
context: Context, context: Context,
@ -62,7 +57,7 @@ class MainForumListAdapter(
getRadiusDrawable() getRadiusDrawable()
} }
) )
if (appPreferences.listItemsBackgroundIntermixed) { if (context.appPreferences.listItemsBackgroundIntermixed) {
if (position % 2 == 1) { if (position % 2 == 1) {
viewHolder.itemView.backgroundTintList = viewHolder.itemView.backgroundTintList =
ColorStateList.valueOf(Color.TRANSPARENT) ColorStateList.valueOf(Color.TRANSPARENT)

View File

@ -243,7 +243,7 @@ public class PersonalizedFeedAdapter extends BaseMultiTypeAdapter<PersonalizedBe
case TYPE_THREAD_MULTI_PIC: case TYPE_THREAD_MULTI_PIC:
GridLayout gridLayout = viewHolder.getView(R.id.forum_item_content_pics); GridLayout gridLayout = viewHolder.getView(R.id.forum_item_content_pics);
CardView cardView = viewHolder.getView(R.id.forum_item_content_pics_card); CardView cardView = viewHolder.getView(R.id.forum_item_content_pics_card);
cardView.setRadius(DisplayUtil.dp2px(getContext(), AppPreferencesUtilsKt.getAppPreferences().getRadius())); cardView.setRadius(DisplayUtil.dp2px(getContext(), AppPreferencesUtilsKt.getAppPreferences(getContext()).getRadius()));
MarkedImageView firstImageView = viewHolder.getView(R.id.forum_item_content_pic_1); MarkedImageView firstImageView = viewHolder.getView(R.id.forum_item_content_pic_1);
MarkedImageView secondImageView = viewHolder.getView(R.id.forum_item_content_pic_2); MarkedImageView secondImageView = viewHolder.getView(R.id.forum_item_content_pic_2);
MarkedImageView thirdImageView = viewHolder.getView(R.id.forum_item_content_pic_3); MarkedImageView thirdImageView = viewHolder.getView(R.id.forum_item_content_pic_3);

View File

@ -248,7 +248,7 @@ class ThreadMainPostAdapter(
val forumNameView = forumView.findViewById<TextView>(R.id.forum_bar_name) val forumNameView = forumView.findViewById<TextView>(R.id.forum_bar_name)
val forumAvatarView: ImageView = forumView.findViewById(R.id.forum_bar_avatar) val forumAvatarView: ImageView = forumView.findViewById(R.id.forum_bar_avatar)
if (!showForum || if (!showForum ||
!appPreferences.showShortcutInThread || !context.appPreferences.showShortcutInThread ||
"0" == forumInfoBean.isExists || "0" == forumInfoBean.isExists ||
forumInfoBean.name.isNullOrEmpty() forumInfoBean.name.isNullOrEmpty()
) { ) {

View File

@ -263,7 +263,7 @@ public class NewForumAdapter extends BaseMultiTypeDelegateAdapter<ForumPageBean.
cardView.setRadius( cardView.setRadius(
DisplayUtil.dp2px( DisplayUtil.dp2px(
getContext(), getContext(),
AppPreferencesUtilsKt.getAppPreferences().getRadius() AppPreferencesUtilsKt.getAppPreferences(getContext()).getRadius()
) )
); );
MarkedImageView firstImageView = viewHolder.getView(R.id.forum_item_content_pic_1); MarkedImageView firstImageView = viewHolder.getView(R.id.forum_item_content_pic_1);

View File

@ -43,8 +43,8 @@ class CustomThemeDialog(context: Context) : AlertDialog(context),
toolbarPrimaryColor = contentView.findViewById(R.id.custom_theme_toolbar_primary_color) toolbarPrimaryColor = contentView.findViewById(R.id.custom_theme_toolbar_primary_color)
setView(contentView) setView(contentView)
primaryColor = getColorByAttr(context, R.attr.colorPrimary, ThemeUtil.THEME_CUSTOM) primaryColor = getColorByAttr(context, R.attr.colorPrimary, ThemeUtil.THEME_CUSTOM)
statusBarFontDark = appPreferences.customStatusBarFontDark statusBarFontDark = context.appPreferences.customStatusBarFontDark
toolbarPrimary = appPreferences.toolbarPrimaryColor toolbarPrimary = context.appPreferences.toolbarPrimaryColor
refreshView() refreshView()
} }
@ -77,7 +77,7 @@ class CustomThemeDialog(context: Context) : AlertDialog(context),
@SuppressLint("ApplySharedPref") @SuppressLint("ApplySharedPref")
override fun onClick(dialog: DialogInterface, which: Int) { override fun onClick(dialog: DialogInterface, which: Int) {
appPreferences.apply { context.appPreferences.apply {
customPrimaryColor = toString(primaryColor) customPrimaryColor = toString(primaryColor)
customStatusBarFontDark = (statusBarFontDark || !toolbarPrimary) customStatusBarFontDark = (statusBarFontDark || !toolbarPrimary)
toolbarPrimaryColor = toolbarPrimary toolbarPrimaryColor = toolbarPrimary

View File

@ -67,7 +67,7 @@ abstract class BaseFragment : Fragment(), BackHandledInterface, CoroutineScope {
return mContext!! return mContext!!
} }
protected val appPreferences: AppPreferencesUtils protected val appPreferences: AppPreferencesUtils
get() = AppPreferencesUtils get() = AppPreferencesUtils(attachContext)
@TargetApi(23) @TargetApi(23)
override fun onAttach(context: Context) { override fun onAttach(context: Context) {

View File

@ -395,7 +395,7 @@ class MyInfoFragment : BaseFragment(), View.OnClickListener, CompoundButton.OnCh
refreshNightModeStatus() refreshNightModeStatus()
} }
.setNegativeButton(R.string.btn_close_following) { _, _ -> .setNegativeButton(R.string.btn_close_following) { _, _ ->
appPreferences.followSystemNight = false attachContext.appPreferences.followSystemNight = false
switchNightMode(isChecked) switchNightMode(isChecked)
} }
.show() .show()

View File

@ -55,7 +55,7 @@ class PreferencesFragment : PreferencesFragment() {
attachContext.resources.getStringArray(R.array.experimental_features) attachContext.resources.getStringArray(R.array.experimental_features)
experimentalFeatures.forEach { experimentalFeatures.forEach {
findPreference<Preference>(it)?.isVisible = findPreference<Preference>(it)?.isVisible =
appPreferences.showExperimentalFeatures attachContext.appPreferences.showExperimentalFeatures
} }
loginInfo = AccountUtil.getLoginInfo() loginInfo = AccountUtil.getLoginInfo()
val accounts = AccountUtil.allAccounts val accounts = AccountUtil.allAccounts

View File

@ -14,13 +14,13 @@ import java.util.Calendar
class BootCompleteSignReceiver : BroadcastReceiver() { class BootCompleteSignReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
if (Intent.ACTION_BOOT_COMPLETED == intent.action) { if (Intent.ACTION_BOOT_COMPLETED == intent.action) {
val autoSign = appPreferences.autoSign val autoSign = context.appPreferences.autoSign
if (autoSign) { if (autoSign) {
val autoSignTimeStr = appPreferences.autoSignTime val autoSignTimeStr = context.appPreferences.autoSignTime
if (Util.getTimeInMillis(autoSignTimeStr) > System.currentTimeMillis()) { if (Util.getTimeInMillis(autoSignTimeStr) > System.currentTimeMillis()) {
TiebaUtil.initAutoSign(context) TiebaUtil.initAutoSign(context)
} else { } else {
val signDay = appPreferences.signDay val signDay = context.appPreferences.signDay
if (signDay != Calendar.getInstance()[Calendar.DAY_OF_MONTH]) { if (signDay != Calendar.getInstance()[Calendar.DAY_OF_MONTH]) {
TiebaUtil.startSign(context) TiebaUtil.startSign(context)
} }

View File

@ -127,7 +127,7 @@ data class PicContentRender(
imageUri = picUrl, imageUri = picUrl,
contentDescription = null, contentDescription = null,
modifier = Modifier modifier = Modifier
.clip(RoundedCornerShape(appPreferences.radius.dp)) .clip(RoundedCornerShape(context.appPreferences.radius.dp))
.fillMaxWidth(widthFraction) .fillMaxWidth(widthFraction)
.aspectRatio(width * 1f / height), .aspectRatio(width * 1f / height),
photoViewData = photoViewData, photoViewData = photoViewData,
@ -166,7 +166,7 @@ data class VideoContentRender(
if (picUrl.isNotBlank()) { if (picUrl.isNotBlank()) {
val picModifier = Modifier val picModifier = Modifier
.clip(RoundedCornerShape(appPreferences.radius.dp)) .clip(RoundedCornerShape(context.appPreferences.radius.dp))
.fillMaxWidth(widthFraction) .fillMaxWidth(widthFraction)
.aspectRatio(width * 1f / height) .aspectRatio(width * 1f / height)

View File

@ -136,7 +136,7 @@ fun getSortType(
context: Context, context: Context,
forumName: String forumName: String
): Int { ): Int {
val defaultSortType = appPreferences.defaultSortType?.toIntOrNull() ?: 0 val defaultSortType = context.appPreferences.defaultSortType?.toIntOrNull() ?: 0
return context.dataStore.getInt("${forumName}_sort_type", defaultSortType) return context.dataStore.getInt("${forumName}_sort_type", defaultSortType)
} }
@ -766,7 +766,7 @@ fun ForumPage(
floatingActionButton = { floatingActionButton = {
FloatingActionButton( FloatingActionButton(
onClick = { onClick = {
when (appPreferences.forumFabFunction) { when (context.appPreferences.forumFabFunction) {
"refresh" -> { "refresh" -> {
coroutineScope.launch { coroutineScope.launch {
eventFlows[pagerState.currentPage].emit( eventFlows[pagerState.currentPage].emit(
@ -801,7 +801,7 @@ fun ForumPage(
modifier = Modifier.navigationBarsPadding() modifier = Modifier.navigationBarsPadding()
) { ) {
Icon( Icon(
imageVector = when (appPreferences.forumFabFunction) { imageVector = when (context.appPreferences.forumFabFunction) {
"refresh" -> Icons.Rounded.Refresh "refresh" -> Icons.Rounded.Refresh
"back_to_top" -> Icons.Rounded.VerticalAlignTop "back_to_top" -> Icons.Rounded.VerticalAlignTop
else -> Icons.Rounded.Add else -> Icons.Rounded.Add

View File

@ -1,6 +1,7 @@
package com.huanchengfly.tieba.post.ui.page.forum.threadlist package com.huanchengfly.tieba.post.ui.page.forum.threadlist
import androidx.compose.runtime.Stable import androidx.compose.runtime.Stable
import com.huanchengfly.tieba.post.App
import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.TiebaApi
import com.huanchengfly.tieba.post.api.models.AgreeBean import com.huanchengfly.tieba.post.api.models.AgreeBean
import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
@ -103,7 +104,7 @@ private class ForumThreadListPartialChangeProducer(val type: ForumThreadListType
val userList = response.data_.user_list val userList = response.data_.user_list
val threadList = response.data_.thread_list.map { threadInfo -> val threadList = response.data_.thread_list.map { threadInfo ->
threadInfo.copy(author = userList.find { it.id == threadInfo.authorId }) threadInfo.copy(author = userList.find { it.id == threadInfo.authorId })
}.filter { !appPreferences.blockVideo || it.videoInfo == null } }.filter { !App.INSTANCE.appPreferences.blockVideo || it.videoInfo == null }
ForumThreadListPartialChange.FirstLoad.Success( ForumThreadListPartialChange.FirstLoad.Success(
threadList.wrapImmutable(), threadList.wrapImmutable(),
response.data_.thread_id_list, response.data_.thread_id_list,

View File

@ -25,6 +25,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource import androidx.compose.ui.res.vectorResource
import com.huanchengfly.tieba.post.LocalDevicePosture import com.huanchengfly.tieba.post.LocalDevicePosture
@ -133,7 +134,7 @@ fun MainPage(
content = { content = {
HomePage( HomePage(
eventFlow = eventFlows[0], eventFlow = eventFlows[0],
canOpenExplore = !appPreferences.hideExplore canOpenExplore = !LocalContext.current.appPreferences.hideExplore
) { ) {
coroutineScope.launch { coroutineScope.launch {
pagerState.scrollToPage(1) pagerState.scrollToPage(1)
@ -141,7 +142,7 @@ fun MainPage(
} }
} }
), ),
if (appPreferences.hideExplore) null if (LocalContext.current.appPreferences.hideExplore) null
else NavigationItem( else NavigationItem(
id = "explore", id = "explore",
icon = { icon = {

View File

@ -1,6 +1,7 @@
package com.huanchengfly.tieba.post.ui.page.main.explore.concern package com.huanchengfly.tieba.post.ui.page.main.explore.concern
import androidx.compose.runtime.Stable import androidx.compose.runtime.Stable
import com.huanchengfly.tieba.post.App
import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.TiebaApi
import com.huanchengfly.tieba.post.api.models.AgreeBean import com.huanchengfly.tieba.post.api.models.AgreeBean
import com.huanchengfly.tieba.post.api.models.protos.userLike.ConcernData import com.huanchengfly.tieba.post.api.models.protos.userLike.ConcernData
@ -52,9 +53,9 @@ class ConcernViewModel @Inject constructor() :
) )
private fun produceRefreshPartialChange(): Flow<ConcernPartialChange.Refresh> = private fun produceRefreshPartialChange(): Flow<ConcernPartialChange.Refresh> =
TiebaApi.getInstance().userLikeFlow("", appPreferences.userLikeLastRequestUnix, 1) TiebaApi.getInstance().userLikeFlow("", App.INSTANCE.appPreferences.userLikeLastRequestUnix, 1)
.map<UserLikeResponse, ConcernPartialChange.Refresh> { .map<UserLikeResponse, ConcernPartialChange.Refresh> {
appPreferences.userLikeLastRequestUnix = it.data_?.requestUnix ?: 0L App.INSTANCE.appPreferences.userLikeLastRequestUnix = it.data_?.requestUnix ?: 0L
ConcernPartialChange.Refresh.Success( ConcernPartialChange.Refresh.Success(
data = it.toData(), data = it.toData(),
hasMore = it.data_?.hasMore == 1, hasMore = it.data_?.hasMore == 1,
@ -65,7 +66,7 @@ class ConcernViewModel @Inject constructor() :
.catch { emit(ConcernPartialChange.Refresh.Failure(it)) } .catch { emit(ConcernPartialChange.Refresh.Failure(it)) }
private fun ConcernUiIntent.LoadMore.producePartialChange(): Flow<ConcernPartialChange.LoadMore> = private fun ConcernUiIntent.LoadMore.producePartialChange(): Flow<ConcernPartialChange.LoadMore> =
TiebaApi.getInstance().userLikeFlow(pageTag, appPreferences.userLikeLastRequestUnix, 2) TiebaApi.getInstance().userLikeFlow(pageTag, App.INSTANCE.appPreferences.userLikeLastRequestUnix, 2)
.map<UserLikeResponse, ConcernPartialChange.LoadMore> { .map<UserLikeResponse, ConcernPartialChange.LoadMore> {
ConcernPartialChange.LoadMore.Success( ConcernPartialChange.LoadMore.Success(
data = it.toData(), data = it.toData(),

View File

@ -1,6 +1,7 @@
package com.huanchengfly.tieba.post.ui.page.main.explore.personalized package com.huanchengfly.tieba.post.ui.page.main.explore.personalized
import androidx.compose.runtime.Stable import androidx.compose.runtime.Stable
import com.huanchengfly.tieba.post.App
import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.TiebaApi
import com.huanchengfly.tieba.post.api.models.AgreeBean import com.huanchengfly.tieba.post.api.models.AgreeBean
import com.huanchengfly.tieba.post.api.models.CommonResponse import com.huanchengfly.tieba.post.api.models.CommonResponse
@ -66,7 +67,7 @@ class PersonalizedViewModel @Inject constructor() :
TiebaApi.getInstance().personalizedProtoFlow(1, 1) TiebaApi.getInstance().personalizedProtoFlow(1, 1)
.map<PersonalizedResponse, PersonalizedPartialChange.Refresh> { response -> .map<PersonalizedResponse, PersonalizedPartialChange.Refresh> { response ->
val data = response.toData().filter { val data = response.toData().filter {
!appPreferences.blockVideo || it.get { videoInfo } == null !App.INSTANCE.appPreferences.blockVideo || it.get { videoInfo } == null
} }
val threadPersonalizedData = data.map { thread -> val threadPersonalizedData = data.map { thread ->
response.data_?.thread_personalized?.firstOrNull { thread.get { id } == it.tid } response.data_?.thread_personalized?.firstOrNull { thread.get { id } == it.tid }
@ -84,7 +85,7 @@ class PersonalizedViewModel @Inject constructor() :
TiebaApi.getInstance().personalizedProtoFlow(2, page) TiebaApi.getInstance().personalizedProtoFlow(2, page)
.map<PersonalizedResponse, PersonalizedPartialChange.LoadMore> { response -> .map<PersonalizedResponse, PersonalizedPartialChange.LoadMore> { response ->
val data = response.toData().filter { val data = response.toData().filter {
!appPreferences.blockVideo || it.get { videoInfo } == null !App.INSTANCE.appPreferences.blockVideo || it.get { videoInfo } == null
} }
val threadPersonalizedData = data.map { thread -> val threadPersonalizedData = data.map { thread ->
response.data_?.thread_personalized?.firstOrNull { thread.get { id } == it.tid } response.data_?.thread_personalized?.firstOrNull { thread.get { id } == it.tid }

View File

@ -1,5 +1,6 @@
package com.huanchengfly.tieba.post.ui.page.main.home package com.huanchengfly.tieba.post.ui.page.main.home
import android.content.Context
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
@ -96,7 +97,7 @@ import com.huanchengfly.tieba.post.utils.TiebaUtil
import com.huanchengfly.tieba.post.utils.appPreferences import com.huanchengfly.tieba.post.utils.appPreferences
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
private fun getGridCells(listSingle: Boolean = appPreferences.listSingle): GridCells { private fun getGridCells(context: Context, listSingle: Boolean = context.appPreferences.listSingle): GridCells {
return if (listSingle) { return if (listSingle) {
GridCells.Fixed(1) GridCells.Fixed(1)
} else { } else {
@ -400,8 +401,8 @@ fun HomePage(
initial = null initial = null
) )
val isError by remember { derivedStateOf { error != null } } val isError by remember { derivedStateOf { error != null } }
var listSingle by remember { mutableStateOf(appPreferences.listSingle) } var listSingle by remember { mutableStateOf(context.appPreferences.listSingle) }
val gridCells by remember { derivedStateOf { getGridCells(listSingle) } } val gridCells by remember { derivedStateOf { getGridCells(context, listSingle) } }
eventFlow.onEvent<MainUiEvent.Refresh> { eventFlow.onEvent<MainUiEvent.Refresh> {
viewModel.send(HomeUiIntent.Refresh) viewModel.send(HomeUiIntent.Refresh)
@ -424,7 +425,7 @@ fun HomePage(
icon = Icons.Outlined.ViewAgenda, icon = Icons.Outlined.ViewAgenda,
contentDescription = stringResource(id = R.string.title_switch_list_single) contentDescription = stringResource(id = R.string.title_switch_list_single)
) { ) {
appPreferences.listSingle = !listSingle context.appPreferences.listSingle = !listSingle
listSingle = !listSingle listSingle = !listSingle
} }
} }

View File

@ -189,7 +189,7 @@ fun AccountManagePage(
) )
} }
prefsItem { prefsItem {
val littleTail = remember { appPreferences.littleTail } val littleTail = remember { context.appPreferences.littleTail }
EditTextPref( EditTextPref(
key = "little_tail", key = "little_tail",
title = stringResource(id = R.string.title_my_tail), title = stringResource(id = R.string.title_my_tail),

View File

@ -187,7 +187,7 @@ fun ThreadStorePage(
ThreadPageDestination( ThreadPageDestination(
threadId = info.threadId.toLong(), threadId = info.threadId.toLong(),
postId = info.markPid.toLong(), postId = info.markPid.toLong(),
seeLz = appPreferences.collectThreadSeeLz, seeLz = context.appPreferences.collectThreadSeeLz,
from = ThreadPageFrom.FROM_STORE, from = ThreadPageFrom.FROM_STORE,
extra = ThreadPageFromStoreExtra( extra = ThreadPageFromStoreExtra(
maxPid = info.maxPid.toLong(), maxPid = info.maxPid.toLong(),

View File

@ -23,6 +23,9 @@ object AppIconUtil {
private val context: Context private val context: Context
get() = App.INSTANCE get() = App.INSTANCE
private val appPreferences: AppPreferencesUtils
get() = context.appPreferences
fun setIcon(icon: String = appPreferences.appIcon ?: Icons.NEW_ICON) { fun setIcon(icon: String = appPreferences.appIcon ?: Icons.NEW_ICON) {
val newIcon = if (Icons.ICONS.contains(icon) || icon == Icons.DISABLE) { val newIcon = if (Icons.ICONS.contains(icon) || icon == Icons.DISABLE) {
icon icon

View File

@ -1,5 +1,6 @@
package com.huanchengfly.tieba.post.utils package com.huanchengfly.tieba.post.utils
import android.content.Context
import androidx.datastore.core.DataStore import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey import androidx.datastore.preferences.core.booleanPreferencesKey
@ -8,7 +9,6 @@ import androidx.datastore.preferences.core.floatPreferencesKey
import androidx.datastore.preferences.core.intPreferencesKey import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.longPreferencesKey import androidx.datastore.preferences.core.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.core.stringPreferencesKey
import com.huanchengfly.tieba.post.App
import com.huanchengfly.tieba.post.dataStore import com.huanchengfly.tieba.post.dataStore
import com.huanchengfly.tieba.post.getBoolean import com.huanchengfly.tieba.post.getBoolean
import com.huanchengfly.tieba.post.getFloat import com.huanchengfly.tieba.post.getFloat
@ -26,10 +26,9 @@ import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
object AppPreferencesUtils { open class AppPreferencesUtils(private val context: Context) {
private val preferencesDataStore: DataStore<Preferences> private val preferencesDataStore: DataStore<Preferences>
get() = App.INSTANCE.dataStore get() = context.dataStore
private val coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob()) private val coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
var userLikeLastRequestUnix by DataStoreDelegates.long(defaultValue = 0L) var userLikeLastRequestUnix by DataStoreDelegates.long(defaultValue = 0L)
@ -89,8 +88,6 @@ object AppPreferencesUtils {
var forumFabFunction by DataStoreDelegates.string(defaultValue = "post") var forumFabFunction by DataStoreDelegates.string(defaultValue = "post")
var hideBlockedContent by DataStoreDelegates.boolean(defaultValue = false)
var hideExplore by DataStoreDelegates.boolean(defaultValue = false) var hideExplore by DataStoreDelegates.boolean(defaultValue = false)
var hideForumIntroAndStat by DataStoreDelegates.boolean(defaultValue = false) var hideForumIntroAndStat by DataStoreDelegates.boolean(defaultValue = false)
@ -377,5 +374,5 @@ object AppPreferencesUtils {
} }
} }
val appPreferences: AppPreferencesUtils val Context.appPreferences: AppPreferencesUtils
get() = AppPreferencesUtils get() = AppPreferencesUtils(this)

View File

@ -31,6 +31,7 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import com.github.panpf.sketch.request.DownloadRequest import com.github.panpf.sketch.request.DownloadRequest
import com.github.panpf.sketch.request.DownloadResult import com.github.panpf.sketch.request.DownloadResult
import com.huanchengfly.tieba.post.App.Companion.INSTANCE
import com.huanchengfly.tieba.post.R import com.huanchengfly.tieba.post.R
import com.huanchengfly.tieba.post.activities.PhotoViewActivity.Companion.launch import com.huanchengfly.tieba.post.activities.PhotoViewActivity.Companion.launch
import com.huanchengfly.tieba.post.components.transformations.RadiusTransformation import com.huanchengfly.tieba.post.components.transformations.RadiusTransformation
@ -506,11 +507,11 @@ object ImageUtil {
@JvmStatic @JvmStatic
fun getRadiusPx(context: Context): Int { fun getRadiusPx(context: Context): Int {
return DisplayUtil.dp2px(context, getRadiusDp().toFloat()) return DisplayUtil.dp2px(context, getRadiusDp(context).toFloat())
} }
private fun getRadiusDp(): Int { private fun getRadiusDp(context: Context): Int {
return appPreferences.radius return context.appPreferences.radius
} }
fun clear(imageView: ImageView?) { fun clear(imageView: ImageView?) {
@ -539,7 +540,7 @@ object ImageUtil {
if (!Util.canLoadGlide(imageView.context)) { if (!Util.canLoadGlide(imageView.context)) {
return return
} }
val radius = getRadiusDp() val radius = getRadiusDp(imageView.context)
val requestBuilder = val requestBuilder =
if (skipNetworkCheck || if (skipNetworkCheck ||
type == LOAD_TYPE_AVATAR || type == LOAD_TYPE_AVATAR ||
@ -644,7 +645,7 @@ object ImageUtil {
@get:ImageLoadSettings @get:ImageLoadSettings
private val imageLoadSettings: Int private val imageLoadSettings: Int
get() = appPreferences.imageLoadType!!.toInt() get() = INSTANCE.appPreferences.imageLoadType!!.toInt()
fun imageToBase64(inputStream: InputStream?): String? { fun imageToBase64(inputStream: InputStream?): String? {
if (inputStream == null) { if (inputStream == null) {

View File

@ -91,8 +91,10 @@ public final class NavigationHelper {
} }
public void navigationByData(int action) { public void navigationByData(int action) {
if (action == ACTION_LOGIN) { switch (action) {
case ACTION_LOGIN:
startActivity(new Intent(mContext, LoginActivity.class)); startActivity(new Intent(mContext, LoginActivity.class));
break;
} }
} }
@ -237,12 +239,12 @@ public final class NavigationHelper {
if (!(activityName.startsWith("WebViewActivity") || activityName.startsWith("LoginActivity"))) { if (!(activityName.startsWith("WebViewActivity") || activityName.startsWith("LoginActivity"))) {
boolean isTiebaLink = host.contains("tieba.baidu.com") || host.contains("wappass.baidu.com") || host.contains("ufosdk.baidu.com") || host.contains("m.help.baidu.com"); boolean isTiebaLink = host.contains("tieba.baidu.com") || host.contains("wappass.baidu.com") || host.contains("ufosdk.baidu.com") || host.contains("m.help.baidu.com");
if (isTiebaLink || if (isTiebaLink ||
AppPreferencesUtilsKt.getAppPreferences().getUseWebView() AppPreferencesUtilsKt.getAppPreferences(mContext).getUseWebView()
) { ) {
startActivity(new Intent(mContext, WebViewActivity.class).putExtra("url", url)); startActivity(new Intent(mContext, WebViewActivity.class).putExtra("url", url));
return true; return true;
} else { } else {
if (AppPreferencesUtilsKt.getAppPreferences().getUseCustomTabs()) { if (AppPreferencesUtilsKt.getAppPreferences(mContext).getUseCustomTabs()) {
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder() CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder()
.setShowTitle(true) .setShowTitle(true)
.setToolbarColor(ThemeUtils.getColorByAttr(mContext, R.attr.colorToolbar)); .setToolbarColor(ThemeUtils.getColorByAttr(mContext, R.attr.colorToolbar));

View File

@ -34,7 +34,7 @@ abstract class IOKSigner(
} }
fun getSignDelay(): Long { fun getSignDelay(): Long {
return if (appPreferences.oksignSlowMode) { return if (context.appPreferences.oksignSlowMode) {
ThreadLocalRandom.current().nextInt(3500, 8000).toLong() ThreadLocalRandom.current().nextInt(3500, 8000).toLong()
} else { } else {
2000 2000
@ -125,7 +125,7 @@ class SingleAccountSigner(
.zip( .zip(
TiebaApi.getInstance().forumRecommendFlow() TiebaApi.getInstance().forumRecommendFlow()
) { getForumListBean, forumRecommendBean -> ) { getForumListBean, forumRecommendBean ->
val useMSign = appPreferences.oksignUseOfficialOksign val useMSign = context.appPreferences.oksignUseOfficialOksign
val mSignLevel = getForumListBean.level.toInt() val mSignLevel = getForumListBean.level.toInt()
val mSignMax = getForumListBean.msignStepNum.toInt() val mSignMax = getForumListBean.msignStepNum.toInt()
signData.addAll( signData.addAll(

View File

@ -72,7 +72,7 @@ object StringUtil {
@JvmStatic @JvmStatic
fun getUsernameString(context: Context, username: String, nickname: String?): CharSequence { fun getUsernameString(context: Context, username: String, nickname: String?): CharSequence {
val showBoth = appPreferences.showBothUsernameAndNickname val showBoth = context.appPreferences.showBothUsernameAndNickname
if (TextUtils.isEmpty(nickname)) { if (TextUtils.isEmpty(nickname)) {
return if (TextUtils.isEmpty(username)) "" else username return if (TextUtils.isEmpty(username)) "" else username
} else if (showBoth && !TextUtils.isEmpty(username) && !TextUtils.equals( } else if (showBoth && !TextUtils.isEmpty(username) && !TextUtils.equals(
@ -98,7 +98,7 @@ object StringUtil {
nickname: String?, nickname: String?,
color: Color = Color.Unspecified color: Color = Color.Unspecified
): AnnotatedString { ): AnnotatedString {
val showBoth = appPreferences.showBothUsernameAndNickname val showBoth = context.appPreferences.showBothUsernameAndNickname
return buildAnnotatedString { return buildAnnotatedString {
if (showBoth && !nickname.isNullOrBlank() && username != nickname && username.isNotBlank()) { if (showBoth && !nickname.isNullOrBlank() && username != nickname && username.isNotBlank()) {
append(nickname) append(nickname)

View File

@ -51,7 +51,7 @@ object TiebaUtil {
fun initAutoSign(context: Context) { fun initAutoSign(context: Context) {
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val autoSign = appPreferences.autoSign val autoSign = context.appPreferences.autoSign
val pendingIntent = PendingIntent.getBroadcast( val pendingIntent = PendingIntent.getBroadcast(
context, context,
0, 0,
@ -59,7 +59,7 @@ object TiebaUtil {
pendingIntentFlagMutable() pendingIntentFlagMutable()
) )
if (autoSign) { if (autoSign) {
val autoSignTimeStr = appPreferences.autoSignTime!! val autoSignTimeStr = context.appPreferences.autoSignTime!!
val time = autoSignTimeStr.split(":").toTypedArray() val time = autoSignTimeStr.split(":").toTypedArray()
val hour = time[0].toInt() val hour = time[0].toInt()
val minute = time[1].toInt() val minute = time[1].toInt()
@ -81,7 +81,7 @@ object TiebaUtil {
@JvmStatic @JvmStatic
fun startSign(context: Context) { fun startSign(context: Context) {
appPreferences.signDay = Calendar.getInstance()[Calendar.DAY_OF_MONTH] context.appPreferences.signDay = Calendar.getInstance()[Calendar.DAY_OF_MONTH]
// OKSignService.enqueueWork( // OKSignService.enqueueWork(
// context, // context,
// Intent() // Intent()