Skip to content
Snippets Groups Projects
Verified Commit 47583974 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

feat: implement a simple version of the message renderer

parent e4c0c7b7
No related branches found
No related tags found
No related merge requests found
Showing
with 182 additions and 2 deletions
......@@ -9,3 +9,22 @@ val Accent = Color(0xFFffaf3b)
val Secure = Color(0xFF4CAF50)
val PartiallySecure = Color(0xFFFFC107)
val Insecure = Color(0xFFD32F2F)
val SenderColors = listOf(
Color(0xFF_b80a73),
Color(0xFF_814dd5),
Color(0xFF_9f0b0b),
Color(0xFF_139f2f),
Color(0xFF_4e9c9f),
Color(0xFF_8b4a9f),
Color(0xFF_9f8669),
Color(0xFF_2b6b9f),
Color(0xFF_e00d8f),
Color(0xFF_995bfd),
Color(0xFF_c70e0e),
Color(0xFF_18c73e),
Color(0xFF_61c6c7),
Color(0xFF_af5ec7),
Color(0xFF_c7a782),
Color(0xFF_3684c7),
)
......@@ -5,6 +5,7 @@ import androidx.compose.runtime.DisallowComposableCalls
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.emitAll
import kotlinx.coroutines.flow.transform
......@@ -23,3 +24,8 @@ inline fun <T, R> Flow<T?>.flatMapLatestNullable(crossinline transform: suspend
inline fun <T> rememberFlow(initial: T, calculation: @DisallowComposableCalls () -> Flow<T>): T {
return remember(calculation).collectAsState(initial).value
}
@Composable
inline fun <T> rememberFlow(calculation: @DisallowComposableCalls () -> StateFlow<T>): T {
return remember(calculation).collectAsState().value
}
package de.justjanne.quasseldroid.util.saver
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.SaverScope
import de.justjanne.libquassel.protocol.models.ids.BufferId
object BufferIdSaver : Saver<BufferId, Int> {
override fun restore(value: Int) = BufferId(value)
override fun SaverScope.save(value: BufferId) = value.id
}
package de.justjanne.quasseldroid.util.saver
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.SaverScope
import de.justjanne.libquassel.protocol.models.ids.IdentityId
object IdentityIdSaver : Saver<IdentityId, Int> {
override fun restore(value: Int) = IdentityId(value)
override fun SaverScope.save(value: IdentityId) = value.id
}
package de.justjanne.quasseldroid.util.saver
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.SaverScope
import de.justjanne.libquassel.protocol.models.ids.MsgId
object MsgIdSaver : Saver<MsgId, Long> {
override fun restore(value: Long) = MsgId(value)
override fun SaverScope.save(value: MsgId) = value.id
}
package de.justjanne.quasseldroid.util.saver
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.SaverScope
import de.justjanne.libquassel.protocol.models.ids.NetworkId
object NetworkIdSaver : Saver<NetworkId, Int> {
override fun restore(value: Int) = NetworkId(value)
override fun SaverScope.save(value: NetworkId) = value.id
}
package de.justjanne.quasseldroid.util
package de.justjanne.quasseldroid.util.saver
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.SaverScope
......
package irc
object CRCUtils {
fun qChecksum(data: ByteArray): Int {
var crc = 0xffff
val crcHighBitMask = 0x8000
for (b in data) {
val c = reflect(b.toInt(), 8)
var j = 0x80
while (j > 0) {
var highBit = crc and crcHighBitMask
crc = crc shl 1
if (c and j > 0) {
highBit = highBit xor crcHighBitMask
}
if (highBit > 0) {
crc = crc xor 0x1021
}
j = j shr 1
}
}
crc = reflect(crc, 16)
crc = crc xor 0xffff
crc = crc and 0xffff
return crc
}
private fun reflect(crc: Int, n: Int): Int {
var j = 1
var crcout = 0
var i = 1 shl n - 1
while (i > 0) {
if (crc and i > 0) {
crcout = crcout or j
}
j = j shl 1
i = i shr 1
}
return crcout
}
}
package irc
import java.util.*
object SenderColorUtil {
fun senderColor(nick: String): Int {
return 0xf and CRCUtils.qChecksum(
nick.trimEnd('_')
.lowercase(Locale.ENGLISH)
.toByteArray(Charsets.ISO_8859_1)
)
}
}
package de.kuschku.justjanne.quasseldroid.util.irc
import irc.SenderColorUtil
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
class SenderColorUtilTest {
@Test
fun verifyTestData() {
assertEquals(0x5, SenderColorUtil.senderColor("mavhq"))
assertEquals(0xa, SenderColorUtil.senderColor("winch"))
assertEquals(0xc, SenderColorUtil.senderColor("mack"))
}
}
import gradle.kotlin.dsl.accessors._9f9f63157b527b37420ecbe9e569524a.testImplementation
import gradle.kotlin.dsl.accessors._9f9f63157b527b37420ecbe9e569524a.testRuntimeOnly
plugins {
java
id("justjanne.repositories")
}
dependencies {
testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.8.2")
testImplementation("org.junit.jupiter", "junit-jupiter-params", "5.8.2")
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine")
}
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
import gradle.kotlin.dsl.accessors._9f9f63157b527b37420ecbe9e569524a.implementation
import gradle.kotlin.dsl.accessors._9f9f63157b527b37420ecbe9e569524a.testImplementation
import gradle.kotlin.dsl.accessors._9f9f63157b527b37420ecbe9e569524a.testRuntimeOnly
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
......@@ -11,9 +12,16 @@ plugins {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.10")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.0")
testImplementation("org.junit.jupiter", "junit-jupiter-api", "5.8.2")
testImplementation("org.junit.jupiter", "junit-jupiter-params", "5.8.2")
testRuntimeOnly("org.junit.jupiter", "junit-jupiter-engine")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5:1.6.10")
}
tasks.withType<KotlinCompile> {
......@@ -26,3 +34,13 @@ tasks.withType<KotlinCompile> {
jvmTarget = "1.8"
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}
......@@ -2,7 +2,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("justjanne.java")
id("justjanne.repositories")
id("com.google.devtools.ksp")
kotlin("jvm")
kotlin("kapt")
......@@ -10,8 +9,11 @@ plugins {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.10")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.0")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5:1.6.10")
}
tasks.withType<KotlinCompile> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment