wip: Room list
This commit is contained in:
@@ -1,43 +1,55 @@
|
||||
/*
|
||||
* Created by sweetbread on 21.02.2025, 12:01
|
||||
* Created by sweetbread on 22.02.2025, 15:45
|
||||
* Copyright (c) 2025. All rights reserved.
|
||||
* Last modified 21.02.2025, 12:01
|
||||
* Last modified 22.02.2025, 15:45
|
||||
*/
|
||||
|
||||
package ru.risdeveau.pixeldragon
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import androidx.room.Room
|
||||
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.logging.LogLevel
|
||||
import io.ktor.client.plugins.logging.Logger
|
||||
import io.ktor.client.plugins.logging.Logging
|
||||
import ru.risdeveau.pixeldragon.api.getMe
|
||||
import ru.risdeveau.pixeldragon.db.AppDatabase
|
||||
import splitties.init.appCtx
|
||||
|
||||
val client = HttpClient(CIO) {
|
||||
engine {
|
||||
endpoint {
|
||||
maxConnectionsPerRoute = 100
|
||||
pipelineMaxSize = 20
|
||||
keepAliveTime = 30000
|
||||
connectTimeout = 15000
|
||||
connectAttempts = 5
|
||||
val client = HttpClient {
|
||||
install(Logging) {
|
||||
logger = object : Logger {
|
||||
override fun log(message: String) {
|
||||
Log.i("Ktor", message)
|
||||
}
|
||||
}
|
||||
level = LogLevel.ALL
|
||||
}
|
||||
|
||||
install(HttpCache)
|
||||
}
|
||||
|
||||
val accountData = appCtx.getSharedPreferences("settings", Context.MODE_PRIVATE)
|
||||
lateinit var urlBase: String
|
||||
lateinit var homeserver: String
|
||||
lateinit var baseUrl: String
|
||||
lateinit var token: String
|
||||
|
||||
suspend fun initCheck(): Boolean {
|
||||
Log.d("initCheck", "checking...")
|
||||
|
||||
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"
|
||||
homeserver = accountData.getString("homeserver", "").toString()
|
||||
baseUrl = "https://$homeserver/_matrix/client/v3"
|
||||
|
||||
return getMe() != null
|
||||
}
|
||||
}
|
||||
|
||||
val db = Room.databaseBuilder(
|
||||
appCtx,
|
||||
AppDatabase::class.java, "database"
|
||||
).build()
|
||||
Reference in New Issue
Block a user