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
import android.content.ContentUris | |
import android.content.Context | |
import android.database.Cursor | |
import android.net.Uri | |
import android.os.Build | |
import android.os.Environment | |
import android.provider.DocumentsContract | |
import android.provider.MediaStore | |
import android.util.Log | |
import java.io.* |
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 SomeViewModel(private val getUserUseCase: GetUserUseCase) : ViewModel() { | |
// Only your viewmodel should update the value. | |
private val _userName: MutableLiveData<String> = MutableLiveData() | |
val userName: LiveData<String> | |
get() = _userName | |
... | |
private fun executeUseCase() { |
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 SomeViewModel(private val getUserUseCase: GetUserUseCase) : ViewModel() { | |
// Only your viewmodel should update the value. | |
private val _user: MutableLiveData<User> = MutableLiveData() | |
val userName: LiveData<String> = _user.map { | |
resultUser -> "${resultUser.name} + ${resultUser.lastName}" | |
} | |
... | |
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 SomeViewModel( | |
private val getUsersUseCase: GetUserUseCase, | |
private val mapper: PresentationMapper | |
) : ViewModel() { | |
// Only your viewmodel should update the value. | |
private val _users: MutableLiveData<List<PresentationUser>> = MutableLiveData() | |
val users: LiveData<List<PresentationUser>> | |
get() = _users | |
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 SomeViewModel( | |
private val getUsersUseCase: GetUserUseCase, | |
private val mapper: PresentationMapper | |
) : ViewModel() { | |
// Only your viewmodel should update the value. | |
private val _domainUsers: MutableLiveData<List<DomainUser>> = MutableLiveData() | |
val users: LiveData<List<PresentationUser>> = _domainUsers.switchMap { domainUsers -> | |
liveData { | |
emit(mapper.mapDomainUsersToPresentation(domainUsers)) |
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
/** | |
* Extension function for the fragment to handle the activity backPressed(). | |
* Call this inside [Fragment.onAttach] method. | |
* | |
* @param backPressed is invoked when the activity triggers onBackPressed(). | |
* @see [https://developer.android.com/reference/androidx/activity/OnBackPressedDispatcher] | |
*/ | |
inline fun Fragment.handleActivityBackPressed( | |
crossinline backPressed: () -> Unit | |
) { |
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
/** | |
* Set the adapter and call [clearReference] extension function in one call. | |
* Use this extension if the current Fragment is going to be REPLACED. (When using fragmentTransaction.add is not necessary) the back stack. | |
*/ | |
fun <VH : RecyclerView.ViewHolder> RecyclerView.setNullableAdapter( | |
adapter: RecyclerView.Adapter<VH> | |
) { | |
this.adapter = adapter | |
this.clearReference() |
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
/** | |
* Represents the state to render the UI in MovieListFragment. | |
* | |
* @param isLoading if true we have to show a progress bar, else hide the progress bar. | |
* @param movies this list will be submited into recyclerview adapter. | |
* @param error OneTimeEvent that wraps a failure object for display a Toast, Snackbar, etc only once. | |
*/ | |
data class MovieListUiState( | |
val isLoading: Boolean = false, | |
val movies: List<MovieUi> = 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 MovieListFragment : Fragment(R.layout.fragment_movie_list) { | |
... | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
initView() | |
collectUiState() | |
} |
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
/* | |
* This would be your remote data source implementation. Only the [ActorsRemoteDataSource] is injected in your repository implementation. | |
*/ | |
internal class ActorsRemoteDataSourceImpl( | |
private val middlewareProvider: MiddlewareProvider, | |
private val ioDispatcher: CoroutineDispatcher, | |
private val errorAdapter: JsonAdapter<ResponseError>, | |
private val actorsService: ActorsService | |
) : ActorsRemoteDataSource { |
OlderNewer