WIP: callPageV2 #52
@ -1,19 +1,25 @@
|
|||||||
|
import 'dart:typed_data';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
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
|
<<<<<<< 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
|
import '../services/contact_service.dart'; // Import your ContactService
|
||||||
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
|
=======
|
||||||
|
import '../services/contact_service.dart';
|
||||||
|
>>>>>>> c2c646a (feat: give parameters to callPage to avoid fetching when possible)
|
||||||
|
|
||||||
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
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
static String? currentDisplayName;
|
static String? currentDisplayName;
|
||||||
static Uint8List? currentThumbnail;
|
static Uint8List? currentThumbnail;
|
||||||
@ -23,16 +29,27 @@ class CallService {
|
|||||||
=======
|
=======
|
||||||
static String? currentDisplayName; // Store display name
|
static String? currentDisplayName; // Store display name
|
||||||
static Uint8List? currentThumbnail; // Store thumbnail
|
static Uint8List? currentThumbnail; // Store thumbnail
|
||||||
|
=======
|
||||||
|
static String? currentDisplayName;
|
||||||
|
static Uint8List? currentThumbnail;
|
||||||
|
>>>>>>> c2c646a (feat: give parameters to callPage to avoid fetching when possible)
|
||||||
static bool _isCallPageVisible = false;
|
static bool _isCallPageVisible = false;
|
||||||
|
<<<<<<< HEAD
|
||||||
final ContactService _contactService = ContactService(); // Instantiate ContactService
|
final ContactService _contactService = ContactService(); // Instantiate ContactService
|
||||||
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
>>>>>>> 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;
|
||||||
|
<<<<<<< HEAD
|
||||||
final ContactService _contactService = ContactService();
|
final ContactService _contactService = ContactService();
|
||||||
=======
|
=======
|
||||||
static Map<String, dynamic>? _pendingCall;
|
static Map<String, dynamic>? _pendingCall;
|
||||||
static bool wasPhoneLocked = false;
|
static bool wasPhoneLocked = false;
|
||||||
>>>>>>> ec1779b (callNotifications and various fix related to calls (#49))
|
>>>>>>> ec1779b (callNotifications and various fix related to calls (#49))
|
||||||
|
=======
|
||||||
|
=======
|
||||||
|
final ContactService _contactService = ContactService();
|
||||||
|
>>>>>>> acbccaa (feat: give parameters to callPage to avoid fetching when possible)
|
||||||
|
>>>>>>> c2c646a (feat: give parameters to callPage to avoid fetching when possible)
|
||||||
|
|
||||||
static final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
static final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||||
|
|
||||||
@ -49,9 +66,12 @@ class CallService {
|
|||||||
final state = call.arguments["state"] as String;
|
final state = call.arguments["state"] as String;
|
||||||
currentPhoneNumber = phoneNumber.replaceFirst('tel:', '');
|
currentPhoneNumber = phoneNumber.replaceFirst('tel:', '');
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
|
<<<<<<< HEAD
|
||||||
=======
|
=======
|
||||||
// Fetch contact info using ContactService if not already set
|
// Fetch contact info using ContactService if not already set
|
||||||
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
|
=======
|
||||||
|
>>>>>>> c2c646a (feat: give parameters to callPage to avoid fetching when possible)
|
||||||
await _fetchContactInfo(currentPhoneNumber!);
|
await _fetchContactInfo(currentPhoneNumber!);
|
||||||
print('CallService: Call added, number: $currentPhoneNumber, state: $state');
|
print('CallService: Call added, number: $currentPhoneNumber, state: $state');
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
@ -133,13 +153,17 @@ class CallService {
|
|||||||
if (_normalizePhoneNumber(phone.number) == normalizedPhoneNumber) {
|
if (_normalizePhoneNumber(phone.number) == normalizedPhoneNumber) {
|
||||||
=======
|
=======
|
||||||
Future<void> _fetchContactInfo(String phoneNumber) async {
|
Future<void> _fetchContactInfo(String phoneNumber) async {
|
||||||
if (currentDisplayName != null && currentThumbnail != null) return; // Already set
|
|
||||||
try {
|
try {
|
||||||
final contacts = await _contactService.fetchContacts(); // Use ContactService
|
final contacts = await _contactService.fetchContacts();
|
||||||
|
final normalizedPhoneNumber = _normalizePhoneNumber(phoneNumber);
|
||||||
for (var contact in contacts) {
|
for (var contact in contacts) {
|
||||||
for (var phone in contact.phones) {
|
for (var phone in contact.phones) {
|
||||||
|
<<<<<<< HEAD
|
||||||
if (_normalizePhoneNumber(phone.number) == _normalizePhoneNumber(phoneNumber)) {
|
if (_normalizePhoneNumber(phone.number) == _normalizePhoneNumber(phoneNumber)) {
|
||||||
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
|
=======
|
||||||
|
if (_normalizePhoneNumber(phone.number) == normalizedPhoneNumber) {
|
||||||
|
>>>>>>> c2c646a (feat: give parameters to callPage to avoid fetching when possible)
|
||||||
currentDisplayName = contact.displayName;
|
currentDisplayName = contact.displayName;
|
||||||
currentThumbnail = contact.thumbnail;
|
currentThumbnail = contact.thumbnail;
|
||||||
return;
|
return;
|
||||||
@ -151,8 +175,8 @@ class CallService {
|
|||||||
currentThumbnail = null;
|
currentThumbnail = null;
|
||||||
=======
|
=======
|
||||||
// If no match found, use phone number as fallback
|
// If no match found, use phone number as fallback
|
||||||
currentDisplayName ??= phoneNumber;
|
currentDisplayName = phoneNumber;
|
||||||
currentThumbnail ??= null;
|
currentThumbnail = null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('CallService: Error fetching contact info: $e');
|
print('CallService: Error fetching contact info: $e');
|
||||||
currentDisplayName = phoneNumber;
|
currentDisplayName = phoneNumber;
|
||||||
@ -362,15 +386,22 @@ class CallService {
|
|||||||
try {
|
try {
|
||||||
currentPhoneNumber = phoneNumber;
|
currentPhoneNumber = phoneNumber;
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
// Use provided displayName and thumbnail if available, otherwise fetch
|
||||||
|
>>>>>>> c2c646a (feat: give parameters to callPage to avoid fetching when possible)
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD
|
||||||
=======
|
=======
|
||||||
currentDisplayName = displayName ?? phoneNumber; // Use provided or fetch later
|
currentDisplayName = displayName ?? phoneNumber; // Use provided or fetch later
|
||||||
currentThumbnail = thumbnail; // Use provided or fetch later
|
currentThumbnail = thumbnail; // Use provided or fetch later
|
||||||
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
|
=======
|
||||||
|
>>>>>>> c2c646a (feat: give parameters to callPage to avoid fetching when possible)
|
||||||
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');
|
||||||
@ -382,6 +413,7 @@ class CallService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
|
<<<<<<< HEAD
|
||||||
<<<<<<< HEAD
|
<<<<<<< HEAD
|
||||||
_handleCallState("dialing");
|
_handleCallState("dialing");
|
||||||
=======
|
=======
|
||||||
@ -392,6 +424,9 @@ class CallService {
|
|||||||
await _fetchContactInfo(phoneNumber);
|
await _fetchContactInfo(phoneNumber);
|
||||||
_navigateToCallPage(context); // Navigate immediately after call initiation
|
_navigateToCallPage(context); // Navigate immediately after call initiation
|
||||||
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||||
|
=======
|
||||||
|
_navigateToCallPage(context);
|
||||||
|
>>>>>>> c2c646a (feat: give parameters to callPage to avoid fetching when possible)
|
||||||
} 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