Added an optional confirmation dialog for launching apps.

This commit is contained in:
ottoptj 2024-12-22 05:33:59 +02:00
commit f8da87afef
7 changed files with 47 additions and 4 deletions

View file

@ -1189,7 +1189,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
println(leftSwipeActivity)
if (leftSwipeActivity.first != null && leftSwipeActivity.second != null) {
canLaunchShortcut = false
launcherApps.startMainActivity(leftSwipeActivity.first!!.componentName, launcherApps.profiles[leftSwipeActivity.second!!], null, null)
appUtils.launchApp(leftSwipeActivity.first!!.componentName, launcherApps.profiles[leftSwipeActivity.second!!])
} else {
Toast.makeText(this@MainActivity, getString(R.string.launch_error), Toast.LENGTH_SHORT).show()
}
@ -1200,7 +1200,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
else if (deltaX > 0 && abs(deltaX) > swipeThreshold && abs(velocityX) > swipeVelocityThreshold && sharedPreferenceManager.isGestureEnabled("right")) {
if (rightSwipeActivity.first != null && rightSwipeActivity.second != null) {
canLaunchShortcut = false
launcherApps.startMainActivity(rightSwipeActivity.first!!.componentName, launcherApps.profiles[rightSwipeActivity.second!!], null, null)
appUtils.launchApp(rightSwipeActivity.first!!.componentName, launcherApps.profiles[rightSwipeActivity.second!!])
} else {
Toast.makeText(this@MainActivity, getString(R.string.launch_error), Toast.LENGTH_SHORT).show()
}

View file

@ -67,6 +67,10 @@ class SharedPreferenceManager (private val context: Context) {
return preferences.getString("swipeVelocity", "100")?.toInt() ?: 100
}
fun isConfirmationEnabled(): Boolean {
return preferences.getBoolean("enableConfirmation", false)
}
// Home Screen
fun isClockEnabled(): Boolean {
return preferences.getBoolean("clockEnabled", true)

View file

@ -1,11 +1,14 @@
package eu.ottop.yamlauncher.utils
import android.app.AlertDialog
import android.content.ComponentName
import android.content.Context
import android.content.pm.ApplicationInfo
import android.content.pm.LauncherActivityInfo
import android.content.pm.LauncherApps
import android.os.UserHandle
import androidx.core.content.ContextCompat.getString
import eu.ottop.yamlauncher.R
import eu.ottop.yamlauncher.settings.SharedPreferenceManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
@ -83,7 +86,31 @@ class AppUtils(private val context: Context, private val launcherApps: LauncherA
}
}
fun launchApp(componentName: ComponentName, userHandle: UserHandle) {
private fun startApp(componentName: ComponentName, userHandle: UserHandle) {
launcherApps.startMainActivity(componentName, userHandle, null, null)
}
fun launchApp(componentName: ComponentName, userHandle: UserHandle) {
if (sharedPreferenceManager.isConfirmationEnabled()) {
showConfirmationDialog(componentName, userHandle)
} else {
startApp(componentName, userHandle)
}
}
private fun showConfirmationDialog(componentName: ComponentName, userHandle: UserHandle) {
AlertDialog.Builder(context).apply {
setTitle(getString(context, R.string.confirm_title))
setMessage(getString(context, R.string.launch_confirmation_text))
setPositiveButton(getString(context, R.string.confirm_yes)) { _, _ ->
startApp(componentName, userHandle)
}
setNegativeButton(getString(context, R.string.confirm_no)) { _, _ ->
}
}.create().show()
}
}

View file

@ -71,6 +71,8 @@
<string name="swipe_threshold">Schwellenwert für Wischen</string>
<string name="swipe_velocity_threshold">Schwellenwert für Wischgeschwindigkeit</string>
<string name="show_status_bar">Statusleiste anzeigen</string>
<string name="enable_confirmation">App-Bestätigungsdialog</string>
<string name="launch_confirmation_text">Sind Sie sicher, dass Sie diese Anwendung starten möchten?</string>
<string name="home_settings_title">Startbildschirmeinstellungen</string>
<string name="home_settings_text">Startbildschirm</string>

View file

@ -69,6 +69,8 @@
<string name="swipe_threshold">Pyyhkäisyn Kynnysarvo</string>
<string name="swipe_velocity_threshold">Pyyhkäisyn Nopeuden Kynnysarvo</string>
<string name="show_status_bar">Näytä Tilapalkki</string>
<string name="enable_confirmation">Vahvistus Sovellusta Avatessa</string>
<string name="launch_confirmation_text">Oletko varma, että haluat avata tämän sovelluksen?</string>
<string name="home_settings_title">Kotinäytön Asetukset</string>
<string name="home_settings_text">Kotinäyttö</string>

View file

@ -71,6 +71,8 @@
<string name="swipe_threshold">Swipe Threshold</string>
<string name="swipe_velocity_threshold">Swipe Velocity Threshold</string>
<string name="show_status_bar">Show Status Bar</string>
<string name="enable_confirmation">App Confirmation Dialog</string>
<string name="launch_confirmation_text">Are you sure you want to launch this app?</string>
<string name="home_settings_title">Home Screen Settings</string>
<string name="home_settings_text">Home Screen</string>

View file

@ -80,6 +80,12 @@
android:defaultValue="false"
android:title="@string/show_status_bar"
app:key="barVisibility" />
<SwitchPreference
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:defaultValue="false"
android:title="@string/enable_confirmation"
app:key="enableConfirmation" />
</PreferenceCategory>
</PreferenceScreen>