search: Use our custom httpClient with web helpers too

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2024-08-29 12:12:29 +05:30
parent e7c4571302
commit 4107eed2d9
2 changed files with 13 additions and 29 deletions

View File

@@ -51,20 +51,14 @@ class SearchResultViewModel @Inject constructor(
private val TAG = SearchResultViewModel::class.java.simpleName
private val webSearchHelper: WebSearchHelper = WebSearchHelper()
private val searchHelper: SearchHelper = SearchHelper(authProvider.authData!!)
.using(httpClient)
val liveData: MutableLiveData<SearchBundle> = MutableLiveData()
private var searchBundle: SearchBundle = SearchBundle()
fun helper(): SearchContract {
return if (authProvider.isAnonymous) {
webSearchHelper
} else {
searchHelper
}
private val helper: SearchContract = if (authProvider.isAnonymous) {
WebSearchHelper().using(httpClient)
} else {
SearchHelper(authProvider.authData!!).using(httpClient)
}
fun observeSearchResults(query: String) {
@@ -84,10 +78,8 @@ class SearchResultViewModel @Inject constructor(
}
}
private fun search(
query: String
): SearchBundle {
return helper().searchResults(query)
private fun search(query: String): SearchBundle {
return helper.searchResults(query)
}
@Synchronized
@@ -96,7 +88,7 @@ class SearchResultViewModel @Inject constructor(
supervisorScope {
try {
if (nextSubBundleSet.isNotEmpty()) {
val newSearchBundle = helper().next(nextSubBundleSet)
val newSearchBundle = helper.next(nextSubBundleSet)
if (newSearchBundle.appList.isNotEmpty()) {
searchBundle.apply {
subBundles.flushAndAdd(newSearchBundle.subBundles)

View File

@@ -44,18 +44,12 @@ class SearchSuggestionViewModel @Inject constructor(
private val httpClient: IProxyHttpClient
) : ViewModel() {
private val webSearchHelper: WebSearchHelper = WebSearchHelper()
private val searchHelper: SearchHelper = SearchHelper(authProvider.authData!!)
.using(httpClient)
val liveSearchSuggestions: MutableLiveData<List<SearchSuggestEntry>> = MutableLiveData()
fun helper(): SearchContract {
return if (authProvider.isAnonymous) {
webSearchHelper
} else {
searchHelper
}
private val helper: SearchContract = if (authProvider.isAnonymous) {
WebSearchHelper().using(httpClient)
} else {
SearchHelper(authProvider.authData!!).using(httpClient)
}
fun observeStreamBundles(query: String) {
@@ -64,9 +58,7 @@ class SearchSuggestionViewModel @Inject constructor(
}
}
private fun getSearchSuggestions(
query: String
): List<SearchSuggestEntry> {
return helper().searchSuggestions(query)
private fun getSearchSuggestions(query: String): List<SearchSuggestEntry> {
return helper.searchSuggestions(query)
}
}