Add more information to rest timer notifications
From homepage - Name of exercise From plans - Name (count/total)
This commit is contained in:
parent
9b881c3d58
commit
6a9e2224ec
|
@ -76,7 +76,7 @@ export default function EditSet() {
|
|||
const canNotify = await check(PERMISSIONS.ANDROID.POST_NOTIFICATIONS);
|
||||
if (canNotify === RESULTS.DENIED)
|
||||
await request(PERMISSIONS.ANDROID.POST_NOTIFICATIONS);
|
||||
if (milliseconds) NativeModules.AlarmModule.timer(milliseconds);
|
||||
if (milliseconds) NativeModules.AlarmModule.timer(milliseconds, `${first.name}`);
|
||||
},
|
||||
[settings]
|
||||
);
|
||||
|
|
|
@ -15,19 +15,20 @@ import com.facebook.react.bridge.*
|
|||
import com.facebook.react.modules.core.DeviceEventManagerModule
|
||||
import kotlin.math.floor
|
||||
|
||||
|
||||
class AlarmModule constructor(context: ReactApplicationContext?) :
|
||||
ReactContextBaseJavaModule(context) {
|
||||
|
||||
private var countdownTimer: CountDownTimer? = null
|
||||
var currentMs: Long = 0
|
||||
var running = false
|
||||
private var running = false
|
||||
private var currentDescription = ""
|
||||
|
||||
override fun getName(): String {
|
||||
return "AlarmModule"
|
||||
}
|
||||
|
||||
private val stopReceiver = object : BroadcastReceiver() {
|
||||
private val stopReceiver =
|
||||
object : BroadcastReceiver() {
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
Log.d("AlarmModule", "Received stop broadcast intent")
|
||||
|
@ -35,7 +36,8 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
}
|
||||
}
|
||||
|
||||
private val addReceiver = object : BroadcastReceiver() {
|
||||
private val addReceiver =
|
||||
object : BroadcastReceiver() {
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
add()
|
||||
|
@ -71,9 +73,8 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
@ReactMethod(isBlockingSynchronousMethod = true)
|
||||
fun getCurrent(): Int {
|
||||
Log.d("AlarmModule", "currentMs=$currentMs")
|
||||
if (running)
|
||||
return currentMs.toInt();
|
||||
return 0;
|
||||
if (running) return currentMs.toInt()
|
||||
return 0
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
|
@ -87,7 +88,8 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
val manager = getManager()
|
||||
manager.cancel(AlarmService.NOTIFICATION_ID_DONE)
|
||||
manager.cancel(NOTIFICATION_ID_PENDING)
|
||||
val params = Arguments.createMap().apply {
|
||||
val params =
|
||||
Arguments.createMap().apply {
|
||||
putString("minutes", "00")
|
||||
putString("seconds", "00")
|
||||
}
|
||||
|
@ -98,8 +100,9 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
@ReactMethod
|
||||
fun timer(milliseconds: Int) {
|
||||
fun timer(milliseconds: Int, description: String) {
|
||||
Log.d("AlarmModule", "Queue alarm for $milliseconds delay")
|
||||
currentDescription = description
|
||||
val manager = getManager()
|
||||
manager.cancel(AlarmService.NOTIFICATION_ID_DONE)
|
||||
val intent = Intent(reactApplicationContext, AlarmService::class.java)
|
||||
|
@ -123,13 +126,16 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
floor((current / 1000).toDouble() % 60).toInt().toString().padStart(2, '0')
|
||||
val minutes =
|
||||
floor((current / 1000).toDouble() / 60).toInt().toString().padStart(2, '0')
|
||||
builder.setContentText("$minutes:$seconds").setAutoCancel(false).setDefaults(0)
|
||||
builder.setContentText("$minutes:$seconds")
|
||||
.setAutoCancel(false)
|
||||
.setDefaults(0)
|
||||
.setProgress(endMs, current.toInt(), false)
|
||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS).priority =
|
||||
NotificationCompat.PRIORITY_LOW
|
||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
||||
.priority = NotificationCompat.PRIORITY_LOW
|
||||
val manager = getManager()
|
||||
manager.notify(NOTIFICATION_ID_PENDING, builder.build())
|
||||
val params = Arguments.createMap().apply {
|
||||
val params =
|
||||
Arguments.createMap().apply {
|
||||
putString("minutes", minutes)
|
||||
putString("seconds", seconds)
|
||||
}
|
||||
|
@ -142,12 +148,14 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
override fun onFinish() {
|
||||
val context = reactApplicationContext
|
||||
context.startService(Intent(context, AlarmService::class.java))
|
||||
context
|
||||
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
||||
.emit("tick", Arguments.createMap().apply {
|
||||
context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
||||
.emit(
|
||||
"tick",
|
||||
Arguments.createMap().apply {
|
||||
putString("minutes", "00")
|
||||
putString("seconds", "00")
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,9 +167,7 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
val contentIntent = Intent(context, MainActivity::class.java)
|
||||
val pendingContent =
|
||||
PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_IMMUTABLE)
|
||||
val addBroadcast = Intent(ADD_BROADCAST).apply {
|
||||
setPackage(context.packageName)
|
||||
}
|
||||
val addBroadcast = Intent(ADD_BROADCAST).apply { setPackage(context.packageName) }
|
||||
val pendingAdd =
|
||||
PendingIntent.getBroadcast(context, 0, addBroadcast, PendingIntent.FLAG_MUTABLE)
|
||||
val stopBroadcast = Intent(STOP_BROADCAST)
|
||||
|
@ -169,7 +175,8 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
val pendingStop =
|
||||
PendingIntent.getBroadcast(context, 0, stopBroadcast, PendingIntent.FLAG_IMMUTABLE)
|
||||
return NotificationCompat.Builder(context, CHANNEL_ID_PENDING)
|
||||
.setSmallIcon(R.drawable.ic_baseline_hourglass_bottom_24).setContentTitle("Resting")
|
||||
.setSmallIcon(R.drawable.ic_baseline_hourglass_bottom_24)
|
||||
.setContentTitle(currentDescription)
|
||||
.setContentIntent(pendingContent)
|
||||
.addAction(R.drawable.ic_baseline_stop_24, "Stop", pendingStop)
|
||||
.addAction(R.drawable.ic_baseline_stop_24, "Add 1 min", pendingAdd)
|
||||
|
@ -178,11 +185,13 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private fun getManager(): NotificationManager {
|
||||
val notificationManager = reactApplicationContext.getSystemService(
|
||||
NotificationManager::class.java
|
||||
)
|
||||
val timersChannel = NotificationChannel(
|
||||
CHANNEL_ID_PENDING, CHANNEL_ID_PENDING, NotificationManager.IMPORTANCE_LOW
|
||||
val notificationManager =
|
||||
reactApplicationContext.getSystemService(NotificationManager::class.java)
|
||||
val timersChannel =
|
||||
NotificationChannel(
|
||||
CHANNEL_ID_PENDING,
|
||||
CHANNEL_ID_PENDING,
|
||||
NotificationManager.IMPORTANCE_LOW
|
||||
)
|
||||
timersChannel.setSound(null, null)
|
||||
timersChannel.description = "Progress on rest timers."
|
||||
|
|
Loading…
Reference in New Issue
Block a user