From b00ea2e79926dac51470f81d0ad0f8c2988b7ebd Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Mon, 29 Apr 2019 10:51:40 +0200 Subject: [PATCH] Use global scope for global operation in insights management --- .../insights/management/InsightsManagementViewModel.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt index 1cf42e5af703..6feb1c9d30c2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/refresh/lists/sections/insights/management/InsightsManagementViewModel.kt @@ -4,6 +4,7 @@ import android.arch.lifecycle.LiveData import android.arch.lifecycle.MutableLiveData import androidx.annotation.StringRes import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import org.wordpress.android.R import org.wordpress.android.fluxc.store.StatsStore @@ -74,11 +75,12 @@ class InsightsManagementViewModel @Inject constructor( } fun onSaveInsights() { - launch { + // This has to be GlobalScope because otherwise the coroutine gets killed with the ViewModel + GlobalScope.launch { val addedTypes = insights.filter { it.type == ADDED }.map { it.insightType } statsStore.updateTypes(siteProvider.siteModel, addedTypes) - insightsUseCase.refreshData(true) + insightsUseCase.loadData() } _closeInsightsManagement.call() }