Skip to content

Instantly share code, notes, and snippets.

View bagus2x's full-sized avatar
🎯
Focusing

tubagus saifulloh bagus2x

🎯
Focusing
View GitHub Profile
package com.bagus2x.mymovies.ui.detail.movie
import androidx.lifecycle.*
import com.bagus2x.mymovies.data.Movie
import com.bagus2x.mymovies.data.Result
import com.bagus2x.mymovies.data.source.MovieRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.launch
import javax.inject.Inject
@bagus2x
bagus2x / Stack.kt
Created February 5, 2022 11:05
exploring jetpack compose custom Layout
sealed class StackOrientation {
object Horizontal : StackOrientation()
object Vertical : StackOrientation()
}
@Composable
fun Stack(
modifier: Modifier = Modifier,
orientation: StackOrientation = StackOrientation.Vertical,
gap: Dp = 0.dp,
@bagus2x
bagus2x / Indicator.kt
Created March 25, 2022 01:14
Simple custom view for viewpager indicator
package com.bagus2x.indicator
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
class Indicator : View {
@bagus2x
bagus2x / ANDROID_RESOURCE.md
Last active May 11, 2022 00:08
list of common android dependencies

ANDROID DEPENDENCIES

C

dependencies {
  implementation("io.coil-kt:coil-compose:2.0.0")
}
This file has been truncated, but you can view the full file.
[
"{\"structValue\":{\"fields\":{\"raw_detection_scores\":{\"listValue\":{\"values\":[{\"listValue\":{\"values\":[{\"numberValue\":0.000935435295,\"kind\":\"numberValue\"},{\"numberValue\":0.00124356151,\"kind\":\"numberValue\"},{\"numberValue\":0.00174513459,\"kind\":\"numberValue\"},{\"numberValue\":0.00128659606,\"kind\":\"numberValue\"},{\"numberValue\":0.000911355,\"kind\":\"numberValue\"},{\"numberValue\":0.00494873524,\"kind\":\"numberValue\"},{\"numberValue\":0.000826954842,\"kind\":\"numberValue\"},{\"numberValue\":0.00328528881,\"kind\":\"numberValue\"},{\"numberValue\":0.0019146204,\"kind\":\"numberValue\"}]},\"kind\":\"listValue\"},{\"listValue\":{\"values\":[{\"numberValue\":0.00135439634,\"kind\":\"numberValue\"},{\"numberValue\":0.000440776348,\"kind\":\"numberValue\"},{\"numberValue\":0.000671267509,\"kind\":\"numberValue\"},{\"numberValue\":0.000405371189,\"kind\":\"numberValue\"},{\"numberValue\":0.000530421734,\"kind\":\"numberValue\"},{\"numberValue\":0.00103834271,\"kind\":\"numberVal
@bagus2x
bagus2x / Calendar.kt
Last active April 4, 2023 17:19
custom calendar with jetpack compose & java.time
private val DaysInMonthCell = GridCells.Fixed(count = 7)
@Composable
fun Calendar(
modifier: Modifier = Modifier,
localDateTime: LocalDateTime
) {
val firstDate = remember(localDateTime) {
with(localDateTime) {
val firstOfMonth = withDayOfMonth(1)
@bagus2x
bagus2x / RatingBar.kt
Created October 11, 2022 03:46
Rating Bar Jetpack Compose with onClick Handler
@Composable
fun RatingBar(
rating: Float,
onChange: (Int, Float) -> Unit,
max: Int
) {
Row {
val value = rating * max
val fullStar = value.toInt()
var fractionStar = value - fullStar
@bagus2x
bagus2x / materialized_path_generator.sql
Created January 25, 2023 20:57
a postgres function to generate materialized path (ltree)
create or replace function create_path(parent_id_param bigint) returns ltree
language plpgsql
as
$$
declare parent_path ltree;
declare current_id BIGINT;
BEGIN
SELECT currval('"comment_id_seq"') into current_id;
IF parent_id_param is NOT NULL THEN
@bagus2x
bagus2x / CommentListScreen.kt
Created February 25, 2023 01:10
Display nested comment system with LazyColumn Jetpack Compose
fun CommentListScreen() {
val comments by produceDummyComments(10000)
Box {
LazyColumn(
modifier = Modifier
.systemBarsPadding()
.fillMaxSize(),
) {
commentList(comments)
}
@bagus2x
bagus2x / GradientMessageInstagram.kt
Last active April 2, 2023 13:14
Gradient background in LazyColumn items. Instagram message style in jetpack compose
@Composable
fun NotificationScreen(
navController: NavController,
viewModel: NotificationViewModel = hiltViewModel()
) {
val videos by viewModel.videos.collectAsStateWithLifecycle()
val listState = rememberLazyListState()
BoxWithConstraints {
val density = LocalDensity.current