extend configurables, optimize image stretching
This commit is contained in:
parent
96cf7267ee
commit
157acde596
@ -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<T : Activity> : IHasConfigItems
|
||||||
|
|
||||||
|
|
||||||
|
fun <T> T.getConfigContent(): String where T : Activity {
|
||||||
|
val configFile = File(filesDir, "gkms-config.json")
|
||||||
|
return if (configFile.exists()) {
|
||||||
|
configFile.readText()
|
||||||
|
} else {
|
||||||
|
showToast("检测到第一次启动,初始化配置文件...")
|
||||||
|
"{}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> T.getProgramConfigContent(
|
||||||
|
excludes: List<String> = 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<ProgramConfig>(configFile.readText())
|
||||||
|
json.encodeToString(ProgramConfigSerializer(excludes), parsedConfig)
|
||||||
|
} else {
|
||||||
|
"{}"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
json.encodeToString(ProgramConfigSerializer(excludes), origProgramConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> T.loadConfig() where T : Activity, T : IHasConfigItems {
|
||||||
|
val configStr = getConfigContent()
|
||||||
|
config = try {
|
||||||
|
json.decodeFromString<GakumasConfig>(configStr)
|
||||||
|
} catch (e: SerializationException) {
|
||||||
|
showToast("配置文件异常,已重置: $e")
|
||||||
|
GakumasConfig()
|
||||||
|
}
|
||||||
|
saveConfig()
|
||||||
|
|
||||||
|
val programConfigStr = getProgramConfigContent()
|
||||||
|
programConfig = try {
|
||||||
|
json.decodeFromString<ProgramConfig>(programConfigStr)
|
||||||
|
} catch (e: SerializationException) {
|
||||||
|
ProgramConfig()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T> 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)
|
||||||
|
}
|
@ -13,7 +13,6 @@ import kotlinx.coroutines.flow.asStateFlow
|
|||||||
|
|
||||||
|
|
||||||
interface ConfigListener {
|
interface ConfigListener {
|
||||||
fun onClickStartGame()
|
|
||||||
fun onEnabledChanged(value: Boolean)
|
fun onEnabledChanged(value: Boolean)
|
||||||
fun onForceExportResourceChanged(value: Boolean)
|
fun onForceExportResourceChanged(value: Boolean)
|
||||||
fun onTextTestChanged(value: Boolean)
|
fun onTextTestChanged(value: Boolean)
|
||||||
@ -81,19 +80,16 @@ class UserConfigViewModel(initValue: GakumasConfig) : ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface ConfigUpdateListener: ConfigListener {
|
interface ConfigUpdateListener: ConfigListener, IHasConfigItems {
|
||||||
val config: GakumasConfig
|
|
||||||
var factory: UserConfigViewModelFactory
|
var factory: UserConfigViewModelFactory
|
||||||
var viewModel: UserConfigViewModel
|
var viewModel: UserConfigViewModel
|
||||||
|
|
||||||
var programConfig: ProgramConfig
|
|
||||||
var programConfigFactory: ProgramConfigViewModelFactory
|
var programConfigFactory: ProgramConfigViewModelFactory
|
||||||
var programConfigViewModel: ProgramConfigViewModel
|
var programConfigViewModel: ProgramConfigViewModel
|
||||||
|
|
||||||
fun pushKeyEvent(event: KeyEvent): Boolean
|
fun pushKeyEvent(event: KeyEvent): Boolean
|
||||||
fun getConfigContent(): String
|
fun checkConfigAndUpdateView() {} // do nothing
|
||||||
fun checkConfigAndUpdateView()
|
// fun saveConfig()
|
||||||
fun saveConfig()
|
|
||||||
fun saveProgramConfig()
|
fun saveProgramConfig()
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import androidx.activity.compose.setContent
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.State
|
import androidx.compose.runtime.State
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import androidx.core.content.FileProvider
|
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import io.github.chinosk.gakumas.localify.hookUtils.FileHotUpdater
|
import io.github.chinosk.gakumas.localify.hookUtils.FileHotUpdater
|
||||||
import io.github.chinosk.gakumas.localify.hookUtils.FilesChecker
|
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.mainUtils.json
|
||||||
import io.github.chinosk.gakumas.localify.models.GakumasConfig
|
import io.github.chinosk.gakumas.localify.models.GakumasConfig
|
||||||
import io.github.chinosk.gakumas.localify.models.ProgramConfig
|
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.ProgramConfigViewModel
|
||||||
import io.github.chinosk.gakumas.localify.models.ProgramConfigViewModelFactory
|
import io.github.chinosk.gakumas.localify.models.ProgramConfigViewModelFactory
|
||||||
import io.github.chinosk.gakumas.localify.ui.pages.MainUI
|
import io.github.chinosk.gakumas.localify.ui.pages.MainUI
|
||||||
import io.github.chinosk.gakumas.localify.ui.theme.GakumasLocalifyTheme
|
import io.github.chinosk.gakumas.localify.ui.theme.GakumasLocalifyTheme
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.serialization.SerializationException
|
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : ComponentActivity(), ConfigUpdateListener {
|
class MainActivity : ComponentActivity(), ConfigUpdateListener, IConfigurableActivity<MainActivity> {
|
||||||
override lateinit var config: GakumasConfig
|
override lateinit var config: GakumasConfig
|
||||||
override lateinit var programConfig: ProgramConfig
|
override lateinit var programConfig: ProgramConfig
|
||||||
|
|
||||||
@ -42,56 +39,14 @@ class MainActivity : ComponentActivity(), ConfigUpdateListener {
|
|||||||
override lateinit var programConfigFactory: ProgramConfigViewModelFactory
|
override lateinit var programConfigFactory: ProgramConfigViewModelFactory
|
||||||
override lateinit var programConfigViewModel: ProgramConfigViewModel
|
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) {
|
private fun showToast(message: String) {
|
||||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
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<String> = 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() {
|
override fun saveConfig() {
|
||||||
try {
|
try {
|
||||||
|
config.pf = false
|
||||||
viewModel.configState.value = config.copy( pf = true ) // 更新 UI
|
viewModel.configState.value = config.copy( pf = true ) // 更新 UI
|
||||||
}
|
}
|
||||||
catch (e: RuntimeException) {
|
catch (e: RuntimeException) {
|
||||||
@ -137,30 +92,6 @@ class MainActivity : ComponentActivity(), ConfigUpdateListener {
|
|||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadConfig() {
|
|
||||||
val configStr = getConfigContent()
|
|
||||||
config = try {
|
|
||||||
json.decodeFromString<GakumasConfig>(configStr)
|
|
||||||
}
|
|
||||||
catch (e: SerializationException) {
|
|
||||||
showToast("配置文件异常,已重置: $e")
|
|
||||||
GakumasConfig()
|
|
||||||
}
|
|
||||||
saveConfig()
|
|
||||||
|
|
||||||
val programConfigStr = getProgramConfigContent()
|
|
||||||
programConfig = try {
|
|
||||||
json.decodeFromString<ProgramConfig>(programConfigStr)
|
|
||||||
}
|
|
||||||
catch (e: SerializationException) {
|
|
||||||
ProgramConfig()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun checkConfigAndUpdateView() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun pushKeyEvent(event: KeyEvent): Boolean {
|
override fun pushKeyEvent(event: KeyEvent): Boolean {
|
||||||
return dispatchKeyEvent(event)
|
return dispatchKeyEvent(event)
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,14 @@
|
|||||||
package io.github.chinosk.gakumas.localify
|
package io.github.chinosk.gakumas.localify
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
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.GakumasConfig
|
||||||
import io.github.chinosk.gakumas.localify.models.ProgramConfig
|
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<TranslucentActivity> {
|
||||||
|
override lateinit var config: GakumasConfig
|
||||||
|
override lateinit var programConfig: ProgramConfig
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -26,66 +21,4 @@ class TranslucentActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadConfig() {
|
|
||||||
val configStr = getConfigContent()
|
|
||||||
try {
|
|
||||||
json.decodeFromString<GakumasConfig>(configStr)
|
|
||||||
} catch (e: SerializationException) {
|
|
||||||
showToast("配置文件异常,已重置: $e")
|
|
||||||
GakumasConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
val programConfigStr = getProgramConfigContent()
|
|
||||||
programConfig = try {
|
|
||||||
json.decodeFromString<ProgramConfig>(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<String> = 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import androidx.compose.ui.unit.Dp
|
|||||||
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.MainActivity
|
||||||
import io.github.chinosk.gakumas.localify.models.GakumasConfig
|
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.components.GakuTabRow
|
||||||
import io.github.chinosk.gakumas.localify.ui.pages.subPages.AboutPage
|
import io.github.chinosk.gakumas.localify.ui.pages.subPages.AboutPage
|
||||||
import io.github.chinosk.gakumas.localify.ui.pages.subPages.AdvanceSettingsPage
|
import io.github.chinosk.gakumas.localify.ui.pages.subPages.AdvanceSettingsPage
|
||||||
|
BIN
app/src/main/res/drawable-hdpi/splash.png
Normal file
BIN
app/src/main/res/drawable-hdpi/splash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 MiB |
BIN
app/src/main/res/drawable-mdpi/splash.png
Normal file
BIN
app/src/main/res/drawable-mdpi/splash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 650 KiB |
BIN
app/src/main/res/drawable-xhdpi/splash.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/splash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 MiB |
BIN
app/src/main/res/drawable-xxhdpi/splash.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/splash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 MiB |
13
app/src/main/res/drawable/splash_style.xml
Normal file
13
app/src/main/res/drawable/splash_style.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item>
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
<solid android:color="@color/white" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<bitmap android:src="@drawable/splash"
|
||||||
|
android:gravity="center"
|
||||||
|
android:tileMode="disabled"/>
|
||||||
|
</item>
|
||||||
|
</layer-list>
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<style name="Theme.GakumasLocalify" parent="@style/Theme.MaterialComponents.Light.NoActionBar" >
|
<style name="Theme.GakumasLocalify" parent="@style/Theme.MaterialComponents.Light.NoActionBar" >
|
||||||
<item name="android:windowBackground">@drawable/splash</item>
|
<item name="android:windowBackground">@drawable/splash_style</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="Theme.GakumasLocalify.NoDisplay" parent="@style/Theme.MaterialComponents.Light.NoActionBar" >
|
<style name="Theme.GakumasLocalify.NoDisplay" parent="@style/Theme.MaterialComponents.Light.NoActionBar" >
|
||||||
|
Loading…
x
Reference in New Issue
Block a user