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) {
R.attr.colorPrimary -> {
if (ThemeUtil.THEME_CUSTOM == theme) {
val customPrimaryColorStr = appPreferences.customPrimaryColor
val customPrimaryColorStr = context.appPreferences.customPrimaryColor
return if (customPrimaryColorStr != null) {
Color.parseColor(customPrimaryColorStr)
} else getColorByAttr(context, attrId, ThemeUtil.THEME_BLUE)
} else if (ThemeUtil.isTranslucentTheme(theme)) {
val primaryColorStr = appPreferences.translucentPrimaryColor
val primaryColorStr = context.appPreferences.translucentPrimaryColor
return if (primaryColorStr != null) {
Color.parseColor(primaryColorStr)
} else getColorByAttr(context, attrId, ThemeUtil.THEME_BLUE)
@ -363,7 +363,7 @@ class App : Application(), IApp, SketchFactory {
)
)
} else {
val isPrimaryColor = appPreferences.toolbarPrimaryColor
val isPrimaryColor = context.appPreferences.toolbarPrimaryColor
if (isPrimaryColor) {
getColorByAttr(context, R.attr.colorPrimary, theme)
} 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.widgets.VoicePlayerView
import com.huanchengfly.tieba.post.ui.widgets.theme.TintToolbar
import com.huanchengfly.tieba.post.utils.AppPreferencesUtils
import com.huanchengfly.tieba.post.utils.DialogUtil
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 com.huanchengfly.tieba.post.utils.*
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
abstract class BaseActivity : AppCompatActivity(), ExtraRefreshable, CoroutineScope {
@ -62,7 +54,7 @@ abstract class BaseActivity : AppCompatActivity(), ExtraRefreshable, CoroutineSc
private var customStatusColor = -1
private var statusBarTinted = false
val appPreferences: AppPreferencesUtils by lazy { AppPreferencesUtils }
val appPreferences: AppPreferencesUtils by lazy { AppPreferencesUtils(this) }
override fun 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.dpToPx
import com.huanchengfly.tieba.post.ui.common.theme.utils.ColorStateListUtils
import com.huanchengfly.tieba.post.utils.ImageUtil
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
import com.huanchengfly.tieba.post.utils.*
class MainForumListAdapter(
context: Context,
@ -62,7 +57,7 @@ class MainForumListAdapter(
getRadiusDrawable()
}
)
if (appPreferences.listItemsBackgroundIntermixed) {
if (context.appPreferences.listItemsBackgroundIntermixed) {
if (position % 2 == 1) {
viewHolder.itemView.backgroundTintList =
ColorStateList.valueOf(Color.TRANSPARENT)

View File

@ -243,7 +243,7 @@ public class PersonalizedFeedAdapter extends BaseMultiTypeAdapter<PersonalizedBe
case TYPE_THREAD_MULTI_PIC:
GridLayout gridLayout = viewHolder.getView(R.id.forum_item_content_pics);
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 secondImageView = viewHolder.getView(R.id.forum_item_content_pic_2);
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 forumAvatarView: ImageView = forumView.findViewById(R.id.forum_bar_avatar)
if (!showForum ||
!appPreferences.showShortcutInThread ||
!context.appPreferences.showShortcutInThread ||
"0" == forumInfoBean.isExists ||
forumInfoBean.name.isNullOrEmpty()
) {

View File

@ -263,7 +263,7 @@ public class NewForumAdapter extends BaseMultiTypeDelegateAdapter<ForumPageBean.
cardView.setRadius(
DisplayUtil.dp2px(
getContext(),
AppPreferencesUtilsKt.getAppPreferences().getRadius()
AppPreferencesUtilsKt.getAppPreferences(getContext()).getRadius()
)
);
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)
setView(contentView)
primaryColor = getColorByAttr(context, R.attr.colorPrimary, ThemeUtil.THEME_CUSTOM)
statusBarFontDark = appPreferences.customStatusBarFontDark
toolbarPrimary = appPreferences.toolbarPrimaryColor
statusBarFontDark = context.appPreferences.customStatusBarFontDark
toolbarPrimary = context.appPreferences.toolbarPrimaryColor
refreshView()
}
@ -77,7 +77,7 @@ class CustomThemeDialog(context: Context) : AlertDialog(context),
@SuppressLint("ApplySharedPref")
override fun onClick(dialog: DialogInterface, which: Int) {
appPreferences.apply {
context.appPreferences.apply {
customPrimaryColor = toString(primaryColor)
customStatusBarFontDark = (statusBarFontDark || !toolbarPrimary)
toolbarPrimaryColor = toolbarPrimary

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,6 +1,7 @@
package com.huanchengfly.tieba.post.ui.page.forum.threadlist
import androidx.compose.runtime.Stable
import com.huanchengfly.tieba.post.App
import com.huanchengfly.tieba.post.api.TiebaApi
import com.huanchengfly.tieba.post.api.models.AgreeBean
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 threadList = response.data_.thread_list.map { threadInfo ->
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(
threadList.wrapImmutable(),
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.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import com.huanchengfly.tieba.post.LocalDevicePosture
@ -133,7 +134,7 @@ fun MainPage(
content = {
HomePage(
eventFlow = eventFlows[0],
canOpenExplore = !appPreferences.hideExplore
canOpenExplore = !LocalContext.current.appPreferences.hideExplore
) {
coroutineScope.launch {
pagerState.scrollToPage(1)
@ -141,7 +142,7 @@ fun MainPage(
}
}
),
if (appPreferences.hideExplore) null
if (LocalContext.current.appPreferences.hideExplore) null
else NavigationItem(
id = "explore",
icon = {

View File

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

View File

@ -1,6 +1,7 @@
package com.huanchengfly.tieba.post.ui.page.main.explore.personalized
import androidx.compose.runtime.Stable
import com.huanchengfly.tieba.post.App
import com.huanchengfly.tieba.post.api.TiebaApi
import com.huanchengfly.tieba.post.api.models.AgreeBean
import com.huanchengfly.tieba.post.api.models.CommonResponse
@ -66,7 +67,7 @@ class PersonalizedViewModel @Inject constructor() :
TiebaApi.getInstance().personalizedProtoFlow(1, 1)
.map<PersonalizedResponse, PersonalizedPartialChange.Refresh> { response ->
val data = response.toData().filter {
!appPreferences.blockVideo || it.get { videoInfo } == null
!App.INSTANCE.appPreferences.blockVideo || it.get { videoInfo } == null
}
val threadPersonalizedData = data.map { thread ->
response.data_?.thread_personalized?.firstOrNull { thread.get { id } == it.tid }
@ -84,7 +85,7 @@ class PersonalizedViewModel @Inject constructor() :
TiebaApi.getInstance().personalizedProtoFlow(2, page)
.map<PersonalizedResponse, PersonalizedPartialChange.LoadMore> { response ->
val data = response.toData().filter {
!appPreferences.blockVideo || it.get { videoInfo } == null
!App.INSTANCE.appPreferences.blockVideo || it.get { videoInfo } == null
}
val threadPersonalizedData = data.map { thread ->
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
import android.content.Context
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.Image
@ -96,7 +97,7 @@ import com.huanchengfly.tieba.post.utils.TiebaUtil
import com.huanchengfly.tieba.post.utils.appPreferences
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) {
GridCells.Fixed(1)
} else {
@ -400,8 +401,8 @@ fun HomePage(
initial = null
)
val isError by remember { derivedStateOf { error != null } }
var listSingle by remember { mutableStateOf(appPreferences.listSingle) }
val gridCells by remember { derivedStateOf { getGridCells(listSingle) } }
var listSingle by remember { mutableStateOf(context.appPreferences.listSingle) }
val gridCells by remember { derivedStateOf { getGridCells(context, listSingle) } }
eventFlow.onEvent<MainUiEvent.Refresh> {
viewModel.send(HomeUiIntent.Refresh)
@ -424,7 +425,7 @@ fun HomePage(
icon = Icons.Outlined.ViewAgenda,
contentDescription = stringResource(id = R.string.title_switch_list_single)
) {
appPreferences.listSingle = !listSingle
context.appPreferences.listSingle = !listSingle
listSingle = !listSingle
}
}

View File

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

View File

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

View File

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

View File

@ -1,5 +1,6 @@
package com.huanchengfly.tieba.post.utils
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
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.longPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import com.huanchengfly.tieba.post.App
import com.huanchengfly.tieba.post.dataStore
import com.huanchengfly.tieba.post.getBoolean
import com.huanchengfly.tieba.post.getFloat
@ -26,10 +26,9 @@ import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
object AppPreferencesUtils {
open class AppPreferencesUtils(private val context: Context) {
private val preferencesDataStore: DataStore<Preferences>
get() = App.INSTANCE.dataStore
get() = context.dataStore
private val coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
var userLikeLastRequestUnix by DataStoreDelegates.long(defaultValue = 0L)
@ -89,8 +88,6 @@ object AppPreferencesUtils {
var forumFabFunction by DataStoreDelegates.string(defaultValue = "post")
var hideBlockedContent by DataStoreDelegates.boolean(defaultValue = false)
var hideExplore by DataStoreDelegates.boolean(defaultValue = false)
var hideForumIntroAndStat by DataStoreDelegates.boolean(defaultValue = false)
@ -377,5 +374,5 @@ object AppPreferencesUtils {
}
}
val appPreferences: AppPreferencesUtils
get() = AppPreferencesUtils
val Context.appPreferences: 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.github.panpf.sketch.request.DownloadRequest
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.activities.PhotoViewActivity.Companion.launch
import com.huanchengfly.tieba.post.components.transformations.RadiusTransformation
@ -506,11 +507,11 @@ object ImageUtil {
@JvmStatic
fun getRadiusPx(context: Context): Int {
return DisplayUtil.dp2px(context, getRadiusDp().toFloat())
return DisplayUtil.dp2px(context, getRadiusDp(context).toFloat())
}
private fun getRadiusDp(): Int {
return appPreferences.radius
private fun getRadiusDp(context: Context): Int {
return context.appPreferences.radius
}
fun clear(imageView: ImageView?) {
@ -539,7 +540,7 @@ object ImageUtil {
if (!Util.canLoadGlide(imageView.context)) {
return
}
val radius = getRadiusDp()
val radius = getRadiusDp(imageView.context)
val requestBuilder =
if (skipNetworkCheck ||
type == LOAD_TYPE_AVATAR ||
@ -644,7 +645,7 @@ object ImageUtil {
@get:ImageLoadSettings
private val imageLoadSettings: Int
get() = appPreferences.imageLoadType!!.toInt()
get() = INSTANCE.appPreferences.imageLoadType!!.toInt()
fun imageToBase64(inputStream: InputStream?): String? {
if (inputStream == null) {

View File

@ -91,8 +91,10 @@ public final class NavigationHelper {
}
public void navigationByData(int action) {
if (action == ACTION_LOGIN) {
startActivity(new Intent(mContext, LoginActivity.class));
switch (action) {
case ACTION_LOGIN:
startActivity(new Intent(mContext, LoginActivity.class));
break;
}
}
@ -237,12 +239,12 @@ public final class NavigationHelper {
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");
if (isTiebaLink ||
AppPreferencesUtilsKt.getAppPreferences().getUseWebView()
AppPreferencesUtilsKt.getAppPreferences(mContext).getUseWebView()
) {
startActivity(new Intent(mContext, WebViewActivity.class).putExtra("url", url));
return true;
} else {
if (AppPreferencesUtilsKt.getAppPreferences().getUseCustomTabs()) {
if (AppPreferencesUtilsKt.getAppPreferences(mContext).getUseCustomTabs()) {
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder()
.setShowTitle(true)
.setToolbarColor(ThemeUtils.getColorByAttr(mContext, R.attr.colorToolbar));

View File

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

View File

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

View File

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