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
/* | |
* Created by Attila Kruchió on 2023. 09. 13. 22:24 | |
* attila.kruchio.dev@gmail.com | |
* | |
* Copyright (c) 2023. | |
* All rights reserved. | |
*/ | |
package com.attila.kruchio.android.flow |
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
package com.attila.kruchio.test | |
import android.os.Bundle | |
import android.util.Log | |
import androidx.appcompat.app.AppCompatActivity | |
import kotlin.coroutines.CoroutineContext | |
import kotlin.random.Random | |
import kotlinx.coroutines.CoroutineScope | |
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.SupervisorJob |
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
/* | |
* Created by Attila Kruchió on 2022. 01. 09. 18:24 | |
* attila.kruchio.dev@gmail.com | |
* | |
* Copyright (c) 2022. | |
* All rights reserved. | |
*/ | |
package com.attila.kruchio.android.core.ext |
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
@HiltViewModel | |
class EventViewModel @Inject constructor( | |
private val savedStateHandle: SavedStateHandle, | |
// ... | |
) : ViewModel() { | |
private val _selectedEventId = savedStateHandle.getStateFlow<Int?>( | |
KEY_SELECTED_EVENT_ID, null | |
) | |
private val _eventFilter = savedStateHandle.getStateFlow<EventFilter>( |
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
@HiltViewModel | |
class MainViewModel @Inject constructor( | |
private val hotelRepository: HotelRepository | |
) : ViewModel() { | |
private val _filterBySustainability = MutableStateFlow(false) | |
private val _hotels = MutableStateFlow<List<Hotel>>(emptyList()) | |
val state = combine( |
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 HomeViewModel : ViewModel() { | |
private val _contacts = MutableStateFlow<List<String>>(emptyList()) | |
private val _deliveryList = MutableStateFlow<List<String>>(emptyList()) | |
val state = combine(_contacts, _deliveryList) { contacts, deliveryList -> | |
State( | |
contactList = contacts, | |
deliveryList = deliveryList, | |
) |
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 HomeViewModel : ViewModel() { | |
private val _state = MutableStateFlow(State()) | |
val state = _state.asStateFlow() | |
init { | |
loadContacts() | |
loadDeliveryList() | |
} |
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 HomeViewModel : ViewModel() { | |
private val _state = MutableStateFlow(State()) | |
val state = _state.asStateFlow() | |
init { | |
loadContacts() | |
loadDeliveryList() | |
} |
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
@HiltViewModel | |
class HomeViewModel @Inject constructor( | |
private val navigator: Navigator | |
) : ViewModel() { | |
fun navigateToSettings() { | |
navigator.navigateTo( | |
HomeFragmentDirections.showSettings() | |
) | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:id="@+id/container" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<androidx.fragment.app.FragmentContainerView | |
android:id="@+id/nav_host_fragment" | |
android:name="androidx.navigation.fragment.NavHostFragment" |
NewerOlder