Skip to content

Commit f262fb6

Browse files
idk
1 parent 2c8899d commit f262fb6

File tree

61 files changed

+1212
-432
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1212
-432
lines changed

.run/Run Android.run.xml.save

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="Run Android" type="AndroidRunConfigurationType" factoryName="Android App" activateToolWindowBeforeRun="false">
3+
<module name="Awery.app" /.>
4+
<option name="ANDROID_RUN_CONFIGURATION_SCHEMA_VERSION" value="1" />
5+
<option name="DEPLOY" value="true" />
6+
<option name="DEPLOY_APK_FROM_BUNDLE" value="false" />
7+
<option name="DEPLOY_AS_INSTANT" value="false" />
8+
<option name="ARTIFACT_NAME" value="" />
9+
<option name="PM_INSTALL_OPTIONS" value="" />
10+
<option name="ALL_USERS" value="false" />
11+
<option name="ALWAYS_INSTALL_WITH_PM" value="false" />
12+
<option name="ALLOW_ASSUME_VERIFIED" value="false" />
13+
<option name="CLEAR_APP_STORAGE" value="false" />
14+
<option name="DYNAMIC_FEATURES_DISABLED_LIST" value="" />
15+
<option name="ACTIVITY_EXTRA_FLAGS" value="" />
16+
<option name="MODE" value="default_activity" />
17+
<option name="RESTORE_ENABLED" value="false" />
18+
<option name="RESTORE_FILE" value="" />
19+
<option name="RESTORE_FRESH_INSTALL_ONLY" value="false" />
20+
<option name="CLEAR_LOGCAT" value="false" />
21+
<option name="SHOW_LOGCAT_AUTOMATICALLY" value="false" />
22+
<option name="TARGET_SELECTION_MODE" value="DEVICE_AND_SNAPSHOT_COMBO_BOX" />
23+
<option name="DEBUGGER_TYPE" value="Java" />
24+
<Java>
25+
<option name="ATTACH_ON_WAIT_FOR_DEBUGGER" value="false" />
26+
<option name="DEBUG_SANDBOX_SDK" value="false" />
27+
</Java>
28+
<Profilers>
29+
<option name="ADVANCED_PROFILING_ENABLED" value="false" />
30+
<option name="STARTUP_PROFILING_ENABLED" value="false" />
31+
<option name="STARTUP_CPU_PROFILING_ENABLED" value="false" />
32+
<option name="STARTUP_CPU_PROFILING_CONFIGURATION_NAME" value="Java/Kotlin Method Sample (legacy)" />
33+
<option name="STARTUP_NATIVE_MEMORY_PROFILING_ENABLED" value="false" />
34+
<option name="NATIVE_MEMORY_SAMPLE_RATE_BYTES" value="2048" />
35+
</Profilers>
36+
<option name="DEEP_LINK" value="" />
37+
<option name="ACTIVITY" value="" />
38+
<option name="ACTIVITY_CLASS" value="" />
39+
<option name="SEARCH_ACTIVITY_IN_GLOBAL_SCOPE" value="false" />
40+
<option name="SKIP_ACTIVITY_VALIDATION" value="false" />
41+
<method v="2">
42+
<option name="Android.Gradle.BeforeRunTask" enabled="true" />
43+
</method>
44+
</configuration>
45+
</component>
134 Bytes
Binary file not shown.
132 Bytes
Binary file not shown.

app/src/androidMain/kotlin/com/mrboomdev/awery/app/MainActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
88
import com.mrboomdev.awery.core.Awery
99
import com.mrboomdev.awery.core.activity
1010
import com.mrboomdev.awery.ui.App
11-
import com.mrboomdev.awery.ui.Routes
1211
import io.github.vinceglb.filekit.FileKit
1312
import io.github.vinceglb.filekit.dialogs.init
1413

app/src/desktopMain/kotlin/com/mrboomdev/awery/app/Main.kt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ import com.formdev.flatlaf.intellijthemes.FlatOneDarkIJTheme
3838
import com.mrboomdev.awery.core.Awery
3939
import com.mrboomdev.awery.resources.*
4040
import com.mrboomdev.awery.ui.App
41-
import com.mrboomdev.awery.ui.NavigationState
42-
import com.mrboomdev.awery.ui.Routes
41+
import com.mrboomdev.awery.ui.navigation.NavigationState
42+
import com.mrboomdev.awery.ui.navigation.Routes
4343
import com.mrboomdev.awery.ui.components.ContextMenu
4444
import com.mrboomdev.awery.ui.components.IconButton
4545
import com.mrboomdev.awery.ui.theme.AweryTheme
@@ -373,13 +373,14 @@ private object AweryContextMenu: TextContextMenu {
373373
onDismissRequest = { state.status = ContextMenuState.Status.Closed }
374374
) {
375375
listOf(
376-
textManager.cut to "Cut",
377-
textManager.copy to "Copy",
378-
textManager.paste to "Paste",
379-
textManager.selectAll to "Select all"
380-
).filter { it.first != null }.forEach { (onClick, text) ->
376+
Triple(textManager.cut, Res.drawable.ic_cut_outlined, "Cut"),
377+
Triple(textManager.copy, Res.drawable.ic_copy_outlined, "Copy"),
378+
Triple(textManager.paste, Res.drawable.ic_paste_outlined, "Paste"),
379+
Triple(textManager.selectAll, Res.drawable.ic_select_all, "Select all")
380+
).filter { it.first != null }.forEach { (onClick, icon, text) ->
381381
item(
382-
text = text,
382+
icon = { painterResource(icon) },
383+
text = { text },
383384
onClick = onClick!!
384385
)
385386
}

core/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import com.android.build.api.dsl.androidLibrary
2-
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.INT
3-
import com.codingfeline.buildkonfig.compiler.FieldSpec.Type.STRING
4-
import com.codingfeline.buildkonfig.gradle.TargetConfigDsl
52

63
plugins {
74
alias(libs.plugins.kotlin.multiplatform)
@@ -36,6 +33,7 @@ kotlin {
3633
implementation(libs.ktor.client.encoding)
3734

3835
implementation(libs.fileKache)
36+
implementation(composeLibs.runtime)
3937
}
4038

4139
androidMain.dependencies {

core/src/commonMain/kotlin/com/mrboomdev/awery/core/utils/JavaSerializer.kt

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package com.mrboomdev.awery.core.utils
2+
3+
import androidx.compose.runtime.State
4+
import com.mrboomdev.awery.core.utils.collection.iterate
5+
import kotlinx.coroutines.flow.StateFlow
6+
import kotlinx.serialization.KSerializer
7+
import kotlinx.serialization.builtins.ByteArraySerializer
8+
import kotlinx.serialization.encoding.Decoder
9+
import kotlinx.serialization.encoding.Encoder
10+
import java.io.ByteArrayInputStream
11+
import java.io.ByteArrayOutputStream
12+
import java.io.ObjectInputStream
13+
import java.io.ObjectOutputStream
14+
import java.io.Serializable
15+
import kotlin.reflect.KClass
16+
import kotlin.reflect.full.memberProperties
17+
import kotlin.reflect.jvm.isAccessible
18+
import kotlin.text.append
19+
20+
fun Any?.serializeByReflection(
21+
rethrowGetterExceptions: Boolean = true,
22+
maxDepth: Int = Int.MAX_VALUE
23+
): String = serializeByReflection(
24+
obj = this,
25+
tabsCount = 0,
26+
rethrowGetterExceptions = rethrowGetterExceptions,
27+
maxDepth = maxDepth,
28+
currentDepth = 1
29+
)
30+
31+
private fun serializeByReflection(
32+
obj: Any?,
33+
tabsCount: Int,
34+
rethrowGetterExceptions: Boolean,
35+
maxDepth: Int,
36+
currentDepth: Int
37+
): String = when(obj) {
38+
is String,
39+
is Boolean,
40+
is Number,
41+
null -> obj.toString()
42+
43+
is Enum<*> -> obj.name
44+
45+
is State<*> -> serializeByReflection(
46+
obj = obj.value,
47+
tabsCount = tabsCount,
48+
rethrowGetterExceptions = rethrowGetterExceptions,
49+
maxDepth = maxDepth,
50+
currentDepth = currentDepth
51+
)
52+
53+
is StateFlow<*> -> serializeByReflection(
54+
obj = obj.value,
55+
tabsCount = tabsCount,
56+
rethrowGetterExceptions = rethrowGetterExceptions,
57+
maxDepth = maxDepth,
58+
currentDepth = currentDepth
59+
)
60+
61+
is List<*> -> "LISTS ARE NOT SUPPORTED YET! TODO: IMPL"
62+
63+
is Map<*, *> -> "MAPS ARE NOT SUPPORTED YET! TODO: IMPL"
64+
65+
else -> buildString {
66+
if(currentDepth > maxDepth) {
67+
return "null"
68+
}
69+
70+
@Suppress("UNCHECKED_CAST")
71+
val clazz = obj::class as KClass<Any>
72+
73+
if(clazz.qualifiedName?.startsWith("kotlin.Array") == true) {
74+
return "ARRAYS ARE NOT SUPPORTED YET! TODO: IMPL"
75+
}
76+
77+
clazz.memberProperties.also { members ->
78+
if(members.isEmpty()) {
79+
return "{}"
80+
}
81+
82+
append("{\n")
83+
}.iterate { member ->
84+
member.isAccessible = true
85+
86+
append("\t".repeat(tabsCount + 1))
87+
append("\"")
88+
append(member.name)
89+
append("\": ")
90+
91+
append(try {
92+
serializeByReflection(
93+
obj = member.get(obj),
94+
tabsCount = tabsCount + 1,
95+
rethrowGetterExceptions = rethrowGetterExceptions,
96+
maxDepth = maxDepth,
97+
currentDepth = currentDepth + 1
98+
)
99+
} catch(t: Throwable) {
100+
if(rethrowGetterExceptions) {
101+
throw t
102+
} else "null"
103+
})
104+
105+
if(hasNext()) {
106+
append(",")
107+
}
108+
109+
append("\n")
110+
}
111+
112+
append("\t".repeat(tabsCount))
113+
append("}")
114+
}
115+
}
116+
117+
object JavaSerializer: KSerializer<java.io.Serializable> {
118+
private val serializer = ByteArraySerializer()
119+
override val descriptor = serializer.descriptor
120+
121+
override fun serialize(encoder: Encoder, value: java.io.Serializable) {
122+
encoder.encodeSerializableValue(serializer, value.serialize())
123+
}
124+
125+
override fun deserialize(decoder: Decoder): java.io.Serializable {
126+
return decoder.decodeSerializableValue(serializer).deserialize()
127+
}
128+
}
129+
130+
/**
131+
* Uses a built-in Java serialization framework.
132+
* @see deserialize
133+
*/
134+
fun java.io.Serializable.serialize(): ByteArray {
135+
return ByteArrayOutputStream().apply {
136+
val oos = ObjectOutputStream(this)
137+
oos.writeObject(this@serialize)
138+
oos.close()
139+
}.toByteArray()
140+
}
141+
142+
/**
143+
* Uses a built-in Java serialization framework.
144+
* @see serialize
145+
*/
146+
// TODO: Add ability to specify a custom classloader so that we can serializable all external classes.
147+
fun ByteArray.deserialize(): java.io.Serializable {
148+
val bais = ByteArrayInputStream(this)
149+
val ois = ObjectInputStream(bais)
150+
151+
@Suppress("UNCHECKED_CAST")
152+
val o = ois.readObject()
153+
154+
ois.close()
155+
return o as Serializable
156+
}

data/src/commonMain/kotlin/com/mrboomdev/awery/data/database/AweryHistoryDatabase.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.mrboomdev.awery.data.database
22

33
import androidx.room.Database
44
import androidx.room.RoomDatabase
5+
import androidx.room.TypeConverters
56
import androidx.sqlite.driver.bundled.BundledSQLiteDriver
67
import com.mrboomdev.awery.data.database.dao.HistoryDao
78
import com.mrboomdev.awery.data.database.entity.DBHistoryItem
@@ -14,6 +15,7 @@ import kotlinx.coroutines.IO
1415
DBHistoryItem::class
1516
]
1617
)
18+
@TypeConverters(DBTypeConverters::class)
1719
abstract class AweryHistoryDatabase: RoomDatabase() {
1820
abstract val media: HistoryDao
1921
}

data/src/commonMain/kotlin/com/mrboomdev/awery/data/database/DBTypeConverters.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mrboomdev.awery.data.database
22

33
import androidx.room.TypeConverter
4+
import com.mrboomdev.awery.extension.sdk.Media
45
import kotlinx.serialization.json.Json
56

67
internal object DBTypeConverters {
@@ -13,4 +14,14 @@ internal object DBTypeConverters {
1314
fun deserializeStringList(input: String): List<String> {
1415
return Json.decodeFromString(input)
1516
}
17+
18+
@TypeConverter
19+
fun serializeMedia(input: Media): String {
20+
return Json.encodeToString(input)
21+
}
22+
23+
@TypeConverter
24+
fun deserializeMedia(input: String): Media {
25+
return Json.decodeFromString(input)
26+
}
1627
}

0 commit comments

Comments
 (0)