Refactor large Kotlin source files
- Split core game models from sandbox engine, native level setup, and repo state saving. - Move app overlays and completion helpers out of GitHugApp. - Extract the terminal special key bar into its own component.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package solutions.tretter.githugandroid
|
||||
|
||||
import androidx.compose.runtime.saveable.listSaver
|
||||
|
||||
val RepoStateSaver = listSaver<RepoState, Any>(
|
||||
save = { state ->
|
||||
listOf(
|
||||
state.initialized,
|
||||
state.headBranch,
|
||||
state.files.flatMap { listOf(it.name, it.content, it.staged.toString(), it.tracked.toString(), it.deleted.toString()) },
|
||||
state.commits.flatMap { listOf(it.id, it.message) },
|
||||
state.branches.flatMap { listOf(it.key, it.value.toString()) },
|
||||
state.currentDir,
|
||||
state.tags,
|
||||
state.remotes.flatMap { listOf(it.key, it.value) },
|
||||
state.config.flatMap { listOf(it.key, it.value) },
|
||||
state.stashes,
|
||||
state.fetchedBranches.toList(),
|
||||
state.pushedBranches.toList(),
|
||||
state.pushedTags.toList(),
|
||||
state.submodules.flatMap { listOf(it.key, it.value) },
|
||||
state.maintenanceActions.toList(),
|
||||
)
|
||||
},
|
||||
restore = { saved ->
|
||||
val initialized = saved[0] as Boolean
|
||||
val headBranch = saved[1] as String
|
||||
val fileParts = saved[2] as List<*>
|
||||
val commitParts = saved[3] as List<*>
|
||||
val branchParts = saved[4] as List<*>
|
||||
val tags = saved[6] as List<*>
|
||||
val remoteParts = saved[7] as List<*>
|
||||
val configParts = saved.getOrNull(8) as? List<*> ?: emptyList<Any>()
|
||||
val stashes = saved.getOrNull(9) as? List<*> ?: emptyList<Any>()
|
||||
val fetchedBranches = saved.getOrNull(10) as? List<*> ?: emptyList<Any>()
|
||||
val pushedBranches = saved.getOrNull(11) as? List<*> ?: emptyList<Any>()
|
||||
val pushedTags = saved.getOrNull(12) as? List<*> ?: emptyList<Any>()
|
||||
val submoduleParts = saved.getOrNull(13) as? List<*> ?: emptyList<Any>()
|
||||
val maintenanceActions = saved.getOrNull(14) as? List<*> ?: emptyList<Any>()
|
||||
RepoState(
|
||||
initialized = initialized,
|
||||
headBranch = headBranch,
|
||||
files = fileParts.chunked(if (fileParts.size % 5 == 0) 5 else 4).map {
|
||||
GitFile(
|
||||
name = it[0] as String,
|
||||
content = it[1] as String,
|
||||
staged = (it[2] as String).toBoolean(),
|
||||
tracked = (it[3] as String).toBoolean(),
|
||||
deleted = (it.getOrNull(4) as? String)?.toBoolean() ?: false,
|
||||
)
|
||||
},
|
||||
commits = commitParts.chunked(2).map {
|
||||
CommitNode(it[0] as String, it[1] as String)
|
||||
},
|
||||
branches = branchParts.chunked(2).associate { (it[0] as String) to (it[1] as String).toInt() },
|
||||
currentDir = saved[5] as String,
|
||||
tags = tags.filterIsInstance<String>(),
|
||||
remotes = remoteParts.chunked(2).associate { (it[0] as String) to (it[1] as String) },
|
||||
config = configParts.chunked(2).associate { (it[0] as String) to (it[1] as String) },
|
||||
stashes = stashes.filterIsInstance<String>(),
|
||||
fetchedBranches = fetchedBranches.filterIsInstance<String>().toSet(),
|
||||
pushedBranches = pushedBranches.filterIsInstance<String>().toSet(),
|
||||
pushedTags = pushedTags.filterIsInstance<String>().toSet(),
|
||||
submodules = submoduleParts.chunked(2).associate { (it[0] as String) to (it[1] as String) },
|
||||
maintenanceActions = maintenanceActions.filterIsInstance<String>().toSet(),
|
||||
)
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user