Skip to content

Commit

Permalink
Unified BtDevice Object (#940)
Browse files Browse the repository at this point in the history
https://github.com/user-attachments/assets/74687e5c-49c4-4dfa-9302-0e9e32452c14



<!-- This is an auto-generated comment: release notes by OSS
Entelligence.AI -->
### Summary by Entelligence.AI

- Refactor: Unified the Bluetooth device handling across the application
by introducing a new `BtDevice` class and `BtDeviceInfo` class. This
change improves the consistency of device information retrieval and
storage.
- New Feature: Added methods for creating `BtDevice` instances from
different sources, providing more flexibility in device management.
- Refactor: Updated import paths for better organization of the
codebase.
- Refactor: Adjusted button actions related to device disconnection and
unpairing for improved user experience.
- Refactor: Streamlined the usage of the `BtDevice` object consistently
throughout the code, enhancing code maintainability.
- Bug Fix: Fixed potential issues with fetching device info by adding
checks in `initState`.
- Chore: Updated references to properties within `BtDevice` in various
parts of the code for consistency.
<!-- end of auto-generated comment: release notes by OSS Entelligence.AI
-->
  • Loading branch information
beastoin authored Oct 1, 2024
2 parents d854d82 + c687b23 commit 127b1f5
Show file tree
Hide file tree
Showing 27 changed files with 613 additions and 526 deletions.
18 changes: 9 additions & 9 deletions app/lib/backend/preferences.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:convert';

import 'package:collection/collection.dart';
import 'package:friend_private/backend/schema/bt_device.dart';
import 'package:friend_private/backend/schema/memory.dart';
import 'package:friend_private/backend/schema/message.dart';
import 'package:friend_private/backend/schema/bt_device/bt_device.dart';
import 'package:friend_private/backend/schema/person.dart';
import 'package:friend_private/backend/schema/plugin.dart';
import 'package:friend_private/backend/schema/transcript_segment.dart';
Expand All @@ -27,18 +27,18 @@ class SharedPreferencesUtil {

String get uid => getString('uid') ?? '';

set btDeviceStruct(BTDeviceStruct value) {
saveString('btDeviceStruct', jsonEncode(value.toJson()));
set btDevice(BtDevice value) {
saveString('btDevice', jsonEncode(value.toJson()));
}

Future<void> btDeviceStructSet(BTDeviceStruct value) async {
await saveString('btDeviceStruct', jsonEncode(value.toJson()));
Future<void> btDeviceSet(BtDevice value) async {
await saveString('btDevice', jsonEncode(value.toJson()));
}

BTDeviceStruct get btDeviceStruct {
final String device = getString('btDeviceStruct') ?? '';
if (device.isEmpty) return BTDeviceStruct(id: '', name: '');
return BTDeviceStruct.fromJson(jsonDecode(device));
BtDevice get btDevice {
final String device = getString('btDevice') ?? '';
if (device.isEmpty) return BtDevice(id: '', name: '', type: DeviceType.friend, rssi: 0);
return BtDevice.fromJson(jsonDecode(device));
}

set deviceName(String value) => saveString('deviceName', value);
Expand Down
250 changes: 0 additions & 250 deletions app/lib/backend/schema/bt_device.dart

This file was deleted.

Loading

0 comments on commit 127b1f5

Please sign in to comment.