From d1fd030ab0cb734acd6f06a67ce84a3050384d68 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 19 Feb 2023 19:52:37 +0530 Subject: [PATCH] Use viewModelScope extension. --- .../com/github/libretube/ui/models/CommentsViewModel.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/models/CommentsViewModel.kt b/app/src/main/java/com/github/libretube/ui/models/CommentsViewModel.kt index 33d6c2fb1..becb96b71 100644 --- a/app/src/main/java/com/github/libretube/ui/models/CommentsViewModel.kt +++ b/app/src/main/java/com/github/libretube/ui/models/CommentsViewModel.kt @@ -3,16 +3,15 @@ package com.github.libretube.ui.models import android.util.Log import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.github.libretube.api.RetrofitInstance import com.github.libretube.api.obj.CommentsPage import com.github.libretube.extensions.TAG import com.github.libretube.ui.extensions.filterNonEmptyComments -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class CommentsViewModel : ViewModel() { - private val scope = CoroutineScope(Dispatchers.IO) private var isLoading = false val commentsPage = MutableLiveData() @@ -25,7 +24,7 @@ class CommentsViewModel : ViewModel() { fun fetchComments() { videoId ?: return - scope.launch { + viewModelScope.launch(Dispatchers.IO) { isLoading = true val response = try { RetrofitInstance.api.getComments(videoId!!) @@ -42,7 +41,7 @@ class CommentsViewModel : ViewModel() { fun fetchNextComments() { if (isLoading || nextPage == null || videoId == null) return - scope.launch { + viewModelScope.launch(Dispatchers.IO) { isLoading = true val response = try { RetrofitInstance.api.getCommentsNextPage(videoId!!, nextPage!!)