|
|
@ -26,6 +26,7 @@ import android.support.v4.app.*;
|
|
|
|
import android.support.v4.app.NotificationCompat.*;
|
|
|
|
import android.support.v4.app.NotificationCompat.*;
|
|
|
|
|
|
|
|
|
|
|
|
import org.isoron.uhabits.*;
|
|
|
|
import org.isoron.uhabits.*;
|
|
|
|
|
|
|
|
import org.isoron.uhabits.commands.*;
|
|
|
|
import org.isoron.uhabits.intents.*;
|
|
|
|
import org.isoron.uhabits.intents.*;
|
|
|
|
import org.isoron.uhabits.models.*;
|
|
|
|
import org.isoron.uhabits.models.*;
|
|
|
|
import org.isoron.uhabits.tasks.*;
|
|
|
|
import org.isoron.uhabits.tasks.*;
|
|
|
@ -37,7 +38,7 @@ import static android.graphics.BitmapFactory.*;
|
|
|
|
import static org.isoron.uhabits.utils.RingtoneUtils.*;
|
|
|
|
import static org.isoron.uhabits.utils.RingtoneUtils.*;
|
|
|
|
|
|
|
|
|
|
|
|
@AppScope
|
|
|
|
@AppScope
|
|
|
|
public class NotificationTray
|
|
|
|
public class NotificationTray implements CommandRunner.Listener
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
private final Context context;
|
|
|
|
private final Context context;
|
|
|
@ -48,14 +49,18 @@ public class NotificationTray
|
|
|
|
@NonNull
|
|
|
|
@NonNull
|
|
|
|
private final PendingIntentFactory pendingIntents;
|
|
|
|
private final PendingIntentFactory pendingIntents;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private CommandRunner commandRunner;
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
@Inject
|
|
|
|
public NotificationTray(@AppContext @NonNull Context context,
|
|
|
|
public NotificationTray(@AppContext @NonNull Context context,
|
|
|
|
@NonNull TaskRunner taskRunner,
|
|
|
|
@NonNull TaskRunner taskRunner,
|
|
|
|
@NonNull PendingIntentFactory pendingIntents)
|
|
|
|
@NonNull PendingIntentFactory pendingIntents,
|
|
|
|
|
|
|
|
@NonNull CommandRunner commandRunner)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.context = context;
|
|
|
|
this.context = context;
|
|
|
|
this.taskRunner = taskRunner;
|
|
|
|
this.taskRunner = taskRunner;
|
|
|
|
this.pendingIntents = pendingIntents;
|
|
|
|
this.pendingIntents = pendingIntents;
|
|
|
|
|
|
|
|
this.commandRunner = commandRunner;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void cancel(@NonNull Habit habit)
|
|
|
|
public void cancel(@NonNull Habit habit)
|
|
|
@ -64,12 +69,37 @@ public class NotificationTray
|
|
|
|
NotificationManagerCompat.from(context).cancel(notificationId);
|
|
|
|
NotificationManagerCompat.from(context).cancel(notificationId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onCommandExecuted(@NonNull Command command,
|
|
|
|
|
|
|
|
@Nullable Long refreshKey)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!(command instanceof ToggleRepetitionCommand))
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ToggleRepetitionCommand toggleCommand =
|
|
|
|
|
|
|
|
(ToggleRepetitionCommand) command;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Habit habit = toggleCommand.getHabit();
|
|
|
|
|
|
|
|
if(habit.getCheckmarks().getTodayValue() != Checkmark.UNCHECKED)
|
|
|
|
|
|
|
|
cancel(habit);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void show(@NonNull Habit habit, long timestamp, long reminderTime)
|
|
|
|
public void show(@NonNull Habit habit, long timestamp, long reminderTime)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
taskRunner.execute(
|
|
|
|
taskRunner.execute(
|
|
|
|
new ShowNotificationTask(habit, timestamp, reminderTime));
|
|
|
|
new ShowNotificationTask(habit, timestamp, reminderTime));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void startListening()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
commandRunner.addListener(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void stopListening()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
commandRunner.removeListener(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int getNotificationId(Habit habit)
|
|
|
|
private int getNotificationId(Habit habit)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Long id = habit.getId();
|
|
|
|
Long id = habit.getId();
|
|
|
|