feat: add human-readable SIM name handling and update UI accordingly
This commit is contained in:
parent
af9ce4fa3c
commit
dd12b523cc
@ -6,6 +6,7 @@ import 'package:dialer/domain/services/obfuscate_service.dart';
|
|||||||
import 'package:dialer/presentation/common/widgets/username_color_generator.dart';
|
import 'package:dialer/presentation/common/widgets/username_color_generator.dart';
|
||||||
import 'package:dialer/presentation/common/widgets/sim_selection_dialog.dart';
|
import 'package:dialer/presentation/common/widgets/sim_selection_dialog.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:sim_data_new/sim_data.dart';
|
||||||
|
|
||||||
class CallPage extends StatefulWidget {
|
class CallPage extends StatefulWidget {
|
||||||
final String displayName;
|
final String displayName;
|
||||||
@ -38,9 +39,47 @@ class _CallPageState extends State<CallPage> {
|
|||||||
StreamSubscription<Map<String, dynamic>>? _audioStateSubscription;
|
StreamSubscription<Map<String, dynamic>>? _audioStateSubscription;
|
||||||
StreamSubscription<int?>? _simStateSubscription;
|
StreamSubscription<int?>? _simStateSubscription;
|
||||||
bool _isCallActive = true; // Track if call is still active
|
bool _isCallActive = true; // Track if call is still active
|
||||||
|
String? _simName; // Human-readable SIM card name
|
||||||
|
|
||||||
bool get isNumberUnknown => widget.displayName == widget.phoneNumber;
|
bool get isNumberUnknown => widget.displayName == widget.phoneNumber;
|
||||||
|
|
||||||
|
// Fetch and update human-readable SIM name based on slot
|
||||||
|
Future<void> _updateSimName(int? simSlot) async {
|
||||||
|
if (!mounted) return;
|
||||||
|
if (simSlot != null) {
|
||||||
|
try {
|
||||||
|
final simData = await SimDataPlugin.getSimData();
|
||||||
|
// Find the SIM card matching the slot index, if any
|
||||||
|
dynamic card;
|
||||||
|
for (var c in simData.cards) {
|
||||||
|
if (c.slotIndex == simSlot) {
|
||||||
|
card = c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String name;
|
||||||
|
if (card != null && card.displayName.isNotEmpty) {
|
||||||
|
name = card.displayName;
|
||||||
|
} else if (card != null && card.carrierName.isNotEmpty) {
|
||||||
|
name = card.carrierName;
|
||||||
|
} else {
|
||||||
|
name = 'SIM ${simSlot + 1}';
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
_simName = name;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
_simName = 'SIM ${simSlot + 1}';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
_simName = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@ -48,6 +87,7 @@ class _CallPageState extends State<CallPage> {
|
|||||||
_listenToCallState();
|
_listenToCallState();
|
||||||
_listenToAudioState();
|
_listenToAudioState();
|
||||||
_listenToSimState();
|
_listenToSimState();
|
||||||
|
_updateSimName(CallService.getCurrentSimSlot); // Initial SIM name
|
||||||
_setInitialAudioState();
|
_setInitialAudioState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,12 +170,7 @@ class _CallPageState extends State<CallPage> {
|
|||||||
|
|
||||||
void _listenToSimState() {
|
void _listenToSimState() {
|
||||||
_simStateSubscription = _callService.simStateStream.listen((simSlot) {
|
_simStateSubscription = _callService.simStateStream.listen((simSlot) {
|
||||||
if (mounted) {
|
_updateSimName(simSlot);
|
||||||
setState(() {
|
|
||||||
// UI will update automatically because we're listening to the stream
|
|
||||||
// The SIM display will show the new SIM slot
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,8 +438,8 @@ class _CallPageState extends State<CallPage> {
|
|||||||
color: Colors.white70,
|
color: Colors.white70,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
// Show SIM information if available
|
// Show SIM information if a SIM slot has been set
|
||||||
if (CallService.getCurrentSimDisplayName() != null)
|
if (_simName != null)
|
||||||
Container(
|
Container(
|
||||||
margin: const EdgeInsets.only(top: 4.0),
|
margin: const EdgeInsets.only(top: 4.0),
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
@ -418,7 +453,8 @@ class _CallPageState extends State<CallPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
CallService.getCurrentSimDisplayName()!,
|
// Show human-readable SIM name plus slot number
|
||||||
|
'$_simName (SIM ${CallService.getCurrentSimSlot! + 1})',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: statusFontSize - 2,
|
fontSize: statusFontSize - 2,
|
||||||
color: Colors.lightBlueAccent,
|
color: Colors.lightBlueAccent,
|
||||||
|
Loading…
Reference in New Issue
Block a user