WIP: callPageV2 #52
@ -3,18 +3,29 @@ import 'package:flutter/services.dart';
|
|||||||
import '../features/call/call_page.dart';
|
import '../features/call/call_page.dart';
|
||||||
import '../features/call/incoming_call_page.dart';
|
import '../features/call/incoming_call_page.dart';
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
|
<<<<<<< HEAD
|
||||||
import '../services/contact_service.dart';
|
import '../services/contact_service.dart';
|
||||||
=======
|
=======
|
||||||
>>>>>>> ec1779b (callNotifications and various fix related to calls (#49))
|
>>>>>>> ec1779b (callNotifications and various fix related to calls (#49))
|
||||||
|
=======
|
||||||
|
import '../services/contact_service.dart'; // Import your ContactService
|
||||||
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
|
|
||||||
class CallService {
|
class CallService {
|
||||||
static const MethodChannel _channel = MethodChannel('call_service');
|
static const MethodChannel _channel = MethodChannel('call_service');
|
||||||
static String? currentPhoneNumber;
|
static String? currentPhoneNumber;
|
||||||
|
<<<<<<< HEAD
|
||||||
static String? currentDisplayName;
|
static String? currentDisplayName;
|
||||||
static Uint8List? currentThumbnail;
|
static Uint8List? currentThumbnail;
|
||||||
static bool _isCallPageVisible = false;
|
static bool _isCallPageVisible = false;
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
static String? _currentCallState;
|
static String? _currentCallState;
|
||||||
|
=======
|
||||||
|
static String? currentDisplayName; // Store display name
|
||||||
|
static Uint8List? currentThumbnail; // Store thumbnail
|
||||||
|
static bool _isCallPageVisible = false;
|
||||||
|
final ContactService _contactService = ContactService(); // Instantiate ContactService
|
||||||
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
static Map<String, dynamic>? _pendingCall;
|
static Map<String, dynamic>? _pendingCall;
|
||||||
static bool wasPhoneLocked = false;
|
static bool wasPhoneLocked = false;
|
||||||
final ContactService _contactService = ContactService();
|
final ContactService _contactService = ContactService();
|
||||||
@ -37,6 +48,10 @@ class CallService {
|
|||||||
final phoneNumber = call.arguments["callId"] as String;
|
final phoneNumber = call.arguments["callId"] as String;
|
||||||
final state = call.arguments["state"] as String;
|
final state = call.arguments["state"] as String;
|
||||||
currentPhoneNumber = phoneNumber.replaceFirst('tel:', '');
|
currentPhoneNumber = phoneNumber.replaceFirst('tel:', '');
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
// Fetch contact info using ContactService if not already set
|
||||||
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
await _fetchContactInfo(currentPhoneNumber!);
|
await _fetchContactInfo(currentPhoneNumber!);
|
||||||
print('CallService: Call added, number: $currentPhoneNumber, state: $state');
|
print('CallService: Call added, number: $currentPhoneNumber, state: $state');
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
@ -80,13 +95,19 @@ class CallService {
|
|||||||
currentPhoneNumber = null;
|
currentPhoneNumber = null;
|
||||||
currentDisplayName = null;
|
currentDisplayName = null;
|
||||||
currentThumbnail = null;
|
currentThumbnail = null;
|
||||||
|
<<<<<<< HEAD
|
||||||
_currentCallState = null;
|
_currentCallState = null;
|
||||||
|
=======
|
||||||
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
break;
|
break;
|
||||||
case "incomingCallFromNotification":
|
case "incomingCallFromNotification":
|
||||||
final phoneNumber = call.arguments["phoneNumber"] as String;
|
final phoneNumber = call.arguments["phoneNumber"] as String;
|
||||||
wasPhoneLocked = call.arguments["wasPhoneLocked"] as bool? ?? false;
|
wasPhoneLocked = call.arguments["wasPhoneLocked"] as bool? ?? false;
|
||||||
currentPhoneNumber = phoneNumber;
|
currentPhoneNumber = phoneNumber;
|
||||||
|
<<<<<<< HEAD
|
||||||
await _fetchContactInfo(currentPhoneNumber!);
|
await _fetchContactInfo(currentPhoneNumber!);
|
||||||
|
=======
|
||||||
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
print('CallService: Incoming call from notification: $phoneNumber, wasPhoneLocked: $wasPhoneLocked');
|
print('CallService: Incoming call from notification: $phoneNumber, wasPhoneLocked: $wasPhoneLocked');
|
||||||
_handleIncomingCall(phoneNumber);
|
_handleIncomingCall(phoneNumber);
|
||||||
break;
|
break;
|
||||||
@ -101,6 +122,7 @@ class CallService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
Future<void> _fetchContactInfo(String phoneNumber) async {
|
Future<void> _fetchContactInfo(String phoneNumber) async {
|
||||||
try {
|
try {
|
||||||
@ -109,14 +131,28 @@ class CallService {
|
|||||||
for (var contact in contacts) {
|
for (var contact in contacts) {
|
||||||
for (var phone in contact.phones) {
|
for (var phone in contact.phones) {
|
||||||
if (_normalizePhoneNumber(phone.number) == normalizedPhoneNumber) {
|
if (_normalizePhoneNumber(phone.number) == normalizedPhoneNumber) {
|
||||||
|
=======
|
||||||
|
Future<void> _fetchContactInfo(String phoneNumber) async {
|
||||||
|
if (currentDisplayName != null && currentThumbnail != null) return; // Already set
|
||||||
|
try {
|
||||||
|
final contacts = await _contactService.fetchContacts(); // Use ContactService
|
||||||
|
for (var contact in contacts) {
|
||||||
|
for (var phone in contact.phones) {
|
||||||
|
if (_normalizePhoneNumber(phone.number) == _normalizePhoneNumber(phoneNumber)) {
|
||||||
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
currentDisplayName = contact.displayName;
|
currentDisplayName = contact.displayName;
|
||||||
currentThumbnail = contact.thumbnail;
|
currentThumbnail = contact.thumbnail;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD
|
||||||
currentDisplayName = phoneNumber;
|
currentDisplayName = phoneNumber;
|
||||||
currentThumbnail = null;
|
currentThumbnail = null;
|
||||||
|
=======
|
||||||
|
// If no match found, use phone number as fallback
|
||||||
|
currentDisplayName ??= phoneNumber;
|
||||||
|
currentThumbnail ??= null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('CallService: Error fetching contact info: $e');
|
print('CallService: Error fetching contact info: $e');
|
||||||
currentDisplayName = phoneNumber;
|
currentDisplayName = phoneNumber;
|
||||||
@ -128,8 +164,39 @@ class CallService {
|
|||||||
return number.replaceAll(RegExp(r'[\s\-\(\)]'), '');
|
return number.replaceAll(RegExp(r'[\s\-\(\)]'), '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _fetchContactInfo(String phoneNumber) async {
|
||||||
|
if (currentDisplayName != null && currentThumbnail != null) return; // Already set
|
||||||
|
try {
|
||||||
|
final contacts = await _contactService.fetchContacts(); // Use ContactService
|
||||||
|
for (var contact in contacts) {
|
||||||
|
for (var phone in contact.phones) {
|
||||||
|
if (_normalizePhoneNumber(phone.number) == _normalizePhoneNumber(phoneNumber)) {
|
||||||
|
currentDisplayName = contact.displayName;
|
||||||
|
currentThumbnail = contact.thumbnail;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If no match found, use phone number as fallback
|
||||||
|
currentDisplayName ??= phoneNumber;
|
||||||
|
currentThumbnail ??= null;
|
||||||
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
|
} catch (e) {
|
||||||
|
print('CallService: Error fetching contact info: $e');
|
||||||
|
currentDisplayName = phoneNumber;
|
||||||
|
currentThumbnail = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String _normalizePhoneNumber(String number) {
|
||||||
|
return number.replaceAll(RegExp(r'[\s\-\(\)]'), '');
|
||||||
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
=======
|
=======
|
||||||
>>>>>>> ec1779b (callNotifications and various fix related to calls (#49))
|
>>>>>>> ec1779b (callNotifications and various fix related to calls (#49))
|
||||||
|
=======
|
||||||
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
void _handleIncomingCall(String phoneNumber) {
|
void _handleIncomingCall(String phoneNumber) {
|
||||||
final context = navigatorKey.currentContext;
|
final context = navigatorKey.currentContext;
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
@ -294,11 +361,16 @@ class CallService {
|
|||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
currentPhoneNumber = phoneNumber;
|
currentPhoneNumber = phoneNumber;
|
||||||
|
<<<<<<< HEAD
|
||||||
currentDisplayName = displayName ?? phoneNumber;
|
currentDisplayName = displayName ?? phoneNumber;
|
||||||
currentThumbnail = thumbnail;
|
currentThumbnail = thumbnail;
|
||||||
if (displayName == null || thumbnail == null) {
|
if (displayName == null || thumbnail == null) {
|
||||||
await _fetchContactInfo(phoneNumber);
|
await _fetchContactInfo(phoneNumber);
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
currentDisplayName = displayName ?? phoneNumber; // Use provided or fetch later
|
||||||
|
currentThumbnail = thumbnail; // Use provided or fetch later
|
||||||
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
print('CallService: Making GSM call to $phoneNumber');
|
print('CallService: Making GSM call to $phoneNumber');
|
||||||
final result = await _channel.invokeMethod('makeGsmCall', {"phoneNumber": phoneNumber});
|
final result = await _channel.invokeMethod('makeGsmCall', {"phoneNumber": phoneNumber});
|
||||||
print('CallService: makeGsmCall result: $result');
|
print('CallService: makeGsmCall result: $result');
|
||||||
@ -309,11 +381,17 @@ class CallService {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
_handleCallState("dialing");
|
_handleCallState("dialing");
|
||||||
=======
|
=======
|
||||||
return resultMap;
|
return resultMap;
|
||||||
>>>>>>> ec1779b (callNotifications and various fix related to calls (#49))
|
>>>>>>> ec1779b (callNotifications and various fix related to calls (#49))
|
||||||
|
=======
|
||||||
|
// Fetch contact info if not provided
|
||||||
|
await _fetchContactInfo(phoneNumber);
|
||||||
|
_navigateToCallPage(context); // Navigate immediately after call initiation
|
||||||
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("CallService: Error making call: $e");
|
print("CallService: Error making call: $e");
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
Loading…
Reference in New Issue
Block a user