Use Web API only for anonymous accounts
This commit is contained in:
@@ -26,8 +26,10 @@ import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.extensions.flushAndAdd
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.data.models.SearchBundle
|
||||
import com.aurora.gplayapi.helpers.SearchHelper
|
||||
import com.aurora.gplayapi.helpers.WebSearchHelper
|
||||
import com.aurora.store.data.RequestState
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import com.aurora.store.viewmodel.BaseAndroidViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -41,12 +43,22 @@ class SearchResultViewModel(application: Application) : BaseAndroidViewModel(app
|
||||
.with(application)
|
||||
.getAuthData()
|
||||
|
||||
private val searchHelper: WebSearchHelper = WebSearchHelper(authData)
|
||||
private val webSearchHelper: WebSearchHelper = WebSearchHelper(authData)
|
||||
private val searchHelper: SearchHelper = SearchHelper(authData)
|
||||
.using(HttpClient.getPreferredClient())
|
||||
|
||||
val liveData: MutableLiveData<SearchBundle> = MutableLiveData()
|
||||
|
||||
private var searchBundle: SearchBundle = SearchBundle()
|
||||
|
||||
fun helper(): SearchHelper {
|
||||
return if (authData.isAnonymous) {
|
||||
webSearchHelper
|
||||
} else {
|
||||
searchHelper
|
||||
}
|
||||
}
|
||||
|
||||
fun observeSearchResults(query: String) {
|
||||
//Clear old results
|
||||
searchBundle.subBundles.clear()
|
||||
@@ -67,7 +79,7 @@ class SearchResultViewModel(application: Application) : BaseAndroidViewModel(app
|
||||
private fun search(
|
||||
query: String
|
||||
): SearchBundle {
|
||||
return searchHelper.searchResults(query)
|
||||
return helper().searchResults(query)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@@ -76,7 +88,7 @@ class SearchResultViewModel(application: Application) : BaseAndroidViewModel(app
|
||||
supervisorScope {
|
||||
try {
|
||||
if (nextSubBundleSet.isNotEmpty() && responseCode.value != 429) {
|
||||
val newSearchBundle = searchHelper.next(nextSubBundleSet)
|
||||
val newSearchBundle = helper().next(nextSubBundleSet)
|
||||
if (newSearchBundle.appList.isNotEmpty()) {
|
||||
searchBundle.apply {
|
||||
subBundles.flushAndAdd(newSearchBundle.subBundles)
|
||||
|
||||
@@ -25,7 +25,9 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.aurora.gplayapi.SearchSuggestEntry
|
||||
import com.aurora.gplayapi.data.models.AuthData
|
||||
import com.aurora.gplayapi.helpers.SearchHelper
|
||||
import com.aurora.gplayapi.helpers.WebSearchHelper
|
||||
import com.aurora.store.data.network.HttpClient
|
||||
import com.aurora.store.data.providers.AuthProvider
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -36,10 +38,20 @@ class SearchSuggestionViewModel(application: Application) : AndroidViewModel(app
|
||||
.with(application)
|
||||
.getAuthData()
|
||||
|
||||
private val searchHelper: WebSearchHelper = WebSearchHelper(authData)
|
||||
private val webSearchHelper: WebSearchHelper = WebSearchHelper(authData)
|
||||
private val searchHelper: SearchHelper = SearchHelper(authData)
|
||||
.using(HttpClient.getPreferredClient())
|
||||
|
||||
val liveSearchSuggestions: MutableLiveData<List<SearchSuggestEntry>> = MutableLiveData()
|
||||
|
||||
fun helper(): SearchHelper {
|
||||
return if (authData.isAnonymous) {
|
||||
webSearchHelper
|
||||
} else {
|
||||
searchHelper
|
||||
}
|
||||
}
|
||||
|
||||
fun observeStreamBundles(query: String) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
liveSearchSuggestions.postValue(getSearchSuggestions(query))
|
||||
@@ -49,6 +61,6 @@ class SearchSuggestionViewModel(application: Application) : AndroidViewModel(app
|
||||
private fun getSearchSuggestions(
|
||||
query: String
|
||||
): List<SearchSuggestEntry> {
|
||||
return searchHelper.searchSuggestions(query)
|
||||
return helper().searchSuggestions(query)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user