Skip to content

Commit

Permalink
chore: merge branch dev into main
Browse files Browse the repository at this point in the history
  • Loading branch information
aliernfrog authored Dec 22, 2024
2 parents 1cd417c + cba5a47 commit bf1d4ad
Show file tree
Hide file tree
Showing 44 changed files with 643 additions and 252 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ Shizuku method will automatically be enabled if there is no other way for the ap
- Release variant: `./gradlew assembleRelease`
- Debug variant: `./gradlew assembleDebug`
</details>
<details>
<summary>Properties</summary>
Following can be set in `local.properties`:
- `laclibPath` -> Path to a local [LACLib](https://github.com/aliernfrog/laclib) jar (defaults to the one from JitPack)
</details>
127 changes: 68 additions & 59 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import org.apache.commons.io.output.ByteArrayOutputStream
import java.io.FileInputStream
import java.util.Properties

val localProperties = Properties()
try {
localProperties.load(FileInputStream(rootProject.file("local.properties")))
} catch (t: Throwable) {
logger.warn("Failed to load local.properties: ", t)
}

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("org.jetbrains.kotlin.plugin.parcelize")
id("com.mikepenz.aboutlibraries.plugin")
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.parcelize)
alias(libs.plugins.aboutlibraries)
}

val composeMaterialVersion = "1.7.0"
val composeMaterial3Version = "1.3.0"
val composeCompilerVersion = "1.5.15"
val lifecycleVersion = "2.8.5"
val shizukuVersion = "13.1.5"

android {
namespace = "com.aliernfrog.lactool"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "com.aliernfrog.lactool"
minSdk = 21
targetSdk = 34
versionCode = 34300
versionName = "3.4.3"
targetSdk = 35
versionCode = 35000
versionName = "3.5.0"
vectorDrawables { useSupportLibrary = true }
}

Expand All @@ -39,13 +42,13 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
isCoreLibraryDesugaringEnabled = true
}

kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "11"
freeCompilerArgs = freeCompilerArgs + "-opt-in=kotlin.RequiresOptIn"
}

Expand All @@ -55,10 +58,6 @@ android {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = composeCompilerVersion
}

packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
Expand All @@ -83,6 +82,9 @@ android.defaultConfig.buildConfigField("String[]", "LANGUAGES", "new String[]{${
languages.joinToString(",") { "\"$it\"" }
}}")

val laclibPath: String? = localProperties.getProperty("laclibPath")
val useLocalLaclib = !laclibPath.isNullOrEmpty()

// Utilities to get git environment information
// Source: https://github.com/vendetta-mod/VendettaManager/blob/main/app/build.gradle.kts
fun getCurrentBranch() = exec("git", "symbolic-ref", "--short", "HEAD")
Expand All @@ -92,7 +94,7 @@ fun hasLocalChanges(): Boolean {
val branch = getCurrentBranch()
val uncommittedChanges = exec("git", "status", "-s")?.isNotEmpty() ?: false
val unpushedChanges = exec("git", "log", "origin/$branch..HEAD")?.isNotBlank() ?: false
return uncommittedChanges || unpushedChanges
return uncommittedChanges || unpushedChanges || useLocalLaclib
}

android.defaultConfig.run {
Expand All @@ -102,45 +104,52 @@ android.defaultConfig.run {
}

fun exec(vararg command: String) = try {
val stdout = ByteArrayOutputStream()
val errout = ByteArrayOutputStream()
exec {
commandLine = command.toList()
standardOutput = stdout
errorOutput = errout
isIgnoreExitValue = true
}

if (errout.size() > 0) throw Error(errout.toString(Charsets.UTF_8))
stdout.toString(Charsets.UTF_8).trim()
val process = ProcessBuilder(command.toList())
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
val stdout = process.inputStream.bufferedReader().readText()
val stderr = process.errorStream.bufferedReader().readText()
if (stderr.isNotEmpty()) throw Error(stderr)
stdout.trim()
} catch (_: Throwable) {
null
}

dependencies {
implementation("androidx.core:core-ktx:1.13.1")
implementation("androidx.core:core-splashscreen:1.0.1")
implementation("androidx.compose.ui:ui:$composeMaterialVersion")
implementation("androidx.compose.material:material:$composeMaterialVersion")
implementation("androidx.compose.material:material-icons-extended:$composeMaterialVersion")
implementation("androidx.compose.material3:material3:$composeMaterial3Version")
implementation("androidx.compose.material3:material3-window-size-class:$composeMaterial3Version")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion")
implementation("androidx.lifecycle:lifecycle-runtime-compose:$lifecycleVersion")
implementation("androidx.activity:activity-compose:1.9.2")
implementation("androidx.navigation:navigation-compose:2.8.0")
implementation("com.mikepenz:aboutlibraries-core:11.2.3")
implementation("io.insert-koin:koin-androidx-compose:3.5.6")
implementation("com.github.aliernfrog:top-toast-compose:2.1.0")
implementation("com.github.aliernfrog:laclib:1.1.0")
implementation("com.lazygeniouz:dfc:1.0.8")
implementation("dev.rikka.shizuku:api:$shizukuVersion")
implementation("dev.rikka.shizuku:provider:$shizukuVersion")
implementation("io.coil-kt:coil-compose:2.7.0")
implementation("com.github.jeziellago:compose-markdown:0.5.4")
implementation("net.engawapg.lib:zoomable:1.6.2")
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.2")

debugImplementation("androidx.compose.ui:ui-tooling:$composeMaterialVersion")
debugImplementation("androidx.compose.ui:ui-tooling-preview:$composeMaterialVersion")
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.ktx)
implementation(libs.androidx.lifecycle.compose)
implementation(libs.androidx.lifecycle.ktx)
implementation(libs.androidx.navigation)
implementation(libs.androidx.splashscreen)

implementation(libs.compose.ui)
implementation(libs.compose.material)
implementation(libs.compose.material.icons)
implementation(libs.compose.material3)
implementation(libs.compose.material3.window)

implementation(libs.aboutlibraries)
implementation(libs.coil)
implementation(libs.coil.okhttp)
implementation(libs.dfc)
implementation(libs.koin)
implementation(libs.markdown)
implementation(libs.shizuku.api)
implementation(libs.shizuku.provider)
implementation(libs.toptoast)
implementation(libs.zoomable)

implementation(
if (!useLocalLaclib) libs.laclib else {
println("Using local LACLib")
files(laclibPath)
}
)

debugImplementation(libs.compose.ui.tooling)
debugImplementation(libs.compose.ui.tooling.preview)

coreLibraryDesugaring(libs.android.desugar)
}
13 changes: 9 additions & 4 deletions app/src/main/java/com/aliernfrog/lactool/impl/FileWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,20 @@ class FileWrapper(
}

fun writeFile(content: String, context: Context) {
when (file) {
is File -> file.outputStream().use {
var target = file
if (exists()) {
delete()
target = parentFile?.createFile(name)?.file ?: return
}
when (target) {
is File -> target.outputStream().use {
FileUtil.writeFile(it, content)
}
is DocumentFileCompat -> context.contentResolver.openOutputStream(file.uri)?.use {
is DocumentFileCompat -> context.contentResolver.openOutputStream(target.uri)?.use {
FileUtil.writeFile(it, content)
}
is ServiceFile -> {
val fd = shizukuViewModel.fileService!!.getFd(path)
val fd = shizukuViewModel.fileService!!.getFd(target.path)
ParcelFileDescriptor.AutoCloseOutputStream(fd).use {
FileUtil.writeFile(it, content)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.aliernfrog.lactool.impl.laclib

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.aliernfrog.laclib.data.LACMapDownloadableMaterial
import com.aliernfrog.laclib.data.LACMapObject
import com.aliernfrog.laclib.enum.LACMapType
import com.aliernfrog.laclib.map.LACMapEditor

class MapEditorState(
val editor: LACMapEditor
) {
private var _serverName by mutableStateOf(editor.serverName)
var serverName: String?
get() = _serverName
set(value) {
_serverName = value
editor.serverName = value
}

private var _mapType by mutableStateOf(editor.mapType)
var mapType: LACMapType?
get() = _mapType
set(value) {
_mapType = value
editor.mapType = value
}

private var _mapRoles by mutableStateOf(editor.mapRoles?.toList())
var mapRoles: List<String>?
get() = _mapRoles
set(value) {
_mapRoles = value
editor.mapRoles = value?.toMutableList()
}

private var _mapOptions by mutableStateOf(editor.mapOptions.map { MutableMapOption(it) })
var mapOptions: List<MutableMapOption>
get() = _mapOptions
set(value) {
_mapOptions = value
editor.mapOptions = value.map { it.toImmutable() }.toMutableList()
}

fun pushMapOptionsState() {
editor.mapOptions = mapOptions.map { it.toImmutable() }.toMutableList()
}

private var _replaceableObjects by mutableStateOf(editor.replaceableObjects.toList())
var replaceableObjects: List<LACMapObject>
get() = _replaceableObjects
set(value) {
_replaceableObjects = value
editor.replaceableObjects = value.toMutableList()
}

private var _downloadableMaterials by mutableStateOf(editor.downloadableMaterials.toList())
var downloadableMaterials: List<LACMapDownloadableMaterial>
get() = _downloadableMaterials
set(value) {
_downloadableMaterials = value
editor.downloadableMaterials = value.toMutableList()
}

fun replaceOldObjects(): Int {
val replaced = editor.replaceOldObjects()
_replaceableObjects = editor.replaceableObjects.toList()
return replaced
}

fun addRole(
role: String,
onIllegalChar: (String) -> Unit,
onSuccess: () -> Unit
) {
editor.addRole(
role = role,
onIllegalChar = onIllegalChar,
onSuccess = onSuccess
)
_mapRoles = editor.mapRoles?.toList()
}

fun deleteRole(role: String) {
editor.deleteRole(role)
_mapRoles = editor.mapRoles?.toList()
}

fun removeDownloadableMaterial(url: String): Int? {
val removed = editor.removeDownloadableMaterial(url)
_downloadableMaterials = editor.downloadableMaterials.toList()
return removed
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.aliernfrog.lactool.impl.laclib

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.aliernfrog.laclib.map.LACMapMerger

class MapMergerState(
private val merger: LACMapMerger
) {
var mapsToMerge by mutableStateOf(merger.mapsToMerge.map { MutableMapToMerge(it) })
private set

private fun pullMapsState() {
mapsToMerge = merger.mapsToMerge.map { MutableMapToMerge(it) }
}

fun pushMapsState() {
merger.mapsToMerge = mapsToMerge.map { it.toImmutable() }.toMutableList()
}

fun addMap(mapName: String, content: String) {
merger.addMap(mapName, content)
pullMapsState()
}

fun removeMap(index: Int) {
merger.mapsToMerge.removeAt(index)
pullMapsState()
}

fun clearMaps() {
merger.mapsToMerge.clear()
pullMapsState()
}

fun makeMapBase(index: Int) {
merger.makeMapBase(index)
pullMapsState()
}

fun mergeMaps(onNoEnoughMaps: () -> Unit) = merger.mergeMaps(
onNoEnoughMaps = onNoEnoughMaps
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.aliernfrog.lactool.impl.laclib

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.aliernfrog.laclib.data.LACMapOption

class MutableMapOption(option: LACMapOption) {
val type = option.type
val label = option.label
var value by mutableStateOf(option.value)
val line = option.line

fun toImmutable() = LACMapOption(
type = type,
label = label,
value = value,
line = line
)
}
Loading

0 comments on commit bf1d4ad

Please sign in to comment.