WIP: callPageV2 #52
@ -153,6 +153,18 @@ class MainActivity : FlutterActivity() {
|
|||||||
}
|
}
|
||||||
result.success(true)
|
result.success(true)
|
||||||
}
|
}
|
||||||
|
"getCallState" -> {
|
||||||
|
val stateStr = when (MyInCallService.currentCall?.state) {
|
||||||
|
android.telecom.Call.STATE_ACTIVE -> "active"
|
||||||
|
android.telecom.Call.STATE_RINGING -> "ringing"
|
||||||
|
android.telecom.Call.STATE_DIALING -> "dialing"
|
||||||
|
android.telecom.Call.STATE_DISCONNECTED -> "disconnected"
|
||||||
|
android.telecom.Call.STATE_DISCONNECTING -> "disconnecting"
|
||||||
|
else -> "unknown"
|
||||||
|
}
|
||||||
|
Log.d(TAG, "getCallState called, returning: $stateStr")
|
||||||
|
result.success(stateStr)
|
||||||
|
}
|
||||||
else -> result.notImplemented()
|
else -> result.notImplemented()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,7 @@ class _CallPageState extends State<CallPage> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
_checkInitialCallState();
|
||||||
_listenToCallState();
|
_listenToCallState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,10 +48,24 @@ class _CallPageState extends State<CallPage> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _checkInitialCallState() async {
|
||||||
|
try {
|
||||||
|
final state = await _callService.getCallState();
|
||||||
|
print('CallPage: Initial call state: $state');
|
||||||
|
if (mounted && state == "active") {
|
||||||
|
setState(() {
|
||||||
|
_callStatus = "00:00";
|
||||||
|
_startCallTimer();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print('CallPage: Error checking initial state: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _listenToCallState() {
|
void _listenToCallState() {
|
||||||
_callStateSubscription = _callService.callStateStream.listen((state) {
|
_callStateSubscription = _callService.callStateStream.listen((state) {
|
||||||
final eventTime = DateTime.now().millisecondsSinceEpoch;
|
print('CallPage: Call state changed to $state');
|
||||||
print('CallPage: [${eventTime}ms] Call state changed to $state');
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (state == "active") {
|
if (state == "active") {
|
||||||
@ -76,7 +91,6 @@ class _CallPageState extends State<CallPage> {
|
|||||||
final minutes = (_callSeconds ~/ 60).toString().padLeft(2, '0');
|
final minutes = (_callSeconds ~/ 60).toString().padLeft(2, '0');
|
||||||
final seconds = (_callSeconds % 60).toString().padLeft(2, '0');
|
final seconds = (_callSeconds % 60).toString().padLeft(2, '0');
|
||||||
_callStatus = '$minutes:$seconds';
|
_callStatus = '$minutes:$seconds';
|
||||||
print('CallPage: [${DateTime.now().millisecondsSinceEpoch}ms] Timer updated, duration: $_callStatus');
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -114,12 +128,11 @@ class _CallPageState extends State<CallPage> {
|
|||||||
|
|
||||||
void _hangUp() async {
|
void _hangUp() async {
|
||||||
try {
|
try {
|
||||||
final hangUpStart = DateTime.now().millisecondsSinceEpoch;
|
print('CallPage: Initiating hangUp');
|
||||||
print('CallPage: [${hangUpStart}ms] Initiating hangUp');
|
|
||||||
final result = await _callService.hangUpCall(context);
|
final result = await _callService.hangUpCall(context);
|
||||||
print('CallPage: [${DateTime.now().millisecondsSinceEpoch}ms] Hang up result: $result');
|
print('CallPage: Hang up result: $result');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('CallPage: [${DateTime.now().millisecondsSinceEpoch}ms] Error hanging up: $e');
|
print('CallPage: Error hanging up: $e');
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text("Error hanging up: $e")),
|
SnackBar(content: Text("Error hanging up: $e")),
|
||||||
|
@ -8,7 +8,7 @@ import '../services/contact_service.dart';
|
|||||||
class CallService {
|
class CallService {
|
||||||
static const MethodChannel _channel = MethodChannel('call_service');
|
static const MethodChannel _channel = MethodChannel('call_service');
|
||||||
static String? currentPhoneNumber;
|
static String? currentPhoneNumber;
|
||||||
static String? currentDisplayName;
|
static String? currentDisplayName;
|
||||||
static Uint8List? currentThumbnail;
|
static Uint8List? currentThumbnail;
|
||||||
static bool _isCallPageVisible = false;
|
static bool _isCallPageVisible = false;
|
||||||
static Map<String, dynamic>? _pendingCall;
|
static Map<String, dynamic>? _pendingCall;
|
||||||
@ -133,6 +133,17 @@ class CallService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String?> getCallState() async {
|
||||||
|
try {
|
||||||
|
final state = await _channel.invokeMethod('getCallState');
|
||||||
|
print('CallService: getCallState returned: $state');
|
||||||
|
return state as String?;
|
||||||
|
} catch (e) {
|
||||||
|
print('CallService: Error getting call state: $e');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_callStateController.close();
|
_callStateController.close();
|
||||||
}
|
}
|
||||||
@ -322,7 +333,6 @@ class CallService {
|
|||||||
_activeCallNumber = null;
|
_activeCallNumber = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Future<Map<String, dynamic>> makeGsmCall(
|
Future<Map<String, dynamic>> makeGsmCall(
|
||||||
BuildContext context, {
|
BuildContext context, {
|
||||||
required String phoneNumber,
|
required String phoneNumber,
|
||||||
@ -359,7 +369,7 @@ class CallService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, dynamic>> hangUpCall(BuildContext context) async {
|
Future<Map<String, dynamic>> hangUpCall(BuildContext context) async {
|
||||||
try {
|
try {
|
||||||
print('CallService: Hanging up call');
|
print('CallService: Hanging up call');
|
||||||
final result = await _channel.invokeMethod('hangUpCall');
|
final result = await _channel.invokeMethod('hangUpCall');
|
||||||
|
Loading…
Reference in New Issue
Block a user