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
enum class ABTestVariation(val navGraphRes: Int) { | |
BASELINE(R.navigation.baseline_navigation), | |
VARIATION1(R.navigation.variant1_navigation), | |
VARIATION2(R.navigation.variant2_navigation), | |
} | |
private val abTestVariation: ABTestVariation by lazy { | |
intent?.getSerializableExtra(KEY) as? ABTestVariation ?: ABTestVariation.BASELINE | |
} |
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 CustomCrashHandler( | |
private val defaultHandler: Thread.UncaughtExceptionHandler? = null, | |
applicationContext: Context | |
) : Thread.UncaughtExceptionHandler { | |
private val chuckerCollector: ChuckerCollector by lazy { | |
ChuckerCollector( | |
context = applicationContext, | |
// Toggles visibility of the push notification | |
showNotification = true, |
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 App: Application() { | |
override fun onCreate() { | |
super.onCreate() | |
setupChuckerErrors() | |
} | |
private fun setupChuckerErrors() { | |
if (BuildConfig.DEBUG) { | |
val systemHandler = Thread.getDefaultUncaughtExceptionHandler() | |
Thread.setDefaultUncaughtExceptionHandler(CustomCrashHandler(systemHandler, this)) |
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 DebouncingOnClickListener( | |
private val intervalMillis: Long, | |
private val doClick: ((View) -> Unit) | |
) : View.OnClickListener { | |
override fun onClick(v: View) { | |
if (enabled) { | |
enabled = false | |
v.postDelayed(ENABLE_AGAIN, intervalMillis) | |
doClick(v) |
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
fun View.setOnCLick(intervalMillis: Long = 0, doClick: (View) -> Unit) = | |
setOnClickListener(DebouncingOnClickListener(intervalMillis = intervalMillis, doClick = doClick)) | |
// use it like this | |
my_button.setOnCLick(intervalMillis = 500) { | |
// Do stuff | |
} | |
// or this | |
my_button.setOnCLick { |
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
fun <T : View> Activity.bindView(@IdRes res: Int): Lazy<T> { | |
@Suppress("UNCHECKED_CAST") | |
return lazy(LazyThreadSafetyMode.NONE) { findViewById<T>(res) } | |
} | |
fun <T : View> View.bindView(@IdRes res: Int): Lazy<T> { | |
@Suppress("UNCHECKED_CAST") | |
return lazy(LazyThreadSafetyMode.NONE) { findViewById<T>(res) } | |
} |
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 MainActivity : AppCompatActivity() { | |
private val buttonBaseline: Button by bindView(R.id.button_go_to_baseline) | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
buttonBaseline.setOnClickListener { | |
goToABTest(ABTestVariation.BASELINE) | |
} |