Skip to content

Commit

Permalink
fix dialog control
Browse files Browse the repository at this point in the history
close dialog when lifecycle state is DESTROYED
  • Loading branch information
Alex committed Nov 2, 2020
1 parent 9c55d45 commit eae1a38
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ buildscript {
min_sdk_version = 17
sdk_version = 29

kotlin_version = '1.4.0'
rxjava_version = '3.0.5'
kotlin_version = '1.4.10'
rxjava_version = '3.0.6'
rxandroid_version = '3.0.0'
archx_version = '2.2.0'
appcompatx_version = '1.2.0'
material_version = '1.2.0'
material_version = '1.2.1'
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Aug 01 23:44:32 GMT+07:00 2020
#Mon Nov 02 10:30:32 GMT+07:00 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.alexdeww.reactiveviewmodel.widget

import android.app.Dialog
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.Observer
import com.alexdeww.reactiveviewmodel.core.RvmViewComponent
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.BackpressureStrategy
import io.reactivex.rxjava3.core.Maybe
import io.reactivex.rxjava3.disposables.Disposable

sealed class DialogResult {
object Accept : DialogResult()
Expand Down Expand Up @@ -50,8 +47,8 @@ class DialogControl<T, R> internal constructor() : BaseControl() {

}

class DialogControlResult<T, R> internal constructor(
private val dialogControl: DialogControl<T, R>
class DialogControlResult<R> internal constructor(
private val dialogControl: DialogControl<*, R>
) {

fun sendResult(result: R) {
Expand All @@ -71,7 +68,7 @@ class DialogControlResult<T, R> internal constructor(

fun <T, R> dialogControl(): DialogControl<T, R> = DialogControl()

typealias ActionCreateDialog<T, R> = (data: T, dc: DialogControlResult<T, R>) -> Dialog
typealias ActionCreateDialog<T, R> = (data: T, dc: DialogControlResult<R>) -> Dialog

fun <T, R> DialogControl<T, R>.bindTo(
rvmViewComponent: RvmViewComponent,
Expand All @@ -96,7 +93,9 @@ fun <T, R> DialogControl<T, R>.bindTo(
}

override fun onInactive() {
closeDialog()
if (rvmViewComponent.componentLifecycleOwner.lifecycle.currentState == Lifecycle.State.DESTROYED) {
closeDialog()
}
super.onInactive()
}

Expand Down

0 comments on commit eae1a38

Please sign in to comment.