Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit d4774b0

Browse files
committed
feat(android): add option to disable back action to open drawer
[skip ci]
1 parent e6d7e50 commit d4774b0

File tree

5 files changed

+52
-15
lines changed

5 files changed

+52
-15
lines changed

assets/localization/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@
517517
"settings.NoExternalModulesFound": "No External Modules Found",
518518
"settings.NoHeadersAdded": "No Headers Added",
519519
"settings.NoProfilesFound": "No Profiles Found",
520+
"settings.OpenDrawerOnBackAction": "Open Drawer on Back Action",
521+
"settings.OpenDrawerOnBackActionDescription": "Open the drawer instead of closing LunaSea",
520522
"settings.OpenLinksIn": "Open Links In…",
521523
"settings.Password": "Password",
522524
"settings.PasswordHint1": "If your password includes special characters, considering adding a basic authentication header with your username and password instead for better support",

lib/database/tables/lunasea.dart

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:lunasea/vendor.dart';
1111
import 'package:lunasea/widgets/ui.dart';
1212

1313
enum LunaSeaDatabase<T> with LunaTableMixin<T> {
14+
ANDROID_BACK_OPENS_DRAWER<bool>(true),
1415
DRAWER_AUTOMATIC_MANAGE<bool>(true),
1516
DRAWER_MANUAL_ORDER<List>([]),
1617
ENABLED_PROFILE<String>(LunaProfile.DEFAULT_PROFILE),

lib/modules/settings/routes/configuration_general/route.dart

+29
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:lunasea/database/tables/bios.dart';
44
import 'package:lunasea/modules/settings.dart';
55
import 'package:lunasea/system/localization.dart';
66
import 'package:lunasea/system/network/network.dart';
7+
import 'package:lunasea/system/platform.dart';
78

89
class ConfigurationGeneralRoute extends StatefulWidget {
910
const ConfigurationGeneralRoute({
@@ -42,6 +43,7 @@ class _State extends State<ConfigurationGeneralRoute>
4243
..._localization(),
4344
..._modules(),
4445
if (LunaNetwork.isSupported) ..._network(),
46+
..._platform(),
4547
],
4648
);
4749
}
@@ -77,6 +79,33 @@ class _State extends State<ConfigurationGeneralRoute>
7779
];
7880
}
7981

82+
List<Widget> _platform() {
83+
if (LunaPlatform.isAndroid) {
84+
return [
85+
LunaHeader(text: 'settings.Platform'.tr()),
86+
_openDrawerOnBackAction(),
87+
];
88+
}
89+
90+
return [];
91+
}
92+
93+
Widget _openDrawerOnBackAction() {
94+
const _db = LunaSeaDatabase.ANDROID_BACK_OPENS_DRAWER;
95+
return _db.listenableBuilder(
96+
builder: (context, _) => LunaBlock(
97+
title: 'settings.OpenDrawerOnBackAction'.tr(),
98+
body: [
99+
TextSpan(text: 'settings.OpenDrawerOnBackActionDescription'.tr()),
100+
],
101+
trailing: LunaSwitch(
102+
value: _db.read(),
103+
onChanged: _db.update,
104+
),
105+
),
106+
);
107+
}
108+
80109
Widget _amoledTheme() {
81110
const _db = LunaSeaDatabase.THEME_AMOLED;
82111
return _db.listenableBuilder(

lib/widgets/ui/scaffold.dart

+18-15
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,27 @@ class LunaScaffold extends StatelessWidget {
3333

3434
@override
3535
Widget build(BuildContext context) {
36-
if (LunaPlatform.isAndroid) {
37-
return WillPopScope(
38-
onWillPop: () async {
39-
final state = scaffoldKey.currentState;
40-
if (state?.hasDrawer ?? false) {
41-
if (state!.isDrawerOpen) return true;
42-
state.openDrawer();
43-
return false;
44-
}
45-
return true;
46-
},
47-
child: scaffold,
48-
);
49-
}
50-
36+
if (LunaPlatform.isAndroid) return android;
5137
return scaffold;
5238
}
5339

40+
Widget get android {
41+
return WillPopScope(
42+
onWillPop: () async {
43+
if (!LunaSeaDatabase.ANDROID_BACK_OPENS_DRAWER.read()) return true;
44+
45+
final state = scaffoldKey.currentState;
46+
if (state?.hasDrawer ?? false) {
47+
if (state!.isDrawerOpen) return true;
48+
state.openDrawer();
49+
return false;
50+
}
51+
return true;
52+
},
53+
child: scaffold,
54+
);
55+
}
56+
5457
Widget get scaffold {
5558
return LunaSeaDatabase.ENABLED_PROFILE.listenableBuilder(
5659
builder: (context, _) {

localization/settings/en.json

+2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@
189189
"settings.NoExternalModulesFound": "No External Modules Found",
190190
"settings.NoHeadersAdded": "No Headers Added",
191191
"settings.NoProfilesFound": "No Profiles Found",
192+
"settings.OpenDrawerOnBackAction": "Open Drawer on Back Action",
193+
"settings.OpenDrawerOnBackActionDescription": "Open the drawer instead of closing LunaSea",
192194
"settings.OpenLinksIn": "Open Links In…",
193195
"settings.Password": "Password",
194196
"settings.PasswordHint1": "If your password includes special characters, considering adding a basic authentication header with your username and password instead for better support",

0 commit comments

Comments
 (0)