Skip to content

Commit

Permalink
UX enhancement, on device connection state and battery level as well
Browse files Browse the repository at this point in the history
  • Loading branch information
beastoin committed Dec 25, 2024
1 parent b2ecfdf commit 699be87
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 45 deletions.
15 changes: 7 additions & 8 deletions app/lib/pages/conversations/widgets/processing_capture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class _ConversationCaptureWidgetState extends State<ConversationCaptureWidget> {
bool transcriptServiceStateOk = captureProvider.transcriptServiceReady;
bool isHavingTranscript = captureProvider.segments.isNotEmpty;
bool isHavingDesireDevice = SharedPreferencesUtil().btDevice.id.isNotEmpty;
bool isHavingRecordingDevice = captureProvider.havingRecordingDevice;

bool isUsingPhoneMic = captureProvider.recordingState == RecordingState.record ||
captureProvider.recordingState == RecordingState.initialising ||
Expand Down Expand Up @@ -204,17 +205,15 @@ class _ConversationCaptureWidgetState extends State<ConversationCaptureWidget> {
// Right
Widget statusIndicator = const SizedBox.shrink();
var stateText = "";
if (!isHavingDesireDevice && !isUsingPhoneMic) {
if (!isHavingRecordingDevice && !isUsingPhoneMic) {
stateText = "";
} else if (transcriptServiceStateOk) {
} else if (transcriptServiceStateOk && (isUsingPhoneMic || isHavingRecordingDevice)) {
stateText = "Listening";
statusIndicator = const RecordingStatusIndicator();
} else if (!internetConnectionStateOk || !transcriptServiceStateOk) {
stateText = "Reconnecting";
statusIndicator = const CircularProgressIndicator(
strokeWidth: 2.0,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
);
} else if (!internetConnectionStateOk) {
stateText = "Waiting for network";
} else if (!transcriptServiceStateOk) {
stateText = "Connecting";
}
Widget right = stateText.isNotEmpty
? Expanded(
Expand Down
64 changes: 36 additions & 28 deletions app/lib/pages/home/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,34 @@ class _ConnectedDeviceState extends State<ConnectedDevice> {
textAlign: TextAlign.center,
),
const SizedBox(height: 12),
if (provider.pairedDevice != null)
Column(
children: [
Text(
'${provider.pairedDevice?.modelNumber}, firmware ${provider.pairedDevice?.firmwareRevision}',
style: const TextStyle(
color: Colors.white,
fontSize: 10.0,
fontWeight: FontWeight.w500,
height: 1,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 12),
Text(
'by ${provider.pairedDevice?.manufacturerName}',
style: const TextStyle(
color: Colors.white,
fontSize: 10.0,
fontWeight: FontWeight.w500,
height: 1,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 12),
],
),
provider.pairedDevice != null && provider.pairedDevice?.modelNumber != "Unknown"
? Column(
children: [
Text(
'${provider.pairedDevice?.modelNumber}, firmware ${provider.pairedDevice?.firmwareRevision}',
style: const TextStyle(
color: Colors.white,
fontSize: 10.0,
fontWeight: FontWeight.w500,
height: 1,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 12),
Text(
'by ${provider.pairedDevice?.manufacturerName}',
style: const TextStyle(
color: Colors.white,
fontSize: 10.0,
fontWeight: FontWeight.w500,
height: 1,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 12),
],
)
: const SizedBox.shrink(),
provider.connectedDevice != null
? Container(
decoration: BoxDecoration(
Expand Down Expand Up @@ -135,7 +136,14 @@ class _ConnectedDeviceState extends State<ConnectedDevice> {
),
],
))
: const SizedBox.shrink()
: const Text(
"Offline",
style: TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.w600,
),
)
],
),
const SizedBox(height: 32),
Expand Down
2 changes: 1 addition & 1 deletion app/lib/pages/home/widgets/battery_info_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class BatteryInfoWidget extends StatelessWidget {
isMemoriesPage ? const SizedBox(width: 8) : const SizedBox.shrink(),
deviceProvider.isConnecting && isMemoriesPage
? Text(
"Connecting",
"Searching",
style: Theme.of(context).textTheme.bodyMedium!.copyWith(color: Colors.white),
)
: isMemoriesPage
Expand Down
2 changes: 2 additions & 0 deletions app/lib/providers/capture_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class CaptureProvider extends ChangeNotifier

bool get recordingDeviceServiceReady => _recordingDevice != null || recordingState == RecordingState.record;

bool get havingRecordingDevice => _recordingDevice != null;

// -----------------------
// Conversation creation variables
String conversationId = const Uuid().v4();
Expand Down
13 changes: 5 additions & 8 deletions app/lib/providers/device_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
}

initiateBleBatteryListener() async {
if (_bleBatteryLevelListener != null) return;
if (connectedDevice == null) {
return;
}
_bleBatteryLevelListener?.cancel();
_bleBatteryLevelListener = await _getBleBatteryLevelListener(
connectedDevice!.id,
onBatteryLevelChange: (int value) {
batteryLevel = value;
notifyListeners();
},
);
notifyListeners();
Expand All @@ -108,7 +111,6 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
_reconnectionTimer?.cancel();
_reconnectionTimer = Timer.periodic(Duration(seconds: connectionCheckSeconds), (t) async {
debugPrint("period connect...");
print(printer);
print('seconds: $connectionCheckSeconds');
print('triggered timer at ${DateTime.now()}');

Expand Down Expand Up @@ -176,9 +178,6 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
}
updateConnectingStatus(false);
}
if (isConnected) {
await initiateBleBatteryListener();
}

notifyListeners();
}
Expand Down Expand Up @@ -244,9 +243,7 @@ class DeviceProvider extends ChangeNotifier implements IDeviceServiceSubsciption
setConnectedDevice(device);
setIsDeviceV2Connected();
setIsConnected(true);
if (isConnected) {
await initiateBleBatteryListener();
}
await initiateBleBatteryListener();
updateConnectingStatus(false);
await captureProvider?.streamDeviceRecording(device: device);

Expand Down
1 change: 1 addition & 0 deletions app/lib/services/devices/friend_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class FriendDeviceConnection extends DeviceConnection {
var listener = batteryLevelCharacteristic.lastValueStream.listen((value) {
// debugPrint('Battery level listener: $value');
if (value.isNotEmpty) {
debugPrint('Battery level changed: ${value[0]}');
onBatteryLevelChange!(value[0]);
}
});
Expand Down

0 comments on commit 699be87

Please sign in to comment.