mirror of
https://github.com/imcarlost/Acronyms.git
synced 2026-04-10 02:46:53 -04:00
Add: data and domain layers
This commit is contained in:
2
shortform/src/main/AndroidManifest.xml
Normal file
2
shortform/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="dev.carlos.shortform" />
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.carlos.shortform.data
|
||||
|
||||
import dev.carlos.shortform.data.cloud.AcronymsRemoteSource
|
||||
import dev.carlos.shortform.data.models.ShortformModel
|
||||
import dev.carlos.shortform.data.models.toShortformModel
|
||||
import dev.carlos.shortform.domain.AcronymsRepository
|
||||
import io.reactivex.Single
|
||||
|
||||
class AcronymsDataRepository(
|
||||
private val remoteDatasource: AcronymsRemoteSource
|
||||
) : AcronymsRepository {
|
||||
|
||||
override fun getAcronymDefinition(acronym: String): Single<ShortformModel> {
|
||||
return remoteDatasource.getAcronymDefinition(acronym).map { it.single()?.toShortformModel() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package dev.carlos.shortform.data.cloud
|
||||
|
||||
import dev.carlos.shortform.data.cloud.model.ShortformRemote
|
||||
import io.reactivex.Single
|
||||
|
||||
interface AcronymsRemoteSource {
|
||||
fun getAcronymDefinition(acronym: String): Single<List<ShortformRemote>>
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package dev.carlos.shortform.data.cloud.model
|
||||
|
||||
import android.os.Parcelable
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.carlos.shortform.data.cloud.retrofit
|
||||
|
||||
import dev.carlos.shortform.data.cloud.AcronymsRemoteSource
|
||||
import dev.carlos.shortform.data.cloud.model.ShortformRemote
|
||||
import io.reactivex.Single
|
||||
|
||||
class AcronymsRemoteDatasource(private val acronymsService: AcronymsService) : AcronymsRemoteSource {
|
||||
override fun getAcronymDefinition(acronym: String): Single<List<ShortformRemote>> {
|
||||
return acronymsService.getAcronymDefinition(acronym)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.carlos.shortform.data.cloud.retrofit
|
||||
|
||||
import dev.carlos.shortform.data.cloud.model.ShortformRemote
|
||||
import io.reactivex.Single
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface AcronymsService {
|
||||
@GET("/software/acromine/dictionary.py")
|
||||
fun getAcronymDefinition(@Query("sf") acronym: String): Single<List<ShortformRemote>>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.carlos.shortform.data.models
|
||||
|
||||
import dev.carlos.shortform.data.cloud.model.ShortformRemote
|
||||
|
||||
fun ShortformRemote.toShortformModel() = ShortformModel(this.value, this.results.map {
|
||||
ShortformModel.LongformModel(it.value, it.corpusFrequency, it.since)
|
||||
})
|
||||
@@ -0,0 +1,12 @@
|
||||
package dev.carlos.shortform.data.models
|
||||
|
||||
data class ShortformModel(
|
||||
val value: String,
|
||||
val results: List<LongformModel>
|
||||
) {
|
||||
data class LongformModel(
|
||||
val value: String,
|
||||
val corpusFrequency: Int,
|
||||
val since: Int
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package dev.carlos.shortform.di
|
||||
|
||||
import dev.carlos.core.domain.network.RemoteClient
|
||||
import dev.carlos.core.scheduler.Scheduler
|
||||
import dev.carlos.core.scheduler.SchedulerProvider
|
||||
import dev.carlos.shortform.data.AcronymsDataRepository
|
||||
import dev.carlos.shortform.data.cloud.AcronymsRemoteSource
|
||||
import dev.carlos.shortform.data.cloud.retrofit.AcronymsRemoteDatasource
|
||||
import dev.carlos.shortform.data.cloud.retrofit.AcronymsService
|
||||
import dev.carlos.shortform.domain.AcronymsRepository
|
||||
import dev.carlos.shortform.domain.GetAcronymDefinition
|
||||
import org.koin.dsl.module
|
||||
|
||||
val acronymsModule = module {
|
||||
single<Scheduler> { SchedulerProvider() }
|
||||
|
||||
single {
|
||||
get<RemoteClient>().getClient(AcronymsService::class.java)
|
||||
}
|
||||
|
||||
factory<AcronymsRemoteSource> { AcronymsRemoteDatasource(get()) }
|
||||
factory<AcronymsRepository> { AcronymsDataRepository(get()) }
|
||||
|
||||
factory { GetAcronymDefinition(get(), get()) }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package dev.carlos.shortform.domain
|
||||
|
||||
import dev.carlos.shortform.data.models.ShortformModel
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Single
|
||||
|
||||
interface AcronymsRepository {
|
||||
fun getAcronymDefinition(acronym: String): Single<ShortformModel>
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.carlos.shortform.domain
|
||||
|
||||
import dev.carlos.shortform.data.models.ShortformModel
|
||||
import dev.carlos.core.extensions.runOnIo
|
||||
import dev.carlos.core.scheduler.Scheduler
|
||||
import io.reactivex.Single
|
||||
|
||||
class GetAcronymDefinition(
|
||||
private val acronymsRepository: AcronymsRepository,
|
||||
private val scheduler: Scheduler
|
||||
) {
|
||||
fun getAcronymDefinition(acronym: String): Single<ShortformModel> {
|
||||
return acronymsRepository.getAcronymDefinition(acronym).runOnIo(scheduler)
|
||||
}
|
||||
}
|
||||
19
shortform/src/main/res/values-night/themes.xml
Normal file
19
shortform/src/main/res/values-night/themes.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.Acronyms"
|
||||
parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_200</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorOnPrimary">@color/black</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_200</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor"
|
||||
tools:targetApi="l">?attr/colorPrimaryVariant
|
||||
</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
</resources>
|
||||
10
shortform/src/main/res/values/colors.xml
Normal file
10
shortform/src/main/res/values/colors.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
||||
3
shortform/src/main/res/values/strings.xml
Normal file
3
shortform/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">acronyms</string>
|
||||
</resources>
|
||||
19
shortform/src/main/res/values/themes.xml
Normal file
19
shortform/src/main/res/values/themes.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Base application theme. -->
|
||||
<style name="Theme.Acronyms"
|
||||
parent="Theme.MaterialComponents.DayNight.DarkActionBar">
|
||||
<!-- Primary brand color. -->
|
||||
<item name="colorPrimary">@color/purple_500</item>
|
||||
<item name="colorPrimaryVariant">@color/purple_700</item>
|
||||
<item name="colorOnPrimary">@color/white</item>
|
||||
<!-- Secondary brand color. -->
|
||||
<item name="colorSecondary">@color/teal_200</item>
|
||||
<item name="colorSecondaryVariant">@color/teal_700</item>
|
||||
<item name="colorOnSecondary">@color/black</item>
|
||||
<!-- Status bar color. -->
|
||||
<item name="android:statusBarColor"
|
||||
tools:targetApi="l">?attr/colorPrimaryVariant
|
||||
</item>
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user