Ui update
This commit is contained in:
@ -1,9 +1,14 @@
|
||||
package com.tommasoberlose.anotherwidget.helpers
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.text.format.DateFormat
|
||||
import android.util.Log
|
||||
import com.tommasoberlose.anotherwidget.global.Actions
|
||||
import com.tommasoberlose.anotherwidget.receivers.ActivityDetectionReceiver
|
||||
import com.tommasoberlose.anotherwidget.receivers.UpdatesReceiver
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
@ -14,6 +19,7 @@ object AlarmHelper {
|
||||
alarm != null
|
||||
&& alarm.triggerTime - Calendar.getInstance().timeInMillis > 5 * 60 * 1000
|
||||
) {
|
||||
setTimeout(context, alarm.triggerTime)
|
||||
"%s %s".format(
|
||||
SimpleDateFormat("EEE", Locale.getDefault()).format(alarm.triggerTime),
|
||||
DateFormat.getTimeFormat(context).format(Date(alarm.triggerTime))
|
||||
@ -32,4 +38,25 @@ object AlarmHelper {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setTimeout(context: Context, trigger: Long) {
|
||||
with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
|
||||
val intent = Intent(context, UpdatesReceiver::class.java).apply {
|
||||
action = Actions.ACTION_ALARM_UPDATE
|
||||
}
|
||||
cancel(PendingIntent.getBroadcast(context, ALARM_UPDATE_ID, intent, 0))
|
||||
setExact(
|
||||
AlarmManager.RTC,
|
||||
trigger,
|
||||
PendingIntent.getBroadcast(
|
||||
context,
|
||||
ALARM_UPDATE_ID,
|
||||
intent,
|
||||
0
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private const val ALARM_UPDATE_ID = 24953
|
||||
}
|
Reference in New Issue
Block a user