Skip to content

Instantly share code, notes, and snippets.

View raulh82vlc's full-sized avatar

Raul Hernandez raulh82vlc

View GitHub Profile
@raulh82vlc
raulh82vlc / SearchStateHandler.kt
Created March 1, 2021 11:21
SearchStateHandler collects state and passes it directly to the SearchComposablesUI
@ActivityScope
class SearchStateHandler @Inject constructor(@Named("CoroutineUIScope") private val scope: CoroutineScope) {
private var searchComposablesUI: SearchComposablesUI? = null
private lateinit var stateFlow: StateFlow<TweetsUIState>
fun initStateFlowAndViews(
val stateFlow: StateFlow<TweetsUIState>,
val searchComposablesUI: SearchComposablesUI
) {
@raulh82vlc
raulh82vlc / TweetsListUIFragment.java
Created March 1, 2021 11:15
TweetsListUIFragment initialises searchComposablesUI and friends
public class TweetsListUIFragment extends BaseUI {
// ...
@Inject SearchComposablesUI searchComposablesUI;
@Inject SearchViewDelegate viewDelegate;
@Inject SearchStateHandler stateHandler;
public void initStateFlowAndViews() {
stateHandler.initStateFlowAndViews(viewDelegate.getStateFlow(), searchComposablesUI);
@raulh82vlc
raulh82vlc / TweetsListUIFragment.java
Created March 1, 2021 11:10
TweetsListUIFragment initialising the ComposeView
public class TweetsListUIFragment extends BaseUI {
@Inject SearchComposablesUI searchComposablesUI;
@Inject SearchViewDelegate viewDelegate;
@Inject SearchStateHandler stateHandler;
@Override public View onCreateView(@NotNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_search, container, false);
@raulh82vlc
raulh82vlc / fragment_search_view.xml
Last active March 1, 2021 11:10
fragment_search_view with a ComposeView element in it
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- ... -->
<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_view"
android:layout_marginTop="?attr/actionBarSize"
@raulh82vlc
raulh82vlc / UIExtensionFunctions.kt
Created February 28, 2021 14:09
UIExtensionFunctions for Imperative UI
fun TweetsListFragmentUI.showResults(tweets: List<Tweet>) {
hideLoader()
hideError()
showList()
updateList(tweets)
}
@raulh82vlc
raulh82vlc / UIExtensionFunctions.kt
Created February 28, 2021 13:33
UIExtensionFunctions for the View
fun TweetsListFragmentUI.handleStates(uiState: TweetsUIState) {
when (uiState) {
is TweetsUIState.ListResultsUIState -> showResults(uiState.tweets)
// ...
}
}
@raulh82vlc
raulh82vlc / SearchStateHandler.kt
Created February 28, 2021 13:25
SearchStateHandler StateFlow collection
@ActivityScope
class SearchStateHandler @Inject constructor(
@Named("CoroutineUIScope") private val scope: CoroutineScope
) {
private lateinit var stateFlow: StateFlow<TweetsUIState>
fun processStateCollection() {
stateFlow.onEach { uiState ->
tweetsListUI?.handleStates(uiState)
@raulh82vlc
raulh82vlc / SearchStateHandler.kt
Created February 28, 2021 13:17
SearchStateHandler connections
@ActivityScope
class SearchStateHandler @Inject constructor(
@Named("CoroutineUIScope") private val scope: CoroutineScope
) {
private var tweetsListUI: TweetsListUIFragment? = null
private lateinit var stateFlow: StateFlow<TweetsUIState>
fun initStateFlowAndViews(val stateFlow: StateFlow<TweetsUIState>, val tweetsListUI: TweetsListUIFragment) {
this.stateFlow = stateFlow
this.tweetsListUI = tweetsListUI
@raulh82vlc
raulh82vlc / TweetsListUIFragment.java
Last active February 28, 2021 13:26
TweetsListUI has a ViewDelegate and a StateHandler
public class TweetsListUIFragment extends BaseUI {
// ...
@Inject SearchViewDelegate viewDelegate;
@Inject SearchStateHandler stateHandler;
public void initStateFlowAndViews() {
stateHandler.initStateFlowAndViews(viewDelegate.getStateFlow(), this);
stateHandler.processStateFlowCollection();
@raulh82vlc
raulh82vlc / SearchViewDelegate.kt
Last active March 1, 2021 10:28
SearchViewDelegate connection with the View
@ActivityScope
class SearchViewDelegate @Inject constructor(
private val presenter: SearchTweetPresenter,
@Named("CoroutineUIScope") private val scope: CoroutineScope
) {
fun initialiseProcessingQuery(tweetsListUI: TweetsListUIFragment?) {
tweetsListUI?.apply {
initStateFlowAndViews()
}