refactor: simplify handling and add app restart utility
This commit is contained in:
@@ -20,7 +20,6 @@ import androidx.compose.ui.graphics.graphicsLayer
|
|||||||
import androidx.compose.ui.input.pointer.pointerInput
|
import androidx.compose.ui.input.pointer.pointerInput
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.platform.LocalDensity
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
@@ -138,7 +137,7 @@ fun ImageEditorDialog(
|
|||||||
0f
|
0f
|
||||||
}
|
}
|
||||||
updateTransformation(newScale, newOffsetX, newOffsetY)
|
updateTransformation(newScale, newOffsetX, newOffsetY)
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
updateTransformation(lastScale, lastOffsetX, lastOffsetY)
|
updateTransformation(lastScale, lastOffsetX, lastOffsetY)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,7 +185,7 @@ fun ImageEditorDialog(
|
|||||||
val transformation = BackgroundTransformation(scale, offsetX, offsetY)
|
val transformation = BackgroundTransformation(scale, offsetX, offsetY)
|
||||||
val savedUri = context.saveTransformedBackground(imageUri, transformation)
|
val savedUri = context.saveTransformedBackground(imageUri, transformation)
|
||||||
savedUri?.let { onConfirm(it) }
|
savedUri?.let { onConfirm(it) }
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import android.annotation.SuppressLint
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.ComponentName
|
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@@ -92,6 +90,7 @@ import androidx.compose.material3.TextButton
|
|||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||||
|
import com.sukisu.ultra.ui.util.restartApp
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ShirkNeko
|
* @author ShirkNeko
|
||||||
@@ -107,22 +106,6 @@ fun saveCardConfig(context: Context) {
|
|||||||
CardConfig.save(context)
|
CardConfig.save(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 切换启动器图标
|
|
||||||
*/
|
|
||||||
fun toggleLauncherIcon(context: Context, useAlt: Boolean) {
|
|
||||||
val pm = context.packageManager
|
|
||||||
val main = ComponentName(context, MainActivity::class.java.name)
|
|
||||||
val alt = ComponentName(context, "${MainActivity::class.java.name}Alias")
|
|
||||||
if (useAlt) {
|
|
||||||
pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
|
|
||||||
pm.setComponentEnabledSetting(alt, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
|
|
||||||
} else {
|
|
||||||
pm.setComponentEnabledSetting(alt, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
|
|
||||||
pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更多设置屏幕
|
* 更多设置屏幕
|
||||||
*/
|
*/
|
||||||
@@ -313,28 +296,14 @@ fun MoreSettingsScreen(
|
|||||||
val onHideOtherInfoChange = { newValue: Boolean ->
|
val onHideOtherInfoChange = { newValue: Boolean ->
|
||||||
prefs.edit { putBoolean("is_hide_other_info", newValue) }
|
prefs.edit { putBoolean("is_hide_other_info", newValue) }
|
||||||
isHideOtherInfo = newValue
|
isHideOtherInfo = newValue
|
||||||
|
context.restartApp(MainActivity::class.java)
|
||||||
val intent = Intent(context, MainActivity::class.java)
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
context.startActivity(intent)
|
|
||||||
|
|
||||||
if (context is Activity) {
|
|
||||||
context.finish()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新显示KPM开关状态
|
// 更新显示KPM开关状态
|
||||||
val onShowKpmInfoChange = { newValue: Boolean ->
|
val onShowKpmInfoChange = { newValue: Boolean ->
|
||||||
prefs.edit { putBoolean("show_kpm_info", newValue) }
|
prefs.edit { putBoolean("show_kpm_info", newValue) }
|
||||||
isShowKpmInfo = newValue
|
isShowKpmInfo = newValue
|
||||||
|
context.restartApp(MainActivity::class.java)
|
||||||
val intent = Intent(context, MainActivity::class.java)
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
context.startActivity(intent)
|
|
||||||
|
|
||||||
if (context is Activity) {
|
|
||||||
context.finish()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 隐藏SuSFS状态开关状态
|
// 隐藏SuSFS状态开关状态
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.sukisu.ultra.ui.util
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import com.sukisu.ultra.ui.MainActivity
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重启应用程序
|
||||||
|
**/
|
||||||
|
|
||||||
|
fun Context.restartApp(
|
||||||
|
activityClass: Class<out Activity>,
|
||||||
|
finishCurrent: Boolean = true,
|
||||||
|
clearTask: Boolean = true,
|
||||||
|
newTask: Boolean = true
|
||||||
|
) {
|
||||||
|
val intent = Intent(this, activityClass)
|
||||||
|
if (clearTask) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||||
|
if (newTask) intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
startActivity(intent)
|
||||||
|
|
||||||
|
if (finishCurrent && this is Activity) {
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新启动器图标
|
||||||
|
*/
|
||||||
|
fun toggleLauncherIcon(context: Context, useAlt: Boolean) {
|
||||||
|
val pm = context.packageManager
|
||||||
|
val main = ComponentName(context, MainActivity::class.java.name)
|
||||||
|
val alt = ComponentName(context, "${MainActivity::class.java.name}Alias")
|
||||||
|
if (useAlt) {
|
||||||
|
pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
|
||||||
|
pm.setComponentEnabledSetting(alt, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
|
||||||
|
} else {
|
||||||
|
pm.setComponentEnabledSetting(alt, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
|
||||||
|
pm.setComponentEnabledSetting(main, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user