Use coroutines for play services check

pull/1043/head
Alex Baker 4 years ago
parent 76eafc0985
commit e6d9e664ce

@ -150,10 +150,10 @@ dependencies {
implementation("androidx.hilt:hilt-work:${Versions.hilt_androidx}")
implementation("androidx.hilt:hilt-lifecycle-viewmodel:${Versions.hilt_androidx}")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:${Versions.lifecycle}")
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.lifecycle}")
implementation("androidx.room:room-ktx:${Versions.room}")
kapt("androidx.room:room-compiler:${Versions.room}")
implementation("androidx.lifecycle:lifecycle-extensions:2.2.0")
implementation("io.reactivex.rxjava2:rxandroid:2.1.1")
implementation("androidx.paging:paging-runtime:2.1.2")

@ -726,3 +726,9 @@
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://developer.android.com/topic/libraries/architecture/index.html
- artifact: androidx.lifecycle:lifecycle-runtime-ktx:+
name: lifecycle-runtime-ktx
copyrightHolder: Android Open Source Project
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://developer.android.com/jetpack/androidx

@ -6,10 +6,6 @@ import android.widget.Toast
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import dagger.hilt.android.qualifiers.ApplicationContext
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import org.tasks.R
import org.tasks.data.LocationDao
import org.tasks.preferences.Preferences
@ -21,17 +17,12 @@ class PlayServices @Inject constructor(
private val preferences: Preferences,
private val locationDao: LocationDao) {
fun check(activity: Activity?): Disposable {
return Single.fromCallable(locationDao::geofenceCount)
.map { it == 0 || refreshAndCheck() }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { success: Boolean ->
if (!success && !preferences.getBoolean(R.string.warned_play_services, false)) {
preferences.setBoolean(R.string.warned_play_services, true)
resolve(activity)
}
}
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 {

@ -1730,6 +1730,20 @@
"normalizedLicense": "apache2",
"url": "https://developer.android.com/topic/libraries/architecture/index.html",
"libraryName": "room-ktx"
},
{
"artifactId": {
"name": "lifecycle-runtime-ktx",
"group": "androidx.lifecycle",
"version": "+"
},
"copyrightHolder": "Android Open Source Project",
"copyrightStatement": "Copyright © Android Open Source Project. All rights reserved.",
"license": "The Apache Software License, Version 2.0",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt",
"normalizedLicense": "apache2",
"url": "https://developer.android.com/jetpack/androidx",
"libraryName": "lifecycle-runtime-ktx"
}
]
}

@ -17,6 +17,7 @@ import android.view.inputmethod.InputMethodManager
import androidx.appcompat.view.ActionMode
import androidx.drawerlayout.widget.DrawerLayout.SimpleDrawerListener
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.lifecycleScope
import com.todoroo.andlib.utility.AndroidUtilities
import com.todoroo.astrid.activity.TaskEditFragment.TaskEditFragmentCallbackHandler
import com.todoroo.astrid.activity.TaskListFragment.TaskListFragmentCallbackHandler
@ -279,7 +280,7 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl
}
localBroadcastManager.registerRepeatReceiver(repeatConfirmationReceiver)
check(!(BuildConfig.DEBUG && disposables != null && !disposables!!.isDisposed))
disposables = CompositeDisposable(playServices.check(this))
disposables = CompositeDisposable()
if (preferences.getBoolean(R.string.p_just_updated, false)) {
if (preferences.getBoolean(R.string.p_show_whats_new, true)) {
val fragmentManager = supportFragmentManager
@ -435,6 +436,12 @@ class MainActivity : InjectingAppCompatActivity(), TaskListFragmentCallbackHandl
taskEditFragment!!.onRemoteListChanged(filter)
}
init {
lifecycleScope.launchWhenResumed {
playServices.check(this@MainActivity)
}
}
companion object {
/** For indicating the new list screen should be launched at fragment setup time */
const val TOKEN_CREATE_NEW_LIST_NAME = "newListName" // $NON-NLS-1$

@ -3,7 +3,6 @@ package org.tasks.data
import androidx.lifecycle.LiveData
import androidx.room.*
import com.todoroo.astrid.api.FilterListItem.NO_ORDER
import io.reactivex.Single
import org.tasks.filters.LocationFilters
import org.tasks.time.DateTimeUtils.currentTimeMillis
@ -63,7 +62,7 @@ interface LocationDao {
fun getActiveGeofences(): List<Location>
@Query("SELECT COUNT(*) FROM geofences")
fun geofenceCount(): Int
suspend fun geofenceCount(): Int
@Delete
fun delete(location: Geofence)

@ -16,4 +16,5 @@ object Versions {
const val make_it_easy = "4.0.1"
const val hilt = "2.28-alpha"
const val hilt_androidx = "1.0.0-alpha01"
const val lifecycle = "2.2.0"
}
Loading…
Cancel
Save