Initial Web APIs implementation

Introduce a toggle in Settings > Advanced to let user use Web APIs.
Currently implemented for search suggestions and results only.

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2023-10-02 14:05:30 +05:30
parent 4134e1f4f4
commit fd097fbba1
7 changed files with 44 additions and 4 deletions

View File

@@ -166,7 +166,7 @@ dependencies {
implementation("com.github.topjohnwu.libsu:core:5.0.5") implementation("com.github.topjohnwu.libsu:core:5.0.5")
//Love <3 //Love <3
implementation("com.gitlab.AuroraOSS:gplayapi:3.1.4") implementation("com.gitlab.AuroraOSS:gplayapi:3.2.0")
//Browser //Browser
implementation("androidx.browser:browser:1.6.0") implementation("androidx.browser:browser:1.6.0")

View File

@@ -44,6 +44,7 @@ import com.aurora.store.MainActivity
import com.aurora.store.R import com.aurora.store.R
import com.aurora.store.util.Log import com.aurora.store.util.Log
import com.aurora.store.util.Preferences import com.aurora.store.util.Preferences
import com.aurora.store.util.Preferences.PREFERENCE_ADVANCED_USE_WEB_API
import kotlin.system.exitProcess import kotlin.system.exitProcess
val Context.inflater: LayoutInflater val Context.inflater: LayoutInflater
@@ -176,3 +177,7 @@ fun Context.accentColor(): Int {
} }
return ContextCompat.getColor(this, color) return ContextCompat.getColor(this, color)
} }
fun Context.shouldUseWebAPI(): Boolean {
return Preferences.getBoolean(this, PREFERENCE_ADVANCED_USE_WEB_API)
}

View File

@@ -59,6 +59,7 @@ object Preferences {
const val PREFERENCE_UPDATES_CHECK = "PREFERENCE_UPDATES_CHECK" const val PREFERENCE_UPDATES_CHECK = "PREFERENCE_UPDATES_CHECK"
const val PREFERENCE_ADVANCED_SEARCH_IN_CTT = "PREFERENCE_ADVANCED_SEARCH_IN_CTT" const val PREFERENCE_ADVANCED_SEARCH_IN_CTT = "PREFERENCE_ADVANCED_SEARCH_IN_CTT"
const val PREFERENCE_ADVANCED_USE_WEB_API = "PREFERENCE_ADVANCED_USE_WEB_API"
const val PREFERENCE_UNIQUE_GROUP_IDS = "PREFERENCE_UNIQUE_GROUP_IDS" const val PREFERENCE_UNIQUE_GROUP_IDS = "PREFERENCE_UNIQUE_GROUP_IDS"

View File

@@ -20,17 +20,21 @@
package com.aurora.store.viewmodel.search package com.aurora.store.viewmodel.search
import android.app.Application import android.app.Application
import android.content.Context
import android.util.Log import android.util.Log
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.aurora.extensions.flushAndAdd import com.aurora.extensions.flushAndAdd
import com.aurora.extensions.shouldUseWebAPI
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.SearchHelper
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.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 java.util.UUID
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.supervisorScope import kotlinx.coroutines.supervisorScope
@@ -45,6 +49,8 @@ class SearchResultViewModel(application: Application) : BaseAndroidViewModel(app
private val searchHelper: SearchHelper = SearchHelper(authData) private val searchHelper: SearchHelper = SearchHelper(authData)
.using(HttpClient.getPreferredClient()) .using(HttpClient.getPreferredClient())
private val webSearchHelper = WebSearchHelper()
val liveData: MutableLiveData<SearchBundle> = MutableLiveData() val liveData: MutableLiveData<SearchBundle> = MutableLiveData()
private var searchBundle: SearchBundle = SearchBundle() private var searchBundle: SearchBundle = SearchBundle()
@@ -69,7 +75,17 @@ class SearchResultViewModel(application: Application) : BaseAndroidViewModel(app
private fun search( private fun search(
query: String query: String
): SearchBundle { ): SearchBundle {
return searchHelper.searchResults(query) return if ((getApplication() as Context).shouldUseWebAPI()) {
val result = webSearchHelper.searchResults(query)
val searchBundle = SearchBundle().apply {
this.id = 100
this.query = query
appList = result.values.flatten().toSet().toMutableList()
}
return searchBundle
} else {
searchHelper.searchResults(query)
}
} }
@Synchronized @Synchronized

View File

@@ -20,12 +20,15 @@
package com.aurora.store.viewmodel.search package com.aurora.store.viewmodel.search
import android.app.Application import android.app.Application
import android.content.Context
import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.aurora.extensions.shouldUseWebAPI
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.SearchHelper
import com.aurora.gplayapi.helpers.WebSearchSuggestionHelper
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.data.providers.AuthProvider
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@@ -40,6 +43,8 @@ class SearchSuggestionViewModel(application: Application) : AndroidViewModel(app
private val searchHelper: SearchHelper = SearchHelper(authData) private val searchHelper: SearchHelper = SearchHelper(authData)
.using(HttpClient.getPreferredClient()) .using(HttpClient.getPreferredClient())
private val webSearchSuggestionHelper = WebSearchSuggestionHelper()
val liveSearchSuggestions: MutableLiveData<List<SearchSuggestEntry>> = MutableLiveData() val liveSearchSuggestions: MutableLiveData<List<SearchSuggestEntry>> = MutableLiveData()
fun observeStreamBundles(query: String) { fun observeStreamBundles(query: String) {
@@ -51,6 +56,10 @@ 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 if ((getApplication() as Context).shouldUseWebAPI()) {
webSearchSuggestionHelper.searchSuggestions(query)
} else {
searchHelper.searchSuggestions(query)
}
} }
} }

View File

@@ -251,6 +251,8 @@
<string name="pref_updates_extended_desc">Looks for new versions of disabled apps too</string> <string name="pref_updates_extended_desc">Looks for new versions of disabled apps too</string>
<string name="pref_advanced_search_in_ctt">Search in Custom Tab</string> <string name="pref_advanced_search_in_ctt">Search in Custom Tab</string>
<string name="pref_advanced_search_in_ctt_desc">Opens search results in a browser\'s custom tab</string> <string name="pref_advanced_search_in_ctt_desc">Opens search results in a browser\'s custom tab</string>
<string name="pref_advanced_use_web_api">Use Web APIs</string>
<string name="pref_advanced_use_web_api_desc">Switches to Web APIs wherever possible when making a request to Google Play (Increases anonymity, but can be unstable).</string>
<string name="purchase_failed">"Download Failed"</string> <string name="purchase_failed">"Download Failed"</string>
<string name="purchase_invalid">"App not purchased"</string> <string name="purchase_invalid">"App not purchased"</string>
<string name="purchase_unsupported">"App not supported"</string> <string name="purchase_unsupported">"App not supported"</string>

View File

@@ -8,4 +8,11 @@
app:summary="@string/pref_advanced_search_in_ctt_desc" app:summary="@string/pref_advanced_search_in_ctt_desc"
app:title="@string/pref_advanced_search_in_ctt" /> app:title="@string/pref_advanced_search_in_ctt" />
<SwitchPreferenceCompat
app:defaultValue="false"
app:iconSpaceReserved="false"
app:key="PREFERENCE_ADVANCED_USE_WEB_API"
app:summary="@string/pref_advanced_use_web_api_desc"
app:title="@string/pref_advanced_use_web_api" />
</PreferenceScreen> </PreferenceScreen>