mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-17 21:27:01 +05:30
all: switch to moshi-kotlin and fix tests
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
bca96ae215
commit
740d9e432a
8 changed files with 12 additions and 12 deletions
|
@ -7,10 +7,10 @@ plugins {
|
|||
|
||||
dependencies {
|
||||
kapt(Dependencies.AndroidX.Hilt.daggerCompiler)
|
||||
kapt(Dependencies.ThirdParty.Moshi.codegen)
|
||||
api(Dependencies.ThirdParty.Retrofit.lib)
|
||||
implementation(project(":database"))
|
||||
implementation(Dependencies.AndroidX.Hilt.dagger)
|
||||
implementation(Dependencies.ThirdParty.Moshi.kotlinReflect)
|
||||
implementation(Dependencies.ThirdParty.Retrofit.moshi)
|
||||
testImplementation(Dependencies.Kotlin.Coroutines.core)
|
||||
testImplementation(Dependencies.Testing.junit)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dev.msfjarvis.lobsters.injection
|
||||
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
|
@ -11,6 +12,8 @@ import dagger.hilt.components.SingletonComponent
|
|||
object MoshiModule {
|
||||
@Provides
|
||||
fun provideMoshi(): Moshi {
|
||||
return Moshi.Builder().build()
|
||||
return Moshi.Builder()
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ object Dependencies {
|
|||
object Moshi {
|
||||
|
||||
private const val version = "1.11.0"
|
||||
const val codegen = "com.squareup.moshi:moshi-kotlin-codegen:$version"
|
||||
const val kotlinReflect = "com.squareup.moshi:moshi-kotlin:$version"
|
||||
const val lib = "com.squareup.moshi:moshi:$version"
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
plugins {
|
||||
id("com.android.library")
|
||||
kotlin("android")
|
||||
kotlin("kapt")
|
||||
id("com.squareup.sqldelight")
|
||||
`lobsters-plugin`
|
||||
}
|
||||
|
||||
dependencies {
|
||||
kapt(Dependencies.ThirdParty.Moshi.codegen)
|
||||
implementation(Dependencies.ThirdParty.Moshi.lib)
|
||||
implementation(Dependencies.ThirdParty.Moshi.kotlinReflect)
|
||||
testImplementation(Dependencies.Kotlin.Coroutines.core)
|
||||
testImplementation(Dependencies.ThirdParty.SQLDelight.jvmDriver)
|
||||
testImplementation(Dependencies.Testing.junit)
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package dev.msfjarvis.lobsters.model
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class KeybaseSignature(
|
||||
@Json(name = "kb_username")
|
||||
val kbUsername: String,
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package dev.msfjarvis.lobsters.model
|
||||
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
class Submitter(
|
||||
val username: String,
|
||||
@Json(name = "created_at")
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package dev.msfjarvis.lobsters.model
|
||||
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
import com.squareup.sqldelight.ColumnAdapter
|
||||
|
||||
class SubmitterAdapter : ColumnAdapter<Submitter, String> {
|
||||
private val moshi = Moshi.Builder().build()
|
||||
private val submitterJsonAdapter = SubmitterJsonAdapter(moshi)
|
||||
private val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
|
||||
private val submitterJsonAdapter = moshi.adapter(Submitter::class.java)
|
||||
|
||||
override fun decode(databaseValue: String): Submitter {
|
||||
return submitterJsonAdapter.fromJson(databaseValue)!!
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import dev.msfjarvis.lobsters.model.Submitter;
|
||||
import java.lang.Integer;
|
||||
import kotlin.collections.List;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS LobstersPost(
|
||||
|
@ -14,7 +15,7 @@ CREATE TABLE IF NOT EXISTS LobstersPost(
|
|||
comments_url TEXT NOT NULL,
|
||||
submitter_user TEXT as Submitter NOT NULL,
|
||||
tags TEXT as List<String> NOT NULL,
|
||||
is_saved INTEGER DEFAULT 0 NOT NULL
|
||||
is_saved INTEGER as Integer DEFAULT 0
|
||||
);
|
||||
|
||||
selectAllPosts:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue