Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 32 additions & 22 deletions lib/app/modules/debug/controllers/debug_controller.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:get/get_rx/get_rx.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'dart:async';
import '../../../data/providers/isar_provider.dart';
import '../../../modules/settings/controllers/theme_controller.dart';
Expand All @@ -12,14 +10,14 @@ import '../../../data/models/debug_model.dart';
class DebugController extends GetxController {
final ThemeController themeController = Get.find<ThemeController>();
final TextEditingController searchController = TextEditingController();

var logs = <Map<String, dynamic>>[].obs;
var filteredLogs = <Map<String, dynamic>>[].obs;
var selectedLogLevel = Rxn<LogLevel>();
var startDate = Rxn<DateTime>();
var endDate = Rxn<DateTime>();
RxBool isDevMode = false.obs;

Timer? _timer;

@override
Expand Down Expand Up @@ -48,7 +46,8 @@ class DebugController extends GetxController {
final fetchedLogs = await IsarDb().getLogs();
logs.value = fetchedLogs.reversed.toList();
applyFilters();
debugPrint('Debug screen: Successfully loaded ${fetchedLogs.length} logs');
debugPrint(
'Debug screen: Successfully loaded ${fetchedLogs.length} logs',);
} catch (e) {
debugPrint('Debug screen: Error loading logs: $e');
Get.snackbar(
Expand All @@ -63,17 +62,22 @@ class DebugController extends GetxController {
void applyFilters() {
filteredLogs.value = logs.where((log) {
bool matchesSearch = searchController.text.isEmpty ||
log['Status'].toString().toLowerCase().contains(searchController.text.toLowerCase()) ||
log['Status']
.toString()
.toLowerCase()
.contains(searchController.text.toLowerCase()) ||
log['LogID'].toString().contains(searchController.text) ||
Utils.getFormattedDate(DateTime.fromMillisecondsSinceEpoch(log['LogTime']))
Utils.getFormattedDate(
DateTime.fromMillisecondsSinceEpoch(log['LogTime']),)
.toLowerCase()
.contains(searchController.text.toLowerCase());

bool matchesLevel = selectedLogLevel.value == null;
if (selectedLogLevel.value != null) {
final status = log['Status'].toString().toLowerCase();
debugPrint('Checking log: "$status" for level: ${selectedLogLevel.value}');

debugPrint(
'Checking log: "$status" for level: ${selectedLogLevel.value}',);

switch (selectedLogLevel.value!) {
case LogLevel.error:
matchesLevel = status.contains('error');
Expand All @@ -82,23 +86,27 @@ class DebugController extends GetxController {
matchesLevel = status.contains('warning');
break;
case LogLevel.info:
matchesLevel = !status.contains('error') && !status.contains('warning');
matchesLevel =
!status.contains('error') && !status.contains('warning');
break;
}
debugPrint('Matches level: $matchesLevel');
}

bool matchesDateRange = true;
if (startDate.value != null && endDate.value != null) {
final logTime = DateTime.fromMillisecondsSinceEpoch(log['LogTime']);
final startOfDay = DateTime(startDate.value!.year, startDate.value!.month, startDate.value!.day);
final endOfDay = DateTime(endDate.value!.year, endDate.value!.month, endDate.value!.day, 23, 59, 59);
matchesDateRange = logTime.isAfter(startOfDay) && logTime.isBefore(endOfDay);
final startOfDay = DateTime(startDate.value!.year,
startDate.value!.month, startDate.value!.day,);
final endOfDay = DateTime(endDate.value!.year, endDate.value!.month,
endDate.value!.day, 23, 59, 59,);
matchesDateRange =
logTime.isAfter(startOfDay) && logTime.isBefore(endOfDay);
}

return matchesSearch && matchesLevel && matchesDateRange;
}).toList();

debugPrint('Total logs: ${logs.length}');
debugPrint('Filtered logs: ${filteredLogs.length}');
if (filteredLogs.isEmpty) {
Expand Down Expand Up @@ -136,7 +144,8 @@ class DebugController extends GetxController {
firstDate: DateTime(2020),
lastDate: DateTime.now(),
initialDateRange: DateTimeRange(
start: startDate.value ?? DateTime.now().subtract(const Duration(days: 7)),
start:
startDate.value ?? DateTime.now().subtract(const Duration(days: 7)),
end: endDate.value ?? DateTime.now(),
),
builder: (context, child) {
Expand All @@ -147,15 +156,16 @@ class DebugController extends GetxController {
onPrimary: Colors.white,
surface: themeController.secondaryBackgroundColor.value,
onSurface: themeController.primaryTextColor.value,
background: themeController.primaryBackgroundColor.value,
onBackground: themeController.primaryTextColor.value,
),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
foregroundColor: kprimaryColor,
),
),
dialogBackgroundColor: themeController.secondaryBackgroundColor.value,
// ⬇️ was DialogThemeData(...), should be DialogTheme(...)
dialogTheme: DialogThemeData(
backgroundColor: themeController.secondaryBackgroundColor.value,
),
),
child: child!,
);
Expand All @@ -174,4 +184,4 @@ class DebugController extends GetxController {
if (status.contains('warning')) return Colors.orange;
return Colors.green;
}
}
}
90 changes: 73 additions & 17 deletions lib/app/modules/timerRing/controllers/timer_ring_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,96 @@ import 'package:ultimate_alarm_clock/app/utils/utils.dart';
import 'package:vibration/vibration.dart';

class TimerRingController extends GetxController {
MethodChannel timerChannel = const MethodChannel('timer');
final MethodChannel timerChannel = const MethodChannel('timer');
Timer? vibrationTimer;
late StreamSubscription<FGBGType> _subscription;
getFakeTimerModel()async {
TimerModel fakeTimer = await Utils.genFakeTimerModel();
return fakeTimer;
late final StreamSubscription<FGBGType> _subscription;

Future<TimerModel> getFakeTimerModel() async {
return Utils.genFakeTimerModel();
}

@override
void onInit() async {
Future<void> onInit() async {
super.onInit();

// Preventing app from being minimized!
// Keep app foregrounded while ringing
_subscription = FGBGEvents.stream.listen((event) {
if (event == FGBGType.background) {
timerChannel.invokeMethod('bringAppToForeground');
}
});
vibrationTimer =
Timer.periodic(const Duration(milliseconds: 3500), (Timer timer) {
Vibration.vibrate(pattern: [500, 3000]);

vibrationTimer = Timer.periodic(const Duration(milliseconds: 3500), (_) {
Vibration.vibrate(pattern: const [500, 3000]);
});
AudioUtils.playTimer(alarmRecord: await getFakeTimerModel().value);

final model = await getFakeTimerModel(); // FIX: no .value
AudioUtils.playTimer(alarmRecord: model); // FIX

await timerChannel.invokeMethod('cancelTimer');
}

@override
onClose() async {
Future<void> onClose() async {
Vibration.cancel();
vibrationTimer!.cancel();
AudioUtils.stopTimer(
ringtoneName: await getFakeTimerModel().ringtoneName,
);
_subscription.cancel();
vibrationTimer?.cancel(); // FIX: null-safe

final model = await getFakeTimerModel(); // FIX: await once
AudioUtils.stopTimer(ringtoneName: model.ringtoneName); // FIX

await _subscription.cancel();
super.onClose();
}
}




// import 'dart:async';

// import 'package:flutter/services.dart';
// import 'package:flutter_fgbg/flutter_fgbg.dart';
// import 'package:get/get.dart';
// import 'package:ultimate_alarm_clock/app/data/models/timer_model.dart';
// import 'package:ultimate_alarm_clock/app/utils/audio_utils.dart';
// import 'package:ultimate_alarm_clock/app/utils/utils.dart';
// import 'package:vibration/vibration.dart';

// class TimerRingController extends GetxController {
// MethodChannel timerChannel = const MethodChannel('timer');
// Timer? vibrationTimer;
// late StreamSubscription<FGBGType> _subscription;
// getFakeTimerModel()async {
// TimerModel fakeTimer = await Utils.genFakeTimerModel();
// return fakeTimer;
// }
// @override
// void onInit() async {
// super.onInit();

// // Preventing app from being minimized!
// _subscription = FGBGEvents.stream.listen((event) {
// if (event == FGBGType.background) {
// timerChannel.invokeMethod('bringAppToForeground');
// }
// });
// vibrationTimer =
// Timer.periodic(const Duration(milliseconds: 3500), (Timer timer) {
// Vibration.vibrate(pattern: [500, 3000]);
// });
// AudioUtils.playTimer(alarmRecord: await getFakeTimerModel().value);

// await timerChannel.invokeMethod('cancelTimer');
// }

// @override
// onClose() async {
// Vibration.cancel();
// vibrationTimer!.cancel();
// AudioUtils.stopTimer(
// ringtoneName: await getFakeTimerModel().ringtoneName,
// );
// _subscription.cancel();
// super.onClose();
// }
// }