This file contains hidden or 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
#!/bin/bash | |
adb() { | |
if [[ $@ == "ip" ]]; then | |
command adb shell netcfg | grep wlan0 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | |
else | |
command adb "$@" | |
fi | |
} |
This file contains hidden or 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
@Test | |
fun `60 seconds clock`() = coroutineRule.testDispatcher.runBlockingTest { | |
whenever(observeState.invoke()).thenReturn(flowOf(State.Pomodoro(60))) | |
viewModel = ClockViewModel( | |
observeState = observeState, | |
nextState = nextState, | |
errorChannel = errorChannel, | |
defaultDispatcher = coroutineRule.testDispatcher | |
) |
This file contains hidden or 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 ClockViewModel @Inject constructor( | |
observeState: ObserveState, | |
private val nextState: NextState, | |
private val errorChannel: BroadcastChannel<Throwable>, | |
private val defaultDispatcher: CoroutineDispatcher | |
) : ViewModel() { | |
val viewState: LiveData<ClockViewState> = observeState() | |
.map { it.toViewState() } | |
.flowOn(defaultDispatcher) |
This file contains hidden or 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
@Test | |
fun `Turn on DND when Pomodoro starts`() = runBlockingTest { | |
zenModeApi.mode = ZenMode.Off | |
whenever(transitionApi.observeTransitionLog()).thenReturn( | |
flowOf( | |
Transition(State.IDLE, 0), | |
Transition(State.POMODORO, 0), | |
Transition(State.DONE, 0) | |
) | |
) |
This file contains hidden or 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
@Test | |
fun `Idle State`() = runBlockingTest { | |
whenever(transitionApi.observeTransitionLog()).thenReturn(flowOf(Transition(State.IDLE, 0))) | |
val observeStateFlow = observeState() | |
observeStateFlow.test { | |
assertThat(expectItem()).isEqualTo(ObserveState.State.Idle) | |
expectComplete() | |
} |
This file contains hidden or 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
val errors = errorChannel.asFlow().handleErrors() | |
private fun Flow<Throwable>.handleErrors(): Flow<Throwable> = flow { | |
distinctUntilChanged().collect { | |
if (it is ZenModeApi.AccessDeniedException) { | |
navigationChannel.send(ClockNavDirection.AskDndPermission) | |
} else { | |
emit(it) | |
} | |
} |
This file contains hidden or 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
suspend operator fun invoke(action: Action): State { | |
val currentState = transitionApi | |
.getLastTransition() | |
?.state | |
?: throw IllegalNullStateException | |
val nextState = when { | |
currentState == State.IDLE && action == Action.START -> State.POMODORO | |
currentState == State.POMODORO && action == Action.STOP -> State.IDLE | |
currentState == State.POMODORO && action == Action.COMPLETE -> State.DONE |
This file contains hidden or 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
suspend operator fun invoke(): State? = when { | |
transitionApi.getLastTransition() == null -> State.IDLE.also { | |
transitionApi.newTransition(timeApi.now(), it) | |
} | |
else -> null | |
} |
This file contains hidden or 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
val viewState: LiveData<ClockViewState> = observeState() | |
.map { it.toViewState() } | |
.flowOn(defaultDispatcher) | |
.catch { errorChannel.send(it) } | |
.asLiveData(viewModelScope.coroutineContext) |
This file contains hidden or 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
override fun observeTransitionLog(): Flow<Transition> = stateLogDao | |
.observeLast() | |
.map { it?.toTransition() } | |
.filterNotNull() |