chore: Dev 13
This commit is contained in:
parent
40d7218755
commit
22d7eeb2df
|
|
@ -5,6 +5,7 @@ import android.app.Activity
|
|||
import android.app.ActivityManager
|
||||
import android.app.Application
|
||||
import android.app.Dialog
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
|
|
@ -36,6 +37,8 @@ import com.huanchengfly.tieba.post.ui.common.theme.interfaces.ThemeSwitcher
|
|||
import com.huanchengfly.tieba.post.ui.common.theme.utils.ThemeUtils
|
||||
import com.huanchengfly.tieba.post.utils.AccountUtil
|
||||
import com.huanchengfly.tieba.post.utils.AppIconUtil
|
||||
import com.huanchengfly.tieba.post.utils.AppIconUtil.disableComponent
|
||||
import com.huanchengfly.tieba.post.utils.AppIconUtil.enableComponent
|
||||
import com.huanchengfly.tieba.post.utils.ClientUtils
|
||||
import com.huanchengfly.tieba.post.utils.EmoticonManager
|
||||
import com.huanchengfly.tieba.post.utils.Icons
|
||||
|
|
@ -94,7 +97,29 @@ class App : Application(), IApp, IGetter, SketchFactory {
|
|||
return null
|
||||
}
|
||||
|
||||
fun refreshIcon(enableNewUi: Boolean = applicationMetaData.getBoolean("enable_new_ui") || appPreferences.enableNewUi) {
|
||||
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)
|
||||
if (enableNewUi) AppIconUtil.setIcon()
|
||||
else AppIconUtil.setIcon(Icons.DISABLE)
|
||||
}
|
||||
|
|
@ -117,7 +142,7 @@ class App : Application(), IApp, IGetter, SketchFactory {
|
|||
Analytics::class.java, Crashes::class.java, Distribute::class.java
|
||||
)
|
||||
}
|
||||
refreshIcon()
|
||||
setIcon(keepOld = !BuildConfig.DEBUG && !isSelfBuild)
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
|
||||
ThemeUtils.init(ThemeDelegate)
|
||||
registerActivityLifecycleCallbacks(ClipBoardLinkDetector)
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ class PreferencesFragment : PreferencesFragment() {
|
|||
getString(R.string.tip_about, BuildConfig.VERSION_NAME)
|
||||
refresh()
|
||||
findPreference<SwitchPreference>("enableNewUi")?.setOnPreferenceChangeListener { _, newValue ->
|
||||
App.INSTANCE.refreshIcon(newValue == true)
|
||||
App.INSTANCE.setIcon(newValue == true)
|
||||
true
|
||||
}
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import androidx.compose.ui.platform.LocalContext
|
|||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.res.vectorResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.huanchengfly.tieba.post.App
|
||||
import com.huanchengfly.tieba.post.BuildConfig
|
||||
import com.huanchengfly.tieba.post.R
|
||||
import com.huanchengfly.tieba.post.dataStore
|
||||
|
|
@ -93,7 +94,10 @@ fun MoreSettingsPage(
|
|||
key = "enableNewUi",
|
||||
title = stringResource(id = R.string.title_enable_new_ui),
|
||||
defaultChecked = false,
|
||||
summary = stringResource(id = R.string.summary_enable_new_ui)
|
||||
summary = stringResource(id = R.string.summary_enable_new_ui),
|
||||
onCheckedChange = {
|
||||
App.INSTANCE.setIcon(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
prefsItem {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ object AppIconUtil {
|
|||
get() = context.appPreferences
|
||||
|
||||
fun setIcon(icon: String = appPreferences.appIcon ?: Icons.NEW_ICON) {
|
||||
val newIcon = if (Icons.ICONS.contains(icon)) {
|
||||
val newIcon = if (Icons.ICONS.contains(icon) || icon == Icons.DISABLE) {
|
||||
icon
|
||||
} else Icons.DEFAULT_ICON
|
||||
Icons.ICONS.forEach {
|
||||
|
|
@ -44,7 +44,7 @@ object AppIconUtil {
|
|||
*
|
||||
* @param componentName 组件名
|
||||
*/
|
||||
private fun PackageManager.enableComponent(componentName: ComponentName) {
|
||||
fun PackageManager.enableComponent(componentName: ComponentName) {
|
||||
setComponentEnabledSetting(
|
||||
componentName,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
||||
|
|
@ -57,7 +57,7 @@ object AppIconUtil {
|
|||
*
|
||||
* @param componentName 组件名
|
||||
*/
|
||||
private fun PackageManager.disableComponent(componentName: ComponentName) {
|
||||
fun PackageManager.disableComponent(componentName: ComponentName) {
|
||||
setComponentEnabledSetting(
|
||||
componentName,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
package com.huanchengfly.tieba.post.utils
|
||||
|
||||
import android.os.Environment
|
||||
import android.os.StatFs
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.util.Locale
|
||||
import java.util.regex.Pattern
|
||||
|
||||
object DeviceUtils {
|
||||
var coreNum = -1
|
||||
private const val CPU_MAX_INFO_FORMAT = "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq"
|
||||
private const val MEM_INFO_FILE = "/proc/meminfo"
|
||||
|
||||
fun getDeviceScore(): Float {
|
||||
val cpuCores = getDeviceCpuCore().takeIf { it > 0 } ?: 6.9822063f
|
||||
val cpuAverageFrequency = getDeviceCpuAverageFrequency().takeIf { it > 0 } ?: 1.7859616f
|
||||
val totalMemory = getTotalMemory().takeIf { it > 0 } ?: 3.5425532f
|
||||
val totalSDCardSize = getTotalSDCardSize().takeIf { it >= 0 } ?: 51.957294f
|
||||
// val deviceScore = round(totalMemory)*0.0572301f + roundUpRom
|
||||
return 0f
|
||||
}
|
||||
|
||||
fun getTotalSDCardSize(): Float {
|
||||
return runCatching {
|
||||
if (Environment.getExternalStorageState().equals("mounted")) {
|
||||
val path = Environment.getExternalStorageDirectory().path
|
||||
val stat = StatFs(path)
|
||||
val blockSize = stat.blockSizeLong
|
||||
val totalBlocks = stat.blockCountLong
|
||||
val totalSize = totalBlocks * blockSize
|
||||
totalSize / 1024f / 1024 / 1024
|
||||
} else -1f
|
||||
}.getOrDefault(-1f)
|
||||
}
|
||||
|
||||
fun getTotalMemory(): Float {
|
||||
val memory = runCatching {
|
||||
File(MEM_INFO_FILE).bufferedReader(bufferSize = 8192).use { reader ->
|
||||
reader.readLine().split("\\s+".toRegex()).takeIf { it.size >= 2 }?.get(1)
|
||||
?.toLongOrNull() ?: 0
|
||||
}
|
||||
}.getOrDefault(0L)
|
||||
return if (memory > 0) memory.toFloat() / 1024 / 1024
|
||||
else -1f
|
||||
}
|
||||
|
||||
// 获取手机 CPU 平均核心频率
|
||||
fun getDeviceCpuAverageFrequency(): Float {
|
||||
var totalFrequency = 0f
|
||||
val coreNum = getDeviceCpuCore()
|
||||
for (i in 0 until coreNum) {
|
||||
totalFrequency += getDeviceCpuFrequency(i)
|
||||
}
|
||||
return totalFrequency / coreNum
|
||||
}
|
||||
|
||||
// 获取手机 CPU 某个核心的频率
|
||||
fun getDeviceCpuFrequency(core: Int): Float {
|
||||
return getContentFromFileInfo(
|
||||
CPU_MAX_INFO_FORMAT.format(
|
||||
Locale.ENGLISH,
|
||||
core
|
||||
)
|
||||
).toFloatOrNull() ?: -1f
|
||||
}
|
||||
|
||||
// 获取手机 CPU 核心数
|
||||
fun getDeviceCpuCore(): Int {
|
||||
return coreNum.takeIf { it > 0 } ?: runCatching {
|
||||
File("/sys/devices/system/cpu").listFiles { file ->
|
||||
Pattern.matches("cpu[0-9]", file.name)
|
||||
}?.size ?: -1
|
||||
}.getOrDefault(-1).also { coreNum = it }
|
||||
}
|
||||
|
||||
private fun getContentFromFileInfo(filePath: String): String {
|
||||
return try {
|
||||
File(filePath).bufferedReader().use { it.readLine() }
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
versionCode=39012
|
||||
versionCode=39013
|
||||
versionName=4.0.0
|
||||
isPerRelease=true
|
||||
preReleaseName=dev
|
||||
preReleaseVer=12
|
||||
preReleaseVer=13
|
||||
Loading…
Reference in New Issue