From b28c961c8f583c93444243f207f294edf50e0808 Mon Sep 17 00:00:00 2001 From: Rahul Patel Date: Fri, 12 Jul 2024 20:25:21 +0530 Subject: [PATCH] Always use WebAPI to fetch ForYou & TopChart streams --- .../viewmodel/homestream/StreamViewModel.kt | 19 ++++--------------- .../SubCategoryClusterViewModel.kt | 5 ++--- .../viewmodel/topchart/TopChartViewModel.kt | 19 ++++--------------- 3 files changed, 10 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/aurora/store/viewmodel/homestream/StreamViewModel.kt b/app/src/main/java/com/aurora/store/viewmodel/homestream/StreamViewModel.kt index 4b46fbb73..927cbab96 100644 --- a/app/src/main/java/com/aurora/store/viewmodel/homestream/StreamViewModel.kt +++ b/app/src/main/java/com/aurora/store/viewmodel/homestream/StreamViewModel.kt @@ -26,13 +26,11 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.aurora.gplayapi.data.models.StreamBundle import com.aurora.gplayapi.data.models.StreamCluster -import com.aurora.gplayapi.helpers.StreamHelper import com.aurora.gplayapi.helpers.contracts.StreamContract import com.aurora.gplayapi.helpers.web.WebStreamHelper import com.aurora.store.HomeStash import com.aurora.store.data.model.ViewState import com.aurora.store.data.network.HttpClient -import com.aurora.store.data.providers.AuthProvider import com.aurora.store.util.Log import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext @@ -43,13 +41,8 @@ import javax.inject.Inject @HiltViewModel @SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253 -class StreamViewModel @Inject constructor( - @ApplicationContext private val context: Context, - private val authProvider: AuthProvider -) : ViewModel() { - - private var streamHelper: StreamContract = StreamHelper(authProvider.authData) - .using(HttpClient.getPreferredClient(context)) +class StreamViewModel @Inject constructor(@ApplicationContext private val context: Context) : + ViewModel() { private var webStreamHelper: StreamContract = WebStreamHelper() .using(HttpClient.getPreferredClient(context)) @@ -59,11 +52,7 @@ class StreamViewModel @Inject constructor( private var stash: HomeStash = mutableMapOf() fun contract(): StreamContract { - return if (authProvider.isAnonymous) { - webStreamHelper - } else { - streamHelper - } + return webStreamHelper } fun getStreamBundle(category: StreamContract.Category, type: StreamContract.Type) { @@ -142,7 +131,7 @@ class StreamViewModel @Inject constructor( } private fun targetBundle(category: StreamContract.Category): StreamBundle { - val streamBundle = stash.getOrPut(category){ + val streamBundle = stash.getOrPut(category) { StreamBundle() } diff --git a/app/src/main/java/com/aurora/store/viewmodel/subcategory/SubCategoryClusterViewModel.kt b/app/src/main/java/com/aurora/store/viewmodel/subcategory/SubCategoryClusterViewModel.kt index 6bca2979e..2c0faf43b 100644 --- a/app/src/main/java/com/aurora/store/viewmodel/subcategory/SubCategoryClusterViewModel.kt +++ b/app/src/main/java/com/aurora/store/viewmodel/subcategory/SubCategoryClusterViewModel.kt @@ -40,9 +40,8 @@ import javax.inject.Inject @HiltViewModel @SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253 -class SubCategoryClusterViewModel @Inject constructor( - @ApplicationContext private val context: Context -) : ViewModel() { +class SubCategoryClusterViewModel @Inject constructor(@ApplicationContext private val context: Context) : + ViewModel() { var contract: StreamContract = WebStreamHelper() .using(HttpClient.getPreferredClient(context)) diff --git a/app/src/main/java/com/aurora/store/viewmodel/topchart/TopChartViewModel.kt b/app/src/main/java/com/aurora/store/viewmodel/topchart/TopChartViewModel.kt index 838e08bbd..96a8b7e93 100644 --- a/app/src/main/java/com/aurora/store/viewmodel/topchart/TopChartViewModel.kt +++ b/app/src/main/java/com/aurora/store/viewmodel/topchart/TopChartViewModel.kt @@ -25,13 +25,11 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.aurora.gplayapi.data.models.StreamCluster -import com.aurora.gplayapi.helpers.TopChartsHelper import com.aurora.gplayapi.helpers.contracts.TopChartsContract import com.aurora.gplayapi.helpers.web.WebTopChartsHelper import com.aurora.store.TopChartStash import com.aurora.store.data.model.ViewState import com.aurora.store.data.network.HttpClient -import com.aurora.store.data.providers.AuthProvider import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.coroutines.Dispatchers @@ -41,13 +39,8 @@ import javax.inject.Inject @HiltViewModel @SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253 -class TopChartViewModel @Inject constructor( - @ApplicationContext private val context: Context, - private val authProvider: AuthProvider -) : ViewModel() { - - private val topChartsHelper: TopChartsHelper = TopChartsHelper(authProvider.authData) - .using(HttpClient.getPreferredClient(context)) +class TopChartViewModel @Inject constructor(@ApplicationContext private val context: Context) : + ViewModel() { private val webTopChartsHelper: TopChartsContract = WebTopChartsHelper() .using(HttpClient.getPreferredClient(context)) @@ -57,11 +50,7 @@ class TopChartViewModel @Inject constructor( val liveData: MutableLiveData = MutableLiveData() private fun contract(): TopChartsContract { - return if (authProvider.isAnonymous) { - webTopChartsHelper - } else { - topChartsHelper - } + return webTopChartsHelper } fun getStreamCluster(type: TopChartsContract.Type, chart: TopChartsContract.Chart) { @@ -85,7 +74,7 @@ class TopChartViewModel @Inject constructor( try { val target = targetCluster(type, chart) if (target.hasNext()) { - val newCluster = topChartsHelper.getNextStreamCluster( + val newCluster = contract().getNextStreamCluster( target.clusterNextPageUrl )