2020-08-15 22:05:07 +08:00
|
|
|
|
package com.huanchengfly.tieba.post
|
|
|
|
|
|
|
2023-01-05 14:47:24 +08:00
|
|
|
|
import android.annotation.SuppressLint
|
2020-08-15 22:05:07 +08:00
|
|
|
|
import android.app.Activity
|
2021-08-19 16:57:31 +08:00
|
|
|
|
import android.app.ActivityManager
|
2020-08-15 22:05:07 +08:00
|
|
|
|
import android.app.Application
|
2021-08-19 16:57:31 +08:00
|
|
|
|
import android.app.Dialog
|
2023-02-15 22:20:38 +08:00
|
|
|
|
import android.content.ComponentName
|
2020-08-15 22:05:07 +08:00
|
|
|
|
import android.content.Context
|
|
|
|
|
|
import android.content.res.Configuration
|
2021-08-19 16:57:31 +08:00
|
|
|
|
import android.content.res.Resources
|
2020-08-15 22:05:07 +08:00
|
|
|
|
import android.graphics.Color
|
2020-08-15 22:26:17 +08:00
|
|
|
|
import android.graphics.drawable.Drawable
|
2021-08-19 16:57:31 +08:00
|
|
|
|
import android.os.Build
|
|
|
|
|
|
import android.os.Process
|
|
|
|
|
|
import android.webkit.WebView
|
2021-12-31 17:34:37 +08:00
|
|
|
|
import androidx.annotation.Keep
|
2021-08-19 16:57:31 +08:00
|
|
|
|
import androidx.annotation.RequiresApi
|
|
|
|
|
|
import androidx.appcompat.app.AlertDialog
|
2020-08-15 22:05:07 +08:00
|
|
|
|
import androidx.appcompat.app.AppCompatDelegate
|
2022-06-23 20:19:42 +08:00
|
|
|
|
import com.github.gzuliyujiang.oaid.DeviceID
|
|
|
|
|
|
import com.github.gzuliyujiang.oaid.IGetter
|
2022-09-24 16:05:21 +08:00
|
|
|
|
import com.github.panpf.sketch.Sketch
|
|
|
|
|
|
import com.github.panpf.sketch.SketchFactory
|
|
|
|
|
|
import com.github.panpf.sketch.decode.GifAnimatedDrawableDecoder
|
|
|
|
|
|
import com.github.panpf.sketch.decode.GifMovieDrawableDecoder
|
|
|
|
|
|
import com.github.panpf.sketch.decode.HeifAnimatedDrawableDecoder
|
|
|
|
|
|
import com.github.panpf.sketch.decode.WebpAnimatedDrawableDecoder
|
2023-01-05 14:47:24 +08:00
|
|
|
|
import com.github.panpf.sketch.http.OkHttpStack
|
2023-02-15 21:57:46 +08:00
|
|
|
|
import com.github.panpf.sketch.request.PauseLoadWhenScrollingDrawableDecodeInterceptor
|
2021-08-19 16:57:31 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.activities.BaseActivity
|
2022-08-08 17:57:55 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.components.ClipBoardLinkDetector
|
2021-08-19 16:57:31 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.components.dialogs.LoadingDialog
|
2021-08-11 17:10:16 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.plugins.PluginManager
|
|
|
|
|
|
import com.huanchengfly.tieba.post.plugins.interfaces.IApp
|
2022-08-03 15:06:14 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.ui.common.theme.interfaces.ThemeSwitcher
|
|
|
|
|
|
import com.huanchengfly.tieba.post.ui.common.theme.utils.ThemeUtils
|
2022-12-31 12:43:24 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.utils.AccountUtil
|
|
|
|
|
|
import com.huanchengfly.tieba.post.utils.AppIconUtil
|
2023-02-15 22:20:38 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.utils.AppIconUtil.disableComponent
|
|
|
|
|
|
import com.huanchengfly.tieba.post.utils.AppIconUtil.enableComponent
|
2023-01-24 13:37:09 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.utils.ClientUtils
|
2022-12-31 12:43:24 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.utils.EmoticonManager
|
2023-02-15 22:19:26 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.utils.Icons
|
2022-12-31 12:43:24 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.utils.SharedPreferencesUtil
|
|
|
|
|
|
import com.huanchengfly.tieba.post.utils.ThemeUtil
|
|
|
|
|
|
import com.huanchengfly.tieba.post.utils.TiebaUtil
|
|
|
|
|
|
import com.huanchengfly.tieba.post.utils.Util
|
|
|
|
|
|
import com.huanchengfly.tieba.post.utils.appPreferences
|
|
|
|
|
|
import com.huanchengfly.tieba.post.utils.applicationMetaData
|
2023-01-27 20:57:51 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.utils.helios.Base32
|
2022-12-31 12:43:24 +08:00
|
|
|
|
import com.huanchengfly.tieba.post.utils.launchUrl
|
2021-12-03 20:36:11 +08:00
|
|
|
|
import com.microsoft.appcenter.AppCenter
|
|
|
|
|
|
import com.microsoft.appcenter.analytics.Analytics
|
|
|
|
|
|
import com.microsoft.appcenter.crashes.Crashes
|
2022-12-31 12:43:24 +08:00
|
|
|
|
import com.microsoft.appcenter.distribute.Distribute
|
|
|
|
|
|
import com.microsoft.appcenter.distribute.DistributeListener
|
|
|
|
|
|
import com.microsoft.appcenter.distribute.ReleaseDetails
|
|
|
|
|
|
import com.microsoft.appcenter.distribute.UpdateAction
|
|
|
|
|
|
import com.microsoft.appcenter.distribute.UpdateTrack
|
2022-08-03 15:09:09 +08:00
|
|
|
|
import dagger.hilt.android.HiltAndroidApp
|
2023-01-24 13:37:09 +08:00
|
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
|
import kotlinx.coroutines.launch
|
2020-08-15 22:05:07 +08:00
|
|
|
|
import org.litepal.LitePal
|
|
|
|
|
|
|
2021-08-19 16:57:31 +08:00
|
|
|
|
|
2022-08-03 15:09:09 +08:00
|
|
|
|
@HiltAndroidApp
|
2022-09-24 16:05:21 +08:00
|
|
|
|
class App : Application(), IApp, IGetter, SketchFactory {
|
2020-08-15 22:05:07 +08:00
|
|
|
|
private val mActivityList: MutableList<Activity> = mutableListOf()
|
|
|
|
|
|
|
2022-08-08 17:57:55 +08:00
|
|
|
|
override fun onOAIDGetComplete(result: String) {
|
2023-01-27 20:57:51 +08:00
|
|
|
|
oaid = Base32.encode(result.encodeToByteArray())
|
2022-08-08 17:57:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onOAIDGetError(error: Exception) {
|
|
|
|
|
|
oaid = ""
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-19 16:57:31 +08:00
|
|
|
|
@RequiresApi(api = 28)
|
2022-08-08 17:57:55 +08:00
|
|
|
|
private fun setWebViewPath(context: Context) {
|
2021-08-19 16:57:31 +08:00
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
|
|
|
|
val processName = getProcessName(context)
|
|
|
|
|
|
if (applicationContext.packageName != processName) { //判断不等于默认进程名称
|
|
|
|
|
|
WebView.setDataDirectorySuffix(processName!!)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun getProcessName(context: Context): String? {
|
|
|
|
|
|
val manager = context.getSystemService(ACTIVITY_SERVICE) as ActivityManager
|
|
|
|
|
|
for (processInfo in manager.runningAppProcesses) {
|
|
|
|
|
|
if (processInfo.pid == Process.myPid()) {
|
|
|
|
|
|
return processInfo.processName
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return null
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-02-15 22:20:38 +08:00
|
|
|
|
private fun setOldMainActivityEnabled(enabled: Boolean) {
|
|
|
|
|
|
if (enabled) {
|
|
|
|
|
|
packageManager.enableComponent(
|
|
|
|
|
|
ComponentName(
|
|
|
|
|
|
this,
|
|
|
|
|
|
"com.huanchengfly.tieba.post.activities.MainActivity"
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
packageManager.disableComponent(
|
|
|
|
|
|
ComponentName(
|
|
|
|
|
|
this,
|
|
|
|
|
|
"com.huanchengfly.tieba.post.activities.MainActivity"
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun setIcon(
|
|
|
|
|
|
enableNewUi: Boolean = applicationMetaData.getBoolean("enable_new_ui") || appPreferences.enableNewUi,
|
|
|
|
|
|
keepOld: Boolean = BuildConfig.DEBUG
|
|
|
|
|
|
) {
|
|
|
|
|
|
setOldMainActivityEnabled(!enableNewUi && !keepOld)
|
2023-02-15 22:19:26 +08:00
|
|
|
|
if (enableNewUi) AppIconUtil.setIcon()
|
|
|
|
|
|
else AppIconUtil.setIcon(Icons.DISABLE)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-15 22:05:07 +08:00
|
|
|
|
override fun onCreate() {
|
2022-08-02 16:20:05 +08:00
|
|
|
|
INSTANCE = this
|
2020-08-15 22:05:07 +08:00
|
|
|
|
super.onCreate()
|
2022-09-24 16:05:21 +08:00
|
|
|
|
LitePal.initialize(this)
|
|
|
|
|
|
AccountUtil.init(this)
|
2022-08-08 17:57:55 +08:00
|
|
|
|
DeviceID.getOAID(this, this)
|
2021-08-19 16:57:31 +08:00
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
|
|
|
|
setWebViewPath(this)
|
|
|
|
|
|
}
|
2022-08-08 17:57:55 +08:00
|
|
|
|
val isSelfBuild = applicationMetaData.getBoolean("is_self_build")
|
|
|
|
|
|
if (!isSelfBuild) {
|
|
|
|
|
|
Distribute.setUpdateTrack(if (appPreferences.checkCIUpdate) UpdateTrack.PRIVATE else UpdateTrack.PUBLIC)
|
|
|
|
|
|
Distribute.setListener(MyDistributeListener())
|
|
|
|
|
|
AppCenter.start(
|
|
|
|
|
|
this, "b56debcc-264b-4368-a2cd-8c20213f6433",
|
|
|
|
|
|
Analytics::class.java, Crashes::class.java, Distribute::class.java
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
2023-02-15 22:20:38 +08:00
|
|
|
|
setIcon(keepOld = !BuildConfig.DEBUG && !isSelfBuild)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
2022-12-31 12:43:24 +08:00
|
|
|
|
ThemeUtils.init(ThemeDelegate)
|
2022-08-08 17:57:55 +08:00
|
|
|
|
registerActivityLifecycleCallbacks(ClipBoardLinkDetector)
|
2021-08-15 18:30:51 +08:00
|
|
|
|
PluginManager.init(this)
|
2023-01-24 13:37:09 +08:00
|
|
|
|
CoroutineScope(Dispatchers.IO).apply {
|
|
|
|
|
|
launch {
|
|
|
|
|
|
EmoticonManager.init(this@App)
|
|
|
|
|
|
}
|
|
|
|
|
|
launch {
|
|
|
|
|
|
ClientUtils.init(this@App)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-31 17:34:37 +08:00
|
|
|
|
//解决魅族 Flyme 系统夜间模式强制反色
|
|
|
|
|
|
@Keep
|
|
|
|
|
|
fun mzNightModeUseOf(): Int = 2
|
|
|
|
|
|
|
2021-08-19 16:57:31 +08:00
|
|
|
|
//禁止app字体大小跟随系统字体大小调节
|
|
|
|
|
|
override fun getResources(): Resources {
|
2022-12-31 12:43:24 +08:00
|
|
|
|
//INSTANCE = this
|
2021-08-19 16:57:31 +08:00
|
|
|
|
val fontScale = appPreferences.fontScale
|
|
|
|
|
|
val resources = super.getResources()
|
|
|
|
|
|
if (resources.configuration.fontScale != fontScale) {
|
|
|
|
|
|
val configuration = resources.configuration
|
|
|
|
|
|
configuration.fontScale = fontScale
|
|
|
|
|
|
resources.updateConfiguration(configuration, resources.displayMetrics)
|
|
|
|
|
|
}
|
|
|
|
|
|
return resources
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-15 22:05:07 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 添加Activity
|
|
|
|
|
|
*/
|
|
|
|
|
|
fun addActivity(activity: Activity) {
|
|
|
|
|
|
// 判断当前集合中不存在该Activity
|
|
|
|
|
|
if (!mActivityList.contains(activity)) {
|
|
|
|
|
|
mActivityList.add(activity) //把当前Activity添加到集合中
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 销毁单个Activity
|
|
|
|
|
|
*/
|
|
|
|
|
|
@JvmOverloads
|
|
|
|
|
|
fun removeActivity(activity: Activity, finish: Boolean = false) {
|
|
|
|
|
|
//判断当前集合中存在该Activity
|
|
|
|
|
|
if (mActivityList.contains(activity)) {
|
|
|
|
|
|
mActivityList.remove(activity) //从集合中移除
|
|
|
|
|
|
if (finish) activity.finish() //销毁当前Activity
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 销毁所有的Activity
|
|
|
|
|
|
*/
|
|
|
|
|
|
fun removeAllActivity() {
|
|
|
|
|
|
//通过循环,把集合中的所有Activity销毁
|
|
|
|
|
|
for (activity in mActivityList) {
|
|
|
|
|
|
activity.finish()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
object ScreenInfo {
|
|
|
|
|
|
@JvmField
|
|
|
|
|
|
var EXACT_SCREEN_HEIGHT = 0
|
|
|
|
|
|
|
|
|
|
|
|
@JvmField
|
|
|
|
|
|
var EXACT_SCREEN_WIDTH = 0
|
|
|
|
|
|
|
|
|
|
|
|
@JvmField
|
|
|
|
|
|
var SCREEN_HEIGHT = 0
|
|
|
|
|
|
|
|
|
|
|
|
@JvmField
|
|
|
|
|
|
var SCREEN_WIDTH = 0
|
|
|
|
|
|
|
|
|
|
|
|
@JvmField
|
|
|
|
|
|
var DENSITY = 0f
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-03 20:36:11 +08:00
|
|
|
|
class MyDistributeListener : DistributeListener {
|
|
|
|
|
|
override fun onReleaseAvailable(
|
|
|
|
|
|
activity: Activity,
|
|
|
|
|
|
releaseDetails: ReleaseDetails
|
|
|
|
|
|
): Boolean {
|
|
|
|
|
|
val versionName = releaseDetails.shortVersion
|
|
|
|
|
|
val releaseNotes = releaseDetails.releaseNotes
|
|
|
|
|
|
if (activity is BaseActivity) {
|
|
|
|
|
|
activity.showDialog {
|
|
|
|
|
|
setTitle(activity.getString(R.string.title_dialog_update, versionName))
|
|
|
|
|
|
setMessage(releaseNotes)
|
|
|
|
|
|
setCancelable(!releaseDetails.isMandatoryUpdate)
|
|
|
|
|
|
setPositiveButton(R.string.appcenter_distribute_update_dialog_download) { _, _ ->
|
|
|
|
|
|
Distribute.notifyUpdateAction(UpdateAction.UPDATE)
|
|
|
|
|
|
}
|
|
|
|
|
|
if (!releaseDetails.isMandatoryUpdate) {
|
|
|
|
|
|
setNeutralButton(R.string.appcenter_distribute_update_dialog_postpone) { _, _ ->
|
|
|
|
|
|
Distribute.notifyUpdateAction(UpdateAction.POSTPONE)
|
|
|
|
|
|
}
|
|
|
|
|
|
setNegativeButton(R.string.button_next_time, null)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onNoReleaseAvailable(activity: Activity) {}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-15 22:05:07 +08:00
|
|
|
|
companion object {
|
2022-09-24 16:05:21 +08:00
|
|
|
|
val TAG = App::class.java.simpleName
|
2020-08-15 22:05:07 +08:00
|
|
|
|
|
2020-08-15 22:26:17 +08:00
|
|
|
|
@JvmStatic
|
|
|
|
|
|
var translucentBackground: Drawable? = null
|
|
|
|
|
|
|
2020-08-15 22:05:07 +08:00
|
|
|
|
private val packageName: String
|
2022-08-02 16:20:05 +08:00
|
|
|
|
get() = INSTANCE.packageName
|
2020-08-15 22:05:07 +08:00
|
|
|
|
|
|
|
|
|
|
@JvmStatic
|
2022-09-24 16:05:21 +08:00
|
|
|
|
lateinit var INSTANCE: App
|
2020-08-15 22:05:07 +08:00
|
|
|
|
private set
|
|
|
|
|
|
|
2022-06-23 20:19:42 +08:00
|
|
|
|
@JvmStatic
|
2022-08-07 16:56:50 +08:00
|
|
|
|
var oaid: String = ""
|
2022-06-23 20:19:42 +08:00
|
|
|
|
|
2020-08-15 22:05:07 +08:00
|
|
|
|
val isSystemNight: Boolean
|
|
|
|
|
|
get() = nightMode == Configuration.UI_MODE_NIGHT_YES
|
|
|
|
|
|
|
|
|
|
|
|
val isFirstRun: Boolean
|
2022-06-16 12:30:01 +08:00
|
|
|
|
get() = SharedPreferencesUtil.get(SharedPreferencesUtil.SP_APP_DATA)
|
|
|
|
|
|
.getBoolean("first", true)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
|
|
|
|
|
|
private val nightMode: Int
|
2022-08-02 16:20:05 +08:00
|
|
|
|
get() = INSTANCE.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
object ThemeDelegate : ThemeSwitcher {
|
2023-01-05 14:47:24 +08:00
|
|
|
|
@SuppressLint("DiscouragedApi")
|
2020-08-15 22:05:07 +08:00
|
|
|
|
fun getColorByAttr(context: Context, attrId: Int, theme: String): Int {
|
|
|
|
|
|
val resources = context.resources
|
|
|
|
|
|
when (attrId) {
|
|
|
|
|
|
R.attr.colorPrimary -> {
|
|
|
|
|
|
if (ThemeUtil.THEME_CUSTOM == theme) {
|
2020-08-22 11:16:42 +08:00
|
|
|
|
val customPrimaryColorStr = context.appPreferences.customPrimaryColor
|
2020-08-15 22:05:07 +08:00
|
|
|
|
return if (customPrimaryColorStr != null) {
|
|
|
|
|
|
Color.parseColor(customPrimaryColorStr)
|
2022-08-07 16:56:50 +08:00
|
|
|
|
} else getColorByAttr(context, attrId, ThemeUtil.THEME_BLUE)
|
2021-07-10 21:28:00 +08:00
|
|
|
|
} else if (ThemeUtil.isTranslucentTheme(theme)) {
|
2020-08-22 11:16:42 +08:00
|
|
|
|
val primaryColorStr = context.appPreferences.translucentPrimaryColor
|
2020-08-15 22:05:07 +08:00
|
|
|
|
return if (primaryColorStr != null) {
|
|
|
|
|
|
Color.parseColor(primaryColorStr)
|
2022-08-07 16:56:50 +08:00
|
|
|
|
} else getColorByAttr(context, attrId, ThemeUtil.THEME_BLUE)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
2022-06-16 12:30:01 +08:00
|
|
|
|
return context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_primary_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorAccent -> {
|
2021-07-10 21:28:00 +08:00
|
|
|
|
return if (ThemeUtil.THEME_CUSTOM == theme || ThemeUtil.isTranslucentTheme(theme)) {
|
2020-08-15 22:05:07 +08:00
|
|
|
|
getColorByAttr(context, R.attr.colorPrimary, theme)
|
2022-09-24 16:05:21 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_accent_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorNewAccent -> {
|
|
|
|
|
|
return if (ThemeUtil.isNightMode(theme)) {
|
|
|
|
|
|
context.getColorCompat(R.color.theme_color_accent_night)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
R.color.theme_color_accent_light
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
2021-07-10 21:28:00 +08:00
|
|
|
|
R.attr.colorOnAccent -> {
|
2022-09-24 16:05:21 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme) || ThemeUtil.isTranslucentTheme(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_on_accent_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2021-07-10 21:28:00 +08:00
|
|
|
|
} else context.getColorCompat(R.color.theme_color_on_accent_light)
|
|
|
|
|
|
}
|
2020-08-15 22:05:07 +08:00
|
|
|
|
R.attr.colorToolbar -> {
|
2022-08-07 16:56:50 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme) || ThemeUtil.isTranslucentTheme(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_toolbar_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2022-08-07 16:56:50 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
val isPrimaryColor = context.appPreferences.toolbarPrimaryColor
|
|
|
|
|
|
if (isPrimaryColor) {
|
|
|
|
|
|
getColorByAttr(context, R.attr.colorPrimary, theme)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
context.getColorCompat(R.color.white)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorText -> {
|
2021-07-10 21:28:00 +08:00
|
|
|
|
return if (ThemeUtil.isTranslucentTheme(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"color_text_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2022-09-24 16:05:21 +08:00
|
|
|
|
} else context.getColorCompat(if (ThemeUtil.isNightMode(theme)) R.color.color_text_night else R.color.color_text)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
R.attr.color_text_disabled -> {
|
2021-07-10 21:28:00 +08:00
|
|
|
|
return if (ThemeUtil.isTranslucentTheme(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"color_text_disabled_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2022-09-24 16:05:21 +08:00
|
|
|
|
} else context.getColorCompat(if (ThemeUtil.isNightMode(theme)) R.color.color_text_disabled_night else R.color.color_text_disabled)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorTextSecondary -> {
|
2021-07-10 21:28:00 +08:00
|
|
|
|
return if (ThemeUtil.isTranslucentTheme(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"color_text_secondary_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2022-09-24 16:05:21 +08:00
|
|
|
|
} else context.getColorCompat(if (ThemeUtil.isNightMode(theme)) R.color.color_text_secondary_night else R.color.color_text_secondary)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorTextOnPrimary -> {
|
2021-07-10 21:28:00 +08:00
|
|
|
|
return if (ThemeUtil.isTranslucentTheme(theme)) {
|
2020-08-15 22:05:07 +08:00
|
|
|
|
context.getColorCompat(R.color.white)
|
|
|
|
|
|
} else getColorByAttr(context, R.attr.colorBg, theme)
|
|
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorBg -> {
|
2021-07-10 21:28:00 +08:00
|
|
|
|
if (ThemeUtil.isTranslucentTheme(theme)) {
|
2020-08-15 22:05:07 +08:00
|
|
|
|
return context.getColorCompat(R.color.transparent)
|
|
|
|
|
|
}
|
2022-09-24 16:05:21 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_background_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
} else context.getColorCompat(R.color.theme_color_background_light)
|
|
|
|
|
|
}
|
2022-12-31 12:43:24 +08:00
|
|
|
|
R.attr.colorWindowBackground -> {
|
|
|
|
|
|
if (ThemeUtil.isTranslucentTheme(theme)) {
|
|
|
|
|
|
return context.getColorCompat(R.color.transparent)
|
|
|
|
|
|
}
|
|
|
|
|
|
return if (ThemeUtil.isNightMode()) {
|
|
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_window_background_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
|
|
|
|
|
} else context.getColorCompat(R.color.theme_color_window_background_light)
|
|
|
|
|
|
}
|
2022-09-24 16:05:21 +08:00
|
|
|
|
R.attr.colorChip -> {
|
2021-07-10 21:28:00 +08:00
|
|
|
|
if (ThemeUtil.isTranslucentTheme(theme)) {
|
2020-08-22 22:22:06 +08:00
|
|
|
|
return context.getColorCompat(R.color.transparent)
|
|
|
|
|
|
}
|
2022-09-24 16:05:21 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme)) {
|
2023-01-05 14:47:24 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_chip_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2022-09-24 16:05:21 +08:00
|
|
|
|
} else context.getColorCompat(R.color.theme_color_chip_light)
|
|
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorOnChip -> {
|
|
|
|
|
|
if (ThemeUtil.isTranslucentTheme(theme)) {
|
|
|
|
|
|
return getColorByAttr(context, R.attr.colorTextSecondary, theme)
|
|
|
|
|
|
}
|
|
|
|
|
|
return if (ThemeUtil.isNightMode(theme)) {
|
|
|
|
|
|
context.getColorCompat(R.color.theme_color_on_chip_night)
|
|
|
|
|
|
} else context.getColorCompat(R.color.theme_color_on_chip_light)
|
2020-08-22 22:22:06 +08:00
|
|
|
|
}
|
2020-08-15 22:05:07 +08:00
|
|
|
|
R.attr.colorUnselected -> {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
return context.getColorCompat(
|
2022-09-24 16:05:21 +08:00
|
|
|
|
if (ThemeUtil.isNightMode(theme)) resources.getIdentifier(
|
2022-06-16 12:30:01 +08:00
|
|
|
|
"theme_color_unselected_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
) else R.color.theme_color_unselected_day
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorNavBar -> {
|
2021-07-10 21:28:00 +08:00
|
|
|
|
if (ThemeUtil.isTranslucentTheme(theme)) {
|
2020-08-15 22:05:07 +08:00
|
|
|
|
return context.getColorCompat(R.color.transparent)
|
|
|
|
|
|
}
|
2022-09-24 16:05:21 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_nav_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2022-09-24 16:05:21 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
context.getColorCompat(R.color.theme_color_nav_light)
|
|
|
|
|
|
}
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorFloorCard -> {
|
2022-09-24 16:05:21 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme) || ThemeUtil.isTranslucentTheme(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_floor_card_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
} else context.getColorCompat(R.color.theme_color_floor_card_light)
|
|
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorCard -> {
|
2022-09-24 16:05:21 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme) || ThemeUtil.isTranslucentTheme(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_card_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
} else context.getColorCompat(R.color.theme_color_card_light)
|
|
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorDivider -> {
|
2022-09-24 16:05:21 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme) || ThemeUtil.isTranslucentTheme(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_divider_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
} else context.getColorCompat(R.color.theme_color_divider_light)
|
|
|
|
|
|
}
|
|
|
|
|
|
R.attr.shadow_color -> {
|
2021-07-10 21:28:00 +08:00
|
|
|
|
return if (ThemeUtil.isTranslucentTheme(theme)) {
|
2020-08-15 22:05:07 +08:00
|
|
|
|
context.getColorCompat(R.color.transparent)
|
2022-09-24 16:05:21 +08:00
|
|
|
|
} else context.getColorCompat(if (ThemeUtil.isNightMode(theme)) R.color.theme_color_shadow_night else R.color.theme_color_shadow_day)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorToolbarItem -> {
|
2021-07-10 21:28:00 +08:00
|
|
|
|
if (ThemeUtil.isTranslucentTheme(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
return context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_toolbar_item_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
2022-09-24 16:05:21 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme)) {
|
2020-08-15 22:05:07 +08:00
|
|
|
|
context.getColorCompat(R.color.theme_color_toolbar_item_night)
|
2022-08-07 16:56:50 +08:00
|
|
|
|
} else context.getColorCompat(if (ThemeUtil.isStatusBarFontDark()) R.color.theme_color_toolbar_item_light else R.color.theme_color_toolbar_item_dark)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorToolbarItemActive -> {
|
2022-08-07 16:56:50 +08:00
|
|
|
|
if (ThemeUtil.isTranslucentTheme(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
return context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_toolbar_item_active_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
} else if (ThemeUtil.isNightMode(theme)) {
|
|
|
|
|
|
return getColorByAttr(context, R.attr.colorAccent, theme)
|
|
|
|
|
|
}
|
2022-08-07 16:56:50 +08:00
|
|
|
|
return context.getColorCompat(if (ThemeUtil.isStatusBarFontDark()) R.color.theme_color_toolbar_item_light else R.color.theme_color_toolbar_item_dark)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
R.attr.color_toolbar_item_secondary -> {
|
2022-08-07 16:56:50 +08:00
|
|
|
|
return if (
|
|
|
|
|
|
ThemeUtil.isNightMode(theme) ||
|
|
|
|
|
|
ThemeUtil.isTranslucentTheme(theme)
|
2022-06-16 12:30:01 +08:00
|
|
|
|
) {
|
|
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_toolbar_item_secondary_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2022-08-07 16:56:50 +08:00
|
|
|
|
} else context.getColorCompat(if (ThemeUtil.isStatusBarFontDark()) R.color.theme_color_toolbar_item_secondary_white else R.color.theme_color_toolbar_item_secondary_light)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
R.attr.color_swipe_refresh_layout_background -> {
|
2021-07-10 21:28:00 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme) || ThemeUtil.isTranslucentTheme(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_swipe_refresh_view_background_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
} else context.getColorCompat(R.color.theme_color_swipe_refresh_view_background_light)
|
|
|
|
|
|
}
|
2020-11-14 17:02:56 +08:00
|
|
|
|
R.attr.colorToolbarBar -> {
|
2023-01-05 14:47:24 +08:00
|
|
|
|
return if (ThemeUtil.isTranslucentTheme(theme) || ThemeUtil.isNightMode(theme)) {
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_toolbar_bar_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2020-11-14 17:02:56 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
context.getColorCompat(R.color.theme_color_toolbar_bar_light)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorOnToolbarBar -> {
|
2022-09-24 16:05:21 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme) || ThemeUtil.getThemeTranslucent() == ThemeUtil.THEME_TRANSLUCENT_LIGHT) {
|
2020-11-14 17:02:56 +08:00
|
|
|
|
context.getColorCompat(R.color.theme_color_on_toolbar_bar_dark)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
context.getColorCompat(R.color.theme_color_on_toolbar_bar_light)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-02-01 18:36:34 +08:00
|
|
|
|
R.attr.colorNavBarSurface -> {
|
2022-09-24 16:05:21 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme)) {
|
2023-01-05 14:47:24 +08:00
|
|
|
|
context.getColorCompat(
|
|
|
|
|
|
resources.getIdentifier(
|
|
|
|
|
|
"theme_color_nav_bar_surface_$theme",
|
|
|
|
|
|
"color",
|
|
|
|
|
|
packageName
|
|
|
|
|
|
)
|
|
|
|
|
|
)
|
2021-02-01 18:36:34 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
context.getColorCompat(R.color.theme_color_nav_bar_surface_light)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
R.attr.colorOnNavBarSurface -> {
|
2022-09-24 16:05:21 +08:00
|
|
|
|
return if (ThemeUtil.isNightMode(theme)) {
|
2021-02-01 18:36:34 +08:00
|
|
|
|
context.getColorCompat(R.color.theme_color_on_nav_bar_surface_dark)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
context.getColorCompat(R.color.theme_color_on_nav_bar_surface_light)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
return Util.getColorByAttr(context, attrId, R.color.transparent)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun getColorByAttr(context: Context, attrId: Int): Int {
|
2022-08-07 16:56:50 +08:00
|
|
|
|
return getColorByAttr(context, attrId, ThemeUtil.getThemeTranslucent())
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun getColorById(context: Context, colorId: Int): Int {
|
|
|
|
|
|
when (colorId) {
|
|
|
|
|
|
R.color.default_color_primary -> return getColorByAttr(context, R.attr.colorPrimary)
|
|
|
|
|
|
R.color.default_color_accent -> return getColorByAttr(context, R.attr.colorAccent)
|
2022-06-16 12:30:01 +08:00
|
|
|
|
R.color.default_color_on_accent -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorOnAccent
|
|
|
|
|
|
)
|
2022-12-31 12:43:24 +08:00
|
|
|
|
|
2023-01-07 20:12:19 +08:00
|
|
|
|
R.color.default_color_chip -> return return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorChip
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2022-12-31 12:43:24 +08:00
|
|
|
|
R.color.default_color_background -> return getColorByAttr(
|
2022-06-16 12:30:01 +08:00
|
|
|
|
context,
|
2022-09-24 16:05:21 +08:00
|
|
|
|
R.attr.colorBg
|
2022-06-16 12:30:01 +08:00
|
|
|
|
)
|
2022-12-31 12:43:24 +08:00
|
|
|
|
|
|
|
|
|
|
R.color.default_color_window_background -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorWindowBackground
|
|
|
|
|
|
)
|
2023-01-05 14:47:24 +08:00
|
|
|
|
|
2020-08-15 22:05:07 +08:00
|
|
|
|
R.color.default_color_toolbar -> return getColorByAttr(context, R.attr.colorToolbar)
|
2022-06-16 12:30:01 +08:00
|
|
|
|
R.color.default_color_toolbar_item -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorToolbarItem
|
|
|
|
|
|
)
|
2023-01-05 14:47:24 +08:00
|
|
|
|
|
2022-06-16 12:30:01 +08:00
|
|
|
|
R.color.default_color_toolbar_item_active -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorToolbarItemActive
|
|
|
|
|
|
)
|
|
|
|
|
|
R.color.default_color_toolbar_item_secondary -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.color_toolbar_item_secondary
|
|
|
|
|
|
)
|
|
|
|
|
|
R.color.default_color_toolbar_bar -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorToolbarBar
|
|
|
|
|
|
)
|
|
|
|
|
|
R.color.default_color_on_toolbar_bar -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorOnToolbarBar
|
|
|
|
|
|
)
|
|
|
|
|
|
R.color.default_color_nav_bar_surface -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorNavBarSurface
|
|
|
|
|
|
)
|
|
|
|
|
|
R.color.default_color_on_nav_bar_surface -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorOnNavBarSurface
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
R.color.default_color_card -> return getColorByAttr(context, R.attr.colorCard)
|
2022-06-16 12:30:01 +08:00
|
|
|
|
R.color.default_color_floor_card -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorFloorCard
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
R.color.default_color_nav -> return getColorByAttr(context, R.attr.colorNavBar)
|
|
|
|
|
|
R.color.default_color_shadow -> return getColorByAttr(context, R.attr.shadow_color)
|
2022-06-16 12:30:01 +08:00
|
|
|
|
R.color.default_color_unselected -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorUnselected
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
R.color.default_color_text -> return getColorByAttr(context, R.attr.colorText)
|
2021-08-11 17:10:16 +08:00
|
|
|
|
R.color.default_color_text_on_primary -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorTextOnPrimary
|
|
|
|
|
|
)
|
|
|
|
|
|
R.color.default_color_text_secondary -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.colorTextSecondary
|
|
|
|
|
|
)
|
|
|
|
|
|
R.color.default_color_text_disabled -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.color_text_disabled
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
R.color.default_color_divider -> return getColorByAttr(context, R.attr.colorDivider)
|
2021-08-11 17:10:16 +08:00
|
|
|
|
R.color.default_color_swipe_refresh_view_background -> return getColorByAttr(
|
|
|
|
|
|
context,
|
|
|
|
|
|
R.attr.color_swipe_refresh_layout_background
|
|
|
|
|
|
)
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
return context.getColorCompat(colorId)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-08-11 17:10:16 +08:00
|
|
|
|
|
|
|
|
|
|
override fun getAppContext(): Context {
|
|
|
|
|
|
return this
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-19 16:59:13 +08:00
|
|
|
|
override fun getCurrentContext(): Context {
|
|
|
|
|
|
return mActivityList.lastOrNull() ?: this
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-11 17:10:16 +08:00
|
|
|
|
override fun launchUrl(url: String) {
|
2021-08-19 16:59:13 +08:00
|
|
|
|
launchUrl(getCurrentContext(), url)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun showLoadingDialog(): Dialog {
|
|
|
|
|
|
return LoadingDialog(getCurrentContext()).apply { show() }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun toastShort(text: String) {
|
|
|
|
|
|
getCurrentContext().toastShort(text)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun showAlertDialog(builder: AlertDialog.Builder.() -> Unit): AlertDialog {
|
|
|
|
|
|
val dialog = AlertDialog.Builder(getCurrentContext())
|
|
|
|
|
|
.apply(builder)
|
|
|
|
|
|
.create()
|
|
|
|
|
|
if (getCurrentContext() !is BaseActivity || (getCurrentContext() as BaseActivity).isActivityRunning) {
|
|
|
|
|
|
dialog.show()
|
|
|
|
|
|
}
|
|
|
|
|
|
return dialog
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun copyText(text: String) {
|
|
|
|
|
|
TiebaUtil.copyText(getCurrentContext(), text)
|
2021-08-11 17:10:16 +08:00
|
|
|
|
}
|
2022-09-24 16:05:21 +08:00
|
|
|
|
|
|
|
|
|
|
override fun createSketch(): Sketch = Sketch.Builder(this).apply {
|
2023-01-05 14:53:51 +08:00
|
|
|
|
httpStack(OkHttpStack.Builder().apply {
|
|
|
|
|
|
userAgent(System.getProperty("http.agent"))
|
|
|
|
|
|
}.build())
|
2022-09-24 16:05:21 +08:00
|
|
|
|
components {
|
2023-02-15 21:57:46 +08:00
|
|
|
|
addDrawableDecodeInterceptor(PauseLoadWhenScrollingDrawableDecodeInterceptor())
|
2022-09-24 16:05:21 +08:00
|
|
|
|
addDrawableDecoder(
|
|
|
|
|
|
when {
|
|
|
|
|
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P -> GifAnimatedDrawableDecoder.Factory()
|
|
|
|
|
|
else -> GifMovieDrawableDecoder.Factory()
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
|
|
|
|
addDrawableDecoder(WebpAnimatedDrawableDecoder.Factory())
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
|
|
|
|
addDrawableDecoder(HeifAnimatedDrawableDecoder.Factory())
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}.build()
|
2020-08-15 22:05:07 +08:00
|
|
|
|
}
|