Skip to content

Commit 739d82d

Browse files
Feat: Added the ability to toggle settings.
1 parent d3d9001 commit 739d82d

File tree

3 files changed

+52
-22
lines changed

3 files changed

+52
-22
lines changed

app/src/main/java/com/github/droidworksstudio/mlauncher/MainActivity.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import android.view.KeyEvent
1414
import android.view.View
1515
import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
1616
import androidx.appcompat.app.AppCompatActivity
17+
import androidx.appcompat.app.AppCompatDelegate
1718
import androidx.lifecycle.ViewModelProvider
1819
import androidx.navigation.NavController
1920
import androidx.navigation.Navigation
@@ -98,6 +99,13 @@ class MainActivity : AppCompatActivity() {
9899
prefs = Prefs(this)
99100
migration = Migration(this)
100101

102+
val themeMode = when (prefs.appTheme) {
103+
Constants.Theme.Light -> AppCompatDelegate.MODE_NIGHT_NO
104+
Constants.Theme.Dark -> AppCompatDelegate.MODE_NIGHT_YES
105+
Constants.Theme.System -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
106+
}
107+
AppCompatDelegate.setDefaultNightMode(themeMode)
108+
101109
super.onCreate(savedInstanceState)
102110
binding = ActivityMainBinding.inflate(layoutInflater)
103111
val view = binding.root

app/src/main/java/com/github/droidworksstudio/mlauncher/ui/SettingsFragment.kt

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ class SettingsFragment : Fragment() {
172172
val typefaceMapFonts: Map<Constants.Fonts, Typeface?> =
173173
createTypefaceMap(requireActivity(), typeMappings)
174174

175-
175+
// Shared state to track which section is visible
176+
val visibleSection = remember { mutableStateOf<String?>(null) }
176177

177178
Column {
178179
SettingsTopView(
@@ -186,12 +187,6 @@ class SettingsFragment : Fragment() {
186187
)
187188
},
188189
) {
189-
SettingsTextButton(
190-
stringResource(R.string.hidden_apps),
191-
fontSize = iconFs
192-
) {
193-
showHiddenApps()
194-
}
195190
SettingsTextButton(
196191
stringResource(changeLauncherText),
197192
fontSize = iconFs
@@ -204,6 +199,12 @@ class SettingsFragment : Fragment() {
204199
) {
205200
showFavoriteApps()
206201
}
202+
SettingsTextButton(
203+
stringResource(R.string.hidden_apps),
204+
fontSize = iconFs
205+
) {
206+
showHiddenApps()
207+
}
207208
}
208209
SettingsArea(
209210
title = stringResource(R.string.appearance),
@@ -332,7 +333,8 @@ class SettingsFragment : Fragment() {
332333
onSelect = { j -> setLauncherFont(j) }
333334
)
334335
},
335-
)
336+
),
337+
visibleSection = visibleSection
336338
)
337339
SettingsArea(
338340
title = stringResource(R.string.behavior),
@@ -397,7 +399,8 @@ class SettingsFragment : Fragment() {
397399
state = remember { mutableStateOf(prefs.searchFromStart) },
398400
) { toggleSearchFromStart() }
399401
},
400-
)
402+
),
403+
visibleSection = visibleSection
401404
)
402405
SettingsArea(
403406
title = stringResource(R.string.homescreen),
@@ -508,7 +511,8 @@ class SettingsFragment : Fragment() {
508511
state = remember { mutableStateOf(prefs.homeAlignmentBottom) }
509512
) { toggleHomeAppsBottom() }
510513
}
511-
)
514+
),
515+
visibleSection = visibleSection
512516
)
513517
SettingsArea(
514518
title = stringResource(R.string.alignment),
@@ -558,7 +562,8 @@ class SettingsFragment : Fragment() {
558562
onSelect = { j -> viewModel.updateDrawerAlignment(j) }
559563
)
560564
},
561-
)
565+
),
566+
visibleSection = visibleSection
562567
)
563568
SettingsArea(
564569
title = stringResource(R.string.gestures),
@@ -697,7 +702,8 @@ class SettingsFragment : Fragment() {
697702
appLabel = prefs.appDoubleTap.activityLabel
698703
)
699704
}
700-
)
705+
),
706+
visibleSection = visibleSection
701707
)
702708
SettingsArea(
703709
title = getString(R.string.miscellaneous),
@@ -743,7 +749,8 @@ class SettingsFragment : Fragment() {
743749
state = remember { mutableStateOf(prefs.settingsLocked) }
744750
) { toggleSettingsLocked() }
745751
},
746-
)
752+
),
753+
visibleSection = visibleSection
747754
)
748755
SettingsArea(
749756
title = getString(R.string.backup),
@@ -768,7 +775,8 @@ class SettingsFragment : Fragment() {
768775
},
769776
)
770777
}
771-
)
778+
),
779+
visibleSection = visibleSection
772780
)
773781
Text(
774782
modifier = Modifier

app/src/main/java/com/github/droidworksstudio/mlauncher/ui/compose/SettingsComposable.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,32 @@ object SettingsComposable {
8282
title: String,
8383
selected: MutableState<String>,
8484
fontSize: TextUnit = TextUnit.Unspecified,
85-
items: Array<@Composable (MutableState<Boolean>, (Boolean) -> Unit) -> Unit>
85+
items: Array<@Composable (MutableState<Boolean>, (Boolean) -> Unit) -> Unit>,
86+
visibleSection: MutableState<String?> // State to track the currently visible section
8687
) {
8788
var key by remember { mutableIntStateOf(0) } // Add a key to force recomposition
88-
8989
val itemsChanged = remember { mutableStateOf(false) } // Track changes in items
90+
var isVisible by remember { mutableStateOf(false) } // State to control visibility
91+
92+
// Determine if this section should be visible based on the shared state
93+
isVisible = visibleSection.value == title
9094

9195
SettingsTile {
92-
SettingsTitle(text = title, fontSize = fontSize)
93-
items.forEachIndexed { i, item ->
94-
item(mutableStateOf("$title-$i" == selected.value)) { b ->
95-
val number = if (b) i else -1
96-
selected.value = "$title-$number"
97-
itemsChanged.value = true // Mark items as changed
96+
SettingsTitle(
97+
text = title,
98+
fontSize = fontSize,
99+
modifier = Modifier.clickable {
100+
// Toggle visibility and update the shared state to show the current section
101+
visibleSection.value = if (isVisible) null else title
102+
}
103+
)
104+
if (isVisible) {
105+
items.forEachIndexed { i, item ->
106+
item(mutableStateOf("$title-$i" == selected.value)) { b ->
107+
val number = if (b) i else -1
108+
selected.value = "$title-$number"
109+
itemsChanged.value = true // Mark items as changed
110+
}
98111
}
99112
}
100113
}
@@ -108,6 +121,7 @@ object SettingsComposable {
108121
}
109122
}
110123

124+
111125
@Composable
112126
fun SettingsTopView(
113127
title: String,

0 commit comments

Comments
 (0)