mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Changes to task reminders
This commit is contained in:
parent
8a1a55de39
commit
4b2b3c66ca
5 changed files with 21 additions and 14 deletions
|
|
@ -191,7 +191,11 @@
|
|||
android:windowSoftInputMode="stateHidden" />
|
||||
<receiver android:name=".receivers.NotificationPublisher" />
|
||||
|
||||
<receiver android:name=".receivers.TaskReceiver"/>
|
||||
<receiver android:name=".receivers.TaskReceiver" android:enabled="true" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.NOTIFY" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".receivers.LocalNotificationActionReceiver"
|
||||
android:exported="false">
|
||||
|
|
|
|||
|
|
@ -6,13 +6,14 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Build.VERSION.SDK_INT
|
||||
import androidx.core.content.edit
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.habitrpg.android.habitica.data.TaskRepository
|
||||
import com.habitrpg.android.habitica.models.tasks.RemindersItem
|
||||
import com.habitrpg.android.habitica.models.tasks.Task
|
||||
import com.habitrpg.android.habitica.receivers.NotificationPublisher
|
||||
import com.habitrpg.android.habitica.receivers.TaskReceiver
|
||||
import com.habitrpg.shared.habitica.HLogger
|
||||
import com.habitrpg.shared.habitica.LogLevel
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.functions.Consumer
|
||||
import java.util.*
|
||||
|
|
@ -61,9 +62,6 @@ class TaskAlarmManager(private var context: Context, private var taskRepository:
|
|||
if (!preventDailyReminder) {
|
||||
scheduleDailyReminder(context)
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit {
|
||||
putLong("lastReminderSchedule", Date().time)
|
||||
}
|
||||
}
|
||||
|
||||
fun scheduleAlarmsForTask(task: Task) {
|
||||
|
|
@ -168,6 +166,7 @@ class TaskAlarmManager(private var context: Context, private var taskRepository:
|
|||
}
|
||||
|
||||
private fun setAlarm(context: Context, time: Long, pendingIntent: PendingIntent?) {
|
||||
HLogger.log(LogLevel.INFO, "TaskAlarmManager", "Scheduling for $time")
|
||||
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as? AlarmManager
|
||||
|
||||
if (pendingIntent == null) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import android.content.Intent
|
|||
import android.content.SharedPreferences
|
||||
import com.habitrpg.android.habitica.HabiticaBaseApplication
|
||||
import com.habitrpg.android.habitica.helpers.TaskAlarmManager
|
||||
import com.habitrpg.shared.habitica.HLogger
|
||||
import com.habitrpg.shared.habitica.LogLevel
|
||||
import javax.inject.Inject
|
||||
|
||||
class TaskAlarmBootReceiver : BroadcastReceiver() {
|
||||
|
|
@ -18,6 +20,7 @@ class TaskAlarmBootReceiver : BroadcastReceiver() {
|
|||
override fun onReceive(context: Context, arg1: Intent) {
|
||||
HabiticaBaseApplication.userComponent?.inject(this)
|
||||
taskAlarmManager.scheduleAllSavedAlarms(sharedPreferences.getBoolean("preventDailyReminder", false))
|
||||
HLogger.log(LogLevel.INFO, this::javaClass.name, "onReceive")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
|||
import com.habitrpg.android.habitica.helpers.TaskAlarmManager
|
||||
import com.habitrpg.android.habitica.models.tasks.Task
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity
|
||||
import com.habitrpg.shared.habitica.HLogger
|
||||
import com.habitrpg.shared.habitica.LogLevel
|
||||
import io.reactivex.functions.Consumer
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
|
@ -31,6 +33,7 @@ class TaskReceiver : BroadcastReceiver() {
|
|||
lateinit var taskRepository: TaskRepository
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
HLogger.log(LogLevel.INFO, this::javaClass.name, "onReceive")
|
||||
HabiticaBaseApplication.userComponent?.inject(this)
|
||||
val extras = intent.extras
|
||||
if (extras != null) {
|
||||
|
|
@ -58,6 +61,7 @@ class TaskReceiver : BroadcastReceiver() {
|
|||
|
||||
private fun createNotification(context: Context, task: Task) {
|
||||
val intent = Intent(context, MainActivity::class.java)
|
||||
HLogger.log(LogLevel.INFO, this::javaClass.name, "Create Notification")
|
||||
|
||||
intent.putExtra("notificationIdentifier", "task_reminder")
|
||||
val pendingIntent = PendingIntent.getActivity(context, System.currentTimeMillis().toInt(), intent, 0)
|
||||
|
|
|
|||
|
|
@ -214,6 +214,12 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
|
||||
setupNotifications()
|
||||
setupBottomnavigationLayoutListener()
|
||||
|
||||
try {
|
||||
taskAlarmManager.scheduleAllSavedAlarms(sharedPreferences.getBoolean("preventDailyReminder", false))
|
||||
} catch (e: Exception) {
|
||||
crashlyticsProxy.logException(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupNotifications() {
|
||||
|
|
@ -273,15 +279,6 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
}
|
||||
resumeFromActivity = false
|
||||
|
||||
|
||||
if (this.sharedPreferences.getLong("lastReminderSchedule", 0) < Date().time - DateUtils.hoursInMs(2)) {
|
||||
try {
|
||||
taskAlarmManager.scheduleAllSavedAlarms(sharedPreferences.getBoolean("preventDailyReminder", false))
|
||||
} catch (e: Exception) {
|
||||
crashlyticsProxy.logException(e)
|
||||
}
|
||||
}
|
||||
|
||||
//Track when the app was last opened, so that we can use this to send out special reminders after a week of inactivity
|
||||
sharedPreferences.edit {
|
||||
putLong("lastAppLaunch", Date().time)
|
||||
|
|
|
|||
Loading…
Reference in a new issue