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