mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-28 21:07:57 +01:00
Grab extension repo detail from repo.json and include in DB (#506)
* WIP Extension Repo DB Support * Wired in to extension screen, browse settings screen * Detekt changes * Ui tweaks and open in browser * Migrate ExtensionRepos on Update * Migration Cleanup * Slight cleanup / error handling * Update ExtensionRepo from Repo.json during extension search. Added Manual refresh in extension repos page. * Split repo fetching into separate API module, major refactor work * Removed development strings * Moved migration to #3 * Fixed rebase * Detekt changes * Added Replace Repository Dialog * Cleanup, removed platform specific code, PR comments * Removed extra function, reverted small change * Detekt cleanup * Apply suggestions from code review Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> * Fixed error introduced in cleanup * Tweak for multiline when * Moved getCount() to flow * changed getCount to non-suspend, used property delegation * Apply suggestions from code review Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> * Fixed formatting with updated comment string * Big wave of PR comments, renaming/other tweaks * onOpenWebsite changes * onOpenWebsite changes * trying to make single line * Renamed ExtensionRepoApi.kt to ExtensionRepoService.kt --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
package mihon.data.repository
|
||||
|
||||
import android.database.sqlite.SQLiteException
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import mihon.domain.extensionrepo.exception.SaveExtensionRepoException
|
||||
import mihon.domain.extensionrepo.model.ExtensionRepo
|
||||
import mihon.domain.extensionrepo.repository.ExtensionRepoRepository
|
||||
import tachiyomi.data.DatabaseHandler
|
||||
|
||||
class ExtensionRepoRepositoryImpl(
|
||||
private val handler: DatabaseHandler,
|
||||
) : ExtensionRepoRepository {
|
||||
override fun subscribeAll(): Flow<List<ExtensionRepo>> {
|
||||
return handler.subscribeToList { extension_reposQueries.findAll(::mapExtensionRepo) }
|
||||
}
|
||||
|
||||
override suspend fun getAll(): List<ExtensionRepo> {
|
||||
return handler.awaitList { extension_reposQueries.findAll(::mapExtensionRepo) }
|
||||
}
|
||||
|
||||
override suspend fun getRepository(baseUrl: String): ExtensionRepo? {
|
||||
return handler.awaitOneOrNull { extension_reposQueries.findOne(baseUrl, ::mapExtensionRepo) }
|
||||
}
|
||||
|
||||
override suspend fun getRepositoryBySigningKeyFingerprint(fingerprint: String): ExtensionRepo? {
|
||||
return handler.awaitOneOrNull {
|
||||
extension_reposQueries.findOneBySigningKeyFingerprint(fingerprint, ::mapExtensionRepo)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getCount(): Flow<Int> {
|
||||
return handler.subscribeToOne { extension_reposQueries.count() }.map { it.toInt() }
|
||||
}
|
||||
|
||||
override suspend fun insertRepository(
|
||||
baseUrl: String,
|
||||
name: String,
|
||||
shortName: String?,
|
||||
website: String,
|
||||
signingKeyFingerprint: String,
|
||||
) {
|
||||
try {
|
||||
handler.await { extension_reposQueries.insert(baseUrl, name, shortName, website, signingKeyFingerprint) }
|
||||
} catch (ex: SQLiteException) {
|
||||
throw SaveExtensionRepoException(ex)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun upsertRepository(
|
||||
baseUrl: String,
|
||||
name: String,
|
||||
shortName: String?,
|
||||
website: String,
|
||||
signingKeyFingerprint: String,
|
||||
) {
|
||||
try {
|
||||
handler.await { extension_reposQueries.upsert(baseUrl, name, shortName, website, signingKeyFingerprint) }
|
||||
} catch (ex: SQLiteException) {
|
||||
throw SaveExtensionRepoException(ex)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun replaceRepository(newRepo: ExtensionRepo) {
|
||||
handler.await {
|
||||
extension_reposQueries.replace(
|
||||
newRepo.baseUrl,
|
||||
newRepo.name,
|
||||
newRepo.shortName,
|
||||
newRepo.website,
|
||||
newRepo.signingKeyFingerprint,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun deleteRepository(baseUrl: String) {
|
||||
return handler.await { extension_reposQueries.delete(baseUrl) }
|
||||
}
|
||||
|
||||
private fun mapExtensionRepo(
|
||||
baseUrl: String,
|
||||
name: String,
|
||||
shortName: String?,
|
||||
website: String,
|
||||
signingKeyFingerprint: String,
|
||||
): ExtensionRepo = ExtensionRepo(
|
||||
baseUrl = baseUrl,
|
||||
name = name,
|
||||
shortName = shortName,
|
||||
website = website,
|
||||
signingKeyFingerprint = signingKeyFingerprint,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user