Skip to content

Commit baae48f

Browse files
author
Alex
committed
update api
1 parent c34c832 commit baae48f

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

reactiveviewmodel/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-parcelize'
34
apply plugin: 'maven-publish'
45

56
android {
@@ -44,7 +45,7 @@ afterEvaluate {
4445
release(MavenPublication) {
4546
from components.release
4647
groupId = 'com.alexdeww.reactiveviewmodel'
47-
version = '2.4.7'
48+
version = '2.4.8'
4849
}
4950
}
5051
}

reactiveviewmodel/src/main/java/com/alexdeww/reactiveviewmodel/core/RvmSavedStateDelegates.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ package com.alexdeww.reactiveviewmodel.core
22

33
import androidx.lifecycle.SavedStateHandle
44
import com.alexdeww.reactiveviewmodel.core.property.State
5-
import com.alexdeww.reactiveviewmodel.widget.BaseVisualControl
6-
import com.alexdeww.reactiveviewmodel.widget.FormatterAction
7-
import com.alexdeww.reactiveviewmodel.widget.InputControl
8-
import com.alexdeww.reactiveviewmodel.widget.RatingControl
5+
import com.alexdeww.reactiveviewmodel.widget.*
96
import kotlin.properties.ReadOnlyProperty
107
import kotlin.properties.ReadWriteProperty
118
import kotlin.reflect.KProperty
@@ -98,6 +95,21 @@ fun SavedStateHandle.ratingControl(
9895
control
9996
}
10097

98+
fun <T : Any> SavedStateHandle.displayableControl(
99+
debounceInterval: Long? = null
100+
): ReadOnlyProperty<ReactiveViewModel, DisplayableControl<T>> =
101+
delegate { thisRef, stateHandle, key ->
102+
val actionKey = "$key.action"
103+
val control = DisplayableControl<T>(debounceInterval)
104+
thisRef.run {
105+
control.action.setValue(stateHandle[actionKey] ?: DisplayableControl.Action.Hide)
106+
control.action.viewFlowable
107+
.subscribe { stateHandle[actionKey] = it }
108+
.disposeOnCleared()
109+
}
110+
control
111+
}
112+
101113
@PublishedApi
102114
internal class SavedStateProperty<T>(
103115
private val savedStateHandle: SavedStateHandle,

reactiveviewmodel/src/main/java/com/alexdeww/reactiveviewmodel/widget/DisplayableControl.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package com.alexdeww.reactiveviewmodel.widget
22

3+
import android.os.Parcelable
34
import androidx.lifecycle.Observer
45
import com.alexdeww.reactiveviewmodel.core.RvmViewComponent
6+
import kotlinx.parcelize.Parcelize
7+
import kotlinx.parcelize.RawValue
58

69
class DisplayableControl<T : Any> internal constructor(
710
debounceInterval: Long? = null
811
) : BaseControl() {
912

10-
sealed class Action<out T : Any> {
13+
sealed class Action<out T : Any> : Parcelable {
14+
15+
@Parcelize
1116
object Hide : Action<Nothing>()
12-
data class Show<T : Any>(val data: T) : Action<T>()
17+
18+
@Parcelize
19+
data class Show<T : Any>(val data: @RawValue T) : Action<T>()
1320

1421
val isShowing: Boolean get() = this is Show
1522
fun getShowingValue(): T? = (this as? Show<T>)?.data

0 commit comments

Comments
 (0)