Add preference to open custom tab for searching apps

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2023-05-03 20:20:33 +05:30
parent 614f367977
commit 6b2f22350c
7 changed files with 74 additions and 9 deletions

View File

@@ -41,6 +41,8 @@ object Constants {
const val URL_DISPENSER = "https://auroraoss.com/api/auth"
const val PLAY_QUERY_URL = "https://play.google.com/store/search?q="
//ACCOUNTS
const val ACCOUNT_SIGNED_IN = "ACCOUNT_SIGNED_IN"
const val ACCOUNT_SIGNED_TIMESTAMP = "ACCOUNT_SIGNED_TIMESTAMP"
@@ -51,4 +53,4 @@ object Constants {
const val PAGE_TYPE = "PAGE_TYPE"
const val TOP_CHART_TYPE = "TOP_CHART_TYPE"
const val TOP_CHART_CATEGORY = "TOP_CHART_CATEGORY"
}
}

View File

@@ -36,12 +36,14 @@ import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.app.ActivityOptionsCompat
import androidx.core.app.ShareCompat
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap
import com.aurora.Constants
import com.aurora.gplayapi.data.models.App
import com.aurora.store.MainActivity
import com.aurora.store.R
import com.aurora.store.util.Log
import com.aurora.store.util.Preferences
import com.aurora.store.view.ui.details.AppDetailsActivity
import kotlin.system.exitProcess
val Context.inflater: LayoutInflater
@@ -50,11 +52,26 @@ val Context.inflater: LayoutInflater
val Context.displayMetrics: DisplayMetrics
get() = resources.displayMetrics
fun Context.browse(url: String) {
fun Context.browse(url: String, showOpenInAuroraAction: Boolean = false) {
try {
CustomTabsIntent.Builder()
.build()
.launchUrl(this, Uri.parse(url))
val customTabsIntent = CustomTabsIntent.Builder()
if (showOpenInAuroraAction) {
val icon =
ContextCompat.getDrawable(this, R.drawable.ic_open_in_new)?.toBitmap()
val pendingIntent = PendingIntent.getActivity(
this,
0,
Intent(this, AppDetailsActivity::class.java),
PendingIntent.FLAG_MUTABLE
)
customTabsIntent.setActionButton(
icon!!,
this.getString(R.string.open_in_aurora),
pendingIntent,
true
)
}
customTabsIntent.build().launchUrl(this, Uri.parse(url))
} catch (e: Exception) {
Log.e(e.message)
}

View File

@@ -59,6 +59,8 @@ object Preferences {
const val PREFERENCE_UPDATES_EXTENDED = "PREFERENCE_UPDATES_EXTENDED"
const val PREFERENCE_ADVANCED_SEARCH_IN_CTT = "PREFERENCE_ADVANCED_SEARCH_IN_CTT"
const val PREFERENCE_UNIQUE_GROUP_IDS = "PREFERENCE_UNIQUE_GROUP_IDS"
private var prefs: SharedPreferences? = null

View File

@@ -28,12 +28,14 @@ import android.view.inputmethod.EditorInfo
import android.widget.TextView
import androidx.lifecycle.ViewModelProvider
import com.aurora.Constants
import com.aurora.extensions.browse
import com.aurora.extensions.close
import com.aurora.extensions.getEmptyActivityBundle
import com.aurora.extensions.open
import com.aurora.extensions.showKeyboard
import com.aurora.gplayapi.SearchSuggestEntry
import com.aurora.store.databinding.ActivitySearchSuggestionBinding
import com.aurora.store.util.Preferences
import com.aurora.store.view.epoxy.views.SearchSuggestionViewModel_
import com.aurora.store.view.ui.commons.BaseActivity
import com.aurora.store.view.ui.downloads.DownloadActivity
@@ -149,8 +151,12 @@ class SearchSuggestionActivity : BaseActivity() {
}
private fun search(query: String) {
val intent = Intent(this, SearchResultsActivity::class.java)
intent.putExtra(Constants.STRING_EXTRA, query)
startActivity(intent, getEmptyActivityBundle())
if (Preferences.getBoolean(this, Preferences.PREFERENCE_ADVANCED_SEARCH_IN_CTT)) {
this.browse("${Constants.PLAY_QUERY_URL}$query", true)
} else {
val intent = Intent(this, SearchResultsActivity::class.java)
intent.putExtra(Constants.STRING_EXTRA, query)
startActivity(intent, getEmptyActivityBundle())
}
}
}

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2023, Google LLC
~
~ Aurora Store is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 2 of the License, or
~ (at your option) any later version.
~
~ Aurora Store is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with Aurora Store. If not, see <http://www.gnu.org/licenses/>.
~
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M180,840Q156,840 138,822Q120,804 120,780L120,180Q120,156 138,138Q156,120 180,120L459,120L459,180L180,180Q180,180 180,180Q180,180 180,180L180,780Q180,780 180,780Q180,780 180,780L780,780Q780,780 780,780Q780,780 780,780L780,501L840,501L840,780Q840,804 822,822Q804,840 780,840L180,840ZM382,621L340,578L738,180L519,180L519,120L840,120L840,441L780,441L780,223L382,621Z"/>
</vector>

View File

@@ -315,6 +315,8 @@
<string name="pref_ui_similar_apps_desc">"Display similar and related clusters on app details page"</string>
<string name="pref_updates_extended">Extended updates</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_desc">Opens search results in a browser\'s custom tab</string>
<string name="purchase_failed">"Download Failed"</string>
<string name="purchase_invalid">"App not purchased"</string>
<string name="purchase_unsupported">"App not supported"</string>
@@ -406,4 +408,5 @@
<string name="error">An error occurred!</string>
<string name="menu">Menu</string>
<string name="expand">Expand</string>
<string name="open_in_aurora">Open in Aurora Store</string>
</resources>

View File

@@ -1,4 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreferenceCompat
app:defaultValue="false"
app:iconSpaceReserved="false"
app:key="PREFERENCE_ADVANCED_SEARCH_IN_CTT"
app:summary="@string/pref_advanced_search_in_ctt_desc"
app:title="@string/pref_advanced_search_in_ctt" />
</PreferenceScreen>