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 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()
}

View File

@@ -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))

View File

@@ -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<ViewState> = 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
)