Skip to content

Commit

Permalink
LA-971 added explanation for contact permission
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledNjim committed Dec 19, 2024
1 parent cd1f484 commit a76ecf5
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 11 deletions.
20 changes: 20 additions & 0 deletions lib/presentation/localizations/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3082,6 +3082,26 @@ class AppLocalizations {
name: 'are_you_sure_you_want_to_discard_recording',
);
}
String get allow {
return Intl.message(
'Allow',
name: 'allow',
);
}

String get not_now {
return Intl.message(
'Not now',
name: 'not_now',
);
}

String get explain_contact_permission {
return Intl.message(
'LinShare requests access to your contacts solely to provide autocomplete suggestions when you are adding a recipient to share files or collaborate with others. Please note that your contacts are not synchronized with the server.',
name: 'explain_contact_permission',
);
}
}

class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
Expand Down
25 changes: 25 additions & 0 deletions lib/presentation/view/dialog/permission_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:flutter/material.dart';
import 'package:linshare_flutter_app/presentation/localizations/app_localizations.dart';

class PermissionDialog {
static Future<bool?> showPermissionDialog(
BuildContext context, Widget title, String content) async {
return showDialog<bool>(
barrierDismissible: false,
context: context,
builder: (context) => AlertDialog(
title: title,
content: Text(content),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text(AppLocalizations.of(context).not_now),
),
TextButton(
onPressed: () => Navigator.of(context).pop(true),
child: Text(AppLocalizations.of(context).allow),
),
],
));
}
}
15 changes: 12 additions & 3 deletions lib/presentation/widget/upload_file/upload_file_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import 'package:linshare_flutter_app/presentation/redux/states/app_state.dart';
import 'package:linshare_flutter_app/presentation/util/extensions/media_type_extension.dart';
import 'package:linshare_flutter_app/presentation/util/router/app_navigation.dart';
import 'package:linshare_flutter_app/presentation/util/router/route_paths.dart';
import 'package:linshare_flutter_app/presentation/view/dialog/permission_dialog.dart';
import 'package:linshare_flutter_app/presentation/widget/base/base_viewmodel.dart';
import 'package:linshare_flutter_app/presentation/widget/destination_picker/destination_picker_action/choose_destination_picker_action.dart';
import 'package:linshare_flutter_app/presentation/widget/destination_picker/destination_picker_action/negative_destination_picker_action.dart';
Expand Down Expand Up @@ -117,8 +118,6 @@ class UploadFileViewModel extends BaseViewModel {
break;
}
});

Future.delayed(Duration(milliseconds: 500), () => _checkContactPermission());
}

void backToMySpace() {
Expand Down Expand Up @@ -338,11 +337,21 @@ class UploadFileViewModel extends BaseViewModel {
store.dispatch(MySpaceClearSelectedDocumentsAction());
}

void _checkContactPermission() async {
void checkContactPermission(BuildContext context) async {
final permissionStatus = await Permission.contacts.status;
if (permissionStatus.isGranted) {
_contactSuggestionSource = ContactSuggestionSource.all;
} else if (!permissionStatus.isPermanentlyDenied) {
final confirmExplanation = await PermissionDialog.showPermissionDialog(
context,
Center(
child: Icon(Icons.warning, color: Colors.orange, size: 40),
),
AppLocalizations.of(context).explain_contact_permission) ??
false;
if (!confirmExplanation) {
return;
}
final requestedPermission = await Permission.contacts.request();
_contactSuggestionSource = requestedPermission == PermissionStatus.granted
? ContactSuggestionSource.all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class _UploadFileWidgetState extends State<UploadFileWidget> {
void initState() {
super.initState();
uploadFileViewModel.cancelSelection();
uploadFileViewModel.checkContactPermission(context);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import 'package:linshare_flutter_app/presentation/util/extensions/list_functiona
import 'package:linshare_flutter_app/presentation/util/extensions/string_extensions.dart';
import 'package:linshare_flutter_app/presentation/util/router/app_navigation.dart';
import 'package:linshare_flutter_app/presentation/util/value_notifier_common.dart';
import 'package:linshare_flutter_app/presentation/view/dialog/permission_dialog.dart';
import 'package:linshare_flutter_app/presentation/view/modal_sheets/modal_card.dart';
import 'package:linshare_flutter_app/presentation/view/modal_sheets/reach_limitation_alert.dart';
import 'package:linshare_flutter_app/presentation/widget/base/base_viewmodel.dart';
Expand All @@ -63,6 +64,7 @@ import 'package:permission_handler/permission_handler.dart';
import 'package:redux/src/store.dart';
import 'package:rxdart/rxdart.dart';


class UploadRequestCreationViewModel extends BaseViewModel {

final AppNavigation _appNavigation;
Expand Down Expand Up @@ -146,8 +148,6 @@ class UploadRequestCreationViewModel extends BaseViewModel {
}).listen((event) {
event ? _enableCreateButton.add(true) : _enableCreateButton.add(false);
});

Future.delayed(Duration(milliseconds: 500), () => _checkContactPermission());
}

void _disposeValueNotifier() {
Expand Down Expand Up @@ -534,11 +534,21 @@ class UploadRequestCreationViewModel extends BaseViewModel {
);
}

void _checkContactPermission() async {
void checkContactPermission(BuildContext context) async {
final permissionStatus = await Permission.contacts.status;
if (permissionStatus.isGranted) {
_contactSuggestionSource = ContactSuggestionSource.all;
} else if (!permissionStatus.isPermanentlyDenied) {
final confirmExplanation = await PermissionDialog.showPermissionDialog(
context,
Center(
child: Icon(Icons.warning, color: Colors.orange, size: 40),
),
AppLocalizations.of(context).explain_contact_permission) ??
false;
if (!confirmExplanation) {
return;
}
final requestedPermission = await Permission.contacts.request();
_contactSuggestionSource = requestedPermission == PermissionStatus.granted
? ContactSuggestionSource.all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class _UploadRequestCreationWidgetState extends State<UploadRequestCreationWidge
_arguments = ModalRoute.of(context)?.settings.arguments as UploadRequestCreationArguments;
_model.initialize(_arguments);
});
_model.checkContactPermission(context);
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import 'package:dartz/dartz.dart';
import 'package:domain/domain.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:linshare_flutter_app/presentation/localizations/app_localizations.dart';
import 'package:linshare_flutter_app/presentation/model/upload_request_group_tab.dart';
import 'package:linshare_flutter_app/presentation/redux/actions/add_recipients_upload_request_group_action.dart';
Expand All @@ -42,6 +43,7 @@ import 'package:linshare_flutter_app/presentation/redux/actions/upload_request_i
import 'package:linshare_flutter_app/presentation/redux/online_thunk_action.dart';
import 'package:linshare_flutter_app/presentation/redux/states/app_state.dart';
import 'package:linshare_flutter_app/presentation/util/router/app_navigation.dart';
import 'package:linshare_flutter_app/presentation/view/dialog/permission_dialog.dart';
import 'package:linshare_flutter_app/presentation/view/modal_sheets/confirm_modal_sheet_builder.dart';
import 'package:linshare_flutter_app/presentation/widget/base/base_viewmodel.dart';
import 'package:linshare_flutter_app/presentation/widget/upload_file/upload_file_viewmodel.dart';
Expand All @@ -68,9 +70,7 @@ class AddRecipientsUploadRequestGroupViewModel extends BaseViewModel {
this._getAutoCompleteSharingWithDeviceContactInteractor,
this._addRecipientsToUploadRequestGroupInteractor,
this._getAllUploadRequestsInteractor)
: super(store) {
Future.delayed(Duration(milliseconds: 500), () => _checkContactPermission());
}
: super(store);

void initState(AddRecipientsUploadRequestGroupArgument argument) {
store.dispatch(_getAllUploadRequests(argument.uploadRequestGroup.uploadRequestGroupId));
Expand Down Expand Up @@ -187,11 +187,21 @@ class AddRecipientsUploadRequestGroupViewModel extends BaseViewModel {
}
}

void _checkContactPermission() async {
void checkContactPermission(BuildContext context) async {
final permissionStatus = await Permission.contacts.status;
if (permissionStatus.isGranted) {
_contactSuggestionSource = ContactSuggestionSource.all;
} else if (!permissionStatus.isPermanentlyDenied) {
final confirmExplanation = await PermissionDialog.showPermissionDialog(
context,
Center(
child: Icon(Icons.warning, color: Colors.orange, size: 40),
),
AppLocalizations.of(context).explain_contact_permission) ??
false;
if (!confirmExplanation) {
return;
}
final requestedPermission = await Permission.contacts.request();
_contactSuggestionSource = requestedPermission == PermissionStatus.granted
? ContactSuggestionSource.all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ class _AddSharedSpaceMemberWidgetState extends State<AddRecipientsUploadRequestG

@override
void initState() {
super.initState();
Future.delayed(Duration.zero, () {
_arguments = ModalRoute.of(context)?.settings.arguments as AddRecipientsUploadRequestGroupArgument;
if (_arguments != null) {
_model.initState(_arguments!);
}
});
super.initState();
_model.checkContactPermission(context);
}

@override
Expand Down

0 comments on commit a76ecf5

Please sign in to comment.