This file contains hidden or 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 BindViewDelegate<T>( | |
| private val createView: () -> T, | |
| private val getLifecycle: () -> Lifecycle | |
| ) : Lazy<T>, LifecycleObserver { | |
| private var view: T? = null | |
| private val lifecycle: Lifecycle? | |
| get() = try { | |
| getLifecycle() |
This file contains hidden or 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 Step1Fragment : ABTestFragment() { | |
| private val button: Button by bindView(R.id.button) | |
| override fun onCreateView( | |
| inflater: LayoutInflater, | |
| container: ViewGroup?, | |
| savedInstanceState: Bundle? | |
| ): View? { | |
| return inflater.inflate(R.layout.fragment_step1_baseline, container, false) |
This file contains hidden or 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 BindViewDelegate<T>( | |
| private val createView: () -> T, | |
| private val getLifecycle: () -> Lifecycle | |
| ) : Lazy<T>, LifecycleObserver { | |
| private var view: T? = null | |
| private val lifecycle: Lifecycle? | |
| get() = try { | |
| getLifecycle() |
This file contains hidden or 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) | |
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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, |
NewerOlder