Add firebase config param

pull/1823/head
Alex Baker 2 years ago
parent 437bb48d62
commit ed48ab15e3

@ -7,6 +7,7 @@ import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings
import com.todoroo.andlib.utility.DateUtilities.now
import dagger.hilt.android.qualifiers.ApplicationContext
import org.tasks.R
import org.tasks.jobs.WorkManager
@ -19,7 +20,7 @@ import javax.inject.Singleton
@Singleton
class Firebase @Inject constructor(
@param:ApplicationContext val context: Context,
preferences: Preferences
private val preferences: Preferences
) {
private var crashlytics: FirebaseCrashlytics? = null
@ -59,8 +60,14 @@ class Firebase @Inject constructor(
})
}
val reviewCooldown: Long
get() = remoteConfig?.getLong("review_cooldown") ?: 14L
val installCooldown: Boolean
get() = preferences.installDate + days("install_cooldown", 14L) > now()
val reviewCooldown: Boolean
get() = preferences.lastReviewRequest + days("review_cooldown", 30L) > now()
private fun days(key: String, default: Long): Long =
TimeUnit.DAYS.toMillis(remoteConfig?.getLong(key) ?: default)
init {
if (preferences.isTrackingEnabled) {

@ -11,9 +11,7 @@ import com.todoroo.andlib.utility.DateUtilities.now
import dagger.hilt.android.qualifiers.ApplicationContext
import org.tasks.analytics.Firebase
import org.tasks.preferences.Preferences
import org.tasks.time.DateTimeUtils.printTimestamp
import timber.log.Timber
import java.util.concurrent.TimeUnit
import javax.inject.Inject
class PlayServices @Inject constructor(
@ -25,30 +23,22 @@ class PlayServices @Inject constructor(
getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS
suspend fun requestReview(activity: Activity) {
val now = now()
val reviewCutoff = preferences.lastReviewRequest + REVIEW_COOLDOWN
if (reviewCutoff > now) {
Timber.d("review cooldown: ${printTimestamp(reviewCutoff)}")
if (firebase.reviewCooldown) {
Timber.d("review cooldown")
return
}
val installCutoff =
preferences.installDate + TimeUnit.DAYS.toMillis(firebase.reviewCooldown)
if (installCutoff > now || reviewCutoff > now) {
Timber.d("install cooldown: ${printTimestamp(installCutoff)}")
if (firebase.installCooldown) {
Timber.d("install cooldown")
return
}
try {
with(ReviewManagerFactory.create(context)) {
val request = requestReview()
launchReview(activity, request)
preferences.lastReviewRequest = now
preferences.lastReviewRequest = now()
}
} catch (e: Exception) {
Timber.e(e)
}
}
companion object {
private val REVIEW_COOLDOWN = TimeUnit.DAYS.toMillis(30)
}
}

@ -3,6 +3,10 @@
tools:ignore="MissingDefaultResource">
<entry>
<key>review_cooldown</key>
<value>30</value>
</entry>
<entry>
<key>install_cooldown</key>
<value>14</value>
</entry>
</defaultsMap>

Loading…
Cancel
Save