mirror of
https://github.com/imcarlost/Acronyms.git
synced 2026-04-09 18:38:28 -04:00
Add: acronyms models
This commit is contained in:
@@ -3,6 +3,7 @@ apply from: '../base.gradle'
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
apply plugin: 'kotlin-parcelize'
|
||||
|
||||
dependencies {
|
||||
implementation project(':core')
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package dev.carlos.acronyms.models
|
||||
|
||||
import android.os.Parcelable
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.TypeConverters
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class ShortformRemote(
|
||||
@SerializedName("sf") val value: String,
|
||||
@SerializedName("lfs") val results: List<LongformRemote>
|
||||
) : Parcelable {
|
||||
@Parcelize
|
||||
data class LongformRemote(
|
||||
@SerializedName("lf") val value: String,
|
||||
@SerializedName("freq") val corpusFrequency: Int,
|
||||
@SerializedName("since") val since: Int
|
||||
) : Parcelable
|
||||
}
|
||||
|
||||
@Entity(tableName = ShortformEntity.TABLE_NAME, indices = [Index(value = ["value"], unique = true)])
|
||||
@TypeConverters(LongformListConverter::class)
|
||||
data class ShortformEntity(
|
||||
@PrimaryKey
|
||||
val value: String,
|
||||
val results: List<LongformEntity>
|
||||
) {
|
||||
data class LongformEntity(
|
||||
val value: String,
|
||||
val corpusFrequency: Int,
|
||||
val since: Int
|
||||
)
|
||||
|
||||
companion object {
|
||||
const val TABLE_NAME = "shortforms"
|
||||
}
|
||||
}
|
||||
|
||||
data class ShortformModel(
|
||||
val value: String,
|
||||
val results: List<LongformModel>
|
||||
) {
|
||||
data class LongformModel(
|
||||
val value: String,
|
||||
val corpusFrequency: Int,
|
||||
val since: Int
|
||||
)
|
||||
}
|
||||
24
acronyms/src/main/java/dev/carlos/acronyms/models/Mappers.kt
Normal file
24
acronyms/src/main/java/dev/carlos/acronyms/models/Mappers.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
package dev.carlos.acronyms.models
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
|
||||
class LongformListConverter {
|
||||
@TypeConverter
|
||||
fun fromString(value: String): List<ShortformEntity.LongformEntity> {
|
||||
val listType = object : TypeToken<List<ShortformEntity.LongformEntity>>() {}.type
|
||||
return Gson().fromJson(value, listType)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun fromList(list: List<ShortformEntity.LongformEntity>) = Gson().toJson(list)
|
||||
}
|
||||
|
||||
fun ShortformRemote.toShortformEntity() = ShortformEntity(this.value, this.results.map {
|
||||
ShortformEntity.LongformEntity(it.value, it.corpusFrequency, it.since)
|
||||
})
|
||||
|
||||
fun ShortformEntity.toShortformModel() = ShortformModel(this.value, this.results.map {
|
||||
ShortformModel.LongformModel(it.value, it.corpusFrequency, it.since)
|
||||
})
|
||||
@@ -2,6 +2,7 @@ apply from: '../versions.gradle'
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
apply plugin: 'kotlin-parcelize'
|
||||
|
||||
android {
|
||||
compileSdkVersion build_versions.target_sdk
|
||||
|
||||
@@ -2,6 +2,7 @@ apply from: '../versions.gradle'
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
apply plugin: 'kotlin-parcelize'
|
||||
|
||||
android {
|
||||
compileSdkVersion build_versions.target_sdk
|
||||
|
||||
@@ -3,6 +3,7 @@ apply from: '../base.gradle'
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
apply plugin: 'kotlin-parcelize'
|
||||
|
||||
dependencies {
|
||||
api deps.google.kotlin.std_lib
|
||||
@@ -15,6 +16,7 @@ dependencies {
|
||||
api deps.google.androidx.navigation_fragment
|
||||
api deps.google.androidx.navigation_ui
|
||||
api deps.google.material.core
|
||||
api deps.google.gson.core
|
||||
api deps.core.okhttp.logging_interceptor
|
||||
api deps.core.retrofit.runtime
|
||||
api deps.core.retrofit.gson
|
||||
|
||||
@@ -11,6 +11,7 @@ versions.androidx_lifecycle = "2.2.0"
|
||||
versions.androidx_recycler_view = "1.2.0"
|
||||
versions.androidx_navigation = "2.3.5"
|
||||
versions.material_core = "1.3.0"
|
||||
versions.gson = "2.8.7"
|
||||
versions.okhttp_interceptor = "4.9.1"
|
||||
versions.retrofit = "2.9.0"
|
||||
versions.timber = "4.7.1"
|
||||
@@ -53,8 +54,12 @@ androidx.navigation_ui = "androidx.navigation:navigation-ui-ktx:$versions.androi
|
||||
def material = [:]
|
||||
material.core = "com.google.android.material:material:$versions.material_core"
|
||||
|
||||
def gson = [:]
|
||||
gson.core = "com.google.code.gson:gson:$versions.gson"
|
||||
|
||||
def google = [:]
|
||||
google.kotlin = kotlin
|
||||
google.gson = gson
|
||||
google.androidx = androidx
|
||||
google.material = material
|
||||
deps.google = google
|
||||
|
||||
Reference in New Issue
Block a user