Skip to content

Commit

Permalink
Clean imports
Browse files Browse the repository at this point in the history
  • Loading branch information
beastoin committed Sep 26, 2024
1 parent d866cf9 commit ef31239
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 336 deletions.
6 changes: 3 additions & 3 deletions app/lib/backend/schema/bt_device.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:friend_private/services/device_connections.dart';
import 'package:friend_private/services/frame_connection.dart';
import 'package:friend_private/utils/ble/gatt_utils.dart';
import 'package:friend_private/services/devices/device_connection.dart';
import 'package:friend_private/services/devices/frame_connection.dart';
import 'package:friend_private/services/devices/models.dart';

enum BleAudioCodec {
pcm16,
Expand Down
253 changes: 0 additions & 253 deletions app/lib/pages/capture/widgets/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,212 +2,16 @@ import 'package:flutter/material.dart';
import 'package:friend_private/backend/preferences.dart';
import 'package:friend_private/backend/schema/bt_device.dart';
import 'package:friend_private/backend/schema/transcript_segment.dart';
import 'package:friend_private/pages/capture/connect.dart';
import 'package:friend_private/pages/speech_profile/page.dart';
import 'package:friend_private/providers/capture_provider.dart';
import 'package:friend_private/providers/connectivity_provider.dart';
import 'package:friend_private/providers/device_provider.dart';
import 'package:friend_private/providers/home_provider.dart';
import 'package:friend_private/utils/analytics/mixpanel.dart';
import 'package:friend_private/utils/enums.dart';
import 'package:friend_private/utils/other/temp.dart';
import 'package:friend_private/utils/websockets.dart';
import 'package:friend_private/widgets/device_widget.dart';
import 'package:friend_private/widgets/dialog.dart';
import 'package:friend_private/widgets/photos_grid.dart';
import 'package:friend_private/widgets/scanning_ui.dart';
import 'package:friend_private/widgets/transcript.dart';
import 'package:gradient_borders/gradient_borders.dart';
import 'package:lottie/lottie.dart';
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';
import 'package:url_launcher/url_launcher.dart';

getConnectionStateWidgets(
BuildContext context,
bool hasTranscripts,
BTDeviceStruct? device,
WebsocketConnectionStatus wsConnectionState,
) {
if (hasTranscripts) return [];
if (device == null) {
return [
const DeviceAnimationWidget(sizeMultiplier: 0.7),
SharedPreferencesUtil().btDeviceStruct.id == ''
? _getNoFriendConnectedYet(context)
: const ScanningUI(
string1: 'Looking for Friend wearable',
string2: 'Locating your Friend device. Keep it near your phone for pairing',
),
];
}

bool isWebsocketError =
wsConnectionState == WebsocketConnectionStatus.failed || wsConnectionState == WebsocketConnectionStatus.error;

return [
const Center(child: DeviceAnimationWidget(sizeMultiplier: 0.7)),
Consumer<ConnectivityProvider>(builder: (context, connectivityProvider, child) {
return GestureDetector(
onTap: !connectivityProvider.isConnected || isWebsocketError
? () {
showDialog(
context: context,
builder: (c) => getDialog(
context,
() => Navigator.pop(context),
() => Navigator.pop(context),
!connectivityProvider.isConnected ? 'Internet Connection Lost' : 'Connection Issue',
!connectivityProvider.isConnected
? 'Your device is offline. Transcription is paused until connection is restored.'
: 'Unable to connect to the transcript service. Please restart the app or contact support if the problem persists.',
okButtonText: 'Ok',
singleButton: true,
),
);
}
: null,
child: Center(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(width: 24),
Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
!connectivityProvider.isConnected
? 'No Internet'
: (connectivityProvider.isConnected && isWebsocketError)
? 'Server Issue'
: 'Listening',
style: TextStyle(
color: Colors.white,
fontSize: !connectivityProvider.isConnected
? 29
: isWebsocketError
? 29
: 29,
letterSpacing: 0.0,
fontWeight: FontWeight.w700,
height: 1.2),
textAlign: TextAlign.center,
),
Text(
'${device.name} (${device.getShortId()})',
style: const TextStyle(
color: Colors.white,
fontSize: 16.0,
fontWeight: FontWeight.w500,
height: 1.5,
),
textAlign: TextAlign.center,
)
],
),
const SizedBox(width: 24),
!connectivityProvider.isConnected
? Lottie.asset('assets/lottie_animations/no_internet.json', height: 56, width: 56)
: isWebsocketError
// ? Lottie.network('https://lottie.host/8223dbf8-8a50-4d48-8e37-0b845b1f1094/TQcT5w5Mn4.json', height: 48, width: 48)
? Lottie.asset('assets/lottie_animations/no_internet.json', height: 56, width: 56)
// TODO: find a better animation for server
: Container(
width: 10,
height: 10,
decoration: const BoxDecoration(
color: Color.fromARGB(255, 0, 255, 9),
shape: BoxShape.circle,
),
),
],
)),
);
}),
const SizedBox(height: 8),
// const Row(
// crossAxisAlignment: CrossAxisAlignment.center,
// mainAxisAlignment: MainAxisAlignment.center,
// children: [],
// ),
];
}

_getNoFriendConnectedYet(BuildContext context) {
return Column(
children: [
const SizedBox(height: 24),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// const Padding(
// padding: EdgeInsets.symmetric(horizontal: 32),
// child: Text(
// 'Get a Friend wearable to start capturing your memories.',
// textAlign: TextAlign.center,
// style: TextStyle(color: Colors.white, fontSize: 18),
// )),
// const SizedBox(height: 32),
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 0),
decoration: BoxDecoration(
border: const GradientBoxBorder(
gradient: LinearGradient(colors: [
Color.fromARGB(127, 208, 208, 208),
Color.fromARGB(127, 188, 99, 121),
Color.fromARGB(127, 86, 101, 182),
Color.fromARGB(127, 126, 190, 236)
]),
width: 2,
),
borderRadius: BorderRadius.circular(12),
),
child: TextButton(
onPressed: () {
launchUrl(Uri.parse('https://omi.me'));
MixpanelManager().getFriendClicked();
},
child: const Text(
'Get a Friend',
style: TextStyle(color: Colors.white, fontSize: 16),
),
),
),
const SizedBox(height: 4),
TextButton(
onPressed: () async {
Navigator.of(context).push(MaterialPageRoute(builder: (c) => const ConnectDevicePage()));
MixpanelManager().connectFriendClicked();
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text(
'Connect',
style: TextStyle(
fontWeight: FontWeight.w400,
fontSize: 18,
color: Colors.white,
decoration: TextDecoration.underline,
),
),
),
const SizedBox(width: 16),
],
),
// const Text(
// 'Or you can use your phone as\nthe audio source 👇',
// style: TextStyle(color: Colors.white, fontSize: 18),
// textAlign: TextAlign.center,
// ),
],
);
}

class SpeechProfileCardWidget extends StatelessWidget {
const SpeechProfileCardWidget({super.key});
Expand Down Expand Up @@ -313,63 +117,6 @@ getLiteTranscriptWidget(
);
}

connectionStatusWidgets(
BuildContext context,
List<TranscriptSegment> segments,
WebsocketConnectionStatus wsConnectionState,
) {
if (segments.isEmpty) return [];

bool isWifiDisconnected = !Provider.of<ConnectivityProvider>(context, listen: false).isConnected;
bool isWebsocketError =
wsConnectionState == WebsocketConnectionStatus.failed || wsConnectionState == WebsocketConnectionStatus.error;
if (!isWifiDisconnected && !isWebsocketError) return [];
return [
GestureDetector(
onTap: () {
showDialog(
context: context,
builder: (c) => getDialog(
context,
() => Navigator.pop(context),
() => Navigator.pop(context),
isWifiDisconnected ? 'Internet Connection Lost' : 'Connection Issue',
isWifiDisconnected
? 'Your device is offline. Transcription is paused until connection is restored.'
: 'Unable to connect to the transcript service. Please restart the app or contact support if the problem persists.',
okButtonText: 'Ok',
singleButton: true,
),
);
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
isWifiDisconnected ? 'No Internet' : 'Server Issue',
style: TextStyle(
color: Colors.grey.shade300,
fontSize: 20,
),
textAlign: TextAlign.center,
),
const SizedBox(width: 16),
Padding(
padding: const EdgeInsets.only(bottom: 6),
child: isWifiDisconnected
? Lottie.asset('assets/lottie_animations/no_internet.json', height: 48, width: 48)
: Lottie.asset('assets/lottie_animations/no_internet.json', height: 48, width: 48),
)
],
),
),
)
];
}

getPhoneMicRecordingButton(VoidCallback recordingToggled, RecordingState state) {
if (SharedPreferencesUtil().btDeviceStruct.id.isNotEmpty) return const SizedBox.shrink();
return Visibility(
Expand Down
3 changes: 1 addition & 2 deletions app/lib/pages/home/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import 'package:friend_private/providers/memory_provider.dart' as mp;
import 'package:friend_private/providers/memory_provider.dart';
import 'package:friend_private/providers/message_provider.dart';
import 'package:friend_private/providers/plugin_provider.dart';
import 'package:friend_private/services/notification_service.dart';
import 'package:friend_private/services/services.dart';
import 'package:friend_private/services/notifications.dart';
import 'package:friend_private/utils/analytics/mixpanel.dart';
import 'package:friend_private/utils/audio/foreground.dart';
import 'package:friend_private/utils/other/temp.dart';
Expand Down
1 change: 0 additions & 1 deletion app/lib/pages/memories/widgets/capture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:friend_private/providers/capture_provider.dart';
import 'package:friend_private/providers/connectivity_provider.dart';
import 'package:friend_private/providers/device_provider.dart';
import 'package:friend_private/providers/onboarding_provider.dart';
import 'package:friend_private/providers/websocket_provider.dart';
import 'package:friend_private/services/services.dart';
import 'package:friend_private/utils/audio/wav_bytes.dart';
import 'package:friend_private/widgets/dialog.dart';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/providers/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:friend_private/backend/auth.dart';
import 'package:friend_private/backend/preferences.dart';
import 'package:friend_private/providers/base_provider.dart';
import 'package:friend_private/services/notification_service.dart';
import 'package:friend_private/services/notifications.dart';
import 'package:friend_private/utils/alerts/app_snackbar.dart';
import 'package:friend_private/utils/analytics/gleap.dart';
import 'package:friend_private/utils/analytics/mixpanel.dart';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/providers/device_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:friend_private/backend/preferences.dart';
import 'package:friend_private/backend/schema/bt_device.dart';
import 'package:friend_private/providers/capture_provider.dart';
import 'package:friend_private/services/devices.dart';
import 'package:friend_private/services/notification_service.dart';
import 'package:friend_private/services/notifications.dart';
import 'package:friend_private/services/services.dart';
import 'package:friend_private/utils/analytics/mixpanel.dart';
import 'package:instabug_flutter/instabug_flutter.dart';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/providers/onboarding_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'package:friend_private/backend/schema/bt_device.dart';
import 'package:friend_private/providers/base_provider.dart';
import 'package:friend_private/providers/device_provider.dart';
import 'package:friend_private/services/devices.dart';
import 'package:friend_private/services/notification_service.dart';
import 'package:friend_private/services/notifications.dart';
import 'package:friend_private/services/services.dart';
import 'package:friend_private/utils/analytics/mixpanel.dart';
import 'package:friend_private/utils/audio/foreground.dart';
Expand Down
3 changes: 1 addition & 2 deletions app/lib/providers/speech_profile_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import 'package:friend_private/backend/schema/memory.dart';
import 'package:friend_private/backend/schema/message_event.dart';
import 'package:friend_private/backend/schema/structured.dart';
import 'package:friend_private/backend/schema/transcript_segment.dart';
import 'package:friend_private/providers/capture_provider.dart';
import 'package:friend_private/providers/device_provider.dart';
import 'package:friend_private/services/devices.dart';
import 'package:friend_private/services/services.dart';
import 'package:friend_private/services/sockets/transcription_connection.dart';
import 'package:friend_private/utils/audio/wav_bytes.dart';
import 'package:friend_private/utils/memories/process.dart';
import 'package:friend_private/utils/pure_socket.dart';
import 'package:uuid/uuid.dart';

class SpeechProfileProvider extends ChangeNotifier
Expand Down
4 changes: 2 additions & 2 deletions app/lib/services/devices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:friend_private/backend/schema/bt_device.dart';
import 'package:friend_private/services/device_connections.dart';
import 'package:friend_private/utils/ble/gatt_utils.dart';
import 'package:friend_private/services/devices/device_connection.dart';
import 'package:friend_private/services/devices/models.dart';

abstract class IDeviceService {
void start();
Expand Down
13 changes: 6 additions & 7 deletions app/lib/services/devices/device_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import 'dart:io';

import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:friend_private/backend/schema/bt_device.dart';
import 'package:friend_private/services/devices.dart';
import 'package:friend_private/services/frame_connection.dart';
import 'package:friend_private/services/friend_connection.dart';
import 'package:friend_private/services/notification_service.dart';
import 'package:friend_private/services/devices/frame_connection.dart';
import 'package:friend_private/services/devices/friend_connection.dart';
import 'package:friend_private/services/notifications.dart';

class DeviceConnectionFactory {
static DeviceConnection? create(
Expand Down Expand Up @@ -200,11 +199,11 @@ abstract class DeviceConnection {

Future<List<int>> performGetStorageList();

Future<bool> performWriteToStorage(int numFile);
Future<bool> performWriteToStorage(int numFile, int command);

Future<bool> writeToStorage(int numFile) async {
Future<bool> writeToStorage(int numFile, int command) async {
if (await isConnected()) {
return await performWriteToStorage(numFile);
return await performWriteToStorage(numFile, command);
}
_showDeviceDisconnectedNotification();
return Future.value(false);
Expand Down
Loading

0 comments on commit ef31239

Please sign in to comment.