Compare commits
36 Commits
master
...
d7d14389fc
| Author | SHA1 | Date | |
|---|---|---|---|
| d7d14389fc | |||
| 902af5e7b5 | |||
| 64de39f0ca | |||
| f8b10ebb34 | |||
| a090ff614a | |||
| dd3b31d0b2 | |||
| c7b5f20c06 | |||
| 8d6a76ccb5 | |||
| 1cfad2ca4e | |||
| b6e8c73758 | |||
| 28337b1306 | |||
| 05d3d739e2 | |||
| 5c6cd29a05 | |||
| 70d9db6cbf | |||
| 7026acc229 | |||
| fa53e0ae86 | |||
| ebbc9a4b1f | |||
| 05fbfbac07 | |||
| 5897d31a51 | |||
| a0bfba23cf | |||
| 00f273c866 | |||
| 0384626d83 | |||
| ea783c9f27 | |||
| 4236c4342b | |||
| c40b13a7ea | |||
| de205b739f | |||
| 8ac9ccfaca | |||
| 7a2567f019 | |||
| 26417b8072 | |||
| 23780489f6 | |||
| bd87ca2729 | |||
| 7ba5876a71 | |||
| cab56d6329 | |||
| e70049f1f5 | |||
| c0944ec0a8 | |||
| 5fbffd8700 |
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AndroidProjectSystem">
|
||||||
|
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+1
-5
@@ -1,7 +1,3 @@
|
|||||||
<component name="CopyrightManager">
|
<component name="CopyrightManager">
|
||||||
<settings default="My">
|
<settings default="My" />
|
||||||
<module2copyright>
|
|
||||||
<element module="All" copyright="My" />
|
|
||||||
</module2copyright>
|
|
||||||
</settings>
|
|
||||||
</component>
|
</component>
|
||||||
Generated
+8
@@ -4,6 +4,14 @@
|
|||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
|
<DropdownSelection timestamp="2025-02-22T11:46:39.159466074Z">
|
||||||
|
<Target type="DEFAULT_BOOT">
|
||||||
|
<handle>
|
||||||
|
<DeviceId pluginId="PhysicalDevice" identifier="serial=22163a3c" />
|
||||||
|
</handle>
|
||||||
|
</Target>
|
||||||
|
</DropdownSelection>
|
||||||
|
<DialogSelection />
|
||||||
</SelectionState>
|
</SelectionState>
|
||||||
</selectionStates>
|
</selectionStates>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
+3
@@ -49,6 +49,9 @@
|
|||||||
<option name="composableFile" value="true" />
|
<option name="composableFile" value="true" />
|
||||||
<option name="previewFile" value="true" />
|
<option name="previewFile" value="true" />
|
||||||
</inspection_tool>
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PreviewParameterProviderOnFirstParameter" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
|
<option name="composableFile" value="true" />
|
||||||
|
</inspection_tool>
|
||||||
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
|
||||||
<option name="composableFile" value="true" />
|
<option name="composableFile" value="true" />
|
||||||
<option name="previewFile" value="true" />
|
<option name="previewFile" value="true" />
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="KotlinJpsPluginSettings">
|
<component name="KotlinJpsPluginSettings">
|
||||||
<option name="version" value="2.0.0" />
|
<option name="version" value="2.0.21" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
Generated
+4
@@ -5,8 +5,12 @@
|
|||||||
<set>
|
<set>
|
||||||
<option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
|
<option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
|
||||||
<option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
|
<option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
|
||||||
|
<option value="com.intellij.execution.junit.PatternConfigurationProducer" />
|
||||||
<option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
|
<option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
|
||||||
<option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
|
<option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
|
||||||
|
<option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
|
||||||
|
<option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
|
||||||
|
<option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="StudioBotProjectSettings">
|
||||||
|
<option name="shareContext" value="OptedIn" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
+40
-13
@@ -1,22 +1,23 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Created by sweetbread on 21.02.2025, 12:01
|
* Created by sweetbread
|
||||||
* Copyright (c) 2025. All rights reserved.
|
* Copyright (c) 2026. All rights reserved.
|
||||||
* Last modified 21.02.2025, 12:01
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application)
|
alias(libs.plugins.android.application)
|
||||||
alias(libs.plugins.kotlin.android)
|
|
||||||
alias(libs.plugins.kotlin.compose)
|
alias(libs.plugins.kotlin.compose)
|
||||||
|
// alias(libs.plugins.ksp)
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "ru.risdeveau.pixeldragon"
|
namespace = "ru.risdeveau.pixeldragon"
|
||||||
compileSdk = 35
|
compileSdk = 36
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "ru.risdeveau.pixeldragon"
|
applicationId = "ru.risdeveau.pixeldragon"
|
||||||
minSdk = 24
|
minSdk = 28
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 1
|
versionCode = 1
|
||||||
versionName = "1.0"
|
versionName = "1.0"
|
||||||
@@ -34,17 +35,20 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = "1.8"
|
|
||||||
}
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
compose = true
|
compose = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
compilerOptions {
|
||||||
|
jvmTarget.set(JvmTarget.JVM_17)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(libs.androidx.core.ktx)
|
implementation(libs.androidx.core.ktx)
|
||||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||||
@@ -62,14 +66,37 @@ dependencies {
|
|||||||
debugImplementation(libs.androidx.ui.tooling)
|
debugImplementation(libs.androidx.ui.tooling)
|
||||||
debugImplementation(libs.androidx.ui.test.manifest)
|
debugImplementation(libs.androidx.ui.test.manifest)
|
||||||
|
|
||||||
|
// Trixnity - Matrix wrapper
|
||||||
|
implementation(libs.trixnity.client)
|
||||||
|
implementation(libs.trixnity.client.media.okio)
|
||||||
|
implementation(libs.trixnity.client.repository.room)
|
||||||
|
implementation(libs.trixnity.client.cryptodriver.vodozemac)
|
||||||
|
// implementation(libs.trixnity.messenger)
|
||||||
|
|
||||||
// Ktor - web client
|
// Ktor - web client
|
||||||
implementation(libs.ktor.client.core)
|
implementation(libs.ktor.client.core)
|
||||||
implementation(libs.ktor.client.cio)
|
implementation(libs.ktor.client.okhttp)
|
||||||
|
implementation(libs.ktor.client.logging)
|
||||||
|
|
||||||
// Coil - image loader
|
// Coil - image loader
|
||||||
implementation(libs.coil.compose)
|
implementation(libs.coil.compose)
|
||||||
implementation(libs.coil.network.okhttp)
|
implementation(libs.coil.network.okhttp)
|
||||||
|
|
||||||
|
// Room - database
|
||||||
|
implementation(libs.androidx.room.runtime)
|
||||||
|
implementation(libs.androidx.lifecycle.viewmodel.ktx)
|
||||||
|
implementation(libs.androidx.room.ktx)
|
||||||
|
// ksp(libs.androidx.room.compiler)
|
||||||
|
|
||||||
|
// Navigation Compose
|
||||||
|
implementation(libs.androidx.navigation.compose)
|
||||||
|
implementation(libs.androidx.navigation.fragment)
|
||||||
|
implementation(libs.androidx.navigation.ui)
|
||||||
|
implementation(libs.androidx.navigation.dynamic.features.fragment)
|
||||||
|
androidTestImplementation(libs.androidx.navigation.testing)
|
||||||
|
|
||||||
// Others
|
// Others
|
||||||
implementation(libs.splitties.base) // Syntax sugar
|
implementation(libs.splitties.base) // Syntax sugar
|
||||||
|
implementation(libs.jsoup) // HTML parser
|
||||||
|
implementation(libs.iconsax.compose) // Material icons
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
~ Created by sweetbread on 21.02.2025, 12:08
|
~ Created by sweetbread
|
||||||
~ Copyright (c) 2025. All rights reserved.
|
~ Copyright (c) 2025. All rights reserved.
|
||||||
~ Last modified 21.02.2025, 12:07
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
@@ -20,15 +19,9 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.PixelDragon"
|
android:theme="@style/Theme.PixelDragon"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
<activity
|
|
||||||
android:name=".ui.activity.Login"
|
|
||||||
android:exported="false"
|
|
||||||
android:label="@string/title_activity_login"
|
|
||||||
android:theme="@style/Theme.PixelDragon" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.activity.MainActivity"
|
android:name=".ui.activity.MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/app_name"
|
|
||||||
android:theme="@style/Theme.PixelDragon">
|
android:theme="@style/Theme.PixelDragon">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
@@ -36,6 +29,11 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".ui.activity.Login"
|
||||||
|
android:exported="false"
|
||||||
|
android:theme="@style/Theme.PixelDragon" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -1,43 +1,29 @@
|
|||||||
/*
|
/*
|
||||||
* Created by sweetbread on 21.02.2025, 12:01
|
* Created by sweetbread
|
||||||
* Copyright (c) 2025. All rights reserved.
|
* Copyright (c) 2026. All rights reserved.
|
||||||
* Last modified 21.02.2025, 12:01
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.risdeveau.pixeldragon
|
package ru.risdeveau.pixeldragon
|
||||||
|
|
||||||
import android.content.Context
|
import android.util.Log
|
||||||
|
import de.connect2x.trixnity.client.MatrixClient
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.engine.cio.CIO
|
|
||||||
import io.ktor.client.engine.cio.endpoint
|
|
||||||
import io.ktor.client.plugins.cache.HttpCache
|
import io.ktor.client.plugins.cache.HttpCache
|
||||||
import ru.risdeveau.pixeldragon.api.getMe
|
import io.ktor.client.plugins.logging.LogLevel
|
||||||
import splitties.init.appCtx
|
import io.ktor.client.plugins.logging.Logger
|
||||||
|
import io.ktor.client.plugins.logging.Logging
|
||||||
|
|
||||||
val client = HttpClient(CIO) {
|
val webClient = HttpClient {
|
||||||
engine {
|
install(Logging) {
|
||||||
endpoint {
|
logger = object : Logger {
|
||||||
maxConnectionsPerRoute = 100
|
override fun log(message: String) {
|
||||||
pipelineMaxSize = 20
|
Log.i("Ktor", message)
|
||||||
keepAliveTime = 30000
|
}
|
||||||
connectTimeout = 15000
|
|
||||||
connectAttempts = 5
|
|
||||||
}
|
}
|
||||||
|
level = LogLevel.ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
install(HttpCache)
|
install(HttpCache)
|
||||||
}
|
}
|
||||||
|
|
||||||
val accountData = appCtx.getSharedPreferences("settings", Context.MODE_PRIVATE)
|
var client: MatrixClient? = null
|
||||||
lateinit var urlBase: String
|
|
||||||
lateinit var token: String
|
|
||||||
|
|
||||||
suspend fun initCheck(): Boolean {
|
|
||||||
if (!accountData.contains("token")) return false
|
|
||||||
if (!accountData.contains("homeserver")) return false
|
|
||||||
|
|
||||||
token = accountData.getString("token", "").toString()
|
|
||||||
urlBase = "https://${accountData.getString("homeserver", "")}/_matrix/client/v3"
|
|
||||||
|
|
||||||
return getMe() != null
|
|
||||||
}
|
|
||||||
+50
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Created by sweetbread
|
||||||
|
* Copyright (c) 2026. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ru.risdeveau.pixeldragon.api
|
||||||
|
|
||||||
|
import org.json.JSONObject
|
||||||
|
import java.time.Instant
|
||||||
|
|
||||||
|
class Event (
|
||||||
|
val id: String,
|
||||||
|
val rid: String,
|
||||||
|
val type: String,
|
||||||
|
val content: JSONObject,
|
||||||
|
val time: Instant,
|
||||||
|
val sender: String
|
||||||
|
) {
|
||||||
|
// constructor(json: JSONObject) : this(
|
||||||
|
// json.getString("event_id"),
|
||||||
|
// json.getString("room_id"),
|
||||||
|
// json.getString("sender"),
|
||||||
|
// json.getString("type"),
|
||||||
|
// json.getJSONObject("content")
|
||||||
|
// )
|
||||||
|
}
|
||||||
|
|
||||||
|
//data class EventsAround (
|
||||||
|
// val base: Event,
|
||||||
|
// val before: List<Event>,
|
||||||
|
// val after: List<Event>
|
||||||
|
//)
|
||||||
|
//
|
||||||
|
//suspend fun getEventsAround(room: String, event: String): EventsAround {
|
||||||
|
// val r = client.get("$baseUrl/rooms/$room/context/$event") {
|
||||||
|
// bearerAuth(token)
|
||||||
|
// parameter("limit", "50")
|
||||||
|
// }
|
||||||
|
// val json = JSONObject(r.bodyAsText())
|
||||||
|
//
|
||||||
|
// return EventsAround(
|
||||||
|
// Event(json.getJSONObject("event")),
|
||||||
|
// if (json.has("events_before")) json.getJSONArray("events_before").let {
|
||||||
|
// List<Event>(it.length()) { i -> Event(it.getJSONObject(i))}.reversed()
|
||||||
|
// } else listOf(),
|
||||||
|
// if (json.has("events_after")) json.getJSONArray("events_after").let {
|
||||||
|
// List<Event>(it.length()) { i -> Event(it.getJSONObject(i))}
|
||||||
|
// } else listOf()
|
||||||
|
// )
|
||||||
|
//}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
* Created by sweetbread
|
||||||
|
* Copyright (c) 2026. All rights reserved.
|
||||||
|
*/
|
||||||
@@ -1,23 +1,44 @@
|
|||||||
/*
|
/*
|
||||||
* Created by sweetbread on 21.02.2025, 12:01
|
* Created by sweetbread
|
||||||
* Copyright (c) 2025. All rights reserved.
|
* Copyright (c) 2026. All rights reserved.
|
||||||
* Last modified 21.02.2025, 12:01
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.risdeveau.pixeldragon.api
|
package ru.risdeveau.pixeldragon.api
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import io.ktor.client.request.get
|
import io.ktor.client.request.get
|
||||||
import io.ktor.client.statement.bodyAsText
|
import io.ktor.client.statement.bodyAsText
|
||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import ru.risdeveau.pixeldragon.client
|
import ru.risdeveau.pixeldragon.webClient
|
||||||
|
//import ru.risdeveau.pixeldragon.homeserver
|
||||||
|
|
||||||
suspend fun isMatrixServer(url: String): Boolean {
|
suspend fun getHomeserver(url: String): String? {
|
||||||
val r = try { client.get("https://$url/.well-known/matrix/client") }
|
val r = try { webClient.get("https://$url/.well-known/matrix/client") }
|
||||||
catch (_: Exception) { return false }
|
catch (e: Exception) {
|
||||||
|
Log.w("getHomeserver", "Fail sending the request", e)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
try { JSONObject(r.bodyAsText()) }
|
val json = try { JSONObject(r.bodyAsText()) }
|
||||||
catch (_: JSONException) { return false }
|
catch (e: JSONException) {
|
||||||
|
Log.w("getHomeserver", "Fail parsing the JSON", e)
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
if (!json.has("m.homeserver")) return null
|
||||||
|
|
||||||
|
var homeserver = json.getJSONObject("m.homeserver").getString("base_url")
|
||||||
|
if (homeserver.endsWith("/")) homeserver = homeserver.dropLast(1)
|
||||||
|
|
||||||
|
return homeserver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fun mxcToUrl(mxc: String): String? {
|
||||||
|
// val pattern = Regex("mxc://([-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6})/([^#?]+)")
|
||||||
|
// val match = pattern.find(mxc)
|
||||||
|
//
|
||||||
|
// if ((match?.groupValues[1] == null) or (match?.groupValues[2] == null)) return null
|
||||||
|
//
|
||||||
|
// return "$homeserver/_matrix/client/v1/media/download/${match?.groupValues[1]}/${match?.groupValues[2]}"
|
||||||
|
//}
|
||||||
@@ -1,82 +1,49 @@
|
|||||||
/*
|
/*
|
||||||
* Created by sweetbread on 21.02.2025, 12:09
|
* Created by sweetbread
|
||||||
* Copyright (c) 2025. All rights reserved.
|
* Copyright (c) 2026. All rights reserved.
|
||||||
* Last modified 21.02.2025, 12:01
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.risdeveau.pixeldragon.api
|
package ru.risdeveau.pixeldragon.api
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import io.ktor.client.request.bearerAuth
|
import de.connect2x.trixnity.client.CryptoDriverModule
|
||||||
import io.ktor.client.request.get
|
import io.ktor.http.Url
|
||||||
import io.ktor.client.request.post
|
import de.connect2x.trixnity.client.MatrixClient
|
||||||
import io.ktor.client.request.setBody
|
import de.connect2x.trixnity.client.create
|
||||||
import io.ktor.client.statement.bodyAsText
|
import de.connect2x.trixnity.client.cryptodriver.vodozemac.vodozemac
|
||||||
import io.ktor.http.ContentType
|
import de.connect2x.trixnity.clientserverapi.client.MatrixClientAuthProviderData
|
||||||
import io.ktor.http.HttpStatusCode
|
import de.connect2x.trixnity.clientserverapi.client.classicLogin
|
||||||
import io.ktor.http.contentType
|
import de.connect2x.trixnity.clientserverapi.model.authentication.IdentifierType
|
||||||
import org.json.JSONObject
|
|
||||||
import ru.risdeveau.pixeldragon.accountData
|
|
||||||
import ru.risdeveau.pixeldragon.client
|
import ru.risdeveau.pixeldragon.client
|
||||||
import ru.risdeveau.pixeldragon.initCheck
|
import ru.risdeveau.pixeldragon.util.getMediaStore
|
||||||
import ru.risdeveau.pixeldragon.token
|
import ru.risdeveau.pixeldragon.util.getRoomStore
|
||||||
import ru.risdeveau.pixeldragon.urlBase
|
import splitties.experimental.ExperimentalSplittiesApi
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
|
|
||||||
data class Me (val userId: String, val deviceId: String)
|
|
||||||
|
|
||||||
/**
|
@OptIn(ExperimentalSplittiesApi::class)
|
||||||
* This func is to validate the token
|
suspend fun login(server: String, login: String, pass: String): Boolean {
|
||||||
*/
|
val hs = Url(getHomeserver(server)!!)
|
||||||
suspend fun getMe(): Me? {
|
|
||||||
val r = client.get("$urlBase/account/whoami") { bearerAuth(token) }
|
|
||||||
if (r.status != HttpStatusCode.OK) {
|
|
||||||
Log.e("getMe", r.bodyAsText())
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
val json = JSONObject(r.bodyAsText())
|
val pinfo = appCtx.packageManager.getPackageInfo(appCtx.packageName, 0)
|
||||||
return Me(json.getString("user_id"), json.getString("device_id"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("ApplySharedPref")
|
try {
|
||||||
suspend fun login(homeserver: String, login: String, pass: String): Boolean {
|
client = MatrixClient.create(
|
||||||
val pinfo = appCtx.packageManager.getPackageInfo(appCtx.packageName, 0);
|
repositoriesModule = getRoomStore(appCtx),
|
||||||
|
mediaStoreModule = getMediaStore(),
|
||||||
|
cryptoDriverModule = CryptoDriverModule.vodozemac(),
|
||||||
|
authProviderData = MatrixClientAuthProviderData.classicLogin(
|
||||||
|
baseUrl = hs,
|
||||||
|
identifier = IdentifierType.User(login),
|
||||||
|
password = pass,
|
||||||
|
initialDeviceDisplayName = "PixelDragon Android v${pinfo.versionName}",
|
||||||
|
).getOrThrow()
|
||||||
|
).getOrThrow()
|
||||||
|
|
||||||
val pattern = """
|
return true
|
||||||
{
|
|
||||||
"type": "m.login.password",
|
|
||||||
"identifier": {
|
|
||||||
"type": "m.id.user"
|
|
||||||
},
|
|
||||||
"initial_device_display_name": "PixelDragon Android v${pinfo.versionName}"
|
|
||||||
}
|
|
||||||
""".trimIndent()
|
|
||||||
val json = JSONObject(pattern)
|
|
||||||
json.getJSONObject("identifier").put("user", login)
|
|
||||||
json.put("password", pass)
|
|
||||||
|
|
||||||
val r = try {
|
|
||||||
client.post("https://$homeserver/_matrix/client/v3/login") {
|
|
||||||
setBody(json.toString())
|
|
||||||
contentType(ContentType.Application.Json)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("login", e.toString())
|
Log.i("Login", "Failed to login", e)
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r.status != HttpStatusCode.OK) {
|
return false
|
||||||
Log.e("login", r.bodyAsText())
|
|
||||||
return false // TODO: Inform a user of error code
|
|
||||||
}
|
|
||||||
|
|
||||||
val res = JSONObject(r.bodyAsText())
|
|
||||||
val editor = accountData.edit()
|
|
||||||
editor.putString("token", res.getString("access_token"))
|
|
||||||
editor.putString("homeserver", res.getString("home_server"))
|
|
||||||
editor.commit()
|
|
||||||
|
|
||||||
return initCheck()
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
* Created by sweetbread
|
||||||
|
* Copyright (c) 2026. All rights reserved.
|
||||||
|
*/
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
* Created by sweetbread
|
||||||
|
* Copyright (c) 2026. All rights reserved.
|
||||||
|
*/
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
* Created by sweetbread
|
||||||
|
* Copyright (c) 2026. All rights reserved.
|
||||||
|
*/
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
* Created by sweetbread
|
||||||
|
* Copyright (c) 2026. All rights reserved.
|
||||||
|
*/
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
* Created by sweetbread
|
||||||
|
* Copyright (c) 2026. All rights reserved.
|
||||||
|
*/
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
* Created by sweetbread
|
||||||
|
* Copyright (c) 2026. All rights reserved.
|
||||||
|
*/
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Created by sweetbread on 21.02.2025, 12:08
|
* Created by sweetbread
|
||||||
* Copyright (c) 2025. All rights reserved.
|
* Copyright (c) 2025. All rights reserved.
|
||||||
* Last modified 21.02.2025, 12:08
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.risdeveau.pixeldragon.ui.activity
|
package ru.risdeveau.pixeldragon.ui.activity
|
||||||
@@ -35,15 +34,18 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import ru.risdeveau.pixeldragon.api.isMatrixServer
|
import ru.risdeveau.pixeldragon.api.getHomeserver
|
||||||
import ru.risdeveau.pixeldragon.api.login
|
import ru.risdeveau.pixeldragon.api.login
|
||||||
import ru.risdeveau.pixeldragon.ui.theme.PixelDragonTheme
|
import ru.risdeveau.pixeldragon.ui.theme.PixelDragonTheme
|
||||||
import splitties.activities.start
|
import splitties.activities.start
|
||||||
|
|
||||||
class Login : ComponentActivity() {
|
class Login : ComponentActivity() {
|
||||||
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
PixelDragonTheme {
|
PixelDragonTheme {
|
||||||
@@ -56,10 +58,16 @@ class Login : ComponentActivity() {
|
|||||||
SnackbarHost(hostState = snackbarHostState)
|
SnackbarHost(hostState = snackbarHostState)
|
||||||
}
|
}
|
||||||
) { innerPadding ->
|
) { innerPadding ->
|
||||||
Box(Modifier.fillMaxSize().padding(innerPadding)) {
|
Box(
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(innerPadding)) {
|
||||||
LoginField(
|
LoginField(
|
||||||
Modifier.align(Alignment.Center),
|
Modifier.align(Alignment.Center),
|
||||||
{ start<MainActivity>() },
|
{
|
||||||
|
start<MainActivity>()
|
||||||
|
finish()
|
||||||
|
},
|
||||||
{
|
{
|
||||||
scope.launch {
|
scope.launch {
|
||||||
snackbarHostState
|
snackbarHostState
|
||||||
@@ -89,7 +97,7 @@ fun LoginField(modifier: Modifier = Modifier, ok: () -> Unit, err: () -> Unit) {
|
|||||||
var login by remember { mutableStateOf("") }
|
var login by remember { mutableStateOf("") }
|
||||||
var pass by remember { mutableStateOf("") }
|
var pass by remember { mutableStateOf("") }
|
||||||
|
|
||||||
var hmsValid by remember { mutableStateOf(false) }
|
var hmsValid: Boolean by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
modifier = Modifier.padding(4.dp),
|
modifier = Modifier.padding(4.dp),
|
||||||
@@ -119,18 +127,17 @@ fun LoginField(modifier: Modifier = Modifier, ok: () -> Unit, err: () -> Unit) {
|
|||||||
Button(
|
Button(
|
||||||
enabled = hmsValid && !login.isEmpty() && !pass.isEmpty(),
|
enabled = hmsValid && !login.isEmpty() && !pass.isEmpty(),
|
||||||
onClick = {
|
onClick = {
|
||||||
var loginSuccess = false
|
scope.launch {
|
||||||
scope.launch { loginSuccess = login(homeserver, login, pass) }
|
if (login(homeserver, login, pass)) ok()
|
||||||
|
else err()
|
||||||
if (loginSuccess) ok()
|
}
|
||||||
else err()
|
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Text("Login")
|
Text("Login")
|
||||||
}
|
}
|
||||||
|
|
||||||
LaunchedEffect(homeserver) {
|
LaunchedEffect(homeserver) {
|
||||||
scope.launch { hmsValid = isMatrixServer(homeserver) }
|
scope.launch { hmsValid = (getHomeserver(homeserver) != null) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,81 +1,144 @@
|
|||||||
/*
|
/*
|
||||||
* Created by sweetbread on 21.02.2025, 12:08
|
* Created by sweetbread
|
||||||
* Copyright (c) 2025. All rights reserved.
|
* Copyright (c) 2026. All rights reserved.
|
||||||
* Last modified 21.02.2025, 12:07
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package ru.risdeveau.pixeldragon.ui.activity
|
package ru.risdeveau.pixeldragon.ui.activity
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TopAppBar
|
|
||||||
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
|
import androidx.compose.material3.TopAppBarDefaults.topAppBarColors
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.navigation.NavType
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import androidx.navigation.compose.NavHost
|
||||||
import kotlinx.coroutines.GlobalScope
|
import androidx.navigation.compose.composable
|
||||||
|
import androidx.navigation.compose.rememberNavController
|
||||||
|
import androidx.navigation.navArgument
|
||||||
|
import de.connect2x.trixnity.client.CryptoDriverModule
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import ru.risdeveau.pixeldragon.initCheck
|
import de.connect2x.trixnity.client.MatrixClient
|
||||||
|
import de.connect2x.trixnity.client.create
|
||||||
|
import de.connect2x.trixnity.client.cryptodriver.vodozemac.vodozemac
|
||||||
|
import de.connect2x.trixnity.clientserverapi.client.SyncState
|
||||||
|
import ru.risdeveau.pixeldragon.R
|
||||||
|
import ru.risdeveau.pixeldragon.client
|
||||||
|
import ru.risdeveau.pixeldragon.ui.layout.Room
|
||||||
|
import ru.risdeveau.pixeldragon.ui.layout.RoomList
|
||||||
import ru.risdeveau.pixeldragon.ui.theme.PixelDragonTheme
|
import ru.risdeveau.pixeldragon.ui.theme.PixelDragonTheme
|
||||||
|
import ru.risdeveau.pixeldragon.util.getMediaStore
|
||||||
|
import ru.risdeveau.pixeldragon.util.getRoomStore
|
||||||
import splitties.activities.start
|
import splitties.activities.start
|
||||||
|
import splitties.init.appCtx
|
||||||
|
import splitties.resources.str
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
@OptIn(ExperimentalMaterial3Api::class, DelicateCoroutinesApi::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
GlobalScope.launch {
|
|
||||||
if (!initCheck()) start<Login>()
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
PixelDragonTheme {
|
PixelDragonTheme {
|
||||||
Scaffold(
|
var isClientReady by remember { mutableStateOf(false) }
|
||||||
modifier = Modifier.fillMaxSize(),
|
val syncState by remember { mutableStateOf(SyncState.STOPPED) }
|
||||||
topBar = {
|
|
||||||
TopAppBar(
|
if (!isClientReady) {
|
||||||
colors = topAppBarColors(
|
CircularProgressIndicator()
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
} else {
|
||||||
titleContentColor = MaterialTheme.colorScheme.primary,
|
Scaffold(
|
||||||
),
|
modifier = Modifier.fillMaxSize(),
|
||||||
title = {
|
topBar = {
|
||||||
Text("Top app bar")
|
CenterAlignedTopAppBar(
|
||||||
|
colors = topAppBarColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||||
|
titleContentColor = MaterialTheme.colorScheme.primary,
|
||||||
|
),
|
||||||
|
title = {
|
||||||
|
when (syncState) {
|
||||||
|
SyncState.STARTED -> Text("Syncing...")
|
||||||
|
SyncState.INITIAL_SYNC -> Text("Initial sync...")
|
||||||
|
SyncState.STOPPED,
|
||||||
|
SyncState.RUNNING -> Text(str(R.string.app_name))
|
||||||
|
SyncState.TIMEOUT -> Text("No network connection")
|
||||||
|
SyncState.ERROR -> Text("Error syncing")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
) { innerPadding ->
|
||||||
|
val navController = rememberNavController()
|
||||||
|
|
||||||
|
NavHost(navController = navController, startDestination = "rooms") {
|
||||||
|
composable("rooms") {
|
||||||
|
RoomList(Modifier.padding(innerPadding), navController)
|
||||||
}
|
}
|
||||||
)
|
composable(
|
||||||
},
|
"room/{rid}",
|
||||||
) { innerPadding ->
|
arguments = listOf(navArgument("rid") { type = NavType.StringType })
|
||||||
Greeting(
|
) { navBackStackEntry ->
|
||||||
name = "Android",
|
Room(Modifier
|
||||||
modifier = Modifier.padding(innerPadding)
|
.padding(innerPadding)
|
||||||
)
|
.fillMaxSize(), navBackStackEntry.arguments!!.getString("rid")!!)
|
||||||
|
}
|
||||||
|
composable(
|
||||||
|
"space/{rid}",
|
||||||
|
arguments = listOf(navArgument("rid") { type = NavType.StringType })
|
||||||
|
) { navBackStackEntry ->
|
||||||
|
Text(
|
||||||
|
modifier = Modifier.padding(innerPadding),
|
||||||
|
text = "Not implemented"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
if (client == null) {
|
||||||
|
client = MatrixClient.create(
|
||||||
|
repositoriesModule = getRoomStore(appCtx),
|
||||||
|
mediaStoreModule = getMediaStore(),
|
||||||
|
cryptoDriverModule = CryptoDriverModule.vodozemac()
|
||||||
|
).getOrNull()
|
||||||
|
|
||||||
|
if (client == null) {
|
||||||
|
start<Login>()
|
||||||
|
finish()
|
||||||
|
return@LaunchedEffect
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.i("MainActivity", "Log in as ${client!!.userId}")
|
||||||
|
client!!.startSync()
|
||||||
|
isClientReady = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
override fun onDestroy() {
|
||||||
fun Greeting(name: String, modifier: Modifier = Modifier) {
|
super.onDestroy()
|
||||||
Text(
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
text = "Hello $name!",
|
client?.stopSync()
|
||||||
modifier = modifier
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Preview(showBackground = true)
|
|
||||||
@Composable
|
|
||||||
fun GreetingPreview() {
|
|
||||||
PixelDragonTheme {
|
|
||||||
Greeting("Android")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+129
@@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* Created by sweetbread
|
||||||
|
* Copyright (c) 2026. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ru.risdeveau.pixeldragon.ui.item
|
||||||
|
|
||||||
|
import androidx.compose.foundation.Image
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import io.github.rabehx.iconsax.Iconsax
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.layout.ContentScale
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import coil3.compose.rememberAsyncImagePainter
|
||||||
|
import coil3.request.ImageRequest
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import de.connect2x.trixnity.client.media
|
||||||
|
import de.connect2x.trixnity.clientserverapi.model.media.FileTransferProgress
|
||||||
|
import io.github.rabehx.iconsax.outline.Warning2
|
||||||
|
import ru.risdeveau.pixeldragon.client
|
||||||
|
|
||||||
|
enum class ImageLoadState {
|
||||||
|
Loading, Success, Error
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun MXCImage(
|
||||||
|
mxcUrl: String,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
contentScale: ContentScale = ContentScale.Fit,
|
||||||
|
contentDescription: String = "",
|
||||||
|
showProgress: Boolean = true
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
var imageLoadState by remember { mutableStateOf(ImageLoadState.Loading) }
|
||||||
|
var imageBytes by remember { mutableStateOf<ByteArray?>(null) }
|
||||||
|
|
||||||
|
val progressFlow = remember { MutableStateFlow<FileTransferProgress?>(null) }
|
||||||
|
|
||||||
|
LaunchedEffect(mxcUrl) {
|
||||||
|
if (mxcUrl.isBlank()) {
|
||||||
|
imageLoadState = ImageLoadState.Error
|
||||||
|
return@LaunchedEffect
|
||||||
|
}
|
||||||
|
imageLoadState = ImageLoadState.Loading
|
||||||
|
progressFlow.value = null
|
||||||
|
|
||||||
|
val result = client!!.media.getMedia(
|
||||||
|
uri = mxcUrl,
|
||||||
|
progress = progressFlow.takeIf { showProgress },
|
||||||
|
saveToCache = true
|
||||||
|
)
|
||||||
|
|
||||||
|
imageLoadState = result.fold(
|
||||||
|
onSuccess = { media ->
|
||||||
|
val bytes = media.toByteArray()
|
||||||
|
if (bytes != null) {
|
||||||
|
imageBytes = bytes
|
||||||
|
ImageLoadState.Success
|
||||||
|
} else {
|
||||||
|
ImageLoadState.Error
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onFailure = {
|
||||||
|
ImageLoadState.Error
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val progress by progressFlow.collectAsState()
|
||||||
|
|
||||||
|
val showProgressIndicator = showProgress &&
|
||||||
|
imageLoadState == ImageLoadState.Loading &&
|
||||||
|
progress != null
|
||||||
|
|
||||||
|
val painter = rememberAsyncImagePainter(
|
||||||
|
model = ImageRequest.Builder(context)
|
||||||
|
.data(imageBytes)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
|
||||||
|
Box(modifier = modifier, contentAlignment = Alignment.Center) {
|
||||||
|
if (imageBytes != null) {
|
||||||
|
Image(
|
||||||
|
painter = painter,
|
||||||
|
contentDescription = contentDescription,
|
||||||
|
contentScale = contentScale,
|
||||||
|
modifier = Modifier.fillMaxSize()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
showProgressIndicator -> {
|
||||||
|
progress?.let { p ->
|
||||||
|
val percent = p.total?.let { p.transferred.toFloat() / it }
|
||||||
|
if (percent == null) {
|
||||||
|
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||||
|
} else {
|
||||||
|
CircularProgressIndicator(
|
||||||
|
progress = percent,
|
||||||
|
modifier = Modifier.align(Alignment.Center)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} ?: CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||||
|
}
|
||||||
|
imageLoadState == ImageLoadState.Loading -> {
|
||||||
|
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||||
|
}
|
||||||
|
imageLoadState == ImageLoadState.Error -> {
|
||||||
|
Icon(
|
||||||
|
Iconsax.Outline.Warning2,
|
||||||
|
contentDescription = "Error",
|
||||||
|
modifier = Modifier.align(Alignment.Center)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,322 @@
|
|||||||
|
/*
|
||||||
|
* Created by sweetbread
|
||||||
|
* Copyright (c) 2025. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ru.risdeveau.pixeldragon.ui.layout
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.net.Uri
|
||||||
|
import android.view.MotionEvent
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.webkit.WebResourceRequest
|
||||||
|
import android.webkit.WebSettings
|
||||||
|
import android.webkit.WebView
|
||||||
|
import android.webkit.WebViewClient
|
||||||
|
import androidx.compose.animation.animateContentSize
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.heightIn
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextField
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.alpha
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.toArgb
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
|
import de.connect2x.trixnity.client.room
|
||||||
|
import de.connect2x.trixnity.client.room.message.MessageBuilder
|
||||||
|
import de.connect2x.trixnity.client.room.message.text
|
||||||
|
import de.connect2x.trixnity.client.room.toFlowList
|
||||||
|
import de.connect2x.trixnity.client.store.TimelineEvent
|
||||||
|
import de.connect2x.trixnity.client.store.eventId
|
||||||
|
import de.connect2x.trixnity.client.store.unsigned
|
||||||
|
import de.connect2x.trixnity.core.model.RoomId
|
||||||
|
import de.connect2x.trixnity.core.model.events.ClientEvent
|
||||||
|
import de.connect2x.trixnity.core.model.events.m.room.AvatarEventContent
|
||||||
|
import de.connect2x.trixnity.core.model.events.m.room.CanonicalAliasEventContent
|
||||||
|
import de.connect2x.trixnity.core.model.events.m.room.HistoryVisibilityEventContent
|
||||||
|
import de.connect2x.trixnity.core.model.events.m.room.MemberEventContent
|
||||||
|
import de.connect2x.trixnity.core.model.events.m.room.NameEventContent
|
||||||
|
import de.connect2x.trixnity.core.model.events.m.room.PowerLevelsEventContent
|
||||||
|
import de.connect2x.trixnity.core.model.events.m.room.RoomMessageEventContent
|
||||||
|
import de.connect2x.trixnity.core.model.events.m.room.TopicEventContent
|
||||||
|
import io.github.rabehx.iconsax.Iconsax
|
||||||
|
import io.github.rabehx.iconsax.filled.ArrowRight
|
||||||
|
import io.github.rabehx.iconsax.filled.Send
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.flatMapLatest
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.jsoup.Jsoup
|
||||||
|
import org.jsoup.safety.Safelist
|
||||||
|
import ru.risdeveau.pixeldragon.client
|
||||||
|
|
||||||
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
|
@Composable
|
||||||
|
fun Room(modifier: Modifier = Modifier, rid: String) {
|
||||||
|
val roomId = remember(rid) { RoomId(rid) }
|
||||||
|
val limit = remember { MutableStateFlow(50) }
|
||||||
|
|
||||||
|
val eventsFlow = remember(roomId) {
|
||||||
|
client!!.room
|
||||||
|
.getLastTimelineEvents(roomId)
|
||||||
|
.toFlowList(limit)
|
||||||
|
.flatMapLatest { flows ->
|
||||||
|
if (flows.isEmpty()) flowOf(emptyList())
|
||||||
|
else combine(flows) { it.toList() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val events by eventsFlow.collectAsState(initial = emptyList())
|
||||||
|
|
||||||
|
val listState = rememberLazyListState()
|
||||||
|
|
||||||
|
Column(modifier) {
|
||||||
|
var message by remember { mutableStateOf("") }
|
||||||
|
|
||||||
|
LazyColumn(Modifier.weight(1f), state = listState, reverseLayout = true) {
|
||||||
|
items(events, key = { it.eventId.full }) { event ->
|
||||||
|
EventItem(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (events.isEmpty()) {
|
||||||
|
item {
|
||||||
|
Text("Empty room", modifier = Modifier.padding(16.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Row (Modifier.fillMaxWidth()) {
|
||||||
|
OutlinedTextField(
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(4.dp)
|
||||||
|
.weight(1f),
|
||||||
|
value = message,
|
||||||
|
onValueChange = { message = it.trim() },
|
||||||
|
)
|
||||||
|
IconButton(
|
||||||
|
enabled = message.isNotBlank(),
|
||||||
|
content = { Icon(Iconsax.Filled.ArrowRight, contentDescription = "Send") },
|
||||||
|
onClick = {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
client!!.room.sendMessage(RoomId(rid)) {
|
||||||
|
text(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
message = ""
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun EventItem(event: TimelineEvent) {
|
||||||
|
val content = event.content?.getOrNull()
|
||||||
|
Box(Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.heightIn(min = 24.dp)) {
|
||||||
|
when {
|
||||||
|
content == null -> Text("Not decrypted",
|
||||||
|
Modifier
|
||||||
|
.fillMaxHeight()
|
||||||
|
.padding(4.dp)
|
||||||
|
.background(MaterialTheme.colorScheme.errorContainer)
|
||||||
|
.padding(4.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
content is RoomMessageEventContent -> {
|
||||||
|
val formatted = content.formattedBody
|
||||||
|
if (formatted != null) {
|
||||||
|
HtmlRenderer(
|
||||||
|
htmlContent = formatted,
|
||||||
|
plainText = content.body
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Text(
|
||||||
|
text = content.body,
|
||||||
|
modifier = Modifier.padding(4.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.event is ClientEvent.RoomEvent.StateEvent -> Text(
|
||||||
|
when (content) {
|
||||||
|
is AvatarEventContent -> "Avatar changed"
|
||||||
|
is PowerLevelsEventContent -> "Permissions changed"
|
||||||
|
is MemberEventContent -> "Membership changed"
|
||||||
|
is CanonicalAliasEventContent -> "Canonical alias changed"
|
||||||
|
is TopicEventContent -> "Topic changed"
|
||||||
|
is NameEventContent -> "Name changed"
|
||||||
|
is HistoryVisibilityEventContent -> "History visibility changed"
|
||||||
|
else -> content.toString()
|
||||||
|
},
|
||||||
|
Modifier.fillMaxWidth(),
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> Text(content.toString(),
|
||||||
|
Modifier
|
||||||
|
.fillMaxHeight()
|
||||||
|
.padding(4.dp)
|
||||||
|
.background(MaterialTheme.colorScheme.errorContainer)
|
||||||
|
.padding(4.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun String.sanitizeHTML(): String {
|
||||||
|
val matrixSafelist = Safelist()
|
||||||
|
.addTags(
|
||||||
|
"h1", "h2", "h3", "h4", "h5", "h6",
|
||||||
|
"b", "i", "u", "strong", "s", "del",
|
||||||
|
"sup", "sub", "code",
|
||||||
|
"table", "thead", "tbody",
|
||||||
|
"tr", "th", "td", "ul", "ol", "li",
|
||||||
|
"blockquote", "details", "summary",
|
||||||
|
"em", "code", "div", "pre", "span", "img"
|
||||||
|
)
|
||||||
|
.addAttributes("a", "target", "href")
|
||||||
|
.addAttributes("img", "width", "height", "alt", "title", "src")
|
||||||
|
.addAttributes("ol", "start")
|
||||||
|
.addAttributes("code", "class")
|
||||||
|
.addAttributes("div", "data-mx-maths")
|
||||||
|
|
||||||
|
val doc = Jsoup.parse(this)
|
||||||
|
doc.select("mx-reply").remove()
|
||||||
|
return Jsoup.clean(doc.body().toString(), matrixSafelist)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
@Composable
|
||||||
|
fun HtmlRenderer(
|
||||||
|
htmlContent: String,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
plainText: String = ""
|
||||||
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
var isLoaded by remember(htmlContent) { mutableStateOf(false) }
|
||||||
|
|
||||||
|
val webView = remember { WebView(context).apply {
|
||||||
|
layoutParams = ViewGroup.LayoutParams(
|
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
|
)
|
||||||
|
settings.apply {
|
||||||
|
javaScriptEnabled = false
|
||||||
|
loadWithOverviewMode = true
|
||||||
|
useWideViewPort = true
|
||||||
|
layoutAlgorithm = WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING
|
||||||
|
}
|
||||||
|
isVerticalScrollBarEnabled = false
|
||||||
|
setBackgroundColor(Color.Transparent.toArgb())
|
||||||
|
setOnTouchListener { _, e -> e.action == MotionEvent.ACTION_MOVE }
|
||||||
|
} }
|
||||||
|
|
||||||
|
val css = """
|
||||||
|
body {
|
||||||
|
font-family: -apple-system, sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 1.5;
|
||||||
|
color: ${colorToCss(MaterialTheme.colorScheme.onBackground)};
|
||||||
|
margin: 0; padding: 2px 0;
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
a { color: ${colorToCss(MaterialTheme.colorScheme.primary)}; text-decoration: none; }
|
||||||
|
img { max-width: 100%; height: auto; display: block; margin: 8px 0; }
|
||||||
|
table { width: 100%; border-collapse: collapse; margin: 8px 0; }
|
||||||
|
th, td { border: 1px solid ${colorToCss(MaterialTheme.colorScheme.outline)}; padding: 8px; text-align: left; }
|
||||||
|
blockquote { border-left: 4px solid ${colorToCss(MaterialTheme.colorScheme.primary)}; padding-left: 12px; margin: 8px 0; }
|
||||||
|
pre, code { background-color: ${colorToCss(MaterialTheme.colorScheme.surfaceVariant)}; padding: 2px 4px; border-radius: 4px; }
|
||||||
|
""".trimIndent()
|
||||||
|
|
||||||
|
LaunchedEffect(htmlContent) {
|
||||||
|
isLoaded = false
|
||||||
|
webView.webViewClient = object : WebViewClient() {
|
||||||
|
override fun onPageFinished(view: WebView?, url: String?) {
|
||||||
|
isLoaded = true
|
||||||
|
view?.requestLayout()
|
||||||
|
}
|
||||||
|
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
|
||||||
|
return try {
|
||||||
|
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(request.url.toString())))
|
||||||
|
true
|
||||||
|
} catch (e: Exception) { false }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
webView.loadDataWithBaseURL(null, wrapHtml(htmlContent, css), "text/html", "UTF-8", null)
|
||||||
|
}
|
||||||
|
|
||||||
|
DisposableEffect(webView) {
|
||||||
|
onDispose { /* webView.destroy() */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.heightIn(min = 24.dp)
|
||||||
|
.animateContentSize()
|
||||||
|
) {
|
||||||
|
if (!isLoaded) {
|
||||||
|
Text(
|
||||||
|
text = plainText.ifBlank { " " },
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(vertical = 2.dp)
|
||||||
|
.alpha(0.6f),
|
||||||
|
style = MaterialTheme.typography.bodyMedium
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
AndroidView(
|
||||||
|
factory = { webView },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.alpha(if (isLoaded) 1f else 0f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun wrapHtml(content: String, css: String): String {
|
||||||
|
return """
|
||||||
|
<!DOCTYPE html><html><head>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<style>$css</style></head><body>${content.sanitizeHTML()}</body></html>
|
||||||
|
""".trimIndent()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun colorToCss(color: Color): String {
|
||||||
|
return String.format("#%06X", 0xFFFFFF and color.toArgb())
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
* Created by sweetbread
|
||||||
|
* Copyright (c) 2026. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ru.risdeveau.pixeldragon.ui.layout
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.layout.ContentScale
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.navigation.NavController
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import de.connect2x.trixnity.client.flattenValues
|
||||||
|
import de.connect2x.trixnity.client.room
|
||||||
|
import de.connect2x.trixnity.client.store.Room
|
||||||
|
import de.connect2x.trixnity.client.store.type
|
||||||
|
import de.connect2x.trixnity.core.model.events.m.room.CreateEventContent
|
||||||
|
import ru.risdeveau.pixeldragon.client
|
||||||
|
import ru.risdeveau.pixeldragon.ui.item.MXCImage
|
||||||
|
|
||||||
|
@SuppressLint("FlowOperatorInvokedInComposition")
|
||||||
|
@Composable
|
||||||
|
fun RoomList(modifier: Modifier = Modifier, navController: NavController) {
|
||||||
|
val rooms by client!!.room.getAll().flattenValues().map { it.toList() }.collectAsState(initial = emptyList())
|
||||||
|
|
||||||
|
val listState = rememberLazyListState()
|
||||||
|
|
||||||
|
// if (itemState.scrollToTop) {
|
||||||
|
// LaunchedEffect(coroutineScope) {
|
||||||
|
// Log.e("TAG", "TopCoinsScreen: scrollToTop" )
|
||||||
|
// listState.scrollToItem(0)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// LaunchedEffect(Unit) {
|
||||||
|
// list = withContext(Dispatchers.IO) { Room.getJoined() }
|
||||||
|
// }
|
||||||
|
|
||||||
|
LazyColumn(modifier = modifier, state = listState) {
|
||||||
|
items(rooms) { room ->
|
||||||
|
RoomItem(room = room, navController = navController )
|
||||||
|
}
|
||||||
|
|
||||||
|
item {
|
||||||
|
if (rooms.isEmpty()) {
|
||||||
|
Text("You have no rooms")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun RoomItem(modifier: Modifier = Modifier, room: Room, navController: NavController) {
|
||||||
|
val name = room.name
|
||||||
|
val isSpace = room.type == CreateEventContent.RoomType.Space
|
||||||
|
|
||||||
|
|
||||||
|
Row(
|
||||||
|
modifier
|
||||||
|
.padding(8.dp)
|
||||||
|
.height((52 + 8 * 2).dp)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.background(
|
||||||
|
color =
|
||||||
|
if (isSpace)
|
||||||
|
MaterialTheme.colorScheme.tertiary
|
||||||
|
else
|
||||||
|
MaterialTheme.colorScheme.background
|
||||||
|
)
|
||||||
|
.clip(RoundedCornerShape(12.dp))
|
||||||
|
.clickable {
|
||||||
|
if (isSpace)
|
||||||
|
navController.navigate("space/${room.roomId}")
|
||||||
|
else
|
||||||
|
navController.navigate("room/${room.roomId}")
|
||||||
|
}
|
||||||
|
.padding(8.dp)
|
||||||
|
) {
|
||||||
|
Log.v("RoomItem", room.avatarUrl.toString())
|
||||||
|
room.avatarUrl?.let { mxc ->
|
||||||
|
MXCImage(
|
||||||
|
mxc,
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(end = 4.dp)
|
||||||
|
.height(52.dp)
|
||||||
|
.width(52.dp)
|
||||||
|
.let {
|
||||||
|
if (isSpace)
|
||||||
|
it.clip(RoundedCornerShape(12.dp))
|
||||||
|
else
|
||||||
|
it.clip(CircleShape)
|
||||||
|
},
|
||||||
|
ContentScale.Crop
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Column {
|
||||||
|
(name?.explicitName ?: name?.heroes?.firstNotNullOf {it.localpart})?.let {
|
||||||
|
Text(
|
||||||
|
it,
|
||||||
|
maxLines = 1,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
fontSize = MaterialTheme.typography.titleLarge.fontSize
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Created by sweetbread
|
||||||
|
* Copyright (c) 2026. All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ru.risdeveau.pixeldragon.util
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.room.Room
|
||||||
|
import de.connect2x.trixnity.client.MediaStoreModule
|
||||||
|
import de.connect2x.trixnity.client.RepositoriesModule
|
||||||
|
import de.connect2x.trixnity.client.media.okio.okio
|
||||||
|
import de.connect2x.trixnity.client.store.repository.room.TrixnityRoomDatabase
|
||||||
|
import de.connect2x.trixnity.client.store.repository.room.room
|
||||||
|
import okio.Path.Companion.toPath
|
||||||
|
import splitties.init.appCtx
|
||||||
|
|
||||||
|
fun getMediaStore() = MediaStoreModule.okio(appCtx.filesDir.resolve("media").absolutePath.toPath())
|
||||||
|
fun getRoomStore(context: Context) = RepositoriesModule.room(
|
||||||
|
databaseBuilder = Room.databaseBuilder<TrixnityRoomDatabase>(
|
||||||
|
context,
|
||||||
|
"trixnity.db"
|
||||||
|
)
|
||||||
|
)
|
||||||
+2
-3
@@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Created by sweetbread on 21.02.2025, 12:00
|
* Created by sweetbread
|
||||||
* Copyright (c) 2025. All rights reserved.
|
* Copyright (c) 2026. All rights reserved.
|
||||||
* Last modified 21.02.2025, 12:00
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|||||||
@@ -1,21 +1,37 @@
|
|||||||
[versions]
|
[versions]
|
||||||
agp = "8.7.3"
|
agp = "9.1.0"
|
||||||
coil = "3.1.0"
|
coil = "3.4.0"
|
||||||
kotlin = "2.0.0"
|
iconsaxCompose = "0.0.5"
|
||||||
|
jsoup = "1.22.1"
|
||||||
|
kotlin = "2.2.21"
|
||||||
coreKtx = "1.15.0"
|
coreKtx = "1.15.0"
|
||||||
junit = "4.13.2"
|
junit = "4.13.2"
|
||||||
junitVersion = "1.2.1"
|
junitVersion = "1.3.0"
|
||||||
espressoCore = "3.6.1"
|
espressoCore = "3.7.0"
|
||||||
ktor = "3.1.0"
|
kotlinxSerializationJson = "1.7.3"
|
||||||
|
ktor = "3.4.1"
|
||||||
lifecycleRuntimeKtx = "2.8.7"
|
lifecycleRuntimeKtx = "2.8.7"
|
||||||
activityCompose = "1.10.0"
|
activityCompose = "1.10.0"
|
||||||
composeBom = "2025.02.00"
|
composeBom = "2026.03.00"
|
||||||
|
navigationCompose = "2.9.7"
|
||||||
|
room = "2.6.1"
|
||||||
splittiesFunPackAndroidBase = "3.0.0"
|
splittiesFunPackAndroidBase = "3.0.0"
|
||||||
|
trixnityClient = "5.2.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||||
|
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "room" }
|
||||||
|
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
|
||||||
|
androidx-navigation-dynamic-features-fragment = { module = "androidx.navigation:navigation-dynamic-features-fragment", version.ref = "navigationCompose" }
|
||||||
|
androidx-navigation-fragment = { module = "androidx.navigation:navigation-fragment", version.ref = "navigationCompose" }
|
||||||
|
androidx-navigation-testing = { module = "androidx.navigation:navigation-testing", version.ref = "navigationCompose" }
|
||||||
|
androidx-navigation-ui = { module = "androidx.navigation:navigation-ui", version.ref = "navigationCompose" }
|
||||||
|
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }
|
||||||
|
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room" }
|
||||||
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
|
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
|
||||||
coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coil" }
|
coil-network-okhttp = { module = "io.coil-kt.coil3:coil-network-okhttp", version.ref = "coil" }
|
||||||
|
iconsax-compose = { module = "io.github.rabehx:iconsax-compose", version.ref = "iconsaxCompose" }
|
||||||
|
jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup" }
|
||||||
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||||
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
||||||
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
|
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
|
||||||
@@ -29,12 +45,16 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin
|
|||||||
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
||||||
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
||||||
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
|
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||||
ktor-client-cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
|
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
|
||||||
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
|
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
|
||||||
|
ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
|
||||||
splitties-base = { module = "com.louiscad.splitties:splitties-fun-pack-android-base", version.ref = "splittiesFunPackAndroidBase" }
|
splitties-base = { module = "com.louiscad.splitties:splitties-fun-pack-android-base", version.ref = "splittiesFunPackAndroidBase" }
|
||||||
|
trixnity-client = { module = "de.connect2x.trixnity:trixnity-client", version.ref = "trixnityClient" }
|
||||||
|
trixnity-client-media-okio = { module = "de.connect2x.trixnity:trixnity-client-media-okio", version.ref = "trixnityClient" }
|
||||||
|
trixnity-client-repository-room = { module = "de.connect2x.trixnity:trixnity-client-repository-room", version.ref = "trixnityClient" }
|
||||||
|
trixnity-client-cryptodriver-vodozemac = { module = "de.connect2x.trixnity:trixnity-client-cryptodriver-vodozemac", version.ref = "trixnityClient" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||||
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -1,12 +1,11 @@
|
|||||||
#
|
#
|
||||||
# Created by sweetbread on 21.02.2025, 12:00
|
# Created by sweetbread
|
||||||
# Copyright (c) 2025. All rights reserved.
|
# Copyright (c) 2025. All rights reserved.
|
||||||
# Last modified 21.02.2025, 12:00
|
|
||||||
#
|
#
|
||||||
|
|
||||||
#Thu Feb 20 10:45:47 GMT 2025
|
#Thu Feb 20 10:45:47 GMT 2025
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
+6
-3
@@ -1,7 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Created by sweetbread on 21.02.2025, 12:00
|
* Created by sweetbread
|
||||||
* Copyright (c) 2025. All rights reserved.
|
* Copyright (c) 2026. All rights reserved.
|
||||||
* Last modified 21.02.2025, 12:00
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pluginManagement {
|
pluginManagement {
|
||||||
@@ -17,11 +16,15 @@ pluginManagement {
|
|||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
plugins {
|
||||||
|
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
|
||||||
|
}
|
||||||
dependencyResolutionManagement {
|
dependencyResolutionManagement {
|
||||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
maven("https://gitlab.com/api/v4/projects/47538655/packages/maven")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user