diff --git a/app/src/main/java/io/github/chinosk/gakumas/localify/ActivityExtends.kt b/app/src/main/java/io/github/chinosk/gakumas/localify/ActivityExtends.kt new file mode 100644 index 0000000..8bbc440 --- /dev/null +++ b/app/src/main/java/io/github/chinosk/gakumas/localify/ActivityExtends.kt @@ -0,0 +1,104 @@ +package io.github.chinosk.gakumas.localify + +import android.app.Activity +import android.content.Intent +import androidx.core.content.FileProvider +import io.github.chinosk.gakumas.localify.GakumasHookMain.Companion.showToast +import io.github.chinosk.gakumas.localify.mainUtils.json +import io.github.chinosk.gakumas.localify.models.GakumasConfig +import io.github.chinosk.gakumas.localify.models.ProgramConfig +import io.github.chinosk.gakumas.localify.models.ProgramConfigSerializer +import kotlinx.serialization.SerializationException +import java.io.File + + +interface IHasConfigItems { + var config: GakumasConfig + var programConfig: ProgramConfig + + fun saveConfig() {} // do nothing +} + +interface IConfigurableActivity : IHasConfigItems + + +fun T.getConfigContent(): String where T : Activity { + val configFile = File(filesDir, "gkms-config.json") + return if (configFile.exists()) { + configFile.readText() + } else { + showToast("检测到第一次启动,初始化配置文件...") + "{}" + } +} + +fun T.getProgramConfigContent( + excludes: List = emptyList(), + origProgramConfig: ProgramConfig? = null +): String where T : Activity { + val configFile = File(filesDir, "localify-config.json") + if (excludes.isEmpty()) { + return if (configFile.exists()) { + configFile.readText() + } else { + "{}" + } + } else { + return if (origProgramConfig == null) { + if (configFile.exists()) { + val parsedConfig = json.decodeFromString(configFile.readText()) + json.encodeToString(ProgramConfigSerializer(excludes), parsedConfig) + } else { + "{}" + } + } else { + json.encodeToString(ProgramConfigSerializer(excludes), origProgramConfig) + } + } +} + +fun T.loadConfig() where T : Activity, T : IHasConfigItems { + val configStr = getConfigContent() + config = try { + json.decodeFromString(configStr) + } catch (e: SerializationException) { + showToast("配置文件异常,已重置: $e") + GakumasConfig() + } + saveConfig() + + val programConfigStr = getProgramConfigContent() + programConfig = try { + json.decodeFromString(programConfigStr) + } catch (e: SerializationException) { + ProgramConfig() + } +} + +fun T.onClickStartGame() where T : Activity, T : IHasConfigItems { + val intent = Intent().apply { + setClassName( + "com.bandainamcoent.idolmaster_gakuen", + "com.google.firebase.MessagingUnityPlayerActivity" + ) + putExtra("gkmsData", getConfigContent()) + putExtra( + "localData", + getProgramConfigContent(listOf("transRemoteZipUrl", "p"), programConfig) + ) + flags = Intent.FLAG_ACTIVITY_NEW_TASK + } + + val updateFile = File(filesDir, "update_trans.zip") + if (updateFile.exists()) { + val dirUri = FileProvider.getUriForFile( + this, + "io.github.chinosk.gakumas.localify.fileprovider", + File(updateFile.absolutePath) + ) + intent.setDataAndType(dirUri, "resource/file") + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) + } + + startActivity(intent) +} diff --git a/app/src/main/java/io/github/chinosk/gakumas/localify/ConfigUpdateListener.kt b/app/src/main/java/io/github/chinosk/gakumas/localify/ConfigUpdateListener.kt index 9c88aca..b7117b4 100644 --- a/app/src/main/java/io/github/chinosk/gakumas/localify/ConfigUpdateListener.kt +++ b/app/src/main/java/io/github/chinosk/gakumas/localify/ConfigUpdateListener.kt @@ -13,7 +13,6 @@ import kotlinx.coroutines.flow.asStateFlow interface ConfigListener { - fun onClickStartGame() fun onEnabledChanged(value: Boolean) fun onForceExportResourceChanged(value: Boolean) fun onTextTestChanged(value: Boolean) @@ -81,19 +80,16 @@ class UserConfigViewModel(initValue: GakumasConfig) : ViewModel() { } -interface ConfigUpdateListener: ConfigListener { - val config: GakumasConfig +interface ConfigUpdateListener: ConfigListener, IHasConfigItems { var factory: UserConfigViewModelFactory var viewModel: UserConfigViewModel - var programConfig: ProgramConfig var programConfigFactory: ProgramConfigViewModelFactory var programConfigViewModel: ProgramConfigViewModel fun pushKeyEvent(event: KeyEvent): Boolean - fun getConfigContent(): String - fun checkConfigAndUpdateView() - fun saveConfig() + fun checkConfigAndUpdateView() {} // do nothing + // fun saveConfig() fun saveProgramConfig() diff --git a/app/src/main/java/io/github/chinosk/gakumas/localify/MainActivity.kt b/app/src/main/java/io/github/chinosk/gakumas/localify/MainActivity.kt index 7339ebf..3bbc159 100644 --- a/app/src/main/java/io/github/chinosk/gakumas/localify/MainActivity.kt +++ b/app/src/main/java/io/github/chinosk/gakumas/localify/MainActivity.kt @@ -12,7 +12,6 @@ import androidx.activity.compose.setContent import androidx.compose.runtime.Composable import androidx.compose.runtime.State import androidx.compose.runtime.collectAsState -import androidx.core.content.FileProvider import androidx.lifecycle.ViewModelProvider import io.github.chinosk.gakumas.localify.hookUtils.FileHotUpdater import io.github.chinosk.gakumas.localify.hookUtils.FilesChecker @@ -20,19 +19,17 @@ import io.github.chinosk.gakumas.localify.hookUtils.MainKeyEventDispatcher import io.github.chinosk.gakumas.localify.mainUtils.json import io.github.chinosk.gakumas.localify.models.GakumasConfig import io.github.chinosk.gakumas.localify.models.ProgramConfig -import io.github.chinosk.gakumas.localify.models.ProgramConfigSerializer import io.github.chinosk.gakumas.localify.models.ProgramConfigViewModel import io.github.chinosk.gakumas.localify.models.ProgramConfigViewModelFactory import io.github.chinosk.gakumas.localify.ui.pages.MainUI import io.github.chinosk.gakumas.localify.ui.theme.GakumasLocalifyTheme import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow -import kotlinx.serialization.SerializationException import kotlinx.serialization.encodeToString import java.io.File -class MainActivity : ComponentActivity(), ConfigUpdateListener { +class MainActivity : ComponentActivity(), ConfigUpdateListener, IConfigurableActivity { override lateinit var config: GakumasConfig override lateinit var programConfig: ProgramConfig @@ -42,56 +39,14 @@ class MainActivity : ComponentActivity(), ConfigUpdateListener { override lateinit var programConfigFactory: ProgramConfigViewModelFactory override lateinit var programConfigViewModel: ProgramConfigViewModel - override fun onClickStartGame() { - val intent = Intent().apply { - setClassName("com.bandainamcoent.idolmaster_gakuen", "com.google.firebase.MessagingUnityPlayerActivity") - putExtra("gkmsData", getConfigContent()) - putExtra("localData", getProgramConfigContent(listOf("transRemoteZipUrl", "p"))) - flags = Intent.FLAG_ACTIVITY_NEW_TASK - } - - val updateFile = File(filesDir, "update_trans.zip") - if (updateFile.exists()) { - val dirUri = FileProvider.getUriForFile(this, "io.github.chinosk.gakumas.localify.fileprovider", File(updateFile.absolutePath)) - intent.setDataAndType(dirUri, "resource/file") - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) - } - - startActivity(intent) - } private fun showToast(message: String) { Toast.makeText(this, message, Toast.LENGTH_SHORT).show() } - override fun getConfigContent(): String { - val configFile = File(filesDir, "gkms-config.json") - return if (configFile.exists()) { - configFile.readText() - } - else { - showToast("检测到第一次启动,初始化配置文件...") - "{}" - } - } - - private fun getProgramConfigContent(excludes: List = emptyList()): String { - if (excludes.isEmpty()) { - val configFile = File(filesDir, "localify-config.json") - return if (configFile.exists()) { - configFile.readText() - } - else { - "{}" - } - } - else { - return json.encodeToString(ProgramConfigSerializer(excludes), programConfig) - } - } - override fun saveConfig() { try { + config.pf = false viewModel.configState.value = config.copy( pf = true ) // 更新 UI } catch (e: RuntimeException) { @@ -137,30 +92,6 @@ class MainActivity : ComponentActivity(), ConfigUpdateListener { startActivity(intent) } - private fun loadConfig() { - val configStr = getConfigContent() - config = try { - json.decodeFromString(configStr) - } - catch (e: SerializationException) { - showToast("配置文件异常,已重置: $e") - GakumasConfig() - } - saveConfig() - - val programConfigStr = getProgramConfigContent() - programConfig = try { - json.decodeFromString(programConfigStr) - } - catch (e: SerializationException) { - ProgramConfig() - } - } - - override fun checkConfigAndUpdateView() { - - } - override fun pushKeyEvent(event: KeyEvent): Boolean { return dispatchKeyEvent(event) } diff --git a/app/src/main/java/io/github/chinosk/gakumas/localify/TranslucentActivity.kt b/app/src/main/java/io/github/chinosk/gakumas/localify/TranslucentActivity.kt index 095aa71..43213af 100644 --- a/app/src/main/java/io/github/chinosk/gakumas/localify/TranslucentActivity.kt +++ b/app/src/main/java/io/github/chinosk/gakumas/localify/TranslucentActivity.kt @@ -1,19 +1,14 @@ package io.github.chinosk.gakumas.localify -import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity -import androidx.core.content.FileProvider -import io.github.chinosk.gakumas.localify.GakumasHookMain.Companion.showToast -import io.github.chinosk.gakumas.localify.mainUtils.json import io.github.chinosk.gakumas.localify.models.GakumasConfig import io.github.chinosk.gakumas.localify.models.ProgramConfig -import io.github.chinosk.gakumas.localify.models.ProgramConfigSerializer -import kotlinx.serialization.SerializationException -import java.io.File -class TranslucentActivity : ComponentActivity() { - private lateinit var programConfig: ProgramConfig + +class TranslucentActivity : ComponentActivity(), IConfigurableActivity { + override lateinit var config: GakumasConfig + override lateinit var programConfig: ProgramConfig override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -26,66 +21,4 @@ class TranslucentActivity : ComponentActivity() { } } } - - private fun loadConfig() { - val configStr = getConfigContent() - try { - json.decodeFromString(configStr) - } catch (e: SerializationException) { - showToast("配置文件异常,已重置: $e") - GakumasConfig() - } - - val programConfigStr = getProgramConfigContent() - programConfig = try { - json.decodeFromString(programConfigStr) - } - catch (e: SerializationException) { - ProgramConfig() - } - } - - private fun onClickStartGame() { - val intent = Intent().apply { - setClassName("com.bandainamcoent.idolmaster_gakuen", "com.google.firebase.MessagingUnityPlayerActivity") - putExtra("gkmsData", getConfigContent()) - putExtra("localData", getProgramConfigContent(listOf("transRemoteZipUrl", "p"))) - flags = Intent.FLAG_ACTIVITY_NEW_TASK - } - - val updateFile = File(filesDir, "update_trans.zip") - if (updateFile.exists()) { - val dirUri = FileProvider.getUriForFile(this, "io.github.chinosk.gakumas.localify.fileprovider", File(updateFile.absolutePath)) - intent.setDataAndType(dirUri, "resource/file") - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION) - } - - startActivity(intent) - } - - private fun getConfigContent(): String { - val configFile = File(filesDir, "gkms-config.json") - return if (configFile.exists()) { - configFile.readText() - } - else { - showToast("检测到第一次启动,初始化配置文件...") - "{}" - } - } - - private fun getProgramConfigContent(excludes: List = emptyList()): String { - if (excludes.isEmpty()) { - val configFile = File(filesDir, "localify-config.json") - return if (configFile.exists()) { - configFile.readText() - } - else { - "{}" - } - } - else { - return json.encodeToString(ProgramConfigSerializer(excludes), programConfig) - } - } } diff --git a/app/src/main/java/io/github/chinosk/gakumas/localify/ui/pages/SettingsTab.kt b/app/src/main/java/io/github/chinosk/gakumas/localify/ui/pages/SettingsTab.kt index b6b8f80..7570648 100644 --- a/app/src/main/java/io/github/chinosk/gakumas/localify/ui/pages/SettingsTab.kt +++ b/app/src/main/java/io/github/chinosk/gakumas/localify/ui/pages/SettingsTab.kt @@ -24,6 +24,7 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import io.github.chinosk.gakumas.localify.MainActivity import io.github.chinosk.gakumas.localify.models.GakumasConfig +import io.github.chinosk.gakumas.localify.onClickStartGame import io.github.chinosk.gakumas.localify.ui.components.GakuTabRow import io.github.chinosk.gakumas.localify.ui.pages.subPages.AboutPage import io.github.chinosk.gakumas.localify.ui.pages.subPages.AdvanceSettingsPage diff --git a/app/src/main/res/drawable-hdpi/splash.png b/app/src/main/res/drawable-hdpi/splash.png new file mode 100644 index 0000000..169884e Binary files /dev/null and b/app/src/main/res/drawable-hdpi/splash.png differ diff --git a/app/src/main/res/drawable-mdpi/splash.png b/app/src/main/res/drawable-mdpi/splash.png new file mode 100644 index 0000000..503701b Binary files /dev/null and b/app/src/main/res/drawable-mdpi/splash.png differ diff --git a/app/src/main/res/drawable-xhdpi/splash.png b/app/src/main/res/drawable-xhdpi/splash.png new file mode 100644 index 0000000..b5090f8 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/splash.png differ diff --git a/app/src/main/res/drawable-xxhdpi/splash.png b/app/src/main/res/drawable-xxhdpi/splash.png new file mode 100644 index 0000000..e1abdf3 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/splash.png differ diff --git a/app/src/main/res/drawable/splash_style.xml b/app/src/main/res/drawable/splash_style.xml new file mode 100644 index 0000000..ccd389f --- /dev/null +++ b/app/src/main/res/drawable/splash_style.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index be04875..3d3f98f 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,7 +1,7 @@