Always use WebAPI to fetch ForYou & TopChart streams

This commit is contained in:
Rahul Patel
2024-07-12 20:25:21 +05:30
parent dae20af9e8
commit b28c961c8f
3 changed files with 10 additions and 33 deletions

View File

@@ -26,13 +26,11 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.aurora.gplayapi.data.models.StreamBundle import com.aurora.gplayapi.data.models.StreamBundle
import com.aurora.gplayapi.data.models.StreamCluster 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.contracts.StreamContract
import com.aurora.gplayapi.helpers.web.WebStreamHelper import com.aurora.gplayapi.helpers.web.WebStreamHelper
import com.aurora.store.HomeStash import com.aurora.store.HomeStash
import com.aurora.store.data.model.ViewState import com.aurora.store.data.model.ViewState
import com.aurora.store.data.network.HttpClient import com.aurora.store.data.network.HttpClient
import com.aurora.store.data.providers.AuthProvider
import com.aurora.store.util.Log import com.aurora.store.util.Log
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
@@ -43,13 +41,8 @@ import javax.inject.Inject
@HiltViewModel @HiltViewModel
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253 @SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
class StreamViewModel @Inject constructor( class StreamViewModel @Inject constructor(@ApplicationContext private val context: Context) :
@ApplicationContext private val context: Context, ViewModel() {
private val authProvider: AuthProvider
) : ViewModel() {
private var streamHelper: StreamContract = StreamHelper(authProvider.authData)
.using(HttpClient.getPreferredClient(context))
private var webStreamHelper: StreamContract = WebStreamHelper() private var webStreamHelper: StreamContract = WebStreamHelper()
.using(HttpClient.getPreferredClient(context)) .using(HttpClient.getPreferredClient(context))
@@ -59,11 +52,7 @@ class StreamViewModel @Inject constructor(
private var stash: HomeStash = mutableMapOf() private var stash: HomeStash = mutableMapOf()
fun contract(): StreamContract { fun contract(): StreamContract {
return if (authProvider.isAnonymous) { return webStreamHelper
webStreamHelper
} else {
streamHelper
}
} }
fun getStreamBundle(category: StreamContract.Category, type: StreamContract.Type) { fun getStreamBundle(category: StreamContract.Category, type: StreamContract.Type) {
@@ -142,7 +131,7 @@ class StreamViewModel @Inject constructor(
} }
private fun targetBundle(category: StreamContract.Category): StreamBundle { private fun targetBundle(category: StreamContract.Category): StreamBundle {
val streamBundle = stash.getOrPut(category){ val streamBundle = stash.getOrPut(category) {
StreamBundle() StreamBundle()
} }

View File

@@ -40,9 +40,8 @@ import javax.inject.Inject
@HiltViewModel @HiltViewModel
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253 @SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
class SubCategoryClusterViewModel @Inject constructor( class SubCategoryClusterViewModel @Inject constructor(@ApplicationContext private val context: Context) :
@ApplicationContext private val context: Context ViewModel() {
) : ViewModel() {
var contract: StreamContract = WebStreamHelper() var contract: StreamContract = WebStreamHelper()
.using(HttpClient.getPreferredClient(context)) .using(HttpClient.getPreferredClient(context))

View File

@@ -25,13 +25,11 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.aurora.gplayapi.data.models.StreamCluster 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.contracts.TopChartsContract
import com.aurora.gplayapi.helpers.web.WebTopChartsHelper import com.aurora.gplayapi.helpers.web.WebTopChartsHelper
import com.aurora.store.TopChartStash import com.aurora.store.TopChartStash
import com.aurora.store.data.model.ViewState import com.aurora.store.data.model.ViewState
import com.aurora.store.data.network.HttpClient import com.aurora.store.data.network.HttpClient
import com.aurora.store.data.providers.AuthProvider
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@@ -41,13 +39,8 @@ import javax.inject.Inject
@HiltViewModel @HiltViewModel
@SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253 @SuppressLint("StaticFieldLeak") // false positive, see https://github.com/google/dagger/issues/3253
class TopChartViewModel @Inject constructor( class TopChartViewModel @Inject constructor(@ApplicationContext private val context: Context) :
@ApplicationContext private val context: Context, ViewModel() {
private val authProvider: AuthProvider
) : ViewModel() {
private val topChartsHelper: TopChartsHelper = TopChartsHelper(authProvider.authData)
.using(HttpClient.getPreferredClient(context))
private val webTopChartsHelper: TopChartsContract = WebTopChartsHelper() private val webTopChartsHelper: TopChartsContract = WebTopChartsHelper()
.using(HttpClient.getPreferredClient(context)) .using(HttpClient.getPreferredClient(context))
@@ -57,11 +50,7 @@ class TopChartViewModel @Inject constructor(
val liveData: MutableLiveData<ViewState> = MutableLiveData() val liveData: MutableLiveData<ViewState> = MutableLiveData()
private fun contract(): TopChartsContract { private fun contract(): TopChartsContract {
return if (authProvider.isAnonymous) { return webTopChartsHelper
webTopChartsHelper
} else {
topChartsHelper
}
} }
fun getStreamCluster(type: TopChartsContract.Type, chart: TopChartsContract.Chart) { fun getStreamCluster(type: TopChartsContract.Type, chart: TopChartsContract.Chart) {
@@ -85,7 +74,7 @@ class TopChartViewModel @Inject constructor(
try { try {
val target = targetCluster(type, chart) val target = targetCluster(type, chart)
if (target.hasNext()) { if (target.hasNext()) {
val newCluster = topChartsHelper.getNextStreamCluster( val newCluster = contract().getNextStreamCluster(
target.clusterNextPageUrl target.clusterNextPageUrl
) )