From ef78e4c17d0be43d449bbe97ce7d3457866a3aea Mon Sep 17 00:00:00 2001 From: Florian Griffon Date: Tue, 4 Mar 2025 13:05:42 +0000 Subject: [PATCH] fix: call correctly in history page (#41) Reviewed-on: https://git.gmoker.com/icing/monorepo/pulls/41 Co-authored-by: Florian Griffon Co-committed-by: Florian Griffon --- dialer/lib/features/history/history_page.dart | 112 ++++++++++-------- 1 file changed, 63 insertions(+), 49 deletions(-) diff --git a/dialer/lib/features/history/history_page.dart b/dialer/lib/features/history/history_page.dart index 1108a2e..117d1e8 100644 --- a/dialer/lib/features/history/history_page.dart +++ b/dialer/lib/features/history/history_page.dart @@ -11,6 +11,7 @@ import 'package:dialer/features/contacts/contact_state.dart'; import 'package:dialer/widgets/username_color_generator.dart'; import '../../services/block_service.dart'; import '../contacts/widgets/contact_modal.dart'; +import '../../services/call_service.dart'; class History { final Contact contact; @@ -20,12 +21,12 @@ class History { final int attempts; History( - this.contact, - this.date, - this.callType, - this.callStatus, - this.attempts, - ); + this.contact, + this.date, + this.callType, + this.callStatus, + this.attempts, + ); } class HistoryPage extends StatefulWidget { @@ -41,6 +42,7 @@ class _HistoryPageState extends State bool loading = true; int? _expandedIndex; final ObfuscateService _obfuscateService = ObfuscateService(); + final CallService _callService = CallService(); // Create a MethodChannel instance. static const MethodChannel _channel = MethodChannel('com.example.calllog'); @@ -83,8 +85,8 @@ class _HistoryPageState extends State } } catch (e) { print("Error updating favorite status: $e"); - ScaffoldMessenger.of(context) - .showSnackBar(SnackBar(content: Text('Failed to update favorite status'))); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Failed to update favorite status'))); } } @@ -155,7 +157,7 @@ class _HistoryPageState extends State // Convert timestamp to DateTime. DateTime callDate = - DateTime.fromMillisecondsSinceEpoch(entry['date'] ?? 0); + DateTime.fromMillisecondsSinceEpoch(entry['date'] ?? 0); int typeInt = entry['type'] ?? 0; int duration = entry['duration'] ?? 0; @@ -193,7 +195,8 @@ class _HistoryPageState extends State ); } - callHistories.add(History(matchedContact, callDate, callType, callStatus, 1)); + callHistories + .add(History(matchedContact, callDate, callType, callStatus, 1)); } // Sort histories by most recent. @@ -218,7 +221,7 @@ class _HistoryPageState extends State for (var history in historyList) { final callDate = - DateTime(history.date.year, history.date.month, history.date.day); + DateTime(history.date.year, history.date.month, history.date.day); if (callDate == today) { todayHistories.add(history); } else if (callDate == yesterday) { @@ -291,7 +294,7 @@ class _HistoryPageState extends State } List missedCalls = - histories.where((h) => h.callStatus == 'missed').toList(); + histories.where((h) => h.callStatus == 'missed').toList(); final allItems = _buildGroupedList(histories); final missedItems = _buildGroupedList(missedCalls); @@ -360,7 +363,8 @@ class _HistoryPageState extends State onEdit: () async { if (await FlutterContacts.requestPermission()) { final updatedContact = - await FlutterContacts.openExternalEdit(contact.id); + await FlutterContacts.openExternalEdit( + contact.id); if (updatedContact != null) { await _refreshContacts(); Navigator.of(context).pop(); @@ -415,18 +419,11 @@ class _HistoryPageState extends State icon: const Icon(Icons.phone, color: Colors.green), onPressed: () async { if (contact.phones.isNotEmpty) { - final Uri callUri = - Uri(scheme: 'tel', path: contact.phones.first.number); - if (await canLaunchUrl(callUri)) { - await launchUrl(callUri); - } else { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Could not launch call')), - ); - } + _callService.makeGsmCall(contact.phones.first.number); } else { ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Contact has no phone number')), + const SnackBar( + content: Text('Contact has no phone number')), ); } }, @@ -444,7 +441,9 @@ class _HistoryPageState extends State color: Colors.grey[850], child: FutureBuilder( future: BlockService().isNumberBlocked( - contact.phones.isNotEmpty ? contact.phones.first.number : ''), + contact.phones.isNotEmpty + ? contact.phones.first.number + : ''), builder: (context, snapshot) { final isBlocked = snapshot.data ?? false; return Row( @@ -460,29 +459,37 @@ class _HistoryPageState extends State await launchUrl(smsUri); } else { ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Could not send message')), + const SnackBar( + content: + Text('Could not send message')), ); } } else { ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Contact has no phone number')), + const SnackBar( + content: + Text('Contact has no phone number')), ); } }, - icon: const Icon(Icons.message, color: Colors.white), - label: const Text('Message', style: TextStyle(color: Colors.white)), + icon: + const Icon(Icons.message, color: Colors.white), + label: const Text('Message', + style: TextStyle(color: Colors.white)), ), TextButton.icon( onPressed: () { Navigator.push( context, MaterialPageRoute( - builder: (_) => CallDetailsPage(history: history), + builder: (_) => + CallDetailsPage(history: history), ), ); }, icon: const Icon(Icons.info, color: Colors.white), - label: const Text('Details', style: TextStyle(color: Colors.white)), + label: const Text('Details', + style: TextStyle(color: Colors.white)), ), TextButton.icon( onPressed: () async { @@ -491,24 +498,29 @@ class _HistoryPageState extends State : null; if (phoneNumber == null) { ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Contact has no phone number')), + const SnackBar( + content: + Text('Contact has no phone number')), ); return; } if (isBlocked) { await BlockService().unblockNumber(phoneNumber); ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('$phoneNumber unblocked')), + SnackBar( + content: Text('$phoneNumber unblocked')), ); } else { await BlockService().blockNumber(phoneNumber); ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text('$phoneNumber blocked')), + SnackBar( + content: Text('$phoneNumber blocked')), ); } setState(() {}); }, - icon: Icon(isBlocked ? Icons.lock_open : Icons.block, + icon: Icon( + isBlocked ? Icons.lock_open : Icons.block, color: Colors.white), label: Text(isBlocked ? 'Unblock' : 'Block', style: const TextStyle(color: Colors.white)), @@ -554,21 +566,22 @@ class CallDetailsPage extends StatelessWidget { children: [ (contact.thumbnail != null && contact.thumbnail!.isNotEmpty) ? ObfuscatedAvatar( - imageBytes: contact.thumbnail, - radius: 30, - backgroundColor: contactBg, - fallbackInitial: contact.displayName, - ) + imageBytes: contact.thumbnail, + radius: 30, + backgroundColor: contactBg, + fallbackInitial: contact.displayName, + ) : CircleAvatar( - backgroundColor: generateColorFromName(contact.displayName), - radius: 30, - child: Text( - contact.displayName.isNotEmpty - ? contact.displayName[0].toUpperCase() - : '?', - style: TextStyle(color: contactLetter), - ), - ), + backgroundColor: + generateColorFromName(contact.displayName), + radius: 30, + child: Text( + contact.displayName.isNotEmpty + ? contact.displayName[0].toUpperCase() + : '?', + style: TextStyle(color: contactLetter), + ), + ), const SizedBox(width: 16), Expanded( child: Text( @@ -600,7 +613,8 @@ class CallDetailsPage extends StatelessWidget { if (contact.phones.isNotEmpty) DetailRow( label: 'Number:', - value: _obfuscateService.obfuscateData(contact.phones.first.number), + value: _obfuscateService + .obfuscateData(contact.phones.first.number), ), ], ),