-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
176 additions
and
26 deletions.
There are no files selected for viewing
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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/github/jing332/tts_dict_editor/const/ExportType.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,7 @@ | ||
package com.github.jing332.tts_dict_editor.const | ||
|
||
object ExportType { | ||
const val JSON = 0 | ||
const val CUSTOM_FORMAT = 1 | ||
const val YAML = 2 | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/github/jing332/tts_dict_editor/replace/ReplaceConfig.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,10 @@ | ||
package com.github.jing332.tts_dict_editor.replace | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
@SerialName("!org.nobody.multitts.tts.replace.ReplaceConfig") | ||
data class ReplaceConfig( | ||
val replaces: List<ReplaceRuleYaml> | ||
) |
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/github/jing332/tts_dict_editor/replace/ReplaceManager.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,58 @@ | ||
package com.github.jing332.tts_dict_editor.replace | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import com.charleskorn.kaml.decodeFromStream | ||
import com.charleskorn.kaml.encodeToStream | ||
import com.github.jing332.tts_dict_editor.const.AppConst | ||
import kotlinx.serialization.encodeToString | ||
import java.io.InputStream | ||
|
||
class ReplaceManager(val context: Context, val uri: Uri) { | ||
companion object { | ||
const val TAG = "ReplaceManager" | ||
|
||
fun toYaml(list: List<ReplaceRuleYaml>): String { | ||
return AppConst.yaml.encodeToString(ReplaceConfig(list)) | ||
} | ||
} | ||
|
||
private val replaceList = mutableListOf<ReplaceRuleYaml>() | ||
|
||
fun addReplace(replaceConfig: ReplaceRuleYaml) { | ||
replaceList.add(replaceConfig) | ||
} | ||
|
||
fun getReplaceList(): List<ReplaceRuleYaml> { | ||
return replaceList | ||
} | ||
|
||
fun clearReplaceList() { | ||
replaceList.clear() | ||
} | ||
|
||
fun readConfigFromFile() { | ||
context.contentResolver.openInputStream(uri)?.use { | ||
readConfigFromInputStream(it) | ||
return | ||
} | ||
|
||
throw Exception("Failed to read config file") | ||
} | ||
|
||
private fun readConfigFromInputStream(ins: InputStream) { | ||
val cfg: ReplaceConfig = AppConst.yaml.decodeFromStream(ins) | ||
replaceList.clear() | ||
replaceList.addAll(cfg.replaces) | ||
} | ||
|
||
private fun updateConfigFile() { | ||
val cfg = ReplaceConfig(replaceList) | ||
context.contentResolver.openOutputStream(uri)?.use { | ||
AppConst.yaml.encodeToStream(cfg, it) | ||
return | ||
} | ||
|
||
throw Exception("Failed to write config file") | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/github/jing332/tts_dict_editor/replace/ReplaceRuleYaml.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,12 @@ | ||
package com.github.jing332.tts_dict_editor.replace | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ReplaceRuleYaml( | ||
val activate: Boolean = false, | ||
val name: String = "", | ||
val regex: Boolean = false, | ||
val source: String, | ||
val target: String | ||
) |
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
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
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