Skip to content

Instantly share code, notes, and snippets.

@thegarlynch
thegarlynch / Cart.kt
Last active June 23, 2020 20:16
Implementation of cart
import com.myapplication.domain.model.checkout.CartItem
import com.myapplication.helper.rx.ThreadConfinedBehaviorSubject
import io.reactivex.Scheduler
import java.math.BigInteger
import javax.annotation.concurrent.ThreadSafe
import javax.inject.Inject
import javax.inject.Singleton
/**
* Beware!!
@thegarlynch
thegarlynch / NavigationGateway.kt
Last active June 22, 2020 15:56
Navigation Gateway in navigation component
import android.os.Bundle
import androidx.annotation.IdRes
import androidx.navigation.*
/**
*
* Act as gateway between current fragment to it's destination
*
* Each [NavigationGateway] may have only one gatewayId (either a NavGraph or Destination)
*
@thegarlynch
thegarlynch / extention.kt
Last active June 11, 2020 11:38
ViewModel Helper Untuk Android
import androidx.annotation.IdRes
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
/**
* This extension is best used when using
package com.thegar.helper
import android.annotation.SuppressLint
import android.graphics.PixelFormat
import android.os.Build
import android.os.Bundle
import android.view.*
import android.widget.FrameLayout
import android.widget.ScrollView
import androidx.annotation.CallSuper
@thegarlynch
thegarlynch / SavedStateHandleHelper.kt
Created March 19, 2020 13:19
configurasi-viewmodel-savedstatehandle
@file:Suppress("UNCHECKED_CAST")
package com.thegar.example.helper.viewmodel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.SavedStateHandle
import kotlin.properties.ReadOnlyProperty
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
@thegarlynch
thegarlynch / ViewModelHelper.kt
Created March 19, 2020 13:17
configurasi_viewmodel
@file:Suppress("UNCHECKED_CAST")
package com.thegar.helper
import android.os.Bundle
import androidx.activity.viewModels
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.AbstractSavedStateViewModelFactory
@thegarlynch
thegarlynch / TutorialComponent.kt
Created March 12, 2020 16:46
tutorial-dagger-snippet-change-scope
import dagger.Component
import javax.inject.Inject
import javax.inject.Scope
@Scope
@Retention(AnnotationRetention.RUNTIME)
annotation class TutorialScope
@Component
@TutorialScope
@thegarlynch
thegarlynch / TutorialComponent.kt
Last active March 12, 2020 16:42
tutorial-dagger-snippet-addsingleton
@Singleton
class Contoh @Inject constructor(private val anakContoh: AnakContoh){
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import javax.inject.Inject
class MainActivity : AppCompatActivity() {
@Inject lateinit var contoh: Contoh
override fun onCreate(savedInstanceState: Bundle?) {
@thegarlynch
thegarlynch / TutorialComponent.kt
Last active March 12, 2020 16:25
tutorial-dagger-snippet-add-component
import dagger.Component
import javax.inject.Inject
import javax.inject.Singleton
@Component
@Singleton
interface TutorialComponent {
val contohMelaluiComponent : Contoh