Skip to content

Commit

Permalink
update ktlint, format code
Browse files Browse the repository at this point in the history
  • Loading branch information
greenart7c3 committed May 27, 2024
1 parent ad979a2 commit f9613ad
Show file tree
Hide file tree
Showing 29 changed files with 241 additions and 218 deletions.
20 changes: 20 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
root = true

[*]
charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true

[*.{kt,kts}]
indent_size = 4
ij_kotlin_packages_to_use_import_on_demand = unset
ij_kotlin_name_count_to_use_star_import = 999
ij_kotlin_name_count_to_use_star_import_for_members = 999
max_line_length = off
ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_code_style = android_studio
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_allow_trailing_comma = true

[*.{yml,yaml}]
indent_size = 2
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.devtools.ksp")
id("org.jlleitschuh.gradle.ktlint") version "11.5.0"
id("org.jlleitschuh.gradle.ktlint") version "12.1.0"
}

android {
Expand Down Expand Up @@ -30,7 +30,7 @@ android {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
resValue("string", "app_name", "@string/app_name_release")
}
Expand Down
36 changes: 18 additions & 18 deletions app/src/main/java/com/greenart7c3/citrine/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ import com.greenart7c3.citrine.service.WebSocketServerService
import com.greenart7c3.citrine.ui.dialogs.ContactsDialog
import com.greenart7c3.citrine.ui.theme.CitrineTheme
import com.vitorpamplona.quartz.events.Event
import java.io.ByteArrayOutputStream
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
import kotlin.text.Charsets.UTF_8
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.ByteArrayOutputStream
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
import kotlin.text.Charsets.UTF_8

class MainActivity : ComponentActivity() {
private val storageHelper = SimpleStorageHelper(this@MainActivity)

@OptIn(DelicateCoroutinesApi::class)
private val requestPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
ActivityResultContracts.RequestPermission(),
) {
GlobalScope.launch(Dispatchers.IO) {
start()
Expand Down Expand Up @@ -169,14 +169,14 @@ class MainActivity : ComponentActivity() {
Toast.makeText(
context,
getString(R.string.sign_request_rejected),
Toast.LENGTH_SHORT
Toast.LENGTH_SHORT,
).show()
} else {
result.data?.let {
pubKey = it.getStringExtra("signature") ?: ""
}
}
}
},
)

CitrineTheme {
Expand All @@ -187,7 +187,7 @@ class MainActivity : ComponentActivity() {
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState()),
color = MaterialTheme.colorScheme.background
color = MaterialTheme.colorScheme.background,
) {
if (pubKey.isNotBlank()) {
ContactsDialog(pubKey = pubKey) {
Expand All @@ -197,7 +197,7 @@ class MainActivity : ComponentActivity() {

Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
horizontalAlignment = Alignment.CenterHorizontally,
) {
if (isLoading.value) {
CircularProgressIndicator()
Expand All @@ -214,7 +214,7 @@ class MainActivity : ComponentActivity() {
delay(1000)
isLoading.value = false
}
}
},
) {
Text(stringResource(R.string.stop))
}
Expand All @@ -228,7 +228,7 @@ class MainActivity : ComponentActivity() {
delay(1000)
isLoading.value = false
}
}
},
) {
Text(stringResource(R.string.start))
}
Expand All @@ -248,13 +248,13 @@ class MainActivity : ComponentActivity() {
Toast.makeText(
context,
getString(R.string.no_external_signer_installed),
Toast.LENGTH_SHORT
Toast.LENGTH_SHORT,
).show()
}
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/greenart7c3/Amber/releases"))
launcherLogin.launch(intent)
}
}
},
) {
Text(stringResource(R.string.restore_follows))
}
Expand All @@ -263,15 +263,15 @@ class MainActivity : ComponentActivity() {
ElevatedButton(
onClick = {
storageHelper.openFolderPicker()
}
},
) {
Text("Export database")
}
Spacer(modifier = Modifier.padding(4.dp))
ElevatedButton(
onClick = {
storageHelper.openFilePicker()
}
},
) {
Text("Import database")
}
Expand All @@ -280,7 +280,7 @@ class MainActivity : ComponentActivity() {
Spacer(modifier = Modifier.padding(4.dp))
Text(
"Relay",
fontWeight = FontWeight.Bold
fontWeight = FontWeight.Bold,
)
Spacer(modifier = Modifier.padding(4.dp))
Text("Connections: ${service?.webSocketServer?.connections?.size ?: 0}")
Expand All @@ -293,7 +293,7 @@ class MainActivity : ComponentActivity() {
Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp),
horizontalArrangement = Arrangement.SpaceBetween
horizontalArrangement = Arrangement.SpaceBetween,
) {
Text("Kind", fontWeight = FontWeight.Bold)
Text("Count", fontWeight = FontWeight.Bold)
Expand All @@ -304,7 +304,7 @@ class MainActivity : ComponentActivity() {
Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp),
horizontalArrangement = Arrangement.SpaceBetween
horizontalArrangement = Arrangement.SpaceBetween,
) {
Text("${item.kind}")
Text("${item.count}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ import androidx.room.TypeConverters

@Database(
entities = [EventEntity::class, TagEntity::class],
version = 1
version = 1,
)
@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun eventDao(): EventDao

companion object {
@Volatile
private var INSTANCE: AppDatabase? = null
private var database: AppDatabase? = null

fun getDatabase(context: Context): AppDatabase {
return INSTANCE ?: synchronized(this) {
return database ?: synchronized(this) {
val instance = Room.databaseBuilder(
context,
AppDatabase::class.java,
"citrine_database"
"citrine_database",
).build()

INSTANCE = instance
database = instance
instance
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ interface EventDao {
AND TagEntity.col0Name = 'd'
AND TagEntity.col1Value = :dTagValue
)
"""
""",
)
@Transaction
fun getOldestReplaceable(kind: Int, pubkey: String, dTagValue: String): List<String>
Expand Down
49 changes: 26 additions & 23 deletions app/src/main/java/com/greenart7c3/citrine/database/EventEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import com.vitorpamplona.quartz.events.EventFactory
Index(
value = ["id"],
name = "id_is_hash",
unique = true
unique = true,
),
Index(
value = ["pubkey", "kind"],
name = "most_common_search_is_pubkey_kind",
orders = [Index.Order.ASC, Index.Order.ASC]
)
]
orders = [Index.Order.ASC, Index.Order.ASC],
),
],
)
data class EventEntity(
@PrimaryKey(autoGenerate = false)
Expand All @@ -34,16 +34,16 @@ data class EventEntity(
val createdAt: Long,
val kind: Int,
val content: String,
val sig: String
val sig: String,
)

data class EventWithTags(
@Embedded val event: EventEntity,
@Relation(
parentColumn = "id",
entityColumn = "pkEvent"
entityColumn = "pkEvent",
)
val tags: List<TagEntity>
val tags: List<TagEntity>,
)

@Entity(
Expand All @@ -52,21 +52,20 @@ data class EventWithTags(
entity = EventEntity::class,
childColumns = ["pkEvent"],
parentColumns = ["id"],
onDelete = CASCADE
)
onDelete = CASCADE,
),
],
indices = [
Index(
value = ["pkEvent"],
name = "tags_by_pk_event"
name = "tags_by_pk_event",
),
Index(
value = ["col0Name", "col1Value"],
name = "tags_by_tags_on_person_or_events"
)
]
name = "tags_by_tags_on_person_or_events",
),
],
)

data class TagEntity(
@PrimaryKey(autoGenerate = true) val pk: Long? = null,
var pkEvent: String? = null,
Expand All @@ -77,7 +76,7 @@ data class TagEntity(
val col1Value: String?,
val col2Differentiator: String?,
val col3Amount: String?,
val col4Plus: List<String>
val col4Plus: List<String>,
)

class Converters {
Expand Down Expand Up @@ -108,7 +107,7 @@ fun EventWithTags.toEvent(): Event {
sig = event.sig,
tags = tags.map {
it.toTags()
}.toTypedArray()
}.toTypedArray(),
)
}

Expand All @@ -117,7 +116,7 @@ fun TagEntity.toTags(): Array<String> {
col0Name,
col1Value,
col2Differentiator,
col3Amount
col3Amount,
).plus(col4Plus).toTypedArray()
}

Expand All @@ -128,17 +127,21 @@ fun Event.toEventWithTags(): EventWithTags {
createdAt = createdAt,
kind = kind,
content = content,
sig = sig
sig = sig,
)

val dbTags = tags.mapIndexed { index, tag ->
TagEntity(
position = index,
col0Name = tag.getOrNull(0), // tag name
col1Value = tag.getOrNull(1), // tag value
col2Differentiator = tag.getOrNull(2), // marker
col3Amount = tag.getOrNull(3), // value
col4Plus = if (tag.size > 4) tag.asList().subList(4, tag.size) else emptyList()
// tag name
col0Name = tag.getOrNull(0),
// tag value
col1Value = tag.getOrNull(1),
// marker
col2Differentiator = tag.getOrNull(2),
// value
col3Amount = tag.getOrNull(3),
col4Plus = if (tag.size > 4) tag.asList().subList(4, tag.size) else emptyList(),
)
}

Expand Down
Loading

0 comments on commit f9613ad

Please sign in to comment.