Kaynağa Gözat

Removed import aliases (refactoring)

Vadik Sirekanyan 2 yıl önce
ebeveyn
işleme
1bb8e2e315

+ 7 - 7
app/src/main/java/org/sirekanyan/outline/MainState.kt

@@ -25,6 +25,7 @@ import kotlinx.parcelize.IgnoredOnParcel
 import kotlinx.parcelize.Parcelize
 import org.sirekanyan.outline.api.OutlineApi
 import org.sirekanyan.outline.api.model.Key
+import org.sirekanyan.outline.api.model.Server
 import org.sirekanyan.outline.db.KeyDao
 import org.sirekanyan.outline.db.KeyValueDao
 import org.sirekanyan.outline.db.ServerDao
@@ -44,7 +45,6 @@ import org.sirekanyan.outline.ui.SearchState
 import org.sirekanyan.outline.ui.rememberSearchState
 import java.net.ConnectException
 import java.net.UnknownHostException
-import org.sirekanyan.outline.api.model.Server as ServerEntity
 
 @Composable
 fun rememberMainState(): MainState {
@@ -139,7 +139,7 @@ class MainState(
         }
     }
 
-    suspend fun refreshHelloPage(server: ServerEntity) {
+    suspend fun refreshHelloPage(server: Server) {
         if (page !is HelloPage) return
         withContext(Dispatchers.IO) {
             try {
@@ -157,7 +157,7 @@ sealed class Page : Parcelable
 
 data object HelloPage : Page()
 
-data class SelectedPage(val server: ServerEntity) : Page() {
+data class SelectedPage(val server: Server) : Page() {
     @IgnoredOnParcel
     var keys by mutableStateOf<KeysState>(KeysIdleState)
 }
@@ -167,10 +167,10 @@ sealed class Dialog : Parcelable
 
 data object AddServerDialog : Dialog()
 
-data class RenameServerDialog(val server: ServerEntity) : Dialog()
+data class RenameServerDialog(val server: Server) : Dialog()
 
-data class RenameKeyDialog(val server: ServerEntity, val key: Key) : Dialog()
+data class RenameKeyDialog(val server: Server, val key: Key) : Dialog()
 
-data class DeleteKeyDialog(val server: ServerEntity, val key: Key) : Dialog()
+data class DeleteKeyDialog(val server: Server, val key: Key) : Dialog()
 
-data class DeleteServerDialog(val server: ServerEntity) : Dialog()
+data class DeleteServerDialog(val server: Server) : Dialog()

+ 11 - 11
app/src/main/java/org/sirekanyan/outline/api/OutlineApi.kt

@@ -19,12 +19,12 @@ import org.sirekanyan.outline.api.model.AccessKeysResponse
 import org.sirekanyan.outline.api.model.Key
 import org.sirekanyan.outline.api.model.Key.AccessKey
 import org.sirekanyan.outline.api.model.RenameRequest
+import org.sirekanyan.outline.api.model.Server
 import org.sirekanyan.outline.api.model.ServerNameResponse
 import org.sirekanyan.outline.api.model.TransferMetricsResponse
 import org.sirekanyan.outline.ext.logDebug
 import java.security.SecureRandom
 import javax.net.ssl.SSLContext
-import org.sirekanyan.outline.api.model.Server as ServerEntity
 
 private fun createOkHttpClient(block: OkHttpConfig.() -> Unit = {}): HttpClient =
     HttpClient(OkHttp) {
@@ -54,7 +54,7 @@ class OutlineApi {
 
     private suspend fun request(
         httpMethod: HttpMethod,
-        server: ServerEntity,
+        server: Server,
         path: String,
         block: HttpRequestBuilder.() -> Unit = {},
     ): HttpResponse {
@@ -62,20 +62,20 @@ class OutlineApi {
         return client.request(server.id + '/' + path) { method = httpMethod; block() }
     }
 
-    suspend fun getServer(server: ServerEntity): ServerEntity {
+    suspend fun getServer(server: Server): Server {
         val name = request(HttpMethod.Get, server, "server").body<ServerNameResponse>().name
         val transferMetrics = getTransferMetrics(server)?.bytesTransferredByUserId
-        return ServerEntity(server.id, server.insecure, name, transferMetrics?.values?.sum())
+        return Server(server.id, server.insecure, name, transferMetrics?.values?.sum())
     }
 
-    suspend fun renameServer(server: ServerEntity, name: String) {
+    suspend fun renameServer(server: Server, name: String) {
         request(HttpMethod.Put, server, "name") {
             contentType(ContentType.Application.Json)
             setBody(RenameRequest(name))
         }
     }
 
-    suspend fun getKeys(server: ServerEntity): List<Key> {
+    suspend fun getKeys(server: Server): List<Key> {
         val accessKeys = getAccessKeys(server).accessKeys
         val transferMetrics = getTransferMetrics(server)?.bytesTransferredByUserId
         return accessKeys.map {
@@ -84,10 +84,10 @@ class OutlineApi {
         }
     }
 
-    private suspend fun getAccessKeys(server: ServerEntity): AccessKeysResponse =
+    private suspend fun getAccessKeys(server: Server): AccessKeysResponse =
         request(HttpMethod.Get, server, "access-keys").body()
 
-    private suspend fun getTransferMetrics(server: ServerEntity): TransferMetricsResponse? =
+    private suspend fun getTransferMetrics(server: Server): TransferMetricsResponse? =
         try {
             request(HttpMethod.Get, server, "metrics/transfer").body()
         } catch (exception: Exception) {
@@ -95,18 +95,18 @@ class OutlineApi {
             null
         }
 
-    suspend fun createAccessKey(server: ServerEntity) {
+    suspend fun createAccessKey(server: Server) {
         request(HttpMethod.Post, server, "access-keys")
     }
 
-    suspend fun renameAccessKey(server: ServerEntity, id: String, name: String) {
+    suspend fun renameAccessKey(server: Server, id: String, name: String) {
         request(HttpMethod.Put, server, "access-keys/$id/name") {
             contentType(ContentType.Application.Json)
             setBody(RenameRequest(name))
         }
     }
 
-    suspend fun deleteAccessKey(server: ServerEntity, id: String) {
+    suspend fun deleteAccessKey(server: Server, id: String) {
         request(HttpMethod.Delete, server, "access-keys/$id")
     }
 

+ 3 - 4
app/src/main/java/org/sirekanyan/outline/api/model/Key.kt

@@ -5,7 +5,6 @@ import kotlinx.parcelize.Parcelize
 import org.sirekanyan.outline.api.model.Key.AccessKey
 import org.sirekanyan.outline.db.model.KeyEntity
 import org.sirekanyan.outline.db.model.KeyWithServerEntity
-import org.sirekanyan.outline.api.model.Server as ServerEntity
 
 fun List<Key>.toEntities(): List<KeyEntity> =
     map { key ->
@@ -13,7 +12,7 @@ fun List<Key>.toEntities(): List<KeyEntity> =
         KeyEntity(key.server.id, accessKey.id, accessKey.accessUrl, accessKey.name, key.traffic)
     }
 
-fun List<KeyEntity>.fromEntities(server: ServerEntity): List<Key> =
+fun List<KeyEntity>.fromEntities(server: Server): List<Key> =
     map { entity ->
         Key(server, AccessKey(entity.id, entity.url, entity.name), entity.traffic)
     }
@@ -21,14 +20,14 @@ fun List<KeyEntity>.fromEntities(server: ServerEntity): List<Key> =
 fun List<KeyWithServerEntity>.fromEntities(): List<Key> =
     map { entity ->
         Key(
-            ServerEntity(entity.serverId, entity.insecure, entity.serverName, entity.serverTraffic),
+            Server(entity.serverId, entity.insecure, entity.serverName, entity.serverTraffic),
             AccessKey(entity.id, entity.url, entity.name),
             entity.traffic,
         )
     }
 
 @Parcelize
-class Key(val server: ServerEntity, val accessKey: AccessKey, val traffic: Long?) : Parcelable {
+class Key(val server: Server, val accessKey: AccessKey, val traffic: Long?) : Parcelable {
 
     @Parcelize
     class AccessKey(

+ 3 - 3
app/src/main/java/org/sirekanyan/outline/db/KeyDao.kt

@@ -6,10 +6,10 @@ import androidx.compose.ui.platform.LocalContext
 import app.cash.sqldelight.Query
 import app.cash.sqldelight.coroutines.asFlow
 import kotlinx.coroutines.flow.Flow
+import org.sirekanyan.outline.api.model.Server
 import org.sirekanyan.outline.app
 import org.sirekanyan.outline.db.model.KeyEntity
 import org.sirekanyan.outline.db.model.KeyWithServerEntity
-import org.sirekanyan.outline.api.model.Server as ServerEntity
 
 @Composable
 fun rememberKeyDao(): KeyDao {
@@ -21,13 +21,13 @@ class KeyDao(database: OutlineDatabase) {
 
     private val queries = database.keyEntityQueries
 
-    fun observe(server: ServerEntity): Flow<Query<KeyEntity>> =
+    fun observe(server: Server): Flow<Query<KeyEntity>> =
         queries.selectKeys(server.id).asFlow()
 
     fun observeAll(query: String): Flow<Query<KeyWithServerEntity>> =
         queries.selectAllKeys("%$query%").asFlow()
 
-    fun update(server: ServerEntity, keys: List<KeyEntity>) {
+    fun update(server: Server, keys: List<KeyEntity>) {
         queries.transaction {
             queries.deleteKeys(server.id)
             keys.forEach(queries::insertKey)

+ 4 - 4
app/src/main/java/org/sirekanyan/outline/repository/KeyRepository.kt

@@ -8,28 +8,28 @@ import kotlinx.coroutines.withContext
 import org.sirekanyan.outline.api.OutlineApi
 import org.sirekanyan.outline.api.model.Key
 import org.sirekanyan.outline.api.model.Key.AccessKey
+import org.sirekanyan.outline.api.model.Server
 import org.sirekanyan.outline.api.model.fromEntities
 import org.sirekanyan.outline.api.model.toEntities
 import org.sirekanyan.outline.db.KeyDao
 import org.sirekanyan.outline.db.model.KeyWithServerEntity
-import org.sirekanyan.outline.api.model.Server as ServerEntity
 
 class KeyRepository(private val api: OutlineApi, private val keyDao: KeyDao) {
 
-    fun observeKeys(server: ServerEntity): Flow<List<Key>> =
+    fun observeKeys(server: Server): Flow<List<Key>> =
         keyDao.observe(server).mapToList(IO).map { it.fromEntities(server) }
 
     fun observeAllKeys(query: String): Flow<List<Key>> =
         keyDao.observeAll(query).mapToList(IO).map(List<KeyWithServerEntity>::fromEntities)
 
-    suspend fun updateKeys(server: ServerEntity) {
+    suspend fun updateKeys(server: Server) {
         withContext(IO) {
             val keys = api.getKeys(server)
             keyDao.update(server, keys.toEntities())
         }
     }
 
-    suspend fun renameKey(server: ServerEntity, accessKey: AccessKey, newName: String) {
+    suspend fun renameKey(server: Server, accessKey: AccessKey, newName: String) {
         withContext(IO) {
             api.renameAccessKey(server, accessKey.id, newName)
         }

+ 6 - 6
app/src/main/java/org/sirekanyan/outline/repository/ServerRepository.kt

@@ -8,19 +8,19 @@ import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.withContext
 import org.sirekanyan.outline.api.OutlineApi
+import org.sirekanyan.outline.api.model.Server
 import org.sirekanyan.outline.api.model.fromEntities
 import org.sirekanyan.outline.api.model.toEntities
 import org.sirekanyan.outline.api.model.toEntity
 import org.sirekanyan.outline.db.ServerDao
 import org.sirekanyan.outline.ext.logDebug
-import org.sirekanyan.outline.api.model.Server as ServerEntity
 
 class ServerRepository(private val api: OutlineApi, private val serverDao: ServerDao) {
 
-    fun observeServers(): Flow<List<ServerEntity>> =
+    fun observeServers(): Flow<List<Server>> =
         serverDao.observeAll().mapToList(IO).map { it.fromEntities() }
 
-    suspend fun updateServers(servers: List<ServerEntity>) {
+    suspend fun updateServers(servers: List<Server>) {
         withContext(IO) {
             val deferredServers = servers.map {
                 async {
@@ -36,18 +36,18 @@ class ServerRepository(private val api: OutlineApi, private val serverDao: Serve
         }
     }
 
-    suspend fun updateServer(server: ServerEntity): ServerEntity =
+    suspend fun updateServer(server: Server): Server =
         withContext(IO) {
             refreshServer(server)
         }
 
-    suspend fun renameServer(server: ServerEntity, newName: String): ServerEntity =
+    suspend fun renameServer(server: Server, newName: String): Server =
         withContext(IO) {
             api.renameServer(server, newName)
             refreshServer(server)
         }
 
-    private suspend fun refreshServer(server: ServerEntity): ServerEntity =
+    private suspend fun refreshServer(server: Server): Server =
         api.getServer(server).also { newServer ->
             serverDao.insert(newServer.toEntity())
         }