mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 21:07:04 +05:30
Revert "feat: init store module"
Store doesn't seem particularly useful for my needs. This reverts commits14007c6e8f
and45701f414b
.
This commit is contained in:
parent
8891667c92
commit
52deb7ca5f
13 changed files with 11 additions and 198 deletions
|
@ -15,7 +15,6 @@ import com.squareup.anvil.annotations.ContributesTo
|
|||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dev.msfjarvis.claw.database.LobstersDatabase
|
||||
import dev.msfjarvis.claw.database.local.CachedNewestPost
|
||||
import dev.msfjarvis.claw.database.local.PostComments
|
||||
import dev.msfjarvis.claw.database.local.SavedPost
|
||||
import dev.msfjarvis.claw.database.model.CSVAdapter
|
||||
|
@ -38,10 +37,8 @@ object DatabaseModule {
|
|||
)
|
||||
return LobstersDatabase(
|
||||
driver = driver,
|
||||
PostCommentsAdapter = PostComments.Adapter(CSVAdapter),
|
||||
SavedPostAdapter = SavedPost.Adapter(IntColumnAdapter, CSVAdapter),
|
||||
CachedNewestPostAdapter =
|
||||
CachedNewestPost.Adapter(IntColumnAdapter, IntColumnAdapter, CSVAdapter),
|
||||
PostCommentsAdapter = PostComments.Adapter(CSVAdapter()),
|
||||
SavedPostAdapter = SavedPost.Adapter(IntColumnAdapter, CSVAdapter()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,7 @@ package dev.msfjarvis.claw.database.model
|
|||
|
||||
import app.cash.sqldelight.ColumnAdapter
|
||||
|
||||
object CSVAdapter : ColumnAdapter<List<String>, String> {
|
||||
private const val SEPARATOR = ","
|
||||
|
||||
class CSVAdapter : ColumnAdapter<List<String>, String> {
|
||||
override fun decode(databaseValue: String): List<String> {
|
||||
return databaseValue.split(SEPARATOR)
|
||||
}
|
||||
|
@ -18,4 +16,8 @@ object CSVAdapter : ColumnAdapter<List<String>, String> {
|
|||
override fun encode(value: List<String>): String {
|
||||
return value.joinToString(SEPARATOR)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private const val SEPARATOR = ","
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
import kotlin.Int;
|
||||
import kotlin.String;
|
||||
import kotlin.collections.List;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS CachedNewestPost(
|
||||
pageNumber INTEGER AS Int,
|
||||
shortId TEXT NOT NULL PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
commentCount INTEGER AS Int,
|
||||
commentsUrl TEXT NOT NULL,
|
||||
tags TEXT AS List<String> NOT NULL
|
||||
);
|
||||
|
||||
insertPost:
|
||||
INSERT OR REPLACE
|
||||
INTO CachedNewestPost
|
||||
VALUES ?;
|
||||
|
||||
getPage:
|
||||
SELECT *
|
||||
FROM CachedNewestPost
|
||||
WHERE pageNumber = ?;
|
||||
|
||||
clearPage:
|
||||
DELETE FROM CachedNewestPost
|
||||
WHERE pageNumber = ?;
|
||||
|
||||
deleteAll:
|
||||
DELETE FROM CachedNewestPost;
|
|
@ -1,14 +0,0 @@
|
|||
import kotlin.Int;
|
||||
import kotlin.String;
|
||||
import kotlin.collections.List;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS CachedNewestPost(
|
||||
pageNumber INTEGER AS Int,
|
||||
shortId TEXT NOT NULL PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
commentCount INTEGER AS Int,
|
||||
commentsUrl TEXT NOT NULL,
|
||||
tags TEXT AS List<String> NOT NULL
|
||||
);
|
|
@ -25,9 +25,8 @@ class PostCommentsQueriesTest {
|
|||
val database =
|
||||
LobstersDatabase(
|
||||
driver,
|
||||
CachedNewestPost.Adapter(IntColumnAdapter, IntColumnAdapter, CSVAdapter),
|
||||
PostComments.Adapter(CSVAdapter),
|
||||
SavedPost.Adapter(IntColumnAdapter, CSVAdapter),
|
||||
PostComments.Adapter(CSVAdapter()),
|
||||
SavedPost.Adapter(IntColumnAdapter, CSVAdapter()),
|
||||
)
|
||||
postQueries = database.postCommentsQueries
|
||||
}
|
||||
|
|
|
@ -24,9 +24,8 @@ class SavedPostQueriesTest {
|
|||
val database =
|
||||
LobstersDatabase(
|
||||
driver,
|
||||
CachedNewestPost.Adapter(IntColumnAdapter, IntColumnAdapter, CSVAdapter),
|
||||
PostComments.Adapter(CSVAdapter),
|
||||
SavedPost.Adapter(IntColumnAdapter, CSVAdapter),
|
||||
PostComments.Adapter(CSVAdapter()),
|
||||
SavedPost.Adapter(IntColumnAdapter, CSVAdapter()),
|
||||
)
|
||||
postQueries = database.savedPostQueries
|
||||
}
|
||||
|
|
|
@ -70,7 +70,6 @@ jsoup = "org.jsoup:jsoup:1.16.1"
|
|||
junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" }
|
||||
junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "junit" }
|
||||
junit-legacy = "junit:junit:4.13.2"
|
||||
kotlinx-atomicfu = "org.jetbrains.kotlinx:atomicfu:0.21.0"
|
||||
kotlinx-collections-immutable = "org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.5"
|
||||
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
|
||||
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
|
||||
|
@ -86,7 +85,6 @@ retrofit-kotlinxSerializationConverter = "com.jakewharton.retrofit:retrofit2-kot
|
|||
sentry-bom = { module = "io.sentry:sentry-bom", version.ref = "sentry-sdk" }
|
||||
sentry-okhttp = { module = "io.sentry:sentry-android-okhttp", version.ref = "sentry-sdk" }
|
||||
slack-compose-lints = "com.slack.lint.compose:compose-lint-checks:1.2.0"
|
||||
store5 = "org.mobilenativefoundation.store:store5:5.0.0-beta02"
|
||||
sqldelight-androidDriver = { module = "app.cash.sqldelight:android-driver", version.ref = "sqldelight" }
|
||||
sqldelight-extensions-coroutines = { module = "app.cash.sqldelight:coroutines-extensions-jvm", version.ref = "sqldelight" }
|
||||
sqldelight-jvmDriver = { module = "app.cash.sqldelight:sqlite-driver", version.ref = "sqldelight" }
|
||||
|
|
|
@ -153,5 +153,4 @@ include(
|
|||
"core",
|
||||
"database",
|
||||
"model",
|
||||
"store",
|
||||
)
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2021-2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
@file:Suppress("UnstableApiUsage")
|
||||
|
||||
plugins {
|
||||
id("dev.msfjarvis.claw.android-library")
|
||||
id("dev.msfjarvis.claw.kotlin-android")
|
||||
alias(libs.plugins.anvil)
|
||||
}
|
||||
|
||||
android { namespace = "dev.msfjarvis.claw.store" }
|
||||
|
||||
anvil { generateDaggerFactories.set(true) }
|
||||
|
||||
dependencies {
|
||||
api(projects.database)
|
||||
api(projects.model)
|
||||
api(projects.core)
|
||||
|
||||
implementation(projects.api)
|
||||
implementation(libs.dagger)
|
||||
implementation(libs.javax.inject)
|
||||
implementation(libs.kotlinx.atomicfu)
|
||||
implementation(libs.kotlinx.coroutines.core)
|
||||
implementation(libs.sqldelight.extensions.coroutines)
|
||||
implementation(libs.store5)
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<issues format="6" by="lint 8.2.0-alpha15" type="baseline" client="gradle" dependencies="true" name="AGP (8.2.0-alpha15)" variant="all" version="8.2.0-alpha15">
|
||||
|
||||
</issues>
|
|
@ -1,10 +0,0 @@
|
|||
<!--
|
||||
~ Copyright © 2021-2023 Harsh Shandilya.
|
||||
~ Use of this source code is governed by an MIT-style
|
||||
~ license that can be found in the LICENSE file or at
|
||||
~ https://opensource.org/licenses/MIT.
|
||||
-->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</manifest>
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.store
|
||||
|
||||
import app.cash.sqldelight.coroutines.asFlow
|
||||
import app.cash.sqldelight.coroutines.mapToList
|
||||
import com.slack.eithernet.ApiResult
|
||||
import dev.msfjarvis.claw.api.LobstersApi
|
||||
import dev.msfjarvis.claw.core.injection.DatabaseDispatcher
|
||||
import dev.msfjarvis.claw.core.injection.IODispatcher
|
||||
import dev.msfjarvis.claw.database.LobstersDatabase
|
||||
import dev.msfjarvis.claw.database.local.CachedNewestPost
|
||||
import dev.msfjarvis.claw.model.LobstersPost
|
||||
import dev.msfjarvis.claw.store.utils.toCachedNewest
|
||||
import java.io.IOException
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.mobilenativefoundation.store.store5.Fetcher
|
||||
import org.mobilenativefoundation.store.store5.SourceOfTruth
|
||||
import org.mobilenativefoundation.store.store5.Store
|
||||
import org.mobilenativefoundation.store.store5.StoreBuilder
|
||||
|
||||
class NewestPostsStore
|
||||
@Inject
|
||||
constructor(
|
||||
private val api: LobstersApi,
|
||||
private val database: LobstersDatabase,
|
||||
@IODispatcher private val ioDispatcher: CoroutineDispatcher,
|
||||
@DatabaseDispatcher private val dbDispatcher: CoroutineDispatcher,
|
||||
) :
|
||||
Store<Int, List<CachedNewestPost>> by StoreBuilder.from<
|
||||
Int, List<LobstersPost>, List<CachedNewestPost>
|
||||
>(
|
||||
fetcher =
|
||||
Fetcher.of { key ->
|
||||
withContext(ioDispatcher) {
|
||||
when (val result = api.getNewestPosts(key)) {
|
||||
is ApiResult.Success -> result.value
|
||||
is ApiResult.Failure.NetworkFailure -> throw result.error
|
||||
is ApiResult.Failure.UnknownFailure -> throw result.error
|
||||
is ApiResult.Failure.HttpFailure,
|
||||
is ApiResult.Failure.ApiFailure ->
|
||||
throw IOException("API returned an invalid response")
|
||||
}
|
||||
}
|
||||
},
|
||||
sourceOfTruth =
|
||||
SourceOfTruth.of(
|
||||
reader = { page ->
|
||||
database.cachedNewestPostQueries.getPage(page).asFlow().mapToList(dbDispatcher)
|
||||
},
|
||||
writer = { page, items ->
|
||||
database.transaction {
|
||||
items
|
||||
.map { it.toCachedNewest(page) }
|
||||
.forEach { database.cachedNewestPostQueries.insertPost(it) }
|
||||
}
|
||||
},
|
||||
delete = { page -> database.cachedNewestPostQueries.clearPage(page) },
|
||||
deleteAll = { database.cachedNewestPostQueries.deleteAll() },
|
||||
),
|
||||
)
|
||||
.build()
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.store.utils
|
||||
|
||||
import dev.msfjarvis.claw.database.local.CachedNewestPost
|
||||
import dev.msfjarvis.claw.model.LobstersPost
|
||||
|
||||
internal fun LobstersPost.toCachedNewest(page: Int): CachedNewestPost {
|
||||
return CachedNewestPost(
|
||||
pageNumber = page,
|
||||
shortId = shortId,
|
||||
title = title,
|
||||
url = url,
|
||||
description = description,
|
||||
commentCount = commentCount,
|
||||
commentsUrl = commentsUrl,
|
||||
tags = tags,
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue