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
/** | |
* Calculates the Y pixel coordinate for a given transaction rate. | |
* | |
* @param higherTransactionRateValue the highest rate value in the whole list of transactions. | |
* @param currentTransactionRate the current transaction RATE while iterating the list of transactions. | |
* @param canvasHeight the canvas HEIGHT for draw the linear chart. | |
* | |
* @return [Float] Y coordinate for a transaction rate. | |
*/ |
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
@Composable | |
fun LinearTransactionsChart( | |
modifier: Modifier = Modifier, | |
transactionsPerSecond: TransactionsPerSecond | |
) { | |
if (transactionsPerSecond.transactions.isEmpty()) return | |
Canvas(modifier = modifier) { | |
// Total number of transactions. | |
val totalRecords = transactionsPerSecond.transactions.size |
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 ProductDetailViewModel @Inject constructor( | |
private val savedStateHandle: SavedStateHandle, | |
... | |
) : ViewModel() { | |
... | |
private fun getProductFromArgs(): ProductDetailArgs { |
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 { |
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
/** | |
* 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
/** | |
* 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
/** | |
* 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
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
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 | |
NewerOlder