File tree Expand file tree Collapse file tree 4 files changed +56
-2
lines changed
base/src/main/java/com/enginebai/base/extensions Expand file tree Collapse file tree 4 files changed +56
-2
lines changed Original file line number Diff line number Diff line change 1+ package com.enginebai.base.extensions
2+
3+ import kotlinx.coroutines.delay
4+ import timber.log.Timber
5+
6+ /* *
7+ * Retry running block with exponential backoff mechanism.
8+ * @param times how many times to retry.
9+ * @param initialDelayMillis The initial delay time in millis second.
10+ * @param delayFactor the factor to multiple [initialDelayMillis] to be next retry delay
11+ */
12+ suspend fun <T > retry (
13+ times : Int = 5,
14+ initialDelayMillis : Long = 1000,
15+ delayFactor : Double = 2.0,
16+ block : suspend () -> T
17+ ): T {
18+ var currentDelay = initialDelayMillis
19+ repeat(times) {
20+ try {
21+ return block()
22+ } catch (e: Exception ) {
23+ Timber .w(e)
24+ }
25+ delay(currentDelay)
26+ currentDelay = (currentDelay * delayFactor).toLong()
27+ }
28+ return block() // last attempt
29+ }
Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ import androidx.core.content.ContextCompat
1010
1111/* *
1212 * Prevent multiple click in a short period of time. Default interval is 1500 milli-second.
13- * @param intervalInMillis: The time interval to trigger next click events.
14- * @param listener: The click listener
13+ * @param intervalInMillis: the time interval to trigger next click events.
14+ * @param listener: the click listener.
1515 */
1616inline fun View.debounceClick (
1717 intervalInMillis : Int = 1500,
Original file line number Diff line number Diff line change @@ -28,6 +28,9 @@ object Dependencies {
2828 " androidx.constraintlayout:constraintlayout:${Versions .AndroidX .constraintLayout} "
2929 const val viewModel =
3030 " androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions .ArchitectureComponents .lifecycle} "
31+ const val livedata =
32+ " androidx.lifecycle:lifecycle-livedata-ktx:${Versions .ArchitectureComponents .lifecycle} "
33+ const val lifecycleCompiler = " androidx.lifecycle:lifecycle-compiler:${Versions .ArchitectureComponents .lifecycle} "
3134 }
3235
3336 object Test {
@@ -92,12 +95,16 @@ fun Project.importCommonDependencies() {
9295 " implementation" (Dependencies .rxAndroid)
9396
9497 val implementation by configurations
98+ val kapt by configurations
9599 val testImplementation by configurations
96100 val androidTestImplementation by configurations
97101
98102 implementation(Dependencies .AndroidX .appCompat)
99103 implementation(Dependencies .AndroidX .coreKtx)
100104 implementation(Dependencies .AndroidX .constraintLayout)
105+ implementation(Dependencies .AndroidX .viewModel)
106+ implementation(Dependencies .AndroidX .livedata)
107+ kapt(Dependencies .AndroidX .lifecycleCompiler)
101108 implementation(Dependencies .material)
102109
103110 implementation(Dependencies .Koin .android)
You can’t perform that action at this time.
0 commit comments