Skip to content

Commit

Permalink
feat(android): add option to disable back action to open drawer
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
JagandeepBrar committed Dec 21, 2022
1 parent e6d7e50 commit d4774b0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
2 changes: 2 additions & 0 deletions assets/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@
"settings.NoExternalModulesFound": "No External Modules Found",
"settings.NoHeadersAdded": "No Headers Added",
"settings.NoProfilesFound": "No Profiles Found",
"settings.OpenDrawerOnBackAction": "Open Drawer on Back Action",
"settings.OpenDrawerOnBackActionDescription": "Open the drawer instead of closing LunaSea",
"settings.OpenLinksIn": "Open Links In…",
"settings.Password": "Password",
"settings.PasswordHint1": "If your password includes special characters, considering adding a basic authentication header with your username and password instead for better support",
Expand Down
1 change: 1 addition & 0 deletions lib/database/tables/lunasea.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:lunasea/vendor.dart';
import 'package:lunasea/widgets/ui.dart';

enum LunaSeaDatabase<T> with LunaTableMixin<T> {
ANDROID_BACK_OPENS_DRAWER<bool>(true),
DRAWER_AUTOMATIC_MANAGE<bool>(true),
DRAWER_MANUAL_ORDER<List>([]),
ENABLED_PROFILE<String>(LunaProfile.DEFAULT_PROFILE),
Expand Down
29 changes: 29 additions & 0 deletions lib/modules/settings/routes/configuration_general/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:lunasea/database/tables/bios.dart';
import 'package:lunasea/modules/settings.dart';
import 'package:lunasea/system/localization.dart';
import 'package:lunasea/system/network/network.dart';
import 'package:lunasea/system/platform.dart';

class ConfigurationGeneralRoute extends StatefulWidget {
const ConfigurationGeneralRoute({
Expand Down Expand Up @@ -42,6 +43,7 @@ class _State extends State<ConfigurationGeneralRoute>
..._localization(),
..._modules(),
if (LunaNetwork.isSupported) ..._network(),
..._platform(),
],
);
}
Expand Down Expand Up @@ -77,6 +79,33 @@ class _State extends State<ConfigurationGeneralRoute>
];
}

List<Widget> _platform() {
if (LunaPlatform.isAndroid) {
return [
LunaHeader(text: 'settings.Platform'.tr()),
_openDrawerOnBackAction(),
];
}

return [];
}

Widget _openDrawerOnBackAction() {
const _db = LunaSeaDatabase.ANDROID_BACK_OPENS_DRAWER;
return _db.listenableBuilder(
builder: (context, _) => LunaBlock(
title: 'settings.OpenDrawerOnBackAction'.tr(),
body: [
TextSpan(text: 'settings.OpenDrawerOnBackActionDescription'.tr()),
],
trailing: LunaSwitch(
value: _db.read(),
onChanged: _db.update,
),
),
);
}

Widget _amoledTheme() {
const _db = LunaSeaDatabase.THEME_AMOLED;
return _db.listenableBuilder(
Expand Down
33 changes: 18 additions & 15 deletions lib/widgets/ui/scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@ class LunaScaffold extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (LunaPlatform.isAndroid) {
return WillPopScope(
onWillPop: () async {
final state = scaffoldKey.currentState;
if (state?.hasDrawer ?? false) {
if (state!.isDrawerOpen) return true;
state.openDrawer();
return false;
}
return true;
},
child: scaffold,
);
}

if (LunaPlatform.isAndroid) return android;
return scaffold;
}

Widget get android {
return WillPopScope(
onWillPop: () async {
if (!LunaSeaDatabase.ANDROID_BACK_OPENS_DRAWER.read()) return true;

final state = scaffoldKey.currentState;
if (state?.hasDrawer ?? false) {
if (state!.isDrawerOpen) return true;
state.openDrawer();
return false;
}
return true;
},
child: scaffold,
);
}

Widget get scaffold {
return LunaSeaDatabase.ENABLED_PROFILE.listenableBuilder(
builder: (context, _) {
Expand Down
2 changes: 2 additions & 0 deletions localization/settings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@
"settings.NoExternalModulesFound": "No External Modules Found",
"settings.NoHeadersAdded": "No Headers Added",
"settings.NoProfilesFound": "No Profiles Found",
"settings.OpenDrawerOnBackAction": "Open Drawer on Back Action",
"settings.OpenDrawerOnBackActionDescription": "Open the drawer instead of closing LunaSea",
"settings.OpenLinksIn": "Open Links In…",
"settings.Password": "Password",
"settings.PasswordHint1": "If your password includes special characters, considering adding a basic authentication header with your username and password instead for better support",
Expand Down

0 comments on commit d4774b0

Please sign in to comment.