Skip to content

Commit

Permalink
feat: add toggle for "open apps automatically" (#236)
Browse files Browse the repository at this point in the history
Co-authored-by: Joscha Loos <j.loos@posteo.net>
  • Loading branch information
HeCodes2Much and jooooscha committed Dec 19, 2022
1 parent 7b3ca5c commit 4832b10
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/app/olaunchercf/data/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ private const val FIRST_SETTINGS_OPEN = "FIRST_SETTINGS_OPEN"
private const val LOCK_MODE = "LOCK_MODE"
private const val HOME_APPS_NUM = "HOME_APPS_NUM"
private const val AUTO_SHOW_KEYBOARD = "AUTO_SHOW_KEYBOARD"
private const val AUTO_OPEN_APP = "AUTO_OPEN_APP"
private const val HOME_ALIGNMENT = "HOME_ALIGNMENT"
private const val HOME_ALIGNMENT_BOTTOM = "HOME_ALIGNMENT_BOTTOM"
private const val HOME_CLICK_AREA = "HOME_CLICK_AREA"
Expand Down Expand Up @@ -72,6 +73,10 @@ class Prefs(val context: Context) {
get() = prefs.getBoolean(AUTO_SHOW_KEYBOARD, true)
set(value) = prefs.edit().putBoolean(AUTO_SHOW_KEYBOARD, value).apply()

var autoOpenApp: Boolean
get() = prefs.getBoolean(AUTO_OPEN_APP, true)
set(value) = prefs.edit().putBoolean(AUTO_OPEN_APP, value).apply()

var homeAppsNum: Int
get() {
return try {
Expand Down
17 changes: 12 additions & 5 deletions app/src/main/java/app/olaunchercf/ui/AppDrawerAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AppDrawerAdapter(
private val appRenameListener: (String, String) -> Unit
) : RecyclerView.Adapter<AppDrawerAdapter.ViewHolder>(), Filterable {

private lateinit var prefs: Prefs
private var appFilter = createAppFilter()
var appsList: MutableList<AppModel> = mutableListOf()
var appFilteredList: MutableList<AppModel> = mutableListOf()
Expand All @@ -44,7 +45,8 @@ class AppDrawerAdapter(

binding = AdapterAppDrawerBinding.inflate(LayoutInflater.from(parent.context), parent, false)
//val view = binding.root
binding.appTitle.textSize = Prefs(parent.context).textSize.toFloat()
prefs = Prefs(parent.context)
binding.appTitle.textSize = prefs.textSize.toFloat()

return ViewHolder(binding)
}
Expand All @@ -69,11 +71,16 @@ class AppDrawerAdapter(
appRenameListener(appModel.appPackage, appModel.appAlias)
}

try { // Automatically open the app when there's only one search result
if ((itemCount == 1) and (flag == AppDrawerFlag.LaunchApp))
// open app if only one app matches
val lastMatch = itemCount == 1
val openApp = flag == AppDrawerFlag.LaunchApp
val autoOpenApp = prefs.autoOpenApp
if (lastMatch && openApp && autoOpenApp) {
try {
clickListener(appFilteredList[position])
} catch (e: Exception) {

} catch (e: Exception) {
e.printStackTrace()
}
}
}

Expand Down
30 changes: 23 additions & 7 deletions app/src/main/java/app/olaunchercf/ui/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ class SettingsFragment : Fragment() {
title = stringResource(R.string.appearance),
selected = selected,
items = arrayOf(
{ _, onChange ->
SettingsToggle(
title = stringResource(R.string.auto_show_keyboard),
onChange = onChange,
state = remember { mutableStateOf(prefs.autoShowKeyboard) },
) { toggleKeyboardText() }
},
{ _, onChange ->
SettingsToggle(
title = stringResource(R.string.status_bar),
Expand Down Expand Up @@ -175,6 +168,25 @@ class SettingsFragment : Fragment() {
}
)
)
SettingsArea(title = stringResource(R.string.behavior),
selected = selected,
items = arrayOf(
{ _, onChange ->
SettingsToggle(
title = stringResource(R.string.auto_show_keyboard),
onChange = onChange,
state = remember { mutableStateOf(prefs.autoShowKeyboard) },
) { toggleKeyboardText() }
},
{ _, onChange ->
SettingsToggle(
title = stringResource(R.string.auto_open_apps),
onChange = onChange,
state = remember { mutableStateOf(prefs.autoOpenApp) },
) { toggleAutoOpenApp() }
},
)
)
SettingsArea(title = stringResource(R.string.homescreen),
selected = selected,
items = arrayOf(
Expand Down Expand Up @@ -422,6 +434,10 @@ class SettingsFragment : Fragment() {
prefs.autoShowKeyboard = !prefs.autoShowKeyboard
}

private fun toggleAutoOpenApp() {
prefs.autoOpenApp = !prefs.autoOpenApp
}

private fun setTheme(appTheme: Constants.Theme) {
// if (AppCompatDelegate.getDefaultNightMode() == appTheme) return // TODO find out what this did
prefs.appTheme = appTheme
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<string name="extend_home_apps_area">Extend clickable area on home apps</string>
<string name="appearance">Appearance</string>
<string name="gestures">Gestures</string>
<string name="behavior">Behavior</string>
<string name="homescreen">Homescreen</string>
<string name="alignment">Alignment</string>
<string name="theme_mode">Theme mode</string>
Expand All @@ -76,6 +77,7 @@
<string name="drawer_list_empty_hint">No apps found</string>

<string name="hidden_apps">Hidden apps</string>
<string name="auto_open_apps">Auto open apps</string>

<string name="show">Show</string>
<string name="reset">Reset</string>
Expand Down

0 comments on commit 4832b10

Please sign in to comment.