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
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ccextractor.uac_companion

import com.ccextractor.uac_companion.Utils.Preferences

import android.app.*
import android.content.*
import android.os.Build
Expand All @@ -9,14 +11,16 @@ import kotlin.math.abs

class AlarmSnoozeReceiver : BroadcastReceiver() {
final val TAG = "AlarmSnoozeReceiver"
//!need fixes alarm snoozes but with warning - W/Ringtone: Neither local nor remote playback available that makes the alarm to ring after 5 min but the alrm do not ring
// Handles snooze action for alarms - reschedules alarm after configured snooze duration
override fun onReceive(context: Context, intent: Intent) {
// val alarmId = intent.getIntExtra("alarmId", -1)
val alarmId = intent.getIntExtra("alarmId", -1)
// ... later in code:
putExtra("alarmId", alarmId) // Cleaner than intent.getIntExtra("alarmId", -1)
val uniqueSyncId = intent.getStringExtra("uniqueSyncId") ?: ""
val hour = intent.getIntExtra("hour", -1)
val minute = intent.getIntExtra("minute", -1)
// val isSnoozed = intent.getBooleanExtra("isSnoozed", false)
val fromPhone = intent.getBooleanExtra("fromPhone", false) ?: false
// val isSnoozed = intent.getBooleanExtra("isSnoozed", false)
val fromPhone = intent.getBooleanExtra("fromPhone", false)

if (!fromPhone) {
WatchAlarmSender.sendActionToPhone(context, "snooze", uniqueSyncId)
Expand All @@ -26,20 +30,27 @@ class AlarmSnoozeReceiver : BroadcastReceiver() {

// Stop current sound/vibration/notification
AlarmServiceHolder.ringtone?.stop()
AlarmServiceHolder.ringtone = null // added
AlarmServiceHolder.vibrator?.cancel()
AlarmServiceHolder.vibrator = null // added
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(NOTIFICATION_ID)

// Reschedule the alarm 5 minute ahead
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
// val triggerAtMillis = System.currentTimeMillis() + 300_000
val triggerAtMillis = System.currentTimeMillis() + 300_000

//Preferences.kt added and AlarmSnoozeReceiver updated.
val snoozeMinutes = Preferences.getSnoozeDurationMinutes(context)
val triggerAtMillis = System.currentTimeMillis() + snoozeMinutes * 60 * 1000


val snoozeIntent = Intent(context, AlarmBroadcastReceiver::class.java).apply {
// putExtra("alarmId", alarmId)
putExtra("alarmId", intent.getIntExtra("alarmId", -1)) // Preserve original alarmId
putExtra("uniqueSyncId", uniqueSyncId)
putExtra("hour", hour)
putExtra("minute", minute)
putExtra("days", intent.getStringExtra("days") ?: "") // ← ADD THIS (optional)
putExtra("isSnoozed", true)
action = "com.ccextractor.uac_companion.ALARM_TRIGGERED_$uniqueSyncId"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ccextractor.uac_companion.Utils

import android.content.Context

object Preferences {

private const val PREF_NAME = "uac_companion_prefs"
private const val KEY_SNOOZE_DURATION_MINUTES = "snooze_duration_minutes"
private const val DEFAULT_SNOOZE_MINUTES = 5

fun getSnoozeDurationMinutes(context: Context): Int {
val prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
return prefs.getInt(KEY_SNOOZE_DURATION_MINUTES, DEFAULT_SNOOZE_MINUTES)
}

fun setSnoozeDurationMinutes(context: Context, minutes: Int) {
val prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE)
prefs.edit().putInt(KEY_SNOOZE_DURATION_MINUTES, minutes).apply()
}
}
53 changes: 48 additions & 5 deletions lib/app/modules/smart_control/controllers/location_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
import 'package:uac_companion/app/modules/smart_control/controllers/smart_controls_controller.dart';
import 'package:uac_companion/app/routes/app_routes.dart';
import 'package:fl_location/fl_location.dart';


class LocationController extends GetxController {
static LocationController get to => Get.find();
Expand All @@ -15,10 +17,51 @@ class LocationController extends GetxController {
{"label": "Cancel Away from Location", "type": 4},
];

//! need to change the defaultLatLng as user's current locaiton
static final LatLng defaultLatLng = LatLng(28.6139, 77.2090);
final MapController mapController = MapController();
var pickerLatLng = defaultLatLng.obs;
final LatLng fallbackLatLng = const LatLng(28.6139, 77.2090);
late Rx<LatLng> currentLatLng = fallbackLatLng.obs;

late Rx<LatLng> pickerLatLng = fallbackLatLng.obs;


@override
void onInit() {
super.onInit();
_fetchCurrentLocation();
}

Future<void> _fetchCurrentLocation() async {
try {
if (!await FlLocation.isLocationServicesEnabled) {
return;
}

var permission = await FlLocation.checkLocationPermission();

if (permission == LocationPermission.deniedForever) {
return;
}

if (permission == LocationPermission.denied) {
permission = await FlLocation.requestLocationPermission();
if (permission == LocationPermission.denied ||
permission == LocationPermission.deniedForever) {
return;
}
}

final location = await FlLocation.getLocation(
accuracy: LocationAccuracy.best,
timeLimit: const Duration(seconds: 10),
);

final latLng = LatLng(location.latitude, location.longitude);
currentLatLng.value = latLng;
pickerLatLng.value = latLng;

} catch (e) {
// Use fallback location
}
}

void onPickerScreenReady() {
if (mapController.camera.center != pickerLatLng.value) {
Expand All @@ -27,7 +70,7 @@ class LocationController extends GetxController {
}

Future<void> onSelectCondition(int index) async {
pickerLatLng.value = defaultLatLng;
pickerLatLng.value = currentLatLng.value;

final result = await Get.toNamed(AppRoutes.locationPicker);

Expand Down