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
val listState = rememberLazyListState() | |
// Horizontal List | |
LazyRow(state = listState) { ... } | |
// Vertical List | |
LazyColumn(state = listState) { ... } |
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
// Adapter and data set | |
class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> { | |
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { ... } | |
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder { ... } | |
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) { ... } | |
override fun getItemCount() = dataSet.size | |
} | |
val rooms: List<Room> = rooms | |
val recyclerViewAdapter = CustomAdapter(rooms) |
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
val backdropState = rememberBackdropScaffoldState(BackdropValue.Concealed) | |
val offset by backdropState.offset | |
val halfHeightDp = LocalConfiguration.current.screenHeightDp / 2 | |
val halfHeightPx = with(LocalDensity.current) { halfHeightDp.dp.toPx() } | |
//... | |
// Current alpha for vertical list | |
val verticalListAlpha = ((halfHeightPx - offset) / halfHeightPx).coerceIn(0f..1f) |
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
// BackdropScaffoldState to be observed by Compose Runtime | |
val backdropState = rememberBackdropScaffoldState(BackdropValue.Concealed) | |
//Launch coroutine to animate revealling backdrop | |
LaunchedEffect(backdropState) { | |
backdropState.reveal() | |
} |
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 CrashlyticsReportTree : Timber.Tree() { | |
override fun log(priority: Int, tag: String?, message: String, t: Throwable?) { | |
if (priority == Log.ERROR) { // only for error level | |
with(Firebase.crashlytics) { | |
// optional: setCustomKey("CUSTOME_TAG", any) | |
recordException(it) | |
} | |
} | |
} | |
} |
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 com.apollographql.apollo.api.Response | |
internal suspend inline fun <S> runApolloRequest(block: () -> Response<S>): Result<S> = try { | |
val value = handleApolloRequest{(block()} | |
Result.success(value) | |
} catch (e: Exception) { | |
if (e is CancellationException) throw e | |
Timber.e("Exception from coroutine (${coroutineContext[CoroutineName]?.name}): " + | |
"${e.stackTraceToString()}") | |
Result.failure(e) |
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
inline fun <T> Flow<T>.catchLog(default: T? = null): Flow<T> = this.catch { e -> | |
if (e is CancellationException) throw e | |
Timber.e( | |
e, | |
"Error from flow (${coroutineContext[CoroutineName]?.name}): " + | |
"${e.stackTraceToString()}" | |
) | |
default?.let { emit(it) } | |
} |
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
internal suspend inline fun <T> getResult(block: () -> T): Result<T> = try { | |
block().let { Result.success(it) } | |
} catch (e: Exception) { | |
if (e is CancellationException) throw e | |
Timber.e("Error from coroutine (${coroutineContext[CoroutineName]?.name}): " + | |
"${e.stackTraceToString()}") | |
Result.failure(e) | |
} |
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
viewModelScope.launch(CoroutineName("GetFavorites")) { | |
postsRepository.observeFavorites().collect { favorites -> | |
viewModelState.update { it.copy(favorites = favorites) } | |
} | |
} | |
// or within your custom coroutine scope | |
launch(CoroutineName("GetFavorites")) { | |
postsRepository.observeFavorites().collect { favorites -> | |
viewModelState.update { it.copy(favorites = favorites) } |