1
0

remove dataBinding

This commit is contained in:
ketal 2024-06-28 14:55:06 +08:00
parent 481ea9ff51
commit 96cf7267ee
No known key found for this signature in database
GPG Key ID: 52E91FA93DA527DA
10 changed files with 100 additions and 1452 deletions

View File

@ -57,9 +57,6 @@ android {
version '3.22.1' version '3.22.1'
} }
} }
dataBinding {
enable true
}
packaging { packaging {
jniLibs { jniLibs {

View File

@ -3,7 +3,6 @@ package io.github.chinosk.gakumas.localify
import android.view.KeyEvent import android.view.KeyEvent
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import io.github.chinosk.gakumas.localify.databinding.ActivityMainBinding
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.ProgramConfigViewModel import io.github.chinosk.gakumas.localify.models.ProgramConfigViewModel
@ -83,7 +82,7 @@ class UserConfigViewModel(initValue: GakumasConfig) : ViewModel() {
interface ConfigUpdateListener: ConfigListener { interface ConfigUpdateListener: ConfigListener {
var binding: ActivityMainBinding val config: GakumasConfig
var factory: UserConfigViewModelFactory var factory: UserConfigViewModelFactory
var viewModel: UserConfigViewModel var viewModel: UserConfigViewModel
@ -99,40 +98,40 @@ interface ConfigUpdateListener: ConfigListener {
override fun onEnabledChanged(value: Boolean) { override fun onEnabledChanged(value: Boolean) {
binding.config!!.enabled = value config.enabled = value
saveConfig() saveConfig()
pushKeyEvent(KeyEvent(1145, 29)) pushKeyEvent(KeyEvent(1145, 29))
} }
override fun onForceExportResourceChanged(value: Boolean) { override fun onForceExportResourceChanged(value: Boolean) {
binding.config!!.forceExportResource = value config.forceExportResource = value
saveConfig() saveConfig()
pushKeyEvent(KeyEvent(1145, 30)) pushKeyEvent(KeyEvent(1145, 30))
} }
override fun onReplaceFontChanged(value: Boolean) { override fun onReplaceFontChanged(value: Boolean) {
binding.config!!.replaceFont = value config.replaceFont = value
saveConfig() saveConfig()
pushKeyEvent(KeyEvent(1145, 30)) pushKeyEvent(KeyEvent(1145, 30))
} }
override fun onTextTestChanged(value: Boolean) { override fun onTextTestChanged(value: Boolean) {
binding.config!!.textTest = value config.textTest = value
saveConfig() saveConfig()
} }
override fun onDumpTextChanged(value: Boolean) { override fun onDumpTextChanged(value: Boolean) {
binding.config!!.dumpText = value config.dumpText = value
saveConfig() saveConfig()
} }
override fun onEnableFreeCameraChanged(value: Boolean) { override fun onEnableFreeCameraChanged(value: Boolean) {
binding.config!!.enableFreeCamera = value config.enableFreeCamera = value
saveConfig() saveConfig()
} }
override fun onUnlockAllLiveChanged(value: Boolean) { override fun onUnlockAllLiveChanged(value: Boolean) {
binding.config!!.unlockAllLive = value config.unlockAllLive = value
saveConfig() saveConfig()
} }
@ -145,7 +144,7 @@ interface ConfigUpdateListener: ConfigListener {
} else { } else {
valueStr.toInt() valueStr.toInt()
} }
binding.config!!.targetFrameRate = value config.targetFrameRate = value
saveConfig() saveConfig()
} }
catch (e: Exception) { catch (e: Exception) {
@ -154,22 +153,22 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onLiveCustomeDressChanged(value: Boolean) { override fun onLiveCustomeDressChanged(value: Boolean) {
binding.config!!.enableLiveCustomeDress = value config.enableLiveCustomeDress = value
saveConfig() saveConfig()
} }
override fun onLiveCustomeCostumeIdChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onLiveCustomeCostumeIdChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.liveCustomeCostumeId = s.toString() config.liveCustomeCostumeId = s.toString()
saveConfig() saveConfig()
} }
override fun onUseCustomeGraphicSettingsChanged(value: Boolean) { override fun onUseCustomeGraphicSettingsChanged(value: Boolean) {
binding.config!!.useCustomeGraphicSettings = value config.useCustomeGraphicSettings = value
saveConfig() saveConfig()
} }
override fun onRenderScaleChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onRenderScaleChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.renderScale = try { config.renderScale = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -179,7 +178,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onQualitySettingsLevelChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onQualitySettingsLevelChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.qualitySettingsLevel = try { config.qualitySettingsLevel = try {
s.toString().toInt() s.toString().toInt()
} }
catch (e: Exception) { catch (e: Exception) {
@ -189,7 +188,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onVolumeIndexChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onVolumeIndexChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.volumeIndex = try { config.volumeIndex = try {
s.toString().toInt() s.toString().toInt()
} }
catch (e: Exception) { catch (e: Exception) {
@ -199,7 +198,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onMaxBufferPixelChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onMaxBufferPixelChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.maxBufferPixel = try { config.maxBufferPixel = try {
s.toString().toInt() s.toString().toInt()
} }
catch (e: Exception) { catch (e: Exception) {
@ -209,12 +208,12 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onLiveCustomeHeadIdChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onLiveCustomeHeadIdChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.liveCustomeHeadId = s.toString() config.liveCustomeHeadId = s.toString()
saveConfig() saveConfig()
} }
override fun onReflectionQualityLevelChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onReflectionQualityLevelChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.reflectionQualityLevel = try { config.reflectionQualityLevel = try {
val value = s.toString().toInt() val value = s.toString().toInt()
if (value > 5) 5 else value if (value > 5) 5 else value
} }
@ -225,7 +224,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onLodQualityLevelChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onLodQualityLevelChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.lodQualityLevel = try { config.lodQualityLevel = try {
val value = s.toString().toInt() val value = s.toString().toInt()
if (value > 5) 5 else value if (value > 5) 5 else value
} }
@ -238,44 +237,44 @@ interface ConfigUpdateListener: ConfigListener {
override fun onChangePresetQuality(level: Int) { override fun onChangePresetQuality(level: Int) {
when (level) { when (level) {
0 -> { 0 -> {
binding.config!!.renderScale = 0.5f config.renderScale = 0.5f
binding.config!!.qualitySettingsLevel = 1 config.qualitySettingsLevel = 1
binding.config!!.volumeIndex = 0 config.volumeIndex = 0
binding.config!!.maxBufferPixel = 1024 config.maxBufferPixel = 1024
binding.config!!.lodQualityLevel = 1 config.lodQualityLevel = 1
binding.config!!.reflectionQualityLevel = 1 config.reflectionQualityLevel = 1
} }
1 -> { 1 -> {
binding.config!!.renderScale = 0.59f config.renderScale = 0.59f
binding.config!!.qualitySettingsLevel = 1 config.qualitySettingsLevel = 1
binding.config!!.volumeIndex = 1 config.volumeIndex = 1
binding.config!!.maxBufferPixel = 1440 config.maxBufferPixel = 1440
binding.config!!.lodQualityLevel = 2 config.lodQualityLevel = 2
binding.config!!.reflectionQualityLevel = 2 config.reflectionQualityLevel = 2
} }
2 -> { 2 -> {
binding.config!!.renderScale = 0.67f config.renderScale = 0.67f
binding.config!!.qualitySettingsLevel = 2 config.qualitySettingsLevel = 2
binding.config!!.volumeIndex = 2 config.volumeIndex = 2
binding.config!!.maxBufferPixel = 2538 config.maxBufferPixel = 2538
binding.config!!.lodQualityLevel = 3 config.lodQualityLevel = 3
binding.config!!.reflectionQualityLevel = 3 config.reflectionQualityLevel = 3
} }
3 -> { 3 -> {
binding.config!!.renderScale = 0.77f config.renderScale = 0.77f
binding.config!!.qualitySettingsLevel = 3 config.qualitySettingsLevel = 3
binding.config!!.volumeIndex = 3 config.volumeIndex = 3
binding.config!!.maxBufferPixel = 3384 config.maxBufferPixel = 3384
binding.config!!.lodQualityLevel = 4 config.lodQualityLevel = 4
binding.config!!.reflectionQualityLevel = 4 config.reflectionQualityLevel = 4
} }
4 -> { 4 -> {
binding.config!!.renderScale = 1.0f config.renderScale = 1.0f
binding.config!!.qualitySettingsLevel = 5 config.qualitySettingsLevel = 5
binding.config!!.volumeIndex = 4 config.volumeIndex = 4
binding.config!!.maxBufferPixel = 8190 config.maxBufferPixel = 8190
binding.config!!.lodQualityLevel = 5 config.lodQualityLevel = 5
binding.config!!.reflectionQualityLevel = 5 config.reflectionQualityLevel = 5
} }
} }
checkConfigAndUpdateView() checkConfigAndUpdateView()
@ -283,38 +282,31 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onGameOrientationChanged(checkedId: Int) { override fun onGameOrientationChanged(checkedId: Int) {
when (checkedId) { if (checkedId in listOf(0, 1, 2)) {
R.id.radioButtonGameDefault -> binding.config!!.gameOrientation = 0 config.gameOrientation = checkedId
R.id.radioButtonGamePortrait -> binding.config!!.gameOrientation = 1
R.id.radioButtonGameLandscape -> binding.config!!.gameOrientation = 2
else -> {
if (listOf(0, 1, 2).contains(checkedId)) {
binding.config!!.gameOrientation = checkedId
}
}
} }
saveConfig() saveConfig()
} }
override fun onEnableBreastParamChanged(value: Boolean) { override fun onEnableBreastParamChanged(value: Boolean) {
binding.config!!.enableBreastParam = value config.enableBreastParam = value
saveConfig() saveConfig()
checkConfigAndUpdateView() checkConfigAndUpdateView()
} }
override fun onBUseArmCorrectionChanged(value: Boolean) { override fun onBUseArmCorrectionChanged(value: Boolean) {
binding.config!!.bUseArmCorrection = value config.bUseArmCorrection = value
saveConfig() saveConfig()
} }
override fun onBUseScaleChanged(value: Boolean) { override fun onBUseScaleChanged(value: Boolean) {
binding.config!!.bUseScale = value config.bUseScale = value
saveConfig() saveConfig()
checkConfigAndUpdateView() checkConfigAndUpdateView()
} }
override fun onBDampingChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onBDampingChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.bDamping = try { config.bDamping = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -324,7 +316,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onBStiffnessChanged(s: CharSequence, start: Int, before: Int, count: Int){ override fun onBStiffnessChanged(s: CharSequence, start: Int, before: Int, count: Int){
binding.config!!.bStiffness = try { config.bStiffness = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -334,7 +326,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onBSpringChanged(s: CharSequence, start: Int, before: Int, count: Int){ override fun onBSpringChanged(s: CharSequence, start: Int, before: Int, count: Int){
binding.config!!.bSpring = try { config.bSpring = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -344,7 +336,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onBPendulumChanged(s: CharSequence, start: Int, before: Int, count: Int){ override fun onBPendulumChanged(s: CharSequence, start: Int, before: Int, count: Int){
binding.config!!.bPendulum = try { config.bPendulum = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -354,7 +346,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onBPendulumRangeChanged(s: CharSequence, start: Int, before: Int, count: Int){ override fun onBPendulumRangeChanged(s: CharSequence, start: Int, before: Int, count: Int){
binding.config!!.bPendulumRange = try { config.bPendulumRange = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -364,7 +356,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onBAverageChanged(s: CharSequence, start: Int, before: Int, count: Int){ override fun onBAverageChanged(s: CharSequence, start: Int, before: Int, count: Int){
binding.config!!.bAverage = try { config.bAverage = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -374,7 +366,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onBRootWeightChanged(s: CharSequence, start: Int, before: Int, count: Int){ override fun onBRootWeightChanged(s: CharSequence, start: Int, before: Int, count: Int){
binding.config!!.bRootWeight = try { config.bRootWeight = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -384,13 +376,13 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onBUseLimitChanged(value: Boolean){ override fun onBUseLimitChanged(value: Boolean){
binding.config!!.bUseLimit = value config.bUseLimit = value
saveConfig() saveConfig()
checkConfigAndUpdateView() checkConfigAndUpdateView()
} }
override fun onBLimitXxChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onBLimitXxChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.bLimitXx = try { config.bLimitXx = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -400,7 +392,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onBLimitXyChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onBLimitXyChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.bLimitXy = try { config.bLimitXy = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -410,7 +402,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onBLimitYxChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onBLimitYxChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.bLimitYx = try { config.bLimitYx = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -420,7 +412,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onBLimitYyChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onBLimitYyChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.bLimitYy = try { config.bLimitYy = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -430,7 +422,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onBLimitZxChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onBLimitZxChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.bLimitZx = try { config.bLimitZx = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -440,7 +432,7 @@ interface ConfigUpdateListener: ConfigListener {
} }
override fun onBLimitZyChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onBLimitZyChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.bLimitZy = try { config.bLimitZy = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -451,7 +443,7 @@ interface ConfigUpdateListener: ConfigListener {
override fun onBScaleChanged(s: CharSequence, start: Int, before: Int, count: Int) { override fun onBScaleChanged(s: CharSequence, start: Int, before: Int, count: Int) {
binding.config!!.bScale = try { config.bScale = try {
s.toString().toFloat() s.toString().toFloat()
} }
catch (e: Exception) { catch (e: Exception) {
@ -481,27 +473,27 @@ interface ConfigUpdateListener: ConfigListener {
1f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f) 1f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f)
} }
binding.config!!.bDamping = setData[0] config.bDamping = setData[0]
binding.config!!.bStiffness = setData[1] config.bStiffness = setData[1]
binding.config!!.bSpring = setData[2] config.bSpring = setData[2]
binding.config!!.bPendulum = setData[3] config.bPendulum = setData[3]
binding.config!!.bPendulumRange = setData[4] config.bPendulumRange = setData[4]
binding.config!!.bAverage = setData[5] config.bAverage = setData[5]
binding.config!!.bRootWeight = setData[6] config.bRootWeight = setData[6]
binding.config!!.bUseLimit = if (setData[7] == 0f) { config.bUseLimit = if (setData[7] == 0f) {
false false
} }
else { else {
binding.config!!.bLimitXx = setData[8] config.bLimitXx = setData[8]
binding.config!!.bLimitXy = setData[9] config.bLimitXy = setData[9]
binding.config!!.bLimitYx = setData[10] config.bLimitYx = setData[10]
binding.config!!.bLimitYy = setData[11] config.bLimitYy = setData[11]
binding.config!!.bLimitZx = setData[12] config.bLimitZx = setData[12]
binding.config!!.bLimitZy = setData[13] config.bLimitZy = setData[13]
true true
} }
binding.config!!.bUseArmCorrection = true config.bUseArmCorrection = true
checkConfigAndUpdateView() checkConfigAndUpdateView()
saveConfig() saveConfig()
@ -539,5 +531,4 @@ interface ConfigUpdateListener: ConfigListener {
localResourceVersionState?.let{ programConfigViewModel.localResourceVersionState.value = localResourceVersionState } localResourceVersionState?.let{ programConfigViewModel.localResourceVersionState.value = localResourceVersionState }
errorString?.let{ programConfigViewModel.errorStringState.value = errorString } errorString?.let{ programConfigViewModel.errorStringState.value = errorString }
} }
} }

View File

@ -13,9 +13,7 @@ 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.core.content.FileProvider
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import io.github.chinosk.gakumas.localify.databinding.ActivityMainBinding
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
import io.github.chinosk.gakumas.localify.hookUtils.MainKeyEventDispatcher import io.github.chinosk.gakumas.localify.hookUtils.MainKeyEventDispatcher
@ -35,7 +33,7 @@ import java.io.File
class MainActivity : ComponentActivity(), ConfigUpdateListener { class MainActivity : ComponentActivity(), ConfigUpdateListener {
override lateinit var binding: ActivityMainBinding override lateinit var config: GakumasConfig
override lateinit var programConfig: ProgramConfig override lateinit var programConfig: ProgramConfig
override lateinit var factory: UserConfigViewModelFactory override lateinit var factory: UserConfigViewModelFactory
@ -94,14 +92,13 @@ class MainActivity : ComponentActivity(), ConfigUpdateListener {
override fun saveConfig() { override fun saveConfig() {
try { try {
binding.config!!.pf = false viewModel.configState.value = config.copy( pf = true ) // 更新 UI
viewModel.configState.value = binding.config!!.copy( pf = true ) // 更新 UI
} }
catch (e: RuntimeException) { catch (e: RuntimeException) {
Log.d(TAG, e.toString()) Log.d(TAG, e.toString())
} }
val configFile = File(filesDir, "gkms-config.json") val configFile = File(filesDir, "gkms-config.json")
configFile.writeText(json.encodeToString(binding.config!!)) configFile.writeText(json.encodeToString(config))
} }
override fun saveProgramConfig() { override fun saveProgramConfig() {
@ -142,7 +139,7 @@ class MainActivity : ComponentActivity(), ConfigUpdateListener {
private fun loadConfig() { private fun loadConfig() {
val configStr = getConfigContent() val configStr = getConfigContent()
binding.config = try { config = try {
json.decodeFromString<GakumasConfig>(configStr) json.decodeFromString<GakumasConfig>(configStr)
} }
catch (e: SerializationException) { catch (e: SerializationException) {
@ -161,8 +158,7 @@ class MainActivity : ComponentActivity(), ConfigUpdateListener {
} }
override fun checkConfigAndUpdateView() { override fun checkConfigAndUpdateView() {
binding.config = binding.config
binding.notifyChange()
} }
override fun pushKeyEvent(event: KeyEvent): Boolean { override fun pushKeyEvent(event: KeyEvent): Boolean {
@ -173,25 +169,21 @@ class MainActivity : ComponentActivity(), ConfigUpdateListener {
override fun dispatchKeyEvent(event: KeyEvent): Boolean { override fun dispatchKeyEvent(event: KeyEvent): Boolean {
// Log.d(TAG, "${event.keyCode}, ${event.action}") // Log.d(TAG, "${event.keyCode}, ${event.action}")
if (MainKeyEventDispatcher.checkDbgKey(event.keyCode, event.action)) { if (MainKeyEventDispatcher.checkDbgKey(event.keyCode, event.action)) {
val origDbg = binding.config?.dbgMode val origDbg = config.dbgMode
if (origDbg != null) { config.dbgMode = !origDbg
binding.config!!.dbgMode = !origDbg
checkConfigAndUpdateView() checkConfigAndUpdateView()
saveConfig() saveConfig()
showToast("TestMode: ${!origDbg}") showToast("TestMode: ${!origDbg}")
} }
}
return if (event.action == 1145) true else super.dispatchKeyEvent(event) return if (event.action == 1145) true else super.dispatchKeyEvent(event)
} }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
loadConfig() loadConfig()
binding.listener = this
factory = UserConfigViewModelFactory(binding.config!!) factory = UserConfigViewModelFactory(config)
viewModel = ViewModelProvider(this, factory)[UserConfigViewModel::class.java] viewModel = ViewModelProvider(this, factory)[UserConfigViewModel::class.java]
programConfigFactory = ProgramConfigViewModelFactory(programConfig, programConfigFactory = ProgramConfigViewModelFactory(programConfig,
@ -202,18 +194,7 @@ class MainActivity : ComponentActivity(), ConfigUpdateListener {
setContent { setContent {
GakumasLocalifyTheme(dynamicColor = false, darkTheme = false) { GakumasLocalifyTheme(dynamicColor = false, darkTheme = false) {
MainUI(context = this) MainUI(context = this)
/*
val navController = rememberNavController()
NavHost(navController, startDestination = "splash") {
composable("splash") {
SplashScreen(navController)
} }
composable("main") {
MainUI(context = this@MainActivity)
}
}*/
}
} }
} }
} }
@ -284,150 +265,3 @@ fun getProgramDownloadErrorStringState(context: MainActivity?): State<String> {
configMSF.asStateFlow().collectAsState() configMSF.asStateFlow().collectAsState()
} }
} }
/*
class OldActivity : AppCompatActivity(), ConfigUpdateListener {
override lateinit var binding: ActivityMainBinding
private val TAG = "GakumasLocalify"
override lateinit var factory: UserConfigViewModelFactory // No usage
override lateinit var viewModel: UserConfigViewModel // No usage
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
binding = DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
loadConfig()
binding.listener = this
val requestData = intent.getStringExtra("gkmsData")
if (requestData != null) {
if (requestData == "requestConfig") {
onClickStartGame()
finish()
}
}
showVersion()
val scrollView: ScrollView = findViewById(R.id.scrollView)
scrollView.viewTreeObserver.addOnScrollChangedListener { onScrollChanged() }
onScrollChanged()
val coordinatorLayout = findViewById<View>(R.id.coordinatorLayout)
coordinatorLayout.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
onScrollChanged()
coordinatorLayout.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
})
}
override fun onClickStartGame() {
val intent = Intent().apply {
setClassName("com.bandainamcoent.idolmaster_gakuen", "com.google.firebase.MessagingUnityPlayerActivity")
putExtra("gkmsData", getConfigContent())
flags = Intent.FLAG_ACTIVITY_NEW_TASK
}
startActivity(intent)
}
private fun onScrollChanged() {
val fab: FloatingActionButton = findViewById(R.id.fabStartGame)
val startGameButton: MaterialButton = findViewById(R.id.StartGameButton)
val scrollView: ScrollView = findViewById(R.id.scrollView)
val location = IntArray(2)
startGameButton.getLocationOnScreen(location)
val buttonTop = location[1]
val buttonBottom = buttonTop + startGameButton.height
val scrollViewLocation = IntArray(2)
scrollView.getLocationOnScreen(scrollViewLocation)
val scrollViewTop = scrollViewLocation[1]
val scrollViewBottom = scrollViewTop + scrollView.height
val isButtonVisible = buttonTop >= scrollViewTop && buttonBottom <= scrollViewBottom
if (isButtonVisible) {
fab.hide()
} else {
fab.show()
}
}
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("检测到第一次启动,初始化配置文件...")
"{}"
}
}
override fun saveConfig() {
val configFile = File(filesDir, "gkms-config.json")
configFile.writeText(Gson().toJson(binding.config!!))
}
@SuppressLint("SetTextI18n")
private fun showVersion() {
val titleLabel = findViewById<TextView>(R.id.textViewTitle)
val versionLabel = findViewById<TextView>(R.id.textViewResVersion)
var versionText = "unknown"
try {
val stream = assets.open("${FilesChecker.localizationFilesDir}/version.txt")
versionText = FilesChecker.convertToString(stream)
val packInfo = packageManager.getPackageInfo(packageName, 0)
val version = packInfo.versionName
val versionCode = packInfo.longVersionCode
titleLabel.text = "${titleLabel.text} $version ($versionCode)"
}
catch (_: Exception) {}
versionLabel.text = "Assets Version: $versionText"
}
private fun loadConfig() {
val configStr = getConfigContent()
binding.config = try {
Gson().fromJson(configStr, GakumasConfig::class.java)
}
catch (e: JsonSyntaxException) {
showToast("配置文件异常,已重置: $e")
Gson().fromJson("{}", GakumasConfig::class.java)
}
saveConfig()
}
override fun checkConfigAndUpdateView() {
binding.config = binding.config
binding.notifyChange()
}
override fun pushKeyEvent(event: KeyEvent): Boolean {
return dispatchKeyEvent(event)
}
override fun dispatchKeyEvent(event: KeyEvent): Boolean {
// Log.d(TAG, "${event.keyCode}, ${event.action}")
if (MainKeyEventDispatcher.checkDbgKey(event.keyCode, event.action)) {
val origDbg = binding.config?.dbgMode
if (origDbg != null) {
binding.config!!.dbgMode = !origDbg
checkConfigAndUpdateView()
saveConfig()
showToast("TestMode: ${!origDbg}")
}
}
return if (event.action == 1145) true else super.dispatchKeyEvent(event)
}
}
*/

View File

@ -1,7 +1,5 @@
package io.github.chinosk.gakumas.localify.mainUtils package io.github.chinosk.gakumas.localify.mainUtils
import android.util.Log
import io.github.chinosk.gakumas.localify.TAG
import okhttp3.* import okhttp3.*
import java.io.IOException import java.io.IOException
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream

View File

@ -1,3 +1,5 @@
package io.github.chinosk.gakumas.localify.ui.components
import android.content.res.Configuration.UI_MODE_NIGHT_NO import android.content.res.Configuration.UI_MODE_NIGHT_NO
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*

View File

@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Text
import androidx.compose.material3.Switch import androidx.compose.material3.Switch
import androidx.compose.material3.SwitchDefaults import androidx.compose.material3.SwitchDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable

View File

@ -2,7 +2,6 @@ package io.github.chinosk.gakumas.localify.ui.components
import android.content.res.Configuration.UI_MODE_NIGHT_NO import android.content.res.Configuration.UI_MODE_NIGHT_NO
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column

View File

@ -1,6 +1,6 @@
package io.github.chinosk.gakumas.localify.ui.pages.subPages package io.github.chinosk.gakumas.localify.ui.pages.subPages
import GakuGroupBox import io.github.chinosk.gakumas.localify.ui.components.GakuGroupBox
import android.content.res.Configuration.UI_MODE_NIGHT_NO import android.content.res.Configuration.UI_MODE_NIGHT_NO
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column

View File

@ -1,6 +1,6 @@
package io.github.chinosk.gakumas.localify.ui.pages.subPages package io.github.chinosk.gakumas.localify.ui.pages.subPages
import GakuGroupBox import io.github.chinosk.gakumas.localify.ui.components.GakuGroupBox
import android.content.res.Configuration.UI_MODE_NIGHT_NO import android.content.res.Configuration.UI_MODE_NIGHT_NO
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement

File diff suppressed because it is too large Load Diff