Skip to content

update(dependencies) #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,41 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.appcompat:appcompat:1.2.0-beta01'
implementation 'androidx.core:core-ktx:1.3.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha03'
implementation 'com.google.android.material:material:1.2.0-alpha04'
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha02'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-beta01'
implementation 'com.google.android.material:material:1.2.0-alpha05'

// viewModelScope
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0-alpha01'

// lifecycleScope
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-alpha01'

// Extensions for LiveData
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-alpha01'

// retrofit2
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
implementation 'com.squareup.retrofit2:converter-moshi:2.7.1'
implementation 'com.squareup.okhttp3:logging-interceptor:4.2.1'
implementation 'com.squareup.retrofit2:retrofit:2.8.1'
implementation 'com.squareup.retrofit2:converter-moshi:2.8.1'
implementation 'com.squareup.okhttp3:logging-interceptor:4.4.0'

// moshi
implementation 'com.squareup.moshi:moshi-kotlin:1.8.0'
implementation 'com.squareup.moshi:moshi-kotlin:1.9.2'

// coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5'

// koin
implementation 'org.koin:koin-androidx-viewmodel:2.0.0'
implementation 'org.koin:koin-androidx-viewmodel:2.1.5'

// coil
implementation 'io.coil-kt:coil:0.8.0'
implementation 'io.coil-kt:coil:0.9.5'

testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
Expand Down
58 changes: 30 additions & 28 deletions app/src/main/java/com/hoc/flowmvi/FlowBinding+Exts+Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ fun View.clicks(): Flow<View> {
}

@ExperimentalCoroutinesApi
@CheckResult
fun EditText.textChanges(): Flow<CharSequence?> {
return callbackFlow {
return callbackFlow<CharSequence?> {
val listener = object : TextWatcher {
override fun afterTextChanged(s: Editable?) = Unit
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = Unit
Expand All @@ -55,7 +56,7 @@ fun EditText.textChanges(): Flow<CharSequence?> {

@ExperimentalCoroutinesApi
fun <T, R> Flow<T>.flatMapFirst(transform: suspend (value: T) -> Flow<R>): Flow<R> =
map(transform).flattenFirst()
map(transform).flattenFirst()

@ExperimentalCoroutinesApi
fun <T> Flow<Flow<T>>.flattenFirst(): Flow<T> = channelFlow {
Expand Down Expand Up @@ -105,47 +106,48 @@ fun <A, B, R> Flow<A>.withLatestFrom(other: Flow<B>, transform: suspend (A, B) -

fun Context.toast(text: CharSequence) = Toast.makeText(this, text, Toast.LENGTH_SHORT).show()

@ExperimentalCoroutinesApi
suspend fun main() {
(1..2000).asFlow()
.onEach { delay(50) }
.flatMapFirst { v ->
flow {
delay(500)
emit(v)
.onEach { delay(50) }
.flatMapFirst { v ->
flow {
delay(500)
emit(v)
}
}
}
.onEach { println("[*] $it") }
.catch { println("Error $it") }
.collect()
.onEach { println("[*] $it") }
.catch { println("Error $it") }
.collect()
}

class SwipeLeftToDeleteCallback(context: Context, private val onSwipedCallback: (Int) -> Unit) :
ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
private val background: ColorDrawable = ColorDrawable(Color.parseColor("#f44336"))
private val iconDelete =
ContextCompat.getDrawable(context, R.drawable.ic_baseline_delete_white_24)!!
ContextCompat.getDrawable(context, R.drawable.ic_baseline_delete_white_24)!!

override fun onMove(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
target: RecyclerView.ViewHolder
) = false

override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
val position = viewHolder.adapterPosition
val position = viewHolder.bindingAdapterPosition
if (position != RecyclerView.NO_POSITION) {
onSwipedCallback(position)
}
}

override fun onChildDraw(
c: Canvas,
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
dX: Float,
dY: Float,
actionState: Int,
isCurrentlyActive: Boolean
c: Canvas,
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
dX: Float,
dY: Float,
actionState: Int,
isCurrentlyActive: Boolean
) {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
val itemView = viewHolder.itemView
Expand All @@ -161,10 +163,10 @@ class SwipeLeftToDeleteCallback(context: Context, private val onSwipedCallback:

iconDelete.setBounds(iconLeft, iconTop, iconRight, iconBottom)
background.setBounds(
itemView.right + dX.toInt() - 8,
itemView.top,
itemView.right,
itemView.bottom
itemView.right + dX.toInt() - 8,
itemView.top,
itemView.right,
itemView.bottom
)
}
else -> background.setBounds(0, 0, 0, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.withContext

@FlowPreview
@ExperimentalCoroutinesApi
class UserRepositoryImpl(
private val userApiService: UserApiService,
Expand All @@ -39,6 +38,7 @@ class UserRepositoryImpl(
}
}

@FlowPreview
override fun getUsers(): Flow<List<User>> {
return flow {
val initial = getUsersFromRemote()
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/com/hoc/flowmvi/koin/DomainModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ import org.koin.dsl.module
@ExperimentalCoroutinesApi
@FlowPreview
val domainModule = module {
single { CoroutineDispatchersImpl() as CoroutineDispatchers }
single<CoroutineDispatchers> { CoroutineDispatchersImpl() }

single {
single<UserRepository> {
UserRepositoryImpl(
get(),
get(),
responseToDomain = get<UserResponseToUserDomainMapper>(),
domainToResponse = get<UserDomainToUserResponseMapper>(),
domainToBody = get<UserDomainToUserBodyMapper>()
) as UserRepository
)
}

single { GetUsersUseCase(get()) }
factory { GetUsersUseCase(get()) }

single { RefreshGetUsersUseCase(get()) }
factory { RefreshGetUsersUseCase(get()) }

single { RemoveUserUseCase(get()) }
factory { RemoveUserUseCase(get()) }

single { AddUserUseCase(get()) }
factory { AddUserUseCase(get()) }
}
46 changes: 23 additions & 23 deletions app/src/main/java/com/hoc/flowmvi/ui/add/AddActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class AddActivity : AppCompatActivity(), View {
// observe view model
addVM.viewState.observe(this, Observer { render(it ?: return@Observer) })
addVM.singleEvent.observe(
this,
Observer { handleSingleEvent(it?.getContentIfNotHandled() ?: return@Observer) }
this,
Observer { handleSingleEvent(it?.getContentIfNotHandled() ?: return@Observer) }
)

// pass view intent to view model
intents()
.onEach { addVM.processIntent(it) }
.launchIn(lifecycleScope)
.onEach { addVM.processIntent(it) }
.launchIn(lifecycleScope)
}

private fun handleSingleEvent(event: SingleEvent) {
Expand Down Expand Up @@ -102,25 +102,25 @@ class AddActivity : AppCompatActivity(), View {

override fun intents(): Flow<ViewIntent> {
return merge(
addBinding
.emailEditText
.editText!!
.textChanges()
.map { ViewIntent.EmailChanged(it?.toString()) },
addBinding
.firstNameEditText
.editText!!
.textChanges()
.map { ViewIntent.FirstNameChanged(it?.toString()) },
addBinding
.lastNameEditText
.editText!!
.textChanges()
.map { ViewIntent.LastNameChanged(it?.toString()) },
addBinding
.addButton
.clicks()
.map { ViewIntent.Submit }
addBinding
.emailEditText
.editText!!
.textChanges()
.map { ViewIntent.EmailChanged(it?.toString()) },
addBinding
.firstNameEditText
.editText!!
.textChanges()
.map { ViewIntent.FirstNameChanged(it?.toString()) },
addBinding
.lastNameEditText
.editText!!
.textChanges()
.map { ViewIntent.LastNameChanged(it?.toString()) },
addBinding
.addButton
.clicks()
.map { ViewIntent.Submit }
)
}
}
8 changes: 4 additions & 4 deletions app/src/main/java/com/hoc/flowmvi/ui/add/AddContract.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ interface AddContract {
}

data class ViewState(
val errors: Set<ValidationError>,
val isLoading: Boolean
val errors: Set<ValidationError>,
val isLoading: Boolean
) {
companion object {
fun initial() = ViewState(
errors = emptySet(),
isLoading = false
errors = emptySet(),
isLoading = false
)
}
}
Expand Down
Loading