Skip to content

Commit 4498d4e

Browse files
committed
Extract model
1 parent cef3807 commit 4498d4e

14 files changed

+163
-232
lines changed

app/build.gradle.kts

-16
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ plugins {
66
kotlin("android")
77
id("kotlin-parcelize")
88
id("androidx.navigation.safeargs.kotlin")
9-
id("com.squareup.sqldelight")
109
// https://github.com/google/ksp/releases
1110
id("com.google.devtools.ksp") version "1.9.23-1.0.20"
1211
}
@@ -84,14 +83,6 @@ android {
8483
}
8584
}
8685

87-
sqldelight {
88-
database("Db") {
89-
packageName = "db"
90-
schemaOutputDirectory = file("src/main/sqldelight/$packageName/schemas")
91-
dialect = "sqlite:3.25"
92-
}
93-
}
94-
9586
dependencies {
9687
// Simplifies non-blocking programming
9788
// https://github.com/Kotlin/kotlinx.coroutines/releases
@@ -162,13 +153,6 @@ dependencies {
162153
// https://github.com/requery/sqlite-android/releases
163154
implementation("com.github.requery:sqlite-android:3.45.0")
164155

165-
// SQLDelight generates typesafe kotlin APIs from SQL statements
166-
// https://github.com/cashapp/sqldelight/releases
167-
val sqlDelightVer = "1.5.5"
168-
implementation("com.squareup.sqldelight:coroutines-extensions:$sqlDelightVer")
169-
implementation("com.squareup.sqldelight:android-driver:$sqlDelightVer")
170-
testImplementation("com.squareup.sqldelight:sqlite-driver:$sqlDelightVer")
171-
172156
// Dependency injection framework
173157
// https://github.com/InsertKoinIO/koin/tags
174158
val koinAnnotationsVer = "1.0.0"

app/src/main/kotlin/api/HotSwapApi.kt

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package api
22

3+
import android.database.sqlite.SQLiteDatabase
34
import api.miniflux.MinifluxApiAdapter
45
import api.miniflux.MinifluxApiBuilder
56
import api.nextcloud.NextcloudApiAdapter
67
import api.nextcloud.NextcloudApiBuilder
78
import api.standalone.StandaloneNewsApi
89
import conf.ConfRepo
9-
import db.Db
1010
import db.Entry
1111
import db.EntryWithoutContent
1212
import db.Feed
@@ -21,7 +21,7 @@ import java.time.OffsetDateTime
2121
@Single(binds = [Api::class])
2222
class HotSwapApi(
2323
private val confRepo: ConfRepo,
24-
private val db: Db,
24+
private val db: SQLiteDatabase,
2525
) : Api {
2626

2727
private lateinit var api: Api
@@ -37,21 +37,21 @@ class HotSwapApi(
3737
ConfRepo.BACKEND_MINIFLUX -> {
3838
api = MinifluxApiAdapter(
3939
MinifluxApiBuilder().build(
40-
url = conf.miniflux_server_url,
41-
username = conf.miniflux_server_username,
42-
password = conf.miniflux_server_password,
43-
trustSelfSignedCerts = conf.miniflux_server_trust_self_signed_certs,
40+
url = conf.minifluxServerUrl,
41+
username = conf.minifluxServerUsername,
42+
password = conf.minifluxServerPassword,
43+
trustSelfSignedCerts = conf.minifluxServerTrustSelfSignedCerts,
4444
)
4545
)
4646
}
4747

4848
ConfRepo.BACKEND_NEXTCLOUD -> {
4949
api = NextcloudApiAdapter(
5050
NextcloudApiBuilder().build(
51-
url = conf.nextcloud_server_url,
52-
username = conf.nextcloud_server_username,
53-
password = conf.nextcloud_server_password,
54-
trustSelfSignedCerts = conf.nextcloud_server_trust_self_signed_certs,
51+
url = conf.nextcloudServerUrl,
52+
username = conf.nextcloudServerUsername,
53+
password = conf.nextcloudServerPassword,
54+
trustSelfSignedCerts = conf.nextcloudServerTrustSelfSignedCerts,
5555
)
5656
)
5757
}

app/src/main/kotlin/api/miniflux/MinifluxApiAdapter.kt

+18-18
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ class MinifluxApiAdapter(
175175
id = feedId,
176176
links = listOfNotNull(selfLink, alternateLink),
177177
title = title,
178-
ext_open_entries_in_browser = false,
179-
ext_blocked_words = "",
180-
ext_show_preview_images = null,
178+
extOpenEntriesInBrowser = false,
179+
extBlockedWords = "",
180+
extShowPreviewImages = null,
181181
)
182182
}
183183

@@ -213,27 +213,27 @@ class MinifluxApiAdapter(
213213
}
214214

215215
return Entry(
216-
content_type = "html",
217-
content_src = "",
218-
content_text = content,
216+
contentType = "html",
217+
contentSrc = "",
218+
contentText = content,
219219
links = links,
220220
summary = null,
221221
id = id.toString(),
222-
feed_id = feed_id.toString(),
222+
feedId = feed_id.toString(),
223223
title = title,
224224
published = OffsetDateTime.parse(published_at),
225225
updated = OffsetDateTime.parse(changed_at),
226-
author_name = author,
227-
ext_read = status == "read",
228-
ext_read_synced = true,
229-
ext_bookmarked = starred,
230-
ext_bookmarked_synced = true,
231-
ext_nc_guid_hash = "",
232-
ext_comments_url = comments_url,
233-
ext_og_image_checked = false,
234-
ext_og_image_url = "",
235-
ext_og_image_width = 0,
236-
ext_og_image_height = 0,
226+
authorName = author,
227+
extRead = status == "read",
228+
extReadSynced = true,
229+
extBookmarked = starred,
230+
extBookmarkedSynced = true,
231+
extNextcloudGuidHash = "",
232+
extCommentsUrl = comments_url,
233+
extOpenGraphImageChecked = false,
234+
extOpenGraphImageUrl = "",
235+
extOpenGraphImageWidth = 0,
236+
extOpenGraphImageHeight = 0,
237237
)
238238
}
239239
}

app/src/main/kotlin/api/nextcloud/NextcloudApiAdapter.kt

+26-20
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ class NextcloudApiAdapter(
7676
if (currentBatch.size < batchSize) {
7777
break
7878
} else {
79-
oldestEntryId = currentBatch.minOfOrNull { it.id ?: Long.MAX_VALUE }?.toLong() ?: 0L
79+
oldestEntryId =
80+
currentBatch.minOfOrNull { it.id ?: Long.MAX_VALUE }?.toLong() ?: 0L
8081
currentBatch.clear()
8182
}
8283
}
@@ -111,7 +112,12 @@ class NextcloudApiAdapter(
111112
bookmarked: Boolean,
112113
): Result<Unit> {
113114
return runCatching {
114-
val args = PutStarredArgs(entries.map { PutStarredArgsItem(it.feed_id.toLong(), it.ext_nc_guid_hash) })
115+
val args = PutStarredArgs(entries.map {
116+
PutStarredArgsItem(
117+
it.feedId.toLong(),
118+
it.extNextcloudGuidHash
119+
)
120+
})
115121

116122
if (bookmarked) {
117123
api.putStarred(args)
@@ -160,9 +166,9 @@ class NextcloudApiAdapter(
160166
id = feedId,
161167
links = links,
162168
title = title ?: "Untitled",
163-
ext_open_entries_in_browser = false,
164-
ext_blocked_words = "",
165-
ext_show_preview_images = null,
169+
extOpenEntriesInBrowser = false,
170+
extBlockedWords = "",
171+
extShowPreviewImages = null,
166172
)
167173
}
168174

@@ -209,27 +215,27 @@ class NextcloudApiAdapter(
209215
}
210216

211217
return Entry(
212-
content_type = "html",
213-
content_src = "",
214-
content_text = body ?: "",
218+
contentType = "html",
219+
contentSrc = "",
220+
contentText = body ?: "",
215221
links = links,
216222
summary = "",
217223
id = id.toString(),
218-
feed_id = feedId?.toString() ?: "",
224+
feedId = feedId?.toString() ?: "",
219225
title = title ?: "Untitled",
220226
published = OffsetDateTime.parse(published),
221227
updated = OffsetDateTime.parse(updated),
222-
author_name = author ?: "",
223-
ext_read = !unread,
224-
ext_read_synced = true,
225-
ext_bookmarked = starred,
226-
ext_bookmarked_synced = true,
227-
ext_nc_guid_hash = guidHash ?: return null,
228-
ext_comments_url = "",
229-
ext_og_image_checked = false,
230-
ext_og_image_url = "",
231-
ext_og_image_width = 0,
232-
ext_og_image_height = 0,
228+
authorName = author ?: "",
229+
extRead = !unread,
230+
extReadSynced = true,
231+
extBookmarked = starred,
232+
extBookmarkedSynced = true,
233+
extNextcloudGuidHash = guidHash ?: return null,
234+
extCommentsUrl = "",
235+
extOpenGraphImageChecked = false,
236+
extOpenGraphImageUrl = "",
237+
extOpenGraphImageWidth = 0,
238+
extOpenGraphImageHeight = 0,
233239
)
234240
}
235241
}

app/src/main/kotlin/api/standalone/StandaloneApi.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package api.standalone
22

3+
import android.database.sqlite.SQLiteDatabase
34
import android.util.Base64
45
import android.util.Log
56
import api.Api
@@ -12,9 +13,6 @@ import co.appreactor.feedk.RssFeed
1213
import co.appreactor.feedk.RssItem
1314
import co.appreactor.feedk.RssItemGuid
1415
import co.appreactor.feedk.feed
15-
import com.squareup.sqldelight.runtime.coroutines.asFlow
16-
import com.squareup.sqldelight.runtime.coroutines.mapToList
17-
import db.Db
1816
import db.Entry
1917
import db.EntryWithoutContent
2018
import db.Feed
@@ -46,7 +44,7 @@ import java.util.Locale
4644
typealias ParsedFeed = co.appreactor.feedk.Feed
4745

4846
class StandaloneNewsApi(
49-
private val db: Db,
47+
private val db: SQLiteDatabase,
5048
) : Api {
5149

5250
private val httpClient = OkHttpClient()

app/src/main/kotlin/db/Conf.kt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package db
2+
3+
data class Conf(
4+
val backend: String,
5+
val minifluxServerUrl: String,
6+
val minifluxServerTrustSelfSignedCerts: Boolean,
7+
val minifluxServerUsername: String,
8+
val minifluxServerPassword: String,
9+
val nextcloudServerUrl: String,
10+
val nextcloudServerTrustSelfSignedCerts: Boolean,
11+
val nextcloudServerUsername: String,
12+
val nextcloudServerPassword: String,
13+
val initialSyncCompleted: Boolean,
14+
val lastEntriesSyncDatetime: String,
15+
val showReadEntries: Boolean,
16+
val sortOrder: String,
17+
val showPreviewImages: Boolean,
18+
val cropPreviewImages: Boolean,
19+
val markScrolledEntriesAsRead: Boolean,
20+
val syncOnStartup: Boolean,
21+
val syncInBackground: Boolean,
22+
val backgroundSyncIntervalMillis: Long,
23+
val useBuiltInBrowser: Boolean,
24+
val showPreviewText: Boolean,
25+
val syncedOnStartup: Boolean,
26+
)

0 commit comments

Comments
 (0)