WIP: callPageV2 #52
@ -51,7 +51,12 @@ class CallService {
|
||||
=======
|
||||
=======
|
||||
static String? _currentCallState;
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> f491fb6 (fix: no screen stacking when making calls)
|
||||
=======
|
||||
static Map<String, dynamic>? _pendingCall;
|
||||
static bool wasPhoneLocked = false;
|
||||
>>>>>>> 6628dd6 (feat: merge call_service with callNotifications changes)
|
||||
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)
|
||||
@ -60,11 +65,15 @@ class CallService {
|
||||
|
||||
CallService() {
|
||||
_channel.setMethodCallHandler((call) async {
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
print('CallService: Received method ${call.method} with args ${call.arguments}');
|
||||
=======
|
||||
print('CallService: Handling method call: ${call.method}');
|
||||
>>>>>>> ec1779b (callNotifications and various fix related to calls (#49))
|
||||
=======
|
||||
print('CallService: Received method ${call.method} with args ${call.arguments}');
|
||||
>>>>>>> b3c8bf7 (feat: merge call_service with callNotifications changes)
|
||||
switch (call.method) {
|
||||
case "callAdded":
|
||||
final phoneNumber = call.arguments["callId"] as String;
|
||||
@ -80,11 +89,14 @@ class CallService {
|
||||
await _fetchContactInfo(currentPhoneNumber!);
|
||||
print('CallService: Call added, number: $currentPhoneNumber, state: $state');
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
_handleCallState(state);
|
||||
=======
|
||||
=======
|
||||
>>>>>>> 9e76148 (fix: no screen stacking when making calls)
|
||||
=======
|
||||
>>>>>>> b3c8bf7 (feat: merge call_service with callNotifications changes)
|
||||
if (state == "ringing") {
|
||||
_handleIncomingCall(phoneNumber);
|
||||
} else {
|
||||
@ -121,7 +133,19 @@ class CallService {
|
||||
print('CallService: State changed to $state');
|
||||
_handleCallState(context, state);
|
||||
>>>>>>> f491fb6 (fix: no screen stacking when making calls)
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> 9e76148 (fix: no screen stacking when making calls)
|
||||
=======
|
||||
=======
|
||||
_handleCallState(state);
|
||||
break;
|
||||
case "callStateChanged":
|
||||
final state = call.arguments["state"] as String;
|
||||
wasPhoneLocked = call.arguments["wasPhoneLocked"] as bool? ?? false;
|
||||
print('CallService: State changed to $state, wasPhoneLocked: $wasPhoneLocked');
|
||||
_handleCallState(state);
|
||||
>>>>>>> 6628dd6 (feat: merge call_service with callNotifications changes)
|
||||
>>>>>>> b3c8bf7 (feat: merge call_service with callNotifications changes)
|
||||
break;
|
||||
case "callEnded":
|
||||
case "callRemoved":
|
||||
@ -147,10 +171,13 @@ class CallService {
|
||||
final phoneNumber = call.arguments["phoneNumber"] as String;
|
||||
wasPhoneLocked = call.arguments["wasPhoneLocked"] as bool? ?? false;
|
||||
currentPhoneNumber = phoneNumber;
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
await _fetchContactInfo(currentPhoneNumber!);
|
||||
=======
|
||||
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||
=======
|
||||
>>>>>>> b3c8bf7 (feat: merge call_service with callNotifications changes)
|
||||
print('CallService: Incoming call from notification: $phoneNumber, wasPhoneLocked: $wasPhoneLocked');
|
||||
_handleIncomingCall(phoneNumber);
|
||||
break;
|
||||
@ -158,6 +185,9 @@ class CallService {
|
||||
final phoneNumber = call.arguments["phoneNumber"] as String;
|
||||
wasPhoneLocked = call.arguments["wasPhoneLocked"] as bool? ?? false;
|
||||
currentPhoneNumber = phoneNumber;
|
||||
=======
|
||||
await _fetchContactInfo(currentPhoneNumber!);
|
||||
>>>>>>> 6628dd6 (feat: merge call_service with callNotifications changes)
|
||||
print('CallService: Incoming call from notification: $phoneNumber, wasPhoneLocked: $wasPhoneLocked');
|
||||
_handleIncomingCall(phoneNumber);
|
||||
break;
|
||||
@ -214,6 +244,7 @@ class CallService {
|
||||
return number.replaceAll(RegExp(r'[\s\-\(\)]'), '');
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
Future<void> _fetchContactInfo(String phoneNumber) async {
|
||||
if (currentDisplayName != null && currentThumbnail != null) return; // Already set
|
||||
@ -243,11 +274,16 @@ class CallService {
|
||||
return number.replaceAll(RegExp(r'[\s\-\(\)]'), '');
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> ec1779b (callNotifications and various fix related to calls (#49))
|
||||
=======
|
||||
>>>>>>> 3e2be8a (feat: fetch contact in makeGsmCall to show it in call)
|
||||
=======
|
||||
=======
|
||||
>>>>>>> 6628dd6 (feat: merge call_service with callNotifications changes)
|
||||
>>>>>>> b3c8bf7 (feat: merge call_service with callNotifications changes)
|
||||
void _handleIncomingCall(String phoneNumber) {
|
||||
final context = navigatorKey.currentContext;
|
||||
if (context == null) {
|
||||
@ -255,8 +291,36 @@ class CallService {
|
||||
_pendingCall = {"phoneNumber": phoneNumber};
|
||||
Future.delayed(Duration(milliseconds: 500), () => _checkPendingCall());
|
||||
} else {
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
void _handleCallState(BuildContext context, String state) {
|
||||
=======
|
||||
_navigateToIncomingCallPage(context);
|
||||
}
|
||||
}
|
||||
|
||||
void _checkPendingCall() {
|
||||
if (_pendingCall != null) {
|
||||
final context = navigatorKey.currentContext;
|
||||
if (context != null) {
|
||||
print('CallService: Processing queued call: ${_pendingCall!["phoneNumber"]}');
|
||||
currentPhoneNumber = _pendingCall!["phoneNumber"];
|
||||
_navigateToIncomingCallPage(context);
|
||||
_pendingCall = null;
|
||||
} else {
|
||||
print('CallService: Context still null, retrying...');
|
||||
Future.delayed(Duration(milliseconds: 500), () => _checkPendingCall());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _handleCallState(String state) {
|
||||
final context = navigatorKey.currentContext;
|
||||
if (context == null) {
|
||||
print('CallService: Navigator context is null, cannot navigate');
|
||||
return;
|
||||
}
|
||||
>>>>>>> 6628dd6 (feat: merge call_service with callNotifications changes)
|
||||
if (_currentCallState == state) {
|
||||
print('CallService: State $state already handled, skipping');
|
||||
return;
|
||||
@ -264,7 +328,7 @@ class CallService {
|
||||
_currentCallState = state;
|
||||
|
||||
if (state == "disconnected" || state == "disconnecting") {
|
||||
_closeCallPage(context);
|
||||
_closeCallPage();
|
||||
} else if (state == "active" || state == "dialing") {
|
||||
_navigateToCallPage(context);
|
||||
} else if (state == "ringing") {
|
||||
@ -366,7 +430,6 @@ class CallService {
|
||||
).then((_) {
|
||||
print('CallService: CallPage popped');
|
||||
_isCallPageVisible = false;
|
||||
print('CallService: CallPage popped, _isCallPageVisible set to false');
|
||||
});
|
||||
_isCallPageVisible = true;
|
||||
}
|
||||
@ -408,17 +471,20 @@ class CallService {
|
||||
).then((_) {
|
||||
print('CallService: IncomingCallPage popped');
|
||||
_isCallPageVisible = false;
|
||||
print('CallService: IncomingCallPage popped, _isCallPageVisible set to false');
|
||||
});
|
||||
_isCallPageVisible = true;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> 6628dd6 (feat: merge call_service with callNotifications changes)
|
||||
void _closeCallPage() {
|
||||
final context = navigatorKey.currentContext;
|
||||
if (context == null) {
|
||||
print('CallService: Cannot close page, context is null');
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
return;
|
||||
}
|
||||
@ -428,8 +494,14 @@ class CallService {
|
||||
=======
|
||||
>>>>>>> ec1779b (callNotifications and various fix related to calls (#49))
|
||||
=======
|
||||
=======
|
||||
>>>>>>> b3c8bf7 (feat: merge call_service with callNotifications changes)
|
||||
=======
|
||||
void _closeCallPage(BuildContext context) {
|
||||
=======
|
||||
return;
|
||||
}
|
||||
>>>>>>> 6628dd6 (feat: merge call_service with callNotifications changes)
|
||||
print('CallService: Attempting to close call page. Visible: $_isCallPageVisible');
|
||||
if (!_isCallPageVisible) {
|
||||
print('CallService: CallPage not visible, skipping pop');
|
||||
@ -437,7 +509,6 @@ class CallService {
|
||||
>>>>>>> 9e76148 (fix: no screen stacking when making calls)
|
||||
return;
|
||||
}
|
||||
print('CallService: Closing call page, _isCallPageVisible: $_isCallPageVisible');
|
||||
if (Navigator.canPop(context)) {
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
@ -468,7 +539,7 @@ class CallService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> makeGsmCall(
|
||||
Future<void> makeGsmCall(
|
||||
BuildContext context, {
|
||||
required String phoneNumber,
|
||||
String? displayName,
|
||||
@ -499,8 +570,7 @@ class CallService {
|
||||
print('CallService: Making GSM call to $phoneNumber');
|
||||
final result = await _channel.invokeMethod('makeGsmCall', {"phoneNumber": phoneNumber});
|
||||
print('CallService: makeGsmCall result: $result');
|
||||
final resultMap = Map<String, dynamic>.from(result as Map);
|
||||
if (resultMap["status"] != "calling") {
|
||||
if (result["status"] != "calling") {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Failed to initiate call")),
|
||||
);
|
||||
@ -509,6 +579,7 @@ class CallService {
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
_handleCallState("dialing");
|
||||
=======
|
||||
@ -525,39 +596,44 @@ class CallService {
|
||||
=======
|
||||
_handleCallState(context, "dialing");
|
||||
>>>>>>> 9e76148 (fix: no screen stacking when making calls)
|
||||
=======
|
||||
_handleCallState("dialing");
|
||||
>>>>>>> b3c8bf7 (feat: merge call_service with callNotifications changes)
|
||||
} catch (e) {
|
||||
print("CallService: Error making call: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Error making call: $e")),
|
||||
);
|
||||
return {"status": "error", "message": e.toString()};
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> hangUpCall(BuildContext context) async {
|
||||
Future<void> hangUpCall(BuildContext context) async {
|
||||
try {
|
||||
print('CallService: Hanging up call');
|
||||
final result = await _channel.invokeMethod('hangUpCall');
|
||||
print('CallService: hangUpCall result: $result');
|
||||
final resultMap = Map<String, dynamic>.from(result as Map);
|
||||
if (resultMap["status"] != "ended") {
|
||||
if (result["status"] != "ended") {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Failed to end call")),
|
||||
);
|
||||
} else {
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
_closeCallPage();
|
||||
=======
|
||||
_closeCallPage(context);
|
||||
>>>>>>> 9e76148 (fix: no screen stacking when making calls)
|
||||
=======
|
||||
_closeCallPage();
|
||||
>>>>>>> b3c8bf7 (feat: merge call_service with callNotifications changes)
|
||||
}
|
||||
return resultMap;
|
||||
} catch (e) {
|
||||
print("CallService: Error hanging up call: $e");
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Error hanging up call: $e")),
|
||||
);
|
||||
return {"status": "error", "message": e.toString()};
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user