Fix some issues with reminders and print more logs

This commit is contained in:
2020-01-02 05:12:44 -06:00
parent b7be459537
commit 2171d582dc
9 changed files with 104 additions and 38 deletions

View File

@@ -30,12 +30,5 @@ import javax.inject.*
class HabitLogger
@Inject constructor() {
fun logReminderScheduled(habit: Habit, reminderTime: Long) {
val min = Math.min(3, habit.name.length)
val name = habit.name.substring(0, min)
val df = DateFormats.getBackupDateFormat()
val time = df.format(Date(reminderTime))
Log.i("ReminderHelper",
String.format("Setting alarm (%s): %s", time, name))
}
}

View File

@@ -25,11 +25,14 @@ import android.content.*
import android.content.Context.*
import android.os.Build.VERSION.*
import android.os.Build.VERSION_CODES.*
import android.util.*
import org.isoron.androidbase.*
import org.isoron.uhabits.*
import org.isoron.uhabits.core.*
import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.core.reminders.*
import org.isoron.uhabits.core.utils.*
import java.util.*
import javax.inject.*
@AppScope
@@ -44,6 +47,13 @@ class IntentScheduler
context.getSystemService(ALARM_SERVICE) as AlarmManager
fun schedule(timestamp: Long, intent: PendingIntent) {
Log.d("IntentScheduler",
"timestamp=" + timestamp + " current=" + System.currentTimeMillis())
if (timestamp < System.currentTimeMillis()) {
Log.e("IntentScheduler",
"Ignoring attempt to schedule intent in the past.")
return;
}
if (SDK_INT >= M)
manager.setExactAndAllowWhileIdle(RTC_WAKEUP, timestamp, intent)
else
@@ -55,6 +65,19 @@ class IntentScheduler
timestamp: Long) {
val intent = pendingIntents.showReminder(habit, reminderTime, timestamp)
schedule(reminderTime, intent)
logger.logReminderScheduled(habit, reminderTime)
logReminderScheduled(habit, reminderTime)
}
override fun log(componentName: String, msg: String) {
Log.d(componentName, msg)
}
private fun logReminderScheduled(habit: Habit, reminderTime: Long) {
val min = Math.min(5, habit.name.length)
val name = habit.name.substring(0, min)
val df = DateFormats.getBackupDateFormat()
val time = df.format(Date(reminderTime))
Log.i("ReminderHelper",
String.format("Setting alarm (%s): %s", time, name))
}
}

View File

@@ -49,9 +49,12 @@ class AndroidNotificationTray
private val preferences: Preferences,
private val ringtoneManager: RingtoneManager
) : NotificationTray.SystemTray {
private var active = HashSet<Int>()
override fun log(msg: String) {
Log.d("AndroidNotificationTray", msg)
}
override fun removeNotification(id: Int) {
val manager = NotificationManagerCompat.from(context)

View File

@@ -85,7 +85,7 @@ public class ReminderController
public void onSnoozeTimePicked(Habit habit, int hour, int minute)
{
Long time = DateUtils.getUpcomingTimeInMillis(hour, minute);
long time = DateUtils.getUpcomingTimeInMillis(hour, minute);
reminderScheduler.scheduleAtTime(habit, time);
notificationTray.cancel(habit);
}

View File

@@ -27,6 +27,8 @@ import org.isoron.uhabits.*;
import org.isoron.uhabits.core.models.*;
import org.isoron.uhabits.core.utils.*;
import java.util.*;
import static android.content.ContentUris.*;
/**
@@ -65,8 +67,8 @@ public class ReminderReceiver extends BroadcastReceiver
if (intent.getData() != null)
habit = habits.getById(parseId(intent.getData()));
final Long timestamp = intent.getLongExtra("timestamp", today);
final Long reminderTime = intent.getLongExtra("reminderTime", today);
final long timestamp = intent.getLongExtra("timestamp", today);
final long reminderTime = intent.getLongExtra("reminderTime", today);
try
{
@@ -74,6 +76,12 @@ public class ReminderReceiver extends BroadcastReceiver
{
case ACTION_SHOW_REMINDER:
if (habit == null) return;
Log.d("ReminderReceiver", String.format(
Locale.US,
"onShowReminder habit=%d timestamp=%d reminderTime=%d",
habit.id,
timestamp,
reminderTime));
reminderController.onShowReminder(habit,
new Timestamp(timestamp), reminderTime);
break;