This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable.fromPublisher<String> { | |
it.onNext("Doing a network call!") | |
Thread.sleep(1000) // Long running process | |
it.onError(Exception()) // Some error thrown | |
}.retryWhen { errors -> | |
errors.zipWith(Observable.range(1, 3) // Zip error observable with a range one | |
.concatMap { retryCount -> | |
Observable.timer(retryCount.toLong() * 10, TimeUnit.SECONDS) | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActionStateLiveData<T>( | |
private val coroutineContext: CoroutineContext, | |
fetchData: (suspend () -> Response<T>) | |
) { | |
private val action = MutableLiveData<Action>() | |
private var data: T? = null // backing data | |
val state = action.switchMap { | |
liveData(context = coroutineContext) { | |
when (action.value) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class Action { | |
object Load : Action() | |
object SwipeRefresh : Action() | |
object Retry : Action() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class UIState<out R> { | |
object Loading : UIState<Nothing>() | |
object Retrying : UIState<Nothing>() | |
object SwipeRefreshing : UIState<Nothing>() | |
data class Success<T>(val data: T) : UIState<T>() | |
data class Failure(val exception: Exception) : UIState<Nothing>() | |
data class SwipeRefreshFailure(val exception: Exception) : UIState<Nothing>() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setContent { | |
MaterialTheme(colors = lightThemeColors) { | |
WithConstraints { constraints, _ -> | |
val boxHeight = with(DensityAmbient.current) { constraints.maxHeight.toDp() } | |
val boxWidth = with(DensityAmbient.current) { constraints.maxWidth.toDp() } | |
Content( | |
constraints = constraints, | |
boxHeight = boxHeight, | |
boxWidth = boxWidth | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Drag( | |
val position: AnimatedFloat, | |
val flingConfig: FlingConfig | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Side drag | |
val sideMin = 90.dp | |
val sideMax = boxWidth - 30.dp | |
val (sideMinPx, sideMaxPx) = with(DensityAmbient.current) { | |
sideMin.toPx().value to sideMax.toPx().value | |
} | |
val sideFlingConfig = AnchorsFlingConfig(listOf(sideMinPx, sideMaxPx)) | |
val sidePosition = animatedFloat(sideMaxPx) | |
sidePosition.setBounds(sideMinPx, sideMaxPx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable() | |
fun SideView( | |
boxHeight: Dp, | |
drag: Drag | |
) { | |
val position = drag.position | |
val flingConfig = drag.flingConfig | |
val yOffset = with(DensityAmbient.current) { position.value.toDp() } | |
val toggleAsset = state { R.drawable.ic_keyboard_arrow_left_24 } | |
Box( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Top drag | |
val topStart = -(constraints.maxHeight.value / 1.4f) | |
val topMax = 0.dp | |
val topMin = -(boxHeight / 1.4f) | |
val (topMinPx, topMaxPx) = with(DensityAmbient.current) { | |
topMin.toPx().value to topMax.toPx().value | |
} | |
val topFlingConfig = AnchorsFlingConfig(listOf(topMinPx, topMaxPx)) | |
val topPosition = animatedFloat(topStart) // for dragging state | |
topPosition.setBounds(topMinPx, topMaxPx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun TopView( | |
boxHeight: Dp, | |
drag: Drag | |
) { | |
val position = drag.position | |
val flingConfig = drag.flingConfig | |
val yOffset = with(DensityAmbient.current) { position.value.toDp() } | |
val scrollerPosition = ScrollerPosition() | |
// scroll the history list to bottom when dragging the top panel |
OlderNewer