Skip to content

Commit

Permalink
feat: ⬆️ update libs and gradle (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffgiraldez authored Sep 30, 2020
1 parent ad8145d commit 5d53349
Show file tree
Hide file tree
Showing 32 changed files with 269 additions and 318 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/captures
*.iml
*/.kotlintest
.idea
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ My way to MVVM using RxJava with new Android databinding
* picasso

### Testing
* [KotlinTest][10]
* [Kotest][10]
* [Android Junit 5][11]

TODO LIST
Expand Down Expand Up @@ -68,5 +68,5 @@ License
[7]: https://developer.android.com/topic/libraries/architecture/room.html
[8]: https://developer.android.com/topic/libraries/architecture/livedata.html
[9]: https://developer.android.com/topic/libraries/architecture/viewmodel.html
[10]: https://github.com/kotlintest/kotlintest
[10]: https://kotest.io
[11]: https://github.com/mannodermaus/android-junit5
52 changes: 28 additions & 24 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ android {
minSdkVersion min_sdk
versionCode 1
versionName "1.0"
javaCompileOptions {
annotationProcessorOptions {
arguments += [
"room.schemaLocation" : "$projectDir/schemas".toString(),
"room.incremental" : "true",
"room.expandProjection": "true"
]
}
}

}

buildTypes {
Expand All @@ -31,8 +41,8 @@ android {
}
}

dataBinding {
enabled = true
buildFeatures {
dataBinding true
}

compileOptions {
Expand All @@ -45,61 +55,55 @@ android {
}
}

kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas".toString())
}
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
}

dependencies {
kapt libs.databinding_compiler
kapt libs.arch_comp_room_compiler
kaptTest libs.arch_comp_room_compiler
kapt libs.androidx_room_compiler
kaptTest libs.androidx_room_compiler

implementation libs.arch_comp_livedata
implementation libs.arch_comp_viewmodel
implementation libs.arch_comp_room
implementation libs.arch_comp_room_rxjava
implementation libs.androidx_constraint
implementation libs.androidx_livedata
implementation libs.androidx_room
implementation libs.androidx_room_rxjava
implementation libs.androidx_viewmodel
implementation libs.arrow
implementation libs.constraint
implementation libs.design
implementation(libs.floating_search) {
exclude module: 'support-v4'
}
implementation libs.material
implementation libs.okhttp
implementation libs.okhttp_logging
implementation libs.picasso
implementation libs.koin
implementation libs.koin_android
implementation libs.koin_architecture
implementation libs.kotlin_stdlib
implementation libs.picasso
implementation libs.retrofit
implementation libs.retrofit_gson
implementation libs.retrofit_rx_java
implementation libs.rx_java
implementation libs.rx_android
implementation libs.steho

testImplementation (libs.arch_comp_room_test) {
testImplementation(libs.androidx_room_test) {
exclude module: 'junit'
}
testImplementation (libs.arch_comp_test) {
testImplementation(libs.androidx_test) {
exclude module: 'junit'
}
testImplementation libs.junit_api
testImplementation libs.junit_params
testImplementation libs.kotlintest
testImplementation (libs.koin_test) {
testImplementation libs.mockito_kotlin
testImplementation libs.kotest_runner
testImplementation libs.kotest_assertions
testImplementation libs.kotest_property
testImplementation(libs.koin_test) {
exclude module: 'junit'
}
testImplementation libs.mockito_kotlin

testRuntimeOnly libs.junit_engine
}
repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package es.ffgiraldez.comicsearch.comics.data

import arrow.core.Option
import es.ffgiraldez.comicsearch.comics.domain.Query
import es.ffgiraldez.comicsearch.platform.Option
import io.reactivex.Completable
import io.reactivex.Flowable
import io.reactivex.Single
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package es.ffgiraldez.comicsearch.comics.data

import arrow.core.Either
import arrow.core.None
import arrow.core.Option
import arrow.core.Some
import arrow.core.Either.Left
import arrow.core.Either.Right
import es.ffgiraldez.comicsearch.comics.domain.ComicError
import es.ffgiraldez.comicsearch.comics.domain.ComicError.EmptyResultsError
import es.ffgiraldez.comicsearch.comics.domain.ComicError.NetworkError
import es.ffgiraldez.comicsearch.comics.domain.Query
import es.ffgiraldez.comicsearch.platform.Option
import es.ffgiraldez.comicsearch.platform.left
import es.ffgiraldez.comicsearch.platform.right
import io.reactivex.Flowable
Expand All @@ -24,8 +24,8 @@ abstract class ComicRepository<T> (
query: Option<Query>,
term: String
): Flowable<out Either<ComicError, List<T>>> = when (query) {
is None -> search(term)
is Some -> fetch(query)
is Left -> search(term)
is Right -> fetch(query)
}

private fun search(term: String): Flowable<Either<ComicError, List<T>>> =
Expand All @@ -44,8 +44,8 @@ abstract class ComicRepository<T> (
local.insert(term, it).toFlowable()
})

private fun fetch(it: Some<Query>): Flowable<Either<EmptyResultsError, List<T>>> =
local.findByQuery(it.t)
private fun fetch(it: Right<Query>): Flowable<Either<EmptyResultsError, List<T>>> =
local.findByQuery(it.b)
.map {
when (it.isEmpty()) {
true -> Either.left(EmptyResultsError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import retrofit2.http.Query
interface ComicVineApi {

companion object {
const val KEY = "75d580a0593b7320727309feb6309f62def786cd"
const val BASE_URL = "http://www.comicvine.com"
const val KEY = "d800216c205879548fdc491e0a260ff402633c00"
const val BASE_URL = "https://www.comicvine.com"
}

@GET("/api/search?format=json&field_list=name&limit=20&page=1&resources=volume&api_key=$KEY")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package es.ffgiraldez.comicsearch.platform

import androidx.databinding.BindingAdapter
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.squareup.picasso.Picasso

@BindingAdapter("image")
fun bindImage(image: ImageView, url: String) = Picasso.with(image.context).load(url).into(image)
fun bindImage(image: ImageView, url: String) = Picasso.get().load(url).into(image)
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package es.ffgiraldez.comicsearch.platform

import arrow.core.Either
import arrow.core.Left
import arrow.core.Right
import arrow.core.left
import arrow.core.right
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable

typealias Option<A> = Either<Unit, A>

fun <A, B> left(a: A): Either<A, B> = a.left()
fun <A, B> right(b: B): Either<A, B> = b.right()
fun <T> T?.toOption(): Option<T> = this?.let { Right(it) } ?: Left(Unit)

operator fun CompositeDisposable.plus(disposable: Disposable): CompositeDisposable = apply {
add(disposable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import es.ffgiraldez.comicsearch.navigation.Navigator
import es.ffgiraldez.comicsearch.query.search.presentation.SearchViewModel
import es.ffgiraldez.comicsearch.query.sugestion.presentation.SuggestionViewModel
import org.koin.android.ext.android.inject
import org.koin.android.viewmodel.ext.android.viewModel
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.koin.core.parameter.parametersOf

class QueryActivity : AppCompatActivity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package es.ffgiraldez.comicsearch.query.base.ui

import arrow.core.Option
import arrow.core.toOption
import es.ffgiraldez.comicsearch.comics.domain.ComicError
import es.ffgiraldez.comicsearch.query.base.presentation.QueryViewState

val <T>QueryViewState<T>.error: Option<ComicError>
val <T>QueryViewState<T>.error: ComicError?
get() = when (this) {
is QueryViewState.Error -> _error.toOption()
else -> Option.empty()
is QueryViewState.Error -> _error
else -> null
}

val <T>QueryViewState<T>.hasError: Boolean
get() = !error.isEmpty()

val <T>QueryViewState<T>.results: List<T>
get() = when (this) {
is QueryViewState.Result -> _results
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package es.ffgiraldez.comicsearch.query.search.data

import arrow.core.Option
import arrow.core.toOption
import es.ffgiraldez.comicsearch.comics.data.ComicLocalDataSource
import es.ffgiraldez.comicsearch.comics.data.ComicRemoteDataSource
import es.ffgiraldez.comicsearch.comics.data.network.ComicVineApi
import es.ffgiraldez.comicsearch.comics.data.storage.ComicDatabase
import es.ffgiraldez.comicsearch.comics.domain.Query
import es.ffgiraldez.comicsearch.comics.domain.Volume
import es.ffgiraldez.comicsearch.platform.ComicSchedulers
import es.ffgiraldez.comicsearch.platform.Option
import es.ffgiraldez.comicsearch.platform.toOption
import io.reactivex.Completable
import io.reactivex.Flowable
import io.reactivex.Single
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import es.ffgiraldez.comicsearch.query.search.data.SearchLocalDataSource
import es.ffgiraldez.comicsearch.query.search.data.SearchRemoteDataSource
import es.ffgiraldez.comicsearch.query.search.data.SearchRepository
import es.ffgiraldez.comicsearch.query.search.presentation.SearchViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

val searchModule = module {
factory { SearchLocalDataSource(get(parameters = { it })) }
factory { SearchRemoteDataSource(get()) }
factory { SearchRepository(get(parameters = { it }), get()) }
factory { SearchViewModel(get(parameters = { it })) }
viewModel { SearchViewModel(get(parameters = { it })) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import es.ffgiraldez.comicsearch.query.base.ui.OnVolumeSelectedListener
import es.ffgiraldez.comicsearch.query.base.ui.QuerySearchSuggestion.ResultSuggestion
import es.ffgiraldez.comicsearch.query.base.ui.QueryVolumeAdapter
import es.ffgiraldez.comicsearch.query.base.ui.error
import es.ffgiraldez.comicsearch.query.base.ui.hasError
import es.ffgiraldez.comicsearch.query.base.ui.loading
import es.ffgiraldez.comicsearch.query.base.ui.results
import es.ffgiraldez.comicsearch.query.base.ui.toHumanResponse
Expand Down Expand Up @@ -55,30 +54,25 @@ fun RecyclerView.bindStateData(inputAdapter: QueryVolumeAdapter, data: QueryView
}

data?.let {
bindError(data.hasError)
gone(data.error != null)
bindResults(data.results)
}
}


@BindingAdapter("state_change")
fun FrameLayout.bindStateVisibility(data: QueryViewState<Volume>?) = data?.let { state ->
state.error.fold({ View.GONE }, { View.VISIBLE }).let { visibility = it }
fun FrameLayout.bindStateVisibility(data: QueryViewState<Volume>?) = data?.run {
visibility = error?.let { View.VISIBLE } ?: View.GONE
}

@BindingAdapter("state_change")
fun TextView.bindErrorText(data: QueryViewState<Volume>?) = data?.let { state ->
state.error.fold({ Unit }, { text = it.toHumanResponse() })
}
fun TextView.bindErrorText(data: QueryViewState<Volume>?) = data?.error?.run { text = toHumanResponse() }

@BindingAdapter("state_change")
fun ProgressBar.bindProgress(data: QueryViewState<Volume>?) = data?.let { state ->
gone(!state.loading)
fun ProgressBar.bindProgress(data: QueryViewState<Volume>?) = data?.run {
gone(!loading)
}

private fun RecyclerView.bindError(error: Boolean): Unit =
gone(error)

private fun RecyclerView.bindResults(error: List<Volume>): Unit = with(adapter as QueryVolumeAdapter) {
this.submitList(error)
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package es.ffgiraldez.comicsearch.query.sugestion.data

import arrow.core.Option
import arrow.core.toOption
import es.ffgiraldez.comicsearch.comics.data.ComicLocalDataSource
import es.ffgiraldez.comicsearch.comics.data.ComicRemoteDataSource
import es.ffgiraldez.comicsearch.comics.data.network.ComicVineApi
import es.ffgiraldez.comicsearch.comics.data.storage.ComicDatabase
import es.ffgiraldez.comicsearch.comics.domain.Query
import es.ffgiraldez.comicsearch.platform.ComicSchedulers
import es.ffgiraldez.comicsearch.platform.Option
import es.ffgiraldez.comicsearch.platform.toOption
import io.reactivex.Completable
import io.reactivex.Flowable
import io.reactivex.Single
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import es.ffgiraldez.comicsearch.query.sugestion.data.SuggestionLocalDataSource
import es.ffgiraldez.comicsearch.query.sugestion.data.SuggestionRemoteDataSource
import es.ffgiraldez.comicsearch.query.sugestion.data.SuggestionRepository
import es.ffgiraldez.comicsearch.query.sugestion.presentation.SuggestionViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

val suggestionModule = module {
factory { SuggestionLocalDataSource(get(parameters = { it })) }
factory { SuggestionRemoteDataSource(get()) }
factory { SuggestionRepository(get(parameters = { it }), get()) }
factory { SuggestionViewModel(get(parameters = { it })) }
viewModel { SuggestionViewModel(get(parameters = { it })) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package es.ffgiraldez.comicsearch.query.sugestion.ui
import androidx.databinding.BindingAdapter
import com.arlib.floatingsearchview.FloatingSearchView
import es.ffgiraldez.comicsearch.query.base.presentation.QueryViewState
import es.ffgiraldez.comicsearch.query.base.ui.QuerySearchSuggestion.ErrorSuggestion
import es.ffgiraldez.comicsearch.query.base.presentation.QueryViewState.Error
import es.ffgiraldez.comicsearch.query.base.ui.QuerySearchSuggestion.ResultSuggestion
import es.ffgiraldez.comicsearch.query.base.ui.error
import es.ffgiraldez.comicsearch.query.base.ui.loading
import es.ffgiraldez.comicsearch.query.base.ui.results
import es.ffgiraldez.comicsearch.query.base.ui.toHumanResponse
Expand All @@ -16,17 +15,18 @@ fun FloatingSearchView.bindQueryChangeListener(
): Unit = setOnQueryChangeListener(listener)

@BindingAdapter("state_change")
fun FloatingSearchView.bindSuggestions(data: QueryViewState<String>?): Unit? = data?.let { state ->
toggleProgress(state.loading)
state.error.fold({
state.results.map { ResultSuggestion(it) }
}, {
listOf(ErrorSuggestion(it.toHumanResponse()))
}).let(::swapSuggestions)
fun FloatingSearchView.bindSuggestions(data: QueryViewState<String>?) = data?.run {
toggleProgress(loading)
swapSuggestions(suggestions)
}

private val QueryViewState<String>.suggestions: List<ResultSuggestion>
get() = when (this) {
is Error -> listOf(ResultSuggestion(_error.toHumanResponse()))
else -> results.map { ResultSuggestion(it) }
}

private fun FloatingSearchView.toggleProgress(show: Boolean): Unit = when (show) {
true -> showProgress()
false -> hideProgress()
}

Loading

0 comments on commit 5d53349

Please sign in to comment.