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
10
10
11
11
/* *
12
12
* 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.
15
15
*/
16
16
inline fun View.debounceClick (
17
17
intervalInMillis : Int = 1500,
Original file line number Diff line number Diff line change @@ -28,6 +28,9 @@ object Dependencies {
28
28
" androidx.constraintlayout:constraintlayout:${Versions .AndroidX .constraintLayout} "
29
29
const val viewModel =
30
30
" 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} "
31
34
}
32
35
33
36
object Test {
@@ -92,12 +95,16 @@ fun Project.importCommonDependencies() {
92
95
" implementation" (Dependencies .rxAndroid)
93
96
94
97
val implementation by configurations
98
+ val kapt by configurations
95
99
val testImplementation by configurations
96
100
val androidTestImplementation by configurations
97
101
98
102
implementation(Dependencies .AndroidX .appCompat)
99
103
implementation(Dependencies .AndroidX .coreKtx)
100
104
implementation(Dependencies .AndroidX .constraintLayout)
105
+ implementation(Dependencies .AndroidX .viewModel)
106
+ implementation(Dependencies .AndroidX .livedata)
107
+ kapt(Dependencies .AndroidX .lifecycleCompiler)
101
108
implementation(Dependencies .material)
102
109
103
110
implementation(Dependencies .Koin .android)
You can’t perform that action at this time.
0 commit comments