Skip to content

Commit 92fe518

Browse files
fix: home layout style change not immediately reflected in appearance settings
HomeLayoutChooseDialog did not trigger refreshTheme after saving preference, causing the layout label and home screen to not update until re-entering the page. Added callback pattern to update currentStyle and trigger refresh signal. Also made Home.kt homeLayout reactive via refreshTheme observer.
1 parent 7ed204f commit 92fe518

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

app/src/main/java/me/bmax/apatch/ui/screen/Home.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ import androidx.compose.runtime.collectAsState
9696
import androidx.compose.runtime.getValue
9797
import androidx.compose.runtime.livedata.observeAsState
9898
import androidx.compose.runtime.mutableStateOf
99+
import me.bmax.apatch.ui.theme.refreshTheme
99100
import androidx.compose.runtime.remember
100101
import androidx.compose.runtime.saveable.rememberSaveable
101102
import androidx.compose.runtime.setValue
@@ -178,7 +179,11 @@ fun HomeScreen(navigator: DestinationsNavigator) {
178179
}
179180
}
180181

181-
val homeLayout = remember { APApplication.sharedPreferences.getString("home_layout_style", "stats") }
182+
var homeLayout by remember { mutableStateOf(APApplication.sharedPreferences.getString("home_layout_style", "stats")) }
183+
val homeRefreshObserver by refreshTheme.observeAsState(false)
184+
if (homeRefreshObserver) {
185+
homeLayout = APApplication.sharedPreferences.getString("home_layout_style", "stats")
186+
}
182187

183188
Scaffold(topBar = {
184189
TopBar(onInstallClick = dropUnlessResumed {

app/src/main/java/me/bmax/apatch/ui/screen/settings/AppearanceSettings.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,10 @@ fun AppearanceSettingsContent(
16671667
}
16681668

16691669
if (showHomeLayoutChooseDialog.value) {
1670-
HomeLayoutChooseDialog(showHomeLayoutChooseDialog)
1670+
HomeLayoutChooseDialog(showHomeLayoutChooseDialog) { selectedLayout ->
1671+
currentStyle = selectedLayout
1672+
refreshTheme.value = true
1673+
}
16711674
}
16721675

16731676
if (showNavSchemeDialog) {
@@ -1860,7 +1863,7 @@ fun ThemeChooseDialog(showDialog: MutableState<Boolean>) {
18601863

18611864
@OptIn(ExperimentalMaterial3Api::class)
18621865
@Composable
1863-
fun HomeLayoutChooseDialog(showDialog: MutableState<Boolean>) {
1866+
fun HomeLayoutChooseDialog(showDialog: MutableState<Boolean>, onLayoutSelected: (String) -> Unit) {
18641867
val prefs = APApplication.sharedPreferences
18651868

18661869
BasicAlertDialog(
@@ -1902,6 +1905,7 @@ fun HomeLayoutChooseDialog(showDialog: MutableState<Boolean>) {
19021905
},
19031906
modifier = Modifier.clickable {
19041907
prefs.edit().putString("home_layout_style", "default").apply()
1908+
onLayoutSelected("default")
19051909
showDialog.value = false
19061910
}
19071911
)
@@ -1916,6 +1920,7 @@ fun HomeLayoutChooseDialog(showDialog: MutableState<Boolean>) {
19161920
},
19171921
modifier = Modifier.clickable {
19181922
prefs.edit().putString("home_layout_style", "kernelsu").apply()
1923+
onLayoutSelected("kernelsu")
19191924
showDialog.value = false
19201925
}
19211926
)
@@ -1930,6 +1935,7 @@ fun HomeLayoutChooseDialog(showDialog: MutableState<Boolean>) {
19301935
},
19311936
modifier = Modifier.clickable {
19321937
prefs.edit().putString("home_layout_style", "focus").apply()
1938+
onLayoutSelected("focus")
19331939
showDialog.value = false
19341940
}
19351941
)
@@ -1944,6 +1950,7 @@ fun HomeLayoutChooseDialog(showDialog: MutableState<Boolean>) {
19441950
},
19451951
modifier = Modifier.clickable {
19461952
prefs.edit().putString("home_layout_style", "sign").apply()
1953+
onLayoutSelected("sign")
19471954
showDialog.value = false
19481955
}
19491956
)
@@ -1958,6 +1965,7 @@ fun HomeLayoutChooseDialog(showDialog: MutableState<Boolean>) {
19581965
},
19591966
modifier = Modifier.clickable {
19601967
prefs.edit().putString("home_layout_style", "circle").apply()
1968+
onLayoutSelected("circle")
19611969
showDialog.value = false
19621970
}
19631971
)
@@ -1972,6 +1980,7 @@ fun HomeLayoutChooseDialog(showDialog: MutableState<Boolean>) {
19721980
},
19731981
modifier = Modifier.clickable {
19741982
prefs.edit().putString("home_layout_style", "dashboard_ui").apply()
1983+
onLayoutSelected("dashboard_ui")
19751984
showDialog.value = false
19761985
}
19771986
)
@@ -1986,6 +1995,7 @@ fun HomeLayoutChooseDialog(showDialog: MutableState<Boolean>) {
19861995
},
19871996
modifier = Modifier.clickable {
19881997
prefs.edit().putString("home_layout_style", "stats").apply()
1998+
onLayoutSelected("stats")
19891999
showDialog.value = false
19902000
}
19912001
)

0 commit comments

Comments
 (0)