mirror of
https://github.com/vmiklos/plees-tracker.git
synced 2025-08-06 16:40:51 +08:00
Fix one last l10n string, address ktlint issues
This commit is contained in:

committed by
Miklos Vajna

parent
f10a4b96b5
commit
e8b1082a16
@ -553,18 +553,39 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
|
||||
val currentWakeMinute = preferences.getInt("wakeup_minute", 0)
|
||||
|
||||
// First, pick bedtime
|
||||
TimePickerDialog(this, { _, bedHour, bedMinute ->
|
||||
// Save bedtime values
|
||||
preferences.edit().putInt("bedtime_hour", bedHour).putInt("bedtime_minute", bedMinute).apply()
|
||||
// Then, pick wakeup time
|
||||
TimePickerDialog(this, { _, wakeHour, wakeMinute ->
|
||||
// Save wakeup values
|
||||
preferences.edit().putInt("wakeup_hour", wakeHour).putInt("wakeup_minute", wakeMinute).apply()
|
||||
// Schedule the alarms with the selected times
|
||||
scheduleReminders(bedHour, bedMinute, wakeHour, wakeMinute)
|
||||
Toast.makeText(this, "Reminders set for bedtime and wakeup.", Toast.LENGTH_SHORT).show()
|
||||
}, currentWakeHour, currentWakeMinute, true).show()
|
||||
}, currentBedHour, currentBedMinute, true).show()
|
||||
TimePickerDialog(
|
||||
this,
|
||||
{ _, bedHour, bedMinute ->
|
||||
// Save bedtime values
|
||||
val editor = preferences.edit()
|
||||
editor.putInt("bedtime_hour", bedHour)
|
||||
editor.putInt("bedtime_minute", bedMinute)
|
||||
editor.apply()
|
||||
// Then, pick wakeup time
|
||||
TimePickerDialog(
|
||||
this,
|
||||
{ _, wakeHour, wakeMinute ->
|
||||
// Save wakeup values
|
||||
editor.putInt("wakeup_hour", wakeHour)
|
||||
editor.putInt("wakeup_minute", wakeMinute)
|
||||
editor.apply()
|
||||
// Schedule the alarms with the selected times
|
||||
scheduleReminders(bedHour, bedMinute, wakeHour, wakeMinute)
|
||||
Toast.makeText(
|
||||
this,
|
||||
getString(R.string.bedtime_toast),
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
},
|
||||
currentWakeHour,
|
||||
currentWakeMinute,
|
||||
true
|
||||
).show()
|
||||
},
|
||||
currentBedHour,
|
||||
currentBedMinute,
|
||||
true
|
||||
).show()
|
||||
}
|
||||
|
||||
// Schedule two daily repeating alarms (one for bedtime and one for wakeup)
|
||||
@ -584,8 +605,18 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
|
||||
val bedIntent = Intent(this, ReminderReceiver::class.java).apply {
|
||||
putExtra("reminder_type", "bedtime")
|
||||
}
|
||||
val bedPendingIntent = PendingIntent.getBroadcast(this, 100, bedIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, bedTimeCalendar.timeInMillis, AlarmManager.INTERVAL_DAY, bedPendingIntent)
|
||||
val bedPendingIntent = PendingIntent.getBroadcast(
|
||||
this,
|
||||
100,
|
||||
bedIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
alarmManager.setRepeating(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
bedTimeCalendar.timeInMillis,
|
||||
AlarmManager.INTERVAL_DAY,
|
||||
bedPendingIntent
|
||||
)
|
||||
|
||||
// Schedule wakeup alarm
|
||||
val wakeTimeCalendar = Calendar.getInstance().apply {
|
||||
@ -600,8 +631,18 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {
|
||||
val wakeIntent = Intent(this, ReminderReceiver::class.java).apply {
|
||||
putExtra("reminder_type", "wakeup")
|
||||
}
|
||||
val wakePendingIntent = PendingIntent.getBroadcast(this, 101, wakeIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, wakeTimeCalendar.timeInMillis, AlarmManager.INTERVAL_DAY, wakePendingIntent)
|
||||
val wakePendingIntent = PendingIntent.getBroadcast(
|
||||
this,
|
||||
101,
|
||||
wakeIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
alarmManager.setRepeating(
|
||||
AlarmManager.RTC_WAKEUP,
|
||||
wakeTimeCalendar.timeInMillis,
|
||||
AlarmManager.INTERVAL_DAY,
|
||||
wakePendingIntent
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -1,23 +1,24 @@
|
||||
/*
|
||||
* Copyright 2023 Miklos Vajna
|
||||
* Copyright 2025 Miklos Vajna
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
package hu.vmiklos.plees_tracker
|
||||
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import androidx.core.app.NotificationCompat
|
||||
import android.os.Build
|
||||
import androidx.core.app.NotificationCompat
|
||||
|
||||
class ReminderReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
val reminderType = intent.getStringExtra("reminder_type") ?: "unknown"
|
||||
val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
val service = context.getSystemService(Context.NOTIFICATION_SERVICE)
|
||||
val notificationManager = service as NotificationManager
|
||||
|
||||
// Create notification channel for API 26+
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
@ -52,3 +53,4 @@ class ReminderReceiver : BroadcastReceiver() {
|
||||
}
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
@ -231,5 +231,6 @@
|
||||
<string name="default_reminder_title">Reminder</string>
|
||||
<string name="default_reminder_message">Time for your reminder.</string>
|
||||
<string name="notification_channel_description">Channel for bedtime and wakeup reminders</string>
|
||||
<string name="bedtime_toast">Reminders set for bedtime and wakeup</string>
|
||||
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user