-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extend configurables, optimize image stretching
- Loading branch information
Showing
11 changed files
with
128 additions
and
150 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
app/src/main/java/io/github/chinosk/gakumas/localify/ActivityExtends.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters