|
|
|
@ -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)
|
|
|
|
|
}
|
|
|
|
|
}
|