Skip to content

Commit

Permalink
update api
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed May 16, 2022
1 parent c34c832 commit baae48f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion reactiveviewmodel/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'maven-publish'

android {
Expand Down Expand Up @@ -44,7 +45,7 @@ afterEvaluate {
release(MavenPublication) {
from components.release
groupId = 'com.alexdeww.reactiveviewmodel'
version = '2.4.7'
version = '2.4.8'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package com.alexdeww.reactiveviewmodel.core

import androidx.lifecycle.SavedStateHandle
import com.alexdeww.reactiveviewmodel.core.property.State
import com.alexdeww.reactiveviewmodel.widget.BaseVisualControl
import com.alexdeww.reactiveviewmodel.widget.FormatterAction
import com.alexdeww.reactiveviewmodel.widget.InputControl
import com.alexdeww.reactiveviewmodel.widget.RatingControl
import com.alexdeww.reactiveviewmodel.widget.*
import kotlin.properties.ReadOnlyProperty
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
Expand Down Expand Up @@ -98,6 +95,21 @@ fun SavedStateHandle.ratingControl(
control
}

fun <T : Any> SavedStateHandle.displayableControl(
debounceInterval: Long? = null
): ReadOnlyProperty<ReactiveViewModel, DisplayableControl<T>> =
delegate { thisRef, stateHandle, key ->
val actionKey = "$key.action"
val control = DisplayableControl<T>(debounceInterval)
thisRef.run {
control.action.setValue(stateHandle[actionKey] ?: DisplayableControl.Action.Hide)
control.action.viewFlowable
.subscribe { stateHandle[actionKey] = it }
.disposeOnCleared()
}
control
}

@PublishedApi
internal class SavedStateProperty<T>(
private val savedStateHandle: SavedStateHandle,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.alexdeww.reactiveviewmodel.widget

import android.os.Parcelable
import androidx.lifecycle.Observer
import com.alexdeww.reactiveviewmodel.core.RvmViewComponent
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.RawValue

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

sealed class Action<out T : Any> {
sealed class Action<out T : Any> : Parcelable {

@Parcelize
object Hide : Action<Nothing>()
data class Show<T : Any>(val data: T) : Action<T>()

@Parcelize
data class Show<T : Any>(val data: @RawValue T) : Action<T>()

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

0 comments on commit baae48f

Please sign in to comment.