Merge pull request #87 from nightscout/adrian/coroutine-scoping
coroutines on lifecycle scope of view they are in
This commit is contained in:
commit
6aa1b0c9e1
|
@ -8,6 +8,7 @@ import android.view.ViewGroup
|
|||
import android.widget.LinearLayout
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.jjoe64.graphview.GraphView
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.R
|
||||
|
@ -37,7 +38,6 @@ import io.reactivex.disposables.CompositeDisposable
|
|||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.android.synthetic.main.activity_historybrowse.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.*
|
||||
|
@ -256,7 +256,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
}
|
||||
|
||||
private fun runCalculation(from: String) {
|
||||
GlobalScope.launch(Dispatchers.Default) {
|
||||
lifecycleScope.launch(Dispatchers.Default) {
|
||||
treatmentsPluginHistory.initializeData(start - T.hours(8).msecs())
|
||||
val end = start + T.hours(rangeToDisplay.toLong()).msecs()
|
||||
iobCobCalculatorPluginHistory.stopCalculation(from)
|
||||
|
@ -273,7 +273,7 @@ class HistoryBrowseActivity : NoSplashAppCompatActivity() {
|
|||
val lowLine = defaultValueHelper.determineLowLine()
|
||||
val highLine = defaultValueHelper.determineHighLine()
|
||||
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
lifecycleScope.launch(Dispatchers.Main) {
|
||||
historybrowse_noprofile?.visibility = (profile == null).toVisibility()
|
||||
profile ?: return@launch
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.widget.LinearLayout
|
|||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.text.toSpanned
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.jjoe64.graphview.GraphView
|
||||
import dagger.android.HasAndroidInjector
|
||||
|
@ -99,7 +100,6 @@ import kotlinx.android.synthetic.main.overview_info_layout.overview_timeagoshort
|
|||
import kotlinx.android.synthetic.main.overview_loop_pumpstatus_layout.*
|
||||
import kotlinx.android.synthetic.main.overview_statuslights_layout.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.*
|
||||
|
@ -798,7 +798,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
|
|||
} ?: ""
|
||||
|
||||
// ****** GRAPH *******
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
|
||||
overview_bggraph ?: return@launch
|
||||
val graphData = GraphData(injector, overview_bggraph, iobCobCalculatorPlugin, treatmentsPlugin)
|
||||
val secondaryGraphsData: ArrayList<GraphData> = ArrayList()
|
||||
|
|
|
@ -45,8 +45,8 @@ dependencies {
|
|||
implementation "androidx.appcompat:appcompat:$appcompat_verison"
|
||||
implementation "androidx.preference:preference-ktx:$preferencektx_version"
|
||||
implementation 'androidx.biometric:biometric:1.0.1'
|
||||
implementation "androidx.activity:activity:${activityVersion}"
|
||||
implementation "androidx.activity:activity-ktx:${activityVersion}"
|
||||
api "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0"
|
||||
implementation "com.google.android.material:material:$material_version"
|
||||
|
||||
implementation "com.google.dagger:dagger-android:$dagger_version"
|
||||
|
|
Loading…
Reference in a new issue