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
adb shell monkey -p packagename -c android.intent.category.LEANBACK_LAUNCHER 1 |
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
// In a Fragment | |
class UserFragment : Fragment() { | |
private val userViewModel: UserViewModel by viewModels() | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
val userId = "12345" // Get this from arguments or somewhere else | |
userViewModel.fetchUserData(userId) // Called from Fragment | |
} | |
} |
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 SearchViewModel @Inject constructor(private val searchRepo: SearchRepository): ViewModel() { | |
private val _searchQuery = MutableStateFlow("") | |
val searchResults: StateFlow<List<SearchResult>> = _searchQuery | |
.debounce(300) // Add a debounce to limit requests | |
.filter(String::isNotEmpty) // Ignore empty queries | |
.flatMapLatest(searchRepository::search) | |
.stateIn(viewModelScope, SharingStarted.Lazily, emptyList()) |
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 SearchViewModel @Inject constructor(private val searchRepo: SearchRepository) : ViewModel() { | |
val searchResults: StateFlow<List<SearchResult>> | |
field = MutableStateFlow<List<SearchResult>>() | |
fun search(query: String) { | |
viewModelScope.launch { | |
val results = searchRepository.search(query) | |
searchResults.update { results } | |
} |
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 RatesViewModel constructor( | |
private val ratesRepository: RatesRepository, | |
) : ViewModel() { | |
val state = MutableStateFlow(RatesUiState(isLoading = true)) | |
} |
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 RatesViewModel constructor( | |
private val ratesRepository: RatesRepository, | |
) : ViewModel() { | |
private val _state = MutableStateFlow(RatesUiState(isLoading = true)) | |
val state: StateFlow<RatesUiState> | |
get() = _state.asStateFlow() | |
} |
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 SearchViewModel @Inject constructor( | |
private val searchUseCase: dagger.Lazy<SearchUseCase>, | |
) : ViewModel() { | |
private val searchQuery = MutableStateFlow("") | |
val uiState: LiveData<SearchUiState> = searchQuery | |
.debounce(DEBOUNCE_TIME_IN_MILLIS) | |
.asLiveData() | |
.switchMap(::createUiState) |
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 SearchViewModel @Inject constructor( | |
private val searchUseCase: SearchUseCase, | |
@IoDispatcher val ioDispatcher: CoroutineDispatcher | |
) : ViewModel() { | |
private val searchQuery = MutableStateFlow("") | |
private val _uiState = MutableLiveData<SearchUiState>() | |
val uiState = _uiState |
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 SearchViewModel @Inject constructor( | |
private val searchUseCase: dagger.Lazy<SearchUseCase>, | |
private val wordsUseCase: GetWordsUseCase, | |
) : ViewModel() { | |
data class UiState( | |
val isLoading: Boolean = true, | |
val words: List<String> = emptyList() | |
) |
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 SearchViewModel @Inject constructor( | |
private val searchUseCase: dagger.Lazy<SearchUseCase>, | |
private val wordsUseCase: GetWordsUseCase, | |
) : ViewModel() { | |
data class UiState( | |
val isLoading: Boolean, | |
val words: List<String> = emptyList() | |
) | |
NewerOlder