Преглед изворни кода

Added insecure flag to api url table

Vadik Sirekanyan пре 2 година
родитељ
комит
3c4c0c754b

+ 5 - 4
app/src/main/java/org/sirekanyan/outline/db/ApiUrlDao.kt

@@ -4,11 +4,12 @@ import android.app.Application
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.remember
 import androidx.compose.ui.platform.LocalContext
-import app.cash.sqldelight.driver.android.AndroidSqliteDriver
 import app.cash.sqldelight.coroutines.asFlow
 import app.cash.sqldelight.coroutines.mapToList
+import app.cash.sqldelight.driver.android.AndroidSqliteDriver
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.flow.Flow
+import org.sirekanyan.outline.db.model.ApiUrl
 
 @Composable
 fun rememberApiUrlDao(): ApiUrlDao {
@@ -21,11 +22,11 @@ class ApiUrlDao(app: Application) {
     private val driver = AndroidSqliteDriver(OutlineDatabase.Schema, app, "outline.db")
     private val queries = OutlineDatabase(driver).apiUrlQueries
 
-    fun observeUrls(): Flow<List<String>> =
+    fun observeUrls(): Flow<List<ApiUrl>> =
         queries.selectUrls().asFlow().mapToList(Dispatchers.IO)
 
-    fun insertUrl(id: String) {
-        queries.insertUrl(id)
+    fun insertUrl(url: ApiUrl) {
+        queries.insertUrl(url)
     }
 
     fun deleteUrl(id: String) {

+ 3 - 2
app/src/main/java/org/sirekanyan/outline/ui/AddServerContent.kt

@@ -30,6 +30,7 @@ import org.sirekanyan.outline.MainState
 import org.sirekanyan.outline.NotSupportedContent
 import org.sirekanyan.outline.SelectedPage
 import org.sirekanyan.outline.db.ApiUrlDao
+import org.sirekanyan.outline.db.model.ApiUrl
 
 @Composable
 fun AddServerContent(dao: ApiUrlDao, state: MainState) {
@@ -45,7 +46,7 @@ fun AddServerContent(dao: ApiUrlDao, state: MainState) {
         try {
             isLoading = true
             state.servers.fetchServer(draft)
-            dao.insertUrl(draft)
+            dao.insertUrl(ApiUrl(draft, true)) // TODO: remove insecure flag
             state.dialog = null
             state.page = SelectedPage(draft)
             state.closeDrawer(animated = false)
@@ -91,7 +92,7 @@ fun AddServerContent(dao: ApiUrlDao, state: MainState) {
                 },
             )
             Text(
-                text = "Trust all certificates (insecure)",
+                text = "Allow insecure connection",
                 modifier = Modifier.padding(end = 16.dp),
                 style = MaterialTheme.typography.bodySmall,
                 color = LocalContentColor.current.copy(alpha = 0.66f),

+ 2 - 1
app/src/main/java/org/sirekanyan/outline/ui/DrawerContent.kt

@@ -37,6 +37,7 @@ import org.sirekanyan.outline.MainState
 import org.sirekanyan.outline.R
 import org.sirekanyan.outline.SelectedPage
 import org.sirekanyan.outline.db.ApiUrlDao
+import org.sirekanyan.outline.db.model.ApiUrl
 import org.sirekanyan.outline.isPlayFlavor
 import org.sirekanyan.outline.text.formatTraffic
 import org.sirekanyan.outline.ui.icons.IconOpenInNew
@@ -65,7 +66,7 @@ private fun DrawerSheetContent(dao: ApiUrlDao, state: MainState, insets: Padding
             style = MaterialTheme.typography.titleSmall,
         )
         val apiUrls by remember { dao.observeUrls() }.collectAsState(listOf())
-        apiUrls.forEach { apiUrl ->
+        apiUrls.map(ApiUrl::id).forEach { apiUrl ->
             val isSelected = state.selectedPage?.apiUrl == apiUrl
             val server by produceState(state.servers.getCachedServer(apiUrl), state.drawer.isOpen) {
                 value = state.servers.getServer(apiUrl)

+ 3 - 2
app/src/main/sqldelight/org/sirekanyan/outline/db/model/ApiUrl.sq

@@ -1,12 +1,13 @@
 CREATE TABLE IF NOT EXISTS ApiUrl (
-  id TEXT NOT NULL PRIMARY KEY
+  id TEXT NOT NULL PRIMARY KEY,
+  insecure INTEGER AS kotlin.Boolean NOT NULL DEFAULT 0
 );
 
 selectUrls:
 SELECT * FROM ApiUrl;
 
 insertUrl:
-INSERT OR IGNORE INTO ApiUrl (id) VALUES (?);
+INSERT OR IGNORE INTO ApiUrl VALUES ?;
 
 deleteUrl:
 DELETE FROM ApiUrl WHERE id = ?;