mirror of https://github.com/tasks/tasks
Choose location service based on gplay availablity
parent
856cd04621
commit
815648ea8c
@ -1,26 +0,0 @@
|
|||||||
package org.tasks.gtasks
|
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import com.todoroo.astrid.activity.MainActivity
|
|
||||||
import io.reactivex.disposables.Disposable
|
|
||||||
import io.reactivex.disposables.Disposables
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@Suppress("UNUSED_PARAMETER")
|
|
||||||
class PlayServices @Inject constructor() {
|
|
||||||
val isPlayServicesAvailable: Boolean
|
|
||||||
get() = false
|
|
||||||
|
|
||||||
fun refreshAndCheck(): Boolean {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
fun resolve(activity: Activity?) {}
|
|
||||||
|
|
||||||
val status: String?
|
|
||||||
get() = null
|
|
||||||
|
|
||||||
fun check(mainActivity: MainActivity?): Disposable {
|
|
||||||
return Disposables.empty()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,65 +1,12 @@
|
|||||||
package org.tasks.gtasks
|
package org.tasks.gtasks
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.widget.Toast
|
|
||||||
import com.google.android.gms.common.ConnectionResult
|
import com.google.android.gms.common.ConnectionResult
|
||||||
import com.google.android.gms.common.GoogleApiAvailability
|
import com.google.android.gms.common.GoogleApiAvailability.getInstance
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
import org.tasks.R
|
|
||||||
import org.tasks.data.LocationDao
|
|
||||||
import org.tasks.preferences.Preferences
|
|
||||||
import timber.log.Timber
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class PlayServices @Inject constructor(
|
object PlayServices {
|
||||||
@param:ApplicationContext private val context: Context,
|
fun isAvailable(context: Context) =
|
||||||
private val preferences: Preferences,
|
getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS
|
||||||
private val locationDao: LocationDao) {
|
|
||||||
|
|
||||||
suspend fun check(activity: Activity?) {
|
|
||||||
val playServicesAvailable = locationDao.geofenceCount() == 0 || refreshAndCheck()
|
|
||||||
if (!playServicesAvailable && !preferences.getBoolean(R.string.warned_play_services, false)) {
|
|
||||||
preferences.setBoolean(R.string.warned_play_services, true)
|
|
||||||
resolve(activity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun refreshAndCheck(): Boolean {
|
|
||||||
refresh()
|
|
||||||
return isPlayServicesAvailable
|
|
||||||
}
|
|
||||||
|
|
||||||
val isPlayServicesAvailable: Boolean
|
|
||||||
get() = result == ConnectionResult.SUCCESS
|
|
||||||
|
|
||||||
private fun refresh() {
|
|
||||||
val instance = GoogleApiAvailability.getInstance()
|
|
||||||
val googlePlayServicesAvailable = instance.isGooglePlayServicesAvailable(context)
|
|
||||||
preferences.setInt(R.string.play_services_available, googlePlayServicesAvailable)
|
|
||||||
if (googlePlayServicesAvailable == ConnectionResult.SUCCESS) {
|
|
||||||
preferences.setBoolean(R.string.warned_play_services, false)
|
|
||||||
}
|
|
||||||
Timber.d(status)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun resolve(activity: Activity?) {
|
|
||||||
val googleApiAvailability = GoogleApiAvailability.getInstance()
|
|
||||||
val error = preferences.getInt(R.string.play_services_available, -1)
|
|
||||||
if (googleApiAvailability.isUserResolvableError(error)) {
|
|
||||||
googleApiAvailability.getErrorDialog(activity, error, REQUEST_RESOLUTION).show()
|
|
||||||
} else {
|
|
||||||
Toast.makeText(activity, status, Toast.LENGTH_LONG).show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val status: String
|
|
||||||
get() = GoogleApiAvailability.getInstance().getErrorString(result)
|
|
||||||
|
|
||||||
private val result: Int
|
|
||||||
get() = preferences.getInt(R.string.play_services_available, -1)
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val REQUEST_RESOLUTION = 10000
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -1,11 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="gp_key">MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAk8mXRE3dDXwtinUILCEzKjov2rxs3kZbLRzNrcjFWXpG9OEsUzRGLzqEN+WwibVuMRpZLj/+IxbU2sJWq/M0q+90rOhmXn46ZPeNyr77IqX2pWKIAWpzBoWq/mshRwtm9m1FIiGdBNlXrhSE7u3TGB5FuEuuSqKWvWzxeqQ7fHmlM04Lqrh1mN3FaMne8rWv+DWVHDbLrtnXBuC36glOAj17HxrzaE2v6Pv7Df3QefJ3rM1+0fAp/5jNInaP0qHAlG8WTbUmDShQ5kG3urbv3HLByyx6TSqhmNudXUK/6TusvIj50OptAG7x+UFYf956dD3diXhY3yoICvyFWx1sNwIDAQAB</string>
|
<string name="gp_key">MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAk8mXRE3dDXwtinUILCEzKjov2rxs3kZbLRzNrcjFWXpG9OEsUzRGLzqEN+WwibVuMRpZLj/+IxbU2sJWq/M0q+90rOhmXn46ZPeNyr77IqX2pWKIAWpzBoWq/mshRwtm9m1FIiGdBNlXrhSE7u3TGB5FuEuuSqKWvWzxeqQ7fHmlM04Lqrh1mN3FaMne8rWv+DWVHDbLrtnXBuC36glOAj17HxrzaE2v6Pv7Df3QefJ3rM1+0fAp/5jNInaP0qHAlG8WTbUmDShQ5kG3urbv3HLByyx6TSqhmNudXUK/6TusvIj50OptAG7x+UFYf956dD3diXhY3yoICvyFWx1sNwIDAQAB</string>
|
||||||
<string name="play_services_available">play_services_available</string>
|
|
||||||
<string name="market_url">market://details?id=org.tasks</string>
|
<string name="market_url">market://details?id=org.tasks</string>
|
||||||
<string name="p_purchases">purchases</string>
|
<string name="p_purchases">purchases</string>
|
||||||
<string name="manage_subscription_url">https://play.google.com/store/account/subscriptions?sku=%s&package=org.tasks</string>
|
<string name="manage_subscription_url">https://play.google.com/store/account/subscriptions?sku=%s&package=org.tasks</string>
|
||||||
<string name="support_email">play-support@tasks.org</string>
|
<string name="support_email">play-support@tasks.org</string>
|
||||||
<string name="default_reverse_geocoder">0</string> <!-- Mapbox -->
|
<string name="default_reverse_geocoder">0</string> <!-- Mapbox -->
|
||||||
<string name="default_geofence_service">0</string> <!-- Google Play Location Services -->
|
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Reference in New Issue