Feat: Added extra search engines to the settings.
Signed-off-by: HeCodes2Much <wayne6324@gmail.com>
This commit is contained in:
@@ -52,12 +52,20 @@ android {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_17.toString()
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose = true
|
||||
viewBinding = true
|
||||
dataBinding = true
|
||||
buildConfig = true
|
||||
}
|
||||
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = "1.4.3"
|
||||
}
|
||||
|
||||
applicationVariants.all {
|
||||
@@ -99,6 +107,8 @@ dependencies {
|
||||
implementation(libs.biometric.ktx)
|
||||
implementation(libs.room.ktx)
|
||||
implementation(libs.room.runtime)
|
||||
implementation(libs.androidx.runtime.android)
|
||||
implementation(libs.androidx.ui.android)
|
||||
|
||||
//noinspection KaptUsageInsteadOfKsp
|
||||
kapt(libs.room.compiler)
|
||||
|
||||
@@ -37,6 +37,7 @@ import androidx.lifecycle.LifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.github.droidworksstudio.launcher.Constants
|
||||
import com.github.droidworksstudio.launcher.data.entities.AppInfo
|
||||
import com.github.droidworksstudio.launcher.helper.PreferenceHelper
|
||||
import com.github.droidworksstudio.launcher.ui.activities.FakeHomeActivity
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
@@ -290,8 +291,37 @@ fun Context.searchOnPlayStore(query: String? = null): Boolean {
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.searchCustomSearchEngine(searchQuery: String? = null): Boolean {
|
||||
val searchUrl = Constants.URL_GOOGLE_SEARCH
|
||||
fun Context.searchCustomSearchEngine(
|
||||
preferenceHelper: PreferenceHelper,
|
||||
searchQuery: String? = null
|
||||
): Boolean {
|
||||
|
||||
val searchUrl = when (preferenceHelper.searchEngines) {
|
||||
Constants.SearchEngines.Google -> {
|
||||
Constants.URL_GOOGLE_SEARCH
|
||||
}
|
||||
|
||||
Constants.SearchEngines.Yahoo -> {
|
||||
Constants.URL_YAHOO_SEARCH
|
||||
}
|
||||
|
||||
Constants.SearchEngines.DuckDuckGo -> {
|
||||
Constants.URL_DUCK_SEARCH
|
||||
}
|
||||
|
||||
Constants.SearchEngines.Bing -> {
|
||||
Constants.URL_BING_SEARCH
|
||||
}
|
||||
|
||||
Constants.SearchEngines.Brave -> {
|
||||
Constants.URL_BRAVE_SEARCH
|
||||
}
|
||||
|
||||
Constants.SearchEngines.SwissCow -> {
|
||||
Constants.URL_SWISSCOW_SEARCH
|
||||
}
|
||||
}
|
||||
|
||||
val encodedQuery = Uri.encode(searchQuery)
|
||||
val fullUrl = "$searchUrl$encodedQuery"
|
||||
Log.d("fullUrl", fullUrl)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.github.droidworksstudio.launcher
|
||||
|
||||
import android.content.Context
|
||||
|
||||
object Constants {
|
||||
const val PACKAGE_NAME = "app.easy.launcher"
|
||||
const val PACKAGE_NAME_DEBUG = "$PACKAGE_NAME.debug"
|
||||
@@ -53,6 +55,7 @@ object Constants {
|
||||
|
||||
const val TOGGLE_SETTING_LOCK = "TOGGLE_SETTING_LOCK"
|
||||
|
||||
const val SEARCH_ENGINE = "SEARCH_ENGINE"
|
||||
const val URL_DUCK_SEARCH = "https://duckduckgo.com/?q="
|
||||
const val URL_GOOGLE_SEARCH = "https://google.com/search?q="
|
||||
const val URL_YAHOO_SEARCH = "https://search.yahoo.com/search?p="
|
||||
@@ -65,4 +68,24 @@ object Constants {
|
||||
const val APP_WIDGET_HOST_ID = 1024
|
||||
const val TRIPLE_TAP_DELAY_MS = 300
|
||||
const val LONG_PRESS_DELAY_MS = 500
|
||||
|
||||
enum class SearchEngines {
|
||||
Google,
|
||||
Yahoo,
|
||||
DuckDuckGo,
|
||||
Bing,
|
||||
Brave,
|
||||
SwissCow;
|
||||
|
||||
fun getString(context: Context): String {
|
||||
return when (this) {
|
||||
Google -> context.getString(R.string.search_google)
|
||||
Yahoo -> context.getString(R.string.search_yahoo)
|
||||
DuckDuckGo -> context.getString(R.string.search_duckduckgo)
|
||||
Bing -> context.getString(R.string.search_bing)
|
||||
Brave -> context.getString(R.string.search_brave)
|
||||
SwissCow -> context.getString(R.string.search_swisscow)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,19 +16,20 @@ import android.view.Window
|
||||
import android.view.WindowInsets
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.widget.LinearLayoutCompat
|
||||
import androidx.fragment.app.viewModels
|
||||
import com.github.droidworksstudio.ktx.backupSharedPreferences
|
||||
import com.github.droidworksstudio.ktx.restoreSharedPreferences
|
||||
//import com.github.droidworksstudio.ktx.backupSharedPreferences
|
||||
//import com.github.droidworksstudio.ktx.restoreSharedPreferences
|
||||
import com.github.droidworksstudio.ktx.showLongToast
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.github.droidworksstudio.launcher.Constants
|
||||
import com.github.droidworksstudio.launcher.R
|
||||
import com.github.droidworksstudio.launcher.accessibility.ActionService
|
||||
import com.github.droidworksstudio.launcher.viewmodel.PreferenceViewModel
|
||||
import java.util.Calendar
|
||||
import javax.inject.Inject
|
||||
|
||||
class AppHelper @Inject constructor() {
|
||||
|
||||
@SuppressLint("WrongConstant", "PrivateApi")
|
||||
fun expandNotificationDrawer(context: Context) {
|
||||
try {
|
||||
|
||||
@@ -84,7 +84,7 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
|
||||
|
||||
var homeDailyWordAlignment: Int
|
||||
get() = prefs.getInt(Constants.HOME_DAILY_WORD_ALIGNMENT, Gravity.START)
|
||||
set(value) = prefs.edit().putInt(Constants.HOME_DAILY_WORD_ALIGNMENT,value).apply()
|
||||
set(value) = prefs.edit().putInt(Constants.HOME_DAILY_WORD_ALIGNMENT, value).apply()
|
||||
|
||||
var batteryTextSize: Float
|
||||
get() = prefs.getFloat(Constants.BATTERY_TEXT_SIZE, 12f)
|
||||
@@ -121,4 +121,19 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
|
||||
var swipeSearch: Boolean
|
||||
get() = prefs.getBoolean(Constants.SWIPE_SEARCH, false)
|
||||
set(value) = prefs.edit().putBoolean(Constants.SWIPE_SEARCH, value).apply()
|
||||
|
||||
var searchEngines: Constants.SearchEngines
|
||||
get() {
|
||||
return try {
|
||||
Constants.SearchEngines.valueOf(
|
||||
prefs.getString(
|
||||
Constants.SEARCH_ENGINE,
|
||||
Constants.SearchEngines.Google.name
|
||||
).toString()
|
||||
)
|
||||
} catch (_: Exception) {
|
||||
Constants.SearchEngines.Google
|
||||
}
|
||||
}
|
||||
set(value) = prefs.edit().putString(Constants.SEARCH_ENGINE, value.name).apply()
|
||||
}
|
||||
@@ -125,7 +125,7 @@ class DrawFragment : Fragment(),
|
||||
if (trimmedQuery.isNotEmpty()) {
|
||||
if (trimmedQuery.startsWith("!")) {
|
||||
val searchQuery = trimmedQuery.substringAfter("!")
|
||||
requireContext().searchCustomSearchEngine(searchQuery)
|
||||
requireContext().searchCustomSearchEngine(preferenceHelper, searchQuery)
|
||||
} else {
|
||||
checkAppThenRun(trimmedQuery)
|
||||
return true // Exit the function
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.navigation.NavController
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.github.droidworksstudio.ktx.resetDefaultLauncher
|
||||
import com.github.droidworksstudio.ktx.restartApp
|
||||
import com.github.droidworksstudio.launcher.Constants
|
||||
import com.github.droidworksstudio.launcher.R
|
||||
import com.github.droidworksstudio.launcher.databinding.FragmentSettingsBinding
|
||||
import com.github.droidworksstudio.launcher.helper.AppHelper
|
||||
@@ -24,6 +25,7 @@ import com.github.droidworksstudio.launcher.ui.bottomsheetdialog.ColorBottomShee
|
||||
import com.github.droidworksstudio.launcher.ui.bottomsheetdialog.PaddingBottomSheetDialogFragment
|
||||
import com.github.droidworksstudio.launcher.ui.bottomsheetdialog.TextBottomSheetDialogFragment
|
||||
import com.github.droidworksstudio.launcher.viewmodel.PreferenceViewModel
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import javax.inject.Inject
|
||||
|
||||
@@ -76,6 +78,9 @@ class SettingsFragment : Fragment(),
|
||||
getString(R.string.app_name),
|
||||
packageInfo.versionName
|
||||
)
|
||||
|
||||
val searchEngine = preferenceHelper.searchEngines.toString()
|
||||
binding.searchEngineText.text = searchEngine
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@@ -138,6 +143,10 @@ class SettingsFragment : Fragment(),
|
||||
bottomSheetFragment.show(parentFragmentManager, "BottomSheetDialog")
|
||||
}
|
||||
|
||||
binding.miscellaneousSearchEngine.setOnClickListener {
|
||||
showSearchEngineDialog()
|
||||
}
|
||||
|
||||
binding.shareView.setOnClickListener {
|
||||
appHelper.shareAppButton(requireContext())
|
||||
}
|
||||
@@ -161,6 +170,7 @@ class SettingsFragment : Fragment(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun setupSwitchListeners() {
|
||||
binding.statueBarSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
|
||||
preferenceViewModel.setShowStatusBar(isChecked)
|
||||
@@ -234,4 +244,51 @@ class SettingsFragment : Fragment(),
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun showSearchEngineDialog() {
|
||||
// Get the array of SearchEngines enum values
|
||||
val items = Constants.SearchEngines.values()
|
||||
|
||||
// Map the enum values to their string representations
|
||||
val itemStrings = items.map { it.getString(context) }.toTypedArray()
|
||||
|
||||
val dialog = MaterialAlertDialogBuilder(context)
|
||||
|
||||
dialog.setTitle("Select a Search Engine")
|
||||
dialog.setItems(itemStrings) { _, which ->
|
||||
val selectedItem = items[which]
|
||||
when (selectedItem) {
|
||||
Constants.SearchEngines.Google -> {
|
||||
preferenceViewModel.setSearchEngine(Constants.SearchEngines.Google)
|
||||
binding.searchEngineText.text = preferenceHelper.searchEngines.name
|
||||
}
|
||||
|
||||
Constants.SearchEngines.Bing -> {
|
||||
preferenceViewModel.setSearchEngine(Constants.SearchEngines.Bing)
|
||||
binding.searchEngineText.text = preferenceHelper.searchEngines.name
|
||||
}
|
||||
|
||||
Constants.SearchEngines.Brave -> {
|
||||
preferenceViewModel.setSearchEngine(Constants.SearchEngines.Brave)
|
||||
binding.searchEngineText.text = preferenceHelper.searchEngines.name
|
||||
}
|
||||
|
||||
Constants.SearchEngines.Yahoo -> {
|
||||
preferenceViewModel.setSearchEngine(Constants.SearchEngines.Yahoo)
|
||||
binding.searchEngineText.text = preferenceHelper.searchEngines.name
|
||||
}
|
||||
|
||||
Constants.SearchEngines.DuckDuckGo -> {
|
||||
preferenceViewModel.setSearchEngine(Constants.SearchEngines.DuckDuckGo)
|
||||
binding.searchEngineText.text = preferenceHelper.searchEngines.name
|
||||
}
|
||||
|
||||
Constants.SearchEngines.SwissCow -> {
|
||||
preferenceViewModel.setSearchEngine(Constants.SearchEngines.SwissCow)
|
||||
binding.searchEngineText.text = preferenceHelper.searchEngines.name
|
||||
}
|
||||
}
|
||||
}
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,15 @@ package com.github.droidworksstudio.launcher.viewmodel
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.github.droidworksstudio.launcher.Constants
|
||||
import com.github.droidworksstudio.launcher.helper.PreferenceHelper
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class PreferenceViewModel @Inject constructor(
|
||||
private val preferenceHelper: PreferenceHelper)
|
||||
: ViewModel() {
|
||||
private val preferenceHelper: PreferenceHelper
|
||||
) : ViewModel() {
|
||||
|
||||
private val firstLaunchLiveData: MutableLiveData<Boolean> = MutableLiveData()
|
||||
val showStatusBarLiveData: MutableLiveData<Boolean> = MutableLiveData()
|
||||
@@ -39,6 +40,8 @@ class PreferenceViewModel @Inject constructor(
|
||||
private val lockSettingsLiveData: MutableLiveData<Boolean> = MutableLiveData()
|
||||
private val appPaddingSizeLiveData: MutableLiveData<Float> = MutableLiveData()
|
||||
|
||||
private val searchEngineLiveData: MutableLiveData<Constants.SearchEngines> = MutableLiveData()
|
||||
|
||||
fun setFirstLaunch(firstLaunch: Boolean) {
|
||||
preferenceHelper.firstLaunch = firstLaunch
|
||||
firstLaunchLiveData.postValue(preferenceHelper.firstLaunch)
|
||||
@@ -59,7 +62,7 @@ class PreferenceViewModel @Inject constructor(
|
||||
showDateLiveData.postValue(preferenceHelper.showDate)
|
||||
}
|
||||
|
||||
fun setShowBattery(showBattery: Boolean){
|
||||
fun setShowBattery(showBattery: Boolean) {
|
||||
preferenceHelper.showBattery = showBattery
|
||||
showBatteryLiveData.postValue(preferenceHelper.showBattery)
|
||||
}
|
||||
@@ -94,7 +97,7 @@ class PreferenceViewModel @Inject constructor(
|
||||
timeColorLiveData.postValue(preferenceHelper.timeColor)
|
||||
}
|
||||
|
||||
fun setBatteryColor(batteryColor: Int){
|
||||
fun setBatteryColor(batteryColor: Int) {
|
||||
preferenceHelper.batteryColor = batteryColor
|
||||
batteryColorLiveData.postValue(preferenceHelper.batteryColor)
|
||||
}
|
||||
@@ -144,33 +147,38 @@ class PreferenceViewModel @Inject constructor(
|
||||
appPaddingSizeLiveData.postValue(preferenceHelper.homeAppPadding)
|
||||
}
|
||||
|
||||
fun setDoubleTapLock(tapLockScreen: Boolean){
|
||||
fun setDoubleTapLock(tapLockScreen: Boolean) {
|
||||
preferenceHelper.tapLockScreen = tapLockScreen
|
||||
tapLockScreenLiveData.postValue((preferenceHelper.tapLockScreen))
|
||||
}
|
||||
|
||||
fun setSwipeNotification(swipeNotification: Boolean){
|
||||
fun setSwipeNotification(swipeNotification: Boolean) {
|
||||
preferenceHelper.swipeNotification = swipeNotification
|
||||
swipeNotificationLiveData.postValue((preferenceHelper.swipeNotification))
|
||||
}
|
||||
|
||||
fun setSwipeSearch(swipeSearch: Boolean){
|
||||
fun setSwipeSearch(swipeSearch: Boolean) {
|
||||
preferenceHelper.swipeSearch = swipeSearch
|
||||
swipeSearchLiveData.postValue((preferenceHelper.swipeSearch))
|
||||
}
|
||||
|
||||
fun setAutoKeyboard(autoKeyboard: Boolean){
|
||||
fun setAutoKeyboard(autoKeyboard: Boolean) {
|
||||
preferenceHelper.automaticKeyboard = autoKeyboard
|
||||
autoKeyboardLiveData.postValue((preferenceHelper.automaticKeyboard))
|
||||
}
|
||||
|
||||
fun setAutoOpenApp(autoOpenApp: Boolean){
|
||||
fun setAutoOpenApp(autoOpenApp: Boolean) {
|
||||
preferenceHelper.automaticOpenApp = autoOpenApp
|
||||
autoOpenAppsLiveData.postValue((preferenceHelper.automaticOpenApp))
|
||||
}
|
||||
|
||||
fun setLockSettings(lockSettings: Boolean){
|
||||
fun setLockSettings(lockSettings: Boolean) {
|
||||
preferenceHelper.settingsLock = lockSettings
|
||||
lockSettingsLiveData.postValue((preferenceHelper.settingsLock))
|
||||
}
|
||||
|
||||
fun setSearchEngine(searchEngine: Constants.SearchEngines) {
|
||||
preferenceHelper.searchEngines = searchEngine
|
||||
searchEngineLiveData.postValue((preferenceHelper.searchEngines))
|
||||
}
|
||||
}
|
||||
@@ -680,6 +680,54 @@
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
tools:ignore="MissingConstraints">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="20dp"
|
||||
android:text="@string/settings_title_miscellaneous"
|
||||
android:textSize="@dimen/text_super_large"
|
||||
style="@style/TextDefaultStyle" />
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="20dp"
|
||||
android:orientation="horizontal"
|
||||
tools:ignore="MissingConstraints">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/miscellaneous_searchEngine"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="left|center"
|
||||
android:text="@string/settings_search_engine"
|
||||
android:textSize="@dimen/text_large"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:ignore="RtlHardcoded"
|
||||
style="@style/TextDefaultStyle" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/searchEngine_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="left|center"
|
||||
android:text="@string/search"
|
||||
android:textSize="@dimen/text_large"
|
||||
tools:ignore="RtlHardcoded"
|
||||
style="@style/TextDefaultStyle" />
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
<string name="settings_title_time_style">Time Style</string>
|
||||
<string name="settings_title_app_manager">App Manage</string>
|
||||
<string name="settings_title_gestures">Gestures</string>
|
||||
<string name="settings_title_miscellaneous">Miscellaneous</string>
|
||||
<string name="settings_title_backups">Backups</string>
|
||||
<string name="settings_title_others">Others</string>
|
||||
|
||||
@@ -79,6 +80,8 @@
|
||||
<string name="settings_swipe_down_notification">Swipe down expand notification</string>
|
||||
<string name="settings_swipe_up_search">Swipe up open search view</string>
|
||||
|
||||
<string name="settings_search_engine">Search Engine</string>
|
||||
|
||||
<string name="settings_others_share">Share</string>
|
||||
<string name="settings_others_feedback">Feedback</string>
|
||||
<string name="settings_others_github">Github</string>
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
[versions]
|
||||
agp = "8.4.1"
|
||||
kotlin = "2.0.0"
|
||||
kotlin = "1.8.10"
|
||||
coreKtx = "1.13.1"
|
||||
junit = "4.13.2"
|
||||
junitVersion = "1.1.5"
|
||||
espressoCore = "3.5.1"
|
||||
appcompat = "1.6.1"
|
||||
appcompat = "1.7.0"
|
||||
material = "1.12.0"
|
||||
constraintlayout = "2.1.4"
|
||||
navigation = "2.7.7"
|
||||
lifecycle = "2.8.0"
|
||||
lifecycle = "2.8.1"
|
||||
dagger = "2.51.1"
|
||||
work = "2.9.0"
|
||||
recyclerview = "1.3.2"
|
||||
@@ -17,6 +17,8 @@ preference = "1.2.1"
|
||||
room = "2.6.1"
|
||||
biometric = "1.2.0-alpha05"
|
||||
color-chooser = "0.7.3"
|
||||
runtimeAndroid = "1.6.7"
|
||||
uiAndroid = "1.6.7"
|
||||
|
||||
[libraries]
|
||||
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
@@ -46,6 +48,8 @@ dagger-hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", ve
|
||||
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
||||
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
||||
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
|
||||
androidx-runtime-android = { group = "androidx.compose.runtime", name = "runtime-android", version.ref = "runtimeAndroid" }
|
||||
androidx-ui-android = { group = "androidx.compose.ui", name = "ui-android", version.ref = "uiAndroid" }
|
||||
|
||||
|
||||
[plugins]
|
||||
|
||||
Reference in New Issue
Block a user