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
private val scope = CoroutineScope(taskThreading.ui() + SupervisorJob()) | |
fun processStateCollection() { | |
stateFlow | |
.filter { | |
stateFlow -> stateFlow != null | |
}.onEach { stateFlow -> | |
tweetsListUI?.handleStates(stateFlow) | |
}.launchIn(scope) | |
} |
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
@ActivityScope | |
class StateFlowHandler @Inject constructor(taskThreading: TaskThreading) { | |
private var tweetsListUI: TweetsListUI? = null | |
private lateinit var stateFlow: StateFlow<TweetsUIState?> | |
fun init(val stateFlow: StateFlow<TweetsUIState?>, val tweetsListUI: TweetsListUI) { | |
stateFlow = stateFlow | |
tweetsListUI = tweetsListUI |
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
public class TweetsListUI extends ViewUI { | |
@Inject | |
SearchViewDelegate viewDelegate; | |
@Inject | |
StateFlowHandler stateFlowHandler; | |
public void initStateFlow(@NotNull StateFlow<? extends TweetsUIState> stateFlow) { | |
stateFlowHandler.init(stateFlow, this); | |
stateFlowHandler.processStateFlowCollection(); |
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
@ActivityScope | |
class SearchViewDelegate @Inject constructor( | |
private val presenter: SearchTweetPresenter, | |
private val taskThreading: TaskThreading | |
) { | |
private fun getStateFlow(): StateFlow<TweetsUIState> = presenter.stateFlow | |
@FlowPreview | |
@ExperimentalCoroutinesApi |
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
@ActivityScope | |
public class SearchTweetPresenter { | |
// ... | |
public void searchTweets(@NotNull final String query) { | |
// TODO Remove callback code: | |
// if (callback == null && view != null) { | |
// callback = new SearchCallbackImpl(view); | |
// } | |
tweetSearchUseCase.execute(query); |
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
@ActivityScope | |
public class SearchTweetPresenter { | |
@NotNull | |
private final SearchTweetUseCase tweetSearchUseCase; | |
@Inject | |
public SearchTweetPresenter(@NotNull SearchTweetUseCase tweetSearchUseCase) { | |
this.tweetSearchUseCase = tweetSearchUseCase; | |
} |
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
override fun execute(query: String) { | |
tweetsStateFlow.value = TweetsUIState.LoadingUIState | |
repository.searchTweet(query) | |
.onEach { tweets -> | |
val stateFlow = | |
if (tweets.isEmpty()) { | |
TweetsUIState.EmptyUIState | |
} else { | |
TweetsUIState.ListResultsUIState(tweets) |
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
override fun execute(query: String) { | |
// TODO remove this: callback?.onShowLoader() | |
// add new Loading state | |
tweetsStateFlow.value = TweetsUIState.LoadingUIState | |
// ... | |
} |
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
// Use Case contract with Callback input parameter | |
interface UseCase<T> { | |
fun execute(param: String, callbackInput: T?) | |
fun cancel() | |
} |
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
/** | |
* UI States defined for StateFlow in the workflow | |
*/ | |
sealed class TweetsUIState { | |
// List of results coming from the Data layer | |
data class ListResultsUIState(val tweets: List<Tweet>): TweetsUIState() | |
// Error state with error message | |
data class ErrorUIState(val msg: String): TweetsUIState() | |
// Empty state with "no results" String | |
object EmptyUIState: TweetsUIState() |