mirror of
https://github.com/imcarlost/Acronyms.git
synced 2026-04-10 02:46:53 -04:00
Change: rename acronyms classes to shortform
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
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,16 @@
|
||||
package dev.carlos.shortform.data
|
||||
|
||||
import dev.carlos.shortform.data.cloud.ShortformRemoteSource
|
||||
import dev.carlos.shortform.data.models.ShortformModel
|
||||
import dev.carlos.shortform.data.models.toShortformModel
|
||||
import dev.carlos.shortform.domain.ShortformRepository
|
||||
import io.reactivex.Single
|
||||
|
||||
class ShortformDataRepository(
|
||||
private val remoteDatasource: ShortformRemoteSource
|
||||
) : ShortformRepository {
|
||||
|
||||
override fun getShortformDefinition(acronym: String): Single<ShortformModel> {
|
||||
return remoteDatasource.getShortformDefinition(acronym).map { it.single().toShortformModel() }
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,6 @@ 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>>
|
||||
interface ShortformRemoteSource {
|
||||
fun getShortformDefinition(acronym: String): Single<List<ShortformRemote>>
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
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.ShortformRemoteSource
|
||||
import dev.carlos.shortform.data.cloud.model.ShortformRemote
|
||||
import io.reactivex.Single
|
||||
|
||||
class ShortformRemoteDatasource(private val shortformService: ShortformService) : ShortformRemoteSource {
|
||||
override fun getShortformDefinition(acronym: String): Single<List<ShortformRemote>> {
|
||||
return shortformService.getShortformDefinition(acronym)
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import io.reactivex.Single
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface AcronymsService {
|
||||
interface ShortformService {
|
||||
@GET("/software/acromine/dictionary.py")
|
||||
fun getAcronymDefinition(@Query("sf") acronym: String): Single<List<ShortformRemote>>
|
||||
fun getShortformDefinition(@Query("sf") acronym: String): Single<List<ShortformRemote>>
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
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 dev.carlos.shortform.viewmodels.AcronymsViewmodel
|
||||
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||
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()) }
|
||||
|
||||
viewModel { AcronymsViewmodel(get()) }
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
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.ShortformDataRepository
|
||||
import dev.carlos.shortform.data.cloud.ShortformRemoteSource
|
||||
import dev.carlos.shortform.data.cloud.retrofit.ShortformRemoteDatasource
|
||||
import dev.carlos.shortform.data.cloud.retrofit.ShortformService
|
||||
import dev.carlos.shortform.domain.ShortformRepository
|
||||
import dev.carlos.shortform.domain.GetShortformDefinition
|
||||
import dev.carlos.shortform.viewmodels.ShortformViewmodel
|
||||
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||
import org.koin.dsl.module
|
||||
|
||||
val shortformModule = module {
|
||||
single<Scheduler> { SchedulerProvider() }
|
||||
|
||||
single {
|
||||
get<RemoteClient>().getClient(ShortformService::class.java)
|
||||
}
|
||||
|
||||
factory<ShortformRemoteSource> { ShortformRemoteDatasource(get()) }
|
||||
factory<ShortformRepository> { ShortformDataRepository(get()) }
|
||||
|
||||
factory { GetShortformDefinition(get(), get()) }
|
||||
|
||||
viewModel { ShortformViewmodel(get()) }
|
||||
}
|
||||
@@ -5,11 +5,11 @@ import dev.carlos.core.extensions.runOnIo
|
||||
import dev.carlos.core.scheduler.Scheduler
|
||||
import io.reactivex.Single
|
||||
|
||||
class GetAcronymDefinition(
|
||||
private val acronymsRepository: AcronymsRepository,
|
||||
class GetShortformDefinition(
|
||||
private val shortformRepository: ShortformRepository,
|
||||
private val scheduler: Scheduler
|
||||
) {
|
||||
fun getAcronymDefinition(acronym: String): Single<ShortformModel> {
|
||||
return acronymsRepository.getAcronymDefinition(acronym).runOnIo(scheduler)
|
||||
fun getShortformDefinition(shortform: String): Single<ShortformModel> {
|
||||
return shortformRepository.getShortformDefinition(shortform).runOnIo(scheduler)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@ import dev.carlos.shortform.data.models.ShortformModel
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Single
|
||||
|
||||
interface AcronymsRepository {
|
||||
fun getAcronymDefinition(acronym: String): Single<ShortformModel>
|
||||
interface ShortformRepository {
|
||||
fun getShortformDefinition(acronym: String): Single<ShortformModel>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package dev.carlos.shortform.feature
|
||||
|
||||
class ShortformFragment {
|
||||
}
|
||||
@@ -5,18 +5,18 @@ import dev.carlos.core.domain.network.RequestError
|
||||
import dev.carlos.core.domain.network.RequestState
|
||||
import dev.carlos.core.viewmodel.RxViewModel
|
||||
import dev.carlos.shortform.data.models.ShortformModel
|
||||
import dev.carlos.shortform.domain.GetAcronymDefinition
|
||||
import dev.carlos.shortform.domain.GetShortformDefinition
|
||||
import retrofit2.HttpException
|
||||
import java.net.UnknownHostException
|
||||
|
||||
class AcronymsViewmodel(
|
||||
private val GetAcronymsDefinition: GetAcronymDefinition
|
||||
class ShortformViewmodel(
|
||||
private val getAcronymsDefinition: GetShortformDefinition
|
||||
) : RxViewModel() {
|
||||
|
||||
val acronymDefinition = MutableLiveData<RequestState>()
|
||||
|
||||
fun fetchAcronymDefinition(acronym: String) {
|
||||
val disposable = GetAcronymsDefinition.getAcronymDefinition(acronym)
|
||||
val disposable = getAcronymsDefinition.getShortformDefinition(acronym)
|
||||
.doOnSubscribe { acronymDefinition.postValue(RequestState.Loading) }
|
||||
.subscribe(::handleSuccess, ::handleError)
|
||||
compositeDisposable.add(disposable)
|
||||
Reference in New Issue
Block a user