Fix theme

This commit is contained in:
世界 2024-03-13 23:01:58 +08:00
parent 7ac5786548
commit 31f51a3974
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
7 changed files with 78 additions and 27 deletions

View file

@ -26,7 +26,7 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.Material3.DayNight"
android:theme="@style/AppTheme"
tools:targetApi="31">
<meta-data
@ -37,7 +37,7 @@
android:name=".ui.MainActivity"
android:exported="true"
android:icon="@mipmap/ic_launcher"
android:theme="@style/Theme.Material3.DayNight.NoActionBar"
android:theme="@style/AppTheme.NoActionBar"
android:launchMode="singleTask">
<meta-data

View file

@ -8,7 +8,6 @@ import android.net.Uri
import android.net.VpnService
import android.os.Build
import android.os.Bundle
import android.os.Process
import android.text.Html
import androidx.activity.result.contract.ActivityResultContract
import androidx.activity.result.contract.ActivityResultContracts
@ -45,6 +44,7 @@ import io.nekohasekai.sfa.ktx.hasPermission
import io.nekohasekai.sfa.ui.profile.NewProfileActivity
import io.nekohasekai.sfa.ui.settings.CoreFragment
import io.nekohasekai.sfa.ui.shared.AbstractActivity
import io.nekohasekai.sfa.utils.MIUIUtils
import io.nekohasekai.sfa.vendor.Vendor
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
@ -414,12 +414,9 @@ class MainActivity : AbstractActivity(),
}
private fun openPermissionSettings() {
if (!getSystemProperty("ro.miui.ui.version.name").isNullOrBlank()) {
val intent = Intent("miui.intent.action.APP_PERM_EDITOR")
intent.putExtra("extra_package_uid", Process.myUid())
intent.putExtra("extra_pkgname", packageName)
if (MIUIUtils.isMIUI) {
try {
startActivity(intent)
MIUIUtils.openPermissionSettings(this)
return
} catch (ignored: Exception) {
}
@ -434,15 +431,6 @@ class MainActivity : AbstractActivity(),
}
}
@SuppressLint("PrivateApi")
fun getSystemProperty(key: String?): String? {
try {
return Class.forName("android.os.SystemProperties").getMethod("get", String::class.java)
.invoke(null, key) as String
} catch (ignored: Exception) {
}
return null
}
private var paused = false
override fun onPause() {

View file

@ -36,12 +36,6 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
val binding = binding ?: return
binding.dashboardPager.adapter = Adapter(this)
binding.dashboardPager.offscreenPageLimit = Page.values().size
mediator = TabLayoutMediator(
activity.binding.dashboardTabLayout,
binding.dashboardPager
) { tab, position ->
tab.setText(Page.values()[position].titleRes)
}.apply { attach() }
activity.serviceStatus.observe(viewLifecycleOwner) {
when (it) {
Status.Stopped -> {
@ -83,6 +77,19 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
}
}
override fun onStart() {
super.onStart()
val activity = activity ?: return
val binding = binding ?: return
if (mediator != null) return
mediator = TabLayoutMediator(
activity.binding.dashboardTabLayout,
binding.dashboardPager
) { tab, position ->
tab.setText(Page.values()[position].titleRes)
}.apply { attach() }
}
override fun onDestroyView() {
super.onDestroyView()
mediator?.detach()

View file

@ -2,12 +2,13 @@ package io.nekohasekai.sfa.ui.shared
import android.os.Bundle
import android.view.MenuItem
import android.view.WindowManager
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import com.google.android.material.color.DynamicColors
import io.nekohasekai.sfa.R
import io.nekohasekai.sfa.ktx.getAttrColor
import io.nekohasekai.sfa.utils.MIUIUtils
abstract class AbstractActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
@ -20,9 +21,14 @@ abstract class AbstractActivity : AppCompatActivity() {
window.statusBarColor = colorSurfaceContainer
window.navigationBarColor = colorSurfaceContainer
// MIUI overrides colorSurfaceContainer to colorSurface without below flags
@Suppress("DEPRECATION") if (MIUIUtils.isMIUI) {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION)
}
supportActionBar?.setHomeAsUpIndicator(AppCompatResources.getDrawable(
this@AbstractActivity,
R.drawable.ic_arrow_back_24
this@AbstractActivity, R.drawable.ic_arrow_back_24
)!!.apply {
setTint(getAttrColor(com.google.android.material.R.attr.colorOnSurface))
})

View file

@ -0,0 +1,31 @@
package io.nekohasekai.sfa.utils
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Process
object MIUIUtils {
val isMIUI by lazy {
!getSystemProperty("ro.miui.ui.version.name").isNullOrBlank()
}
@SuppressLint("PrivateApi")
fun getSystemProperty(key: String?): String? {
try {
return Class.forName("android.os.SystemProperties").getMethod("get", String::class.java)
.invoke(null, key) as String
} catch (ignored: Exception) {
}
return null
}
fun openPermissionSettings(context: Context) {
val intent = Intent("miui.intent.action.APP_PERM_EDITOR")
intent.putExtra("extra_package_uid", Process.myUid())
intent.putExtra("extra_pkgname", context.packageName)
context.startActivity(intent)
}
}

View file

@ -0,0 +1,11 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="Theme.Material3.DayNight">
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
</style>
<style name="AppTheme.NoActionBar" parent="Theme.Material3.DayNight.NoActionBar">
<item name="android:windowLightStatusBar" tools:targetApi="m">false</item>
</style>
</resources>

View file

@ -1,4 +1,12 @@
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="AppTheme" parent="Theme.Material3.DayNight">
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
</style>
<style name="AppTheme.NoActionBar" parent="Theme.Material3.DayNight.NoActionBar">
<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
</style>
<style name="AppTheme.Translucent" parent="Theme.Material3.DayNight.Dialog.Alert">
<item name="android:background">@android:color/transparent</item>