Add hook for checking permission

This commit is contained in:
Neeraj Gupta 2023-06-15 18:15:26 +05:30
parent 3b98ef597f
commit 5b7eb47521
8 changed files with 149 additions and 18 deletions

View file

@ -549,6 +549,9 @@ class MessageLookup extends MessageLookupByLibrary {
MessageLookupByLibrary.simpleMessage("Email your logs"),
"empty": MessageLookupByLibrary.simpleMessage("Empty"),
"emptyTrash": MessageLookupByLibrary.simpleMessage("Empty trash?"),
"enableMaps": MessageLookupByLibrary.simpleMessage("Enable Maps"),
"enableMapsDesc": MessageLookupByLibrary.simpleMessage(
"This will show your photos on a world map.\n\nThe map is hosted by OpenStreetMap, and the exact locations of your photos are never shared.\n\nYou can disable this feature anytime from Settings."),
"encryptingBackup":
MessageLookupByLibrary.simpleMessage("Encrypting backup..."),
"encryption": MessageLookupByLibrary.simpleMessage("Encryption"),
@ -782,6 +785,7 @@ class MessageLookup extends MessageLookupByLibrary {
"manageParticipants": MessageLookupByLibrary.simpleMessage("Manage"),
"manageSubscription":
MessageLookupByLibrary.simpleMessage("Manage subscription"),
"maps": MessageLookupByLibrary.simpleMessage("Maps"),
"mastodon": MessageLookupByLibrary.simpleMessage("Mastodon"),
"matrix": MessageLookupByLibrary.simpleMessage("Matrix"),
"maxDeviceLimitSpikeHandling": m13,

View file

@ -7242,6 +7242,36 @@ class S {
args: [],
);
}
/// `Maps`
String get maps {
return Intl.message(
'Maps',
name: 'maps',
desc: '',
args: [],
);
}
/// `Enable Maps`
String get enableMaps {
return Intl.message(
'Enable Maps',
name: 'enableMaps',
desc: '',
args: [],
);
}
/// `This will show your photos on a world map.\n\nThe map is hosted by OpenStreetMap, and the exact locations of your photos are never shared.\n\nYou can disable this feature anytime from Settings.`
String get enableMapsDesc {
return Intl.message(
'This will show your photos on a world map.\n\nThe map is hosted by OpenStreetMap, and the exact locations of your photos are never shared.\n\nYou can disable this feature anytime from Settings.',
name: 'enableMapsDesc',
desc: '',
args: [],
);
}
}
class AppLocalizationDelegate extends LocalizationsDelegate<S> {

View file

@ -1047,6 +1047,9 @@
"description": "Message showed on a button that the user can click to leave the current dialog. It is used on iOS side. Maximum 30 characters."
},
"openstreetmapContributors": "OpenStreetMap contributors",
"hostedAtOsmFrance": "Hosted at OSM France"
"hostedAtOsmFrance": "Hosted at OSM France",
"maps" : "Maps",
"enableMaps": "Enable Maps",
"enableMapsDesc" : "This will show your photos on a world map.\n\nThe map is hosted by OpenStreetMap, and the exact locations of your photos are never shared.\n\nYou can disable this feature anytime from Settings."
}

View file

@ -43,6 +43,10 @@ class UserRemoteFlagService {
}
}
bool getCachedBoolValue(String key) {
return _prefs.getBool(key) ?? false;
}
Future<bool> getBoolValue(String key) async {
if (_prefs.containsKey(key)) {
return _prefs.getBool(key)!;

View file

@ -0,0 +1,50 @@
import "package:flutter/cupertino.dart";
import "package:photos/generated/l10n.dart";
import "package:photos/models/search/button_result.dart";
import "package:photos/services/user_remote_flag_service.dart";
import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/dialog_widget.dart";
import "package:photos/ui/components/models/button_type.dart";
import "package:photos/utils/toast_util.dart";
Future<bool> requestForMapEnable(BuildContext context) async {
const String flagName = UserRemoteFlagService.mapEnabled;
if (UserRemoteFlagService.instance.getCachedBoolValue(flagName)) {
return true;
}
final ButtonResult? result = await showDialogWidget(
context: context,
title: S.of(context).enableMaps,
body: S.of(context).enableMapsDesc,
isDismissible: true,
buttons: [
ButtonWidget(
buttonType: ButtonType.primary,
buttonAction: ButtonAction.first,
labelText: S.of(context).enableMaps,
isInAlert: true,
onTap: () async {
await UserRemoteFlagService.instance.setBoolValue(
flagName,
true,
);
},
),
ButtonWidget(
buttonType: ButtonType.secondary,
buttonAction: ButtonAction.second,
labelText: S.of(context).cancel,
isInAlert: true,
),
],
);
if (result?.action == ButtonAction.first) {
return true;
}
if (result?.action == ButtonAction.error) {
showShortToast(context, S.of(context).somethingWentWrong);
return false;
}
return false;
}

View file

@ -1,11 +1,13 @@
import 'package:flutter/material.dart';
import "package:photos/generated/l10n.dart";
import "package:photos/services/user_remote_flag_service.dart";
import 'package:photos/theme/ente_theme.dart';
import 'package:photos/ui/components/buttons/icon_button_widget.dart';
import 'package:photos/ui/components/captioned_text_widget.dart';
import 'package:photos/ui/components/menu_item_widget/menu_item_widget.dart';
import 'package:photos/ui/components/title_bar_title_widget.dart';
import 'package:photos/ui/components/title_bar_widget.dart';
import "package:photos/ui/components/toggle_switch_widget.dart";
import 'package:photos/ui/tools/debug/app_storage_viewer.dart';
import 'package:photos/ui/viewer/gallery/photo_grid_size_picker_page.dart';
import 'package:photos/utils/local_settings.dart';
@ -106,6 +108,36 @@ class _AdvancedSettingsScreenState extends State<AdvancedSettingsScreen> {
routeToPage(context, const AppStorageViewer());
},
),
const SizedBox(
height: 24,
),
MenuItemWidget(
captionedTextWidget: const CaptionedTextWidget(
title: "Maps",
),
menuItemColor: colorScheme.fillFaint,
singleBorderRadius: 8,
alignCaptionedTextToLeft: true,
trailingWidget: ToggleSwitchWidget(
value: () => UserRemoteFlagService.instance
.getCachedBoolValue(
UserRemoteFlagService.mapEnabled,
),
onChanged: () async {
final isEnabled = UserRemoteFlagService
.instance
.getCachedBoolValue(
UserRemoteFlagService.mapEnabled,
);
await UserRemoteFlagService.instance
.setBoolValue(
UserRemoteFlagService.mapEnabled,
!isEnabled,
);
},
),
)
],
),
],

View file

@ -23,6 +23,7 @@ import 'package:photos/ui/components/action_sheet_widget.dart';
import 'package:photos/ui/components/buttons/button_widget.dart';
import 'package:photos/ui/components/dialog_widget.dart';
import 'package:photos/ui/components/models/button_type.dart';
import "package:photos/ui/map/enable_map.dart";
import "package:photos/ui/map/map_screen.dart";
import 'package:photos/ui/sharing/album_participants_page.dart';
import 'package:photos/ui/sharing/share_collection_page.dart';
@ -459,17 +460,20 @@ class _GalleryAppBarWidgetState extends State<GalleryAppBarWidget> {
}
Future<void> showOnMap() async {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => MapScreen(
filesFutureFn: () async {
return FilesDB.instance.getAllFilesCollection(
widget.collection!.id,
);
},
final bool result = await requestForMapEnable(context);
if (result) {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => MapScreen(
filesFutureFn: () async {
return FilesDB.instance.getAllFilesCollection(
widget.collection!.id,
);
},
),
),
),
);
);
}
}
Future<void> _showSortOption(BuildContext bContext) async {

View file

@ -8,6 +8,7 @@ import 'package:photos/models/search/search_result.dart';
import 'package:photos/services/search_service.dart';
import "package:photos/theme/ente_theme.dart";
import 'package:photos/ui/components/buttons/icon_button_widget.dart';
import "package:photos/ui/map/enable_map.dart";
import "package:photos/ui/map/map_screen.dart";
import 'package:photos/ui/viewer/search/result/no_result_widget.dart';
import 'package:photos/ui/viewer/search/search_suffix_icon_widget.dart';
@ -255,14 +256,17 @@ class NavigateToMap extends StatelessWidget {
defaultColor: colorScheme.backgroundElevated,
pressedColor: colorScheme.backgroundElevated2,
size: 28,
onTap: () {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => MapScreen(
filesFutureFn: SearchService.instance.getAllFiles,
onTap: () async {
final bool result = await requestForMapEnable(context);
if (result) {
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => MapScreen(
filesFutureFn: SearchService.instance.getAllFiles,
),
),
),
);
);
}
},
),
);