WIP: callPageV2 #52

Draft
florian wants to merge 16 commits from callPageV2 into dev
Showing only changes of commit 59e813974c - Show all commits

View File

@ -17,13 +17,7 @@ class CallService {
CallService() {
_channel.setMethodCallHandler((call) async {
final context = navigatorKey.currentContext;
print('CallService: Received method ${call.method} with args ${call.arguments}');
if (context == null) {
print('CallService: Navigator context is null, cannot navigate');
return;
}
print('CallService: Handling method call: ${call.method}');
switch (call.method) {
case "callAdded":
final phoneNumber = call.arguments["callId"] as String;
@ -40,8 +34,12 @@ class CallService {
break;
case "callEnded":
case "callRemoved":
print('CallService: Call ended/removed');
_closeCallPage(context);
wasPhoneLocked = call.arguments["wasPhoneLocked"] as bool? ?? false;
print('CallService: Call ended/removed, wasPhoneLocked: $wasPhoneLocked');
_closeCallPage();
if (wasPhoneLocked) {
_channel.invokeMethod("callEndedFromFlutter");
}
currentPhoneNumber = null;
currentDisplayName = null;
currentThumbnail = null;
@ -117,6 +115,7 @@ class CallService {
).then((_) {
print('CallService: CallPage popped');
_isCallPageVisible = false;
print('CallService: CallPage popped, _isCallPageVisible set to false');
});
_isCallPageVisible = true;
}
@ -145,6 +144,7 @@ class CallService {
).then((_) {
print('CallService: IncomingCallPage popped');
_isCallPageVisible = false;
print('CallService: IncomingCallPage popped, _isCallPageVisible set to false');
});
_isCallPageVisible = true;
}
@ -155,6 +155,7 @@ class CallService {
print('CallService: CallPage not visible, skipping pop');
return;
}
print('CallService: Closing call page, _isCallPageVisible: $_isCallPageVisible');
if (Navigator.canPop(context)) {
print('CallService: Popping CallPage. Current Route: ${ModalRoute.of(context)?.settings.name}');
Navigator.pop(context);
@ -164,7 +165,7 @@ class CallService {
}
}
Future<void> makeGsmCall(
Future<Map<String, dynamic>> makeGsmCall(
BuildContext context, {
required String phoneNumber,
String? displayName,
@ -180,7 +181,8 @@ class CallService {
print('CallService: Making GSM call to $phoneNumber');
final result = await _channel.invokeMethod('makeGsmCall', {"phoneNumber": phoneNumber});
print('CallService: makeGsmCall result: $result');
if (result["status"] != "calling") {
final resultMap = Map<String, dynamic>.from(result as Map);
if (resultMap["status"] != "calling") {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Failed to initiate call")),
);
@ -192,28 +194,30 @@ class CallService {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Error making call: $e")),
);
rethrow;
return {"status": "error", "message": e.toString()};
}
}
Future<void> hangUpCall(BuildContext context) async {
Future<Map<String, dynamic>> hangUpCall(BuildContext context) async {
try {
print('CallService: Hanging up call');
final result = await _channel.invokeMethod('hangUpCall');
print('CallService: hangUpCall result: $result');
if (result["status"] != "ended") {
final resultMap = Map<String, dynamic>.from(result as Map);
if (resultMap["status"] != "ended") {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Failed to end call")),
);
} else {
_closeCallPage(context);
}
return resultMap;
} catch (e) {
print("CallService: Error hanging up call: $e");
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text("Error hanging up call: $e")),
);
rethrow;
return {"status": "error", "message": e.toString()};
}
}
}