Add more information to rest timer notifications - 2.11 🚀
From homepage - Name of exercise From plans - Name (count/total)
This commit is contained in:
parent
9b881c3d58
commit
936a47b8b2
|
@ -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]
|
||||
);
|
||||
|
|
|
@ -85,8 +85,8 @@ android {
|
|||
applicationId "com.massive"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 36225
|
||||
versionName "2.10"
|
||||
versionCode 36226
|
||||
versionName "2.11"
|
||||
}
|
||||
signingConfigs {
|
||||
release {
|
||||
|
|
|
@ -15,32 +15,34 @@ import com.facebook.react.bridge.*
|
|||
import com.facebook.react.modules.core.DeviceEventManagerModule
|
||||
import kotlin.math.floor
|
||||
|
||||
|
||||
class AlarmModule constructor(context: ReactApplicationContext?) :
|
||||
ReactContextBaseJavaModule(context) {
|
||||
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() {
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
Log.d("AlarmModule", "Received stop broadcast intent")
|
||||
stop()
|
||||
}
|
||||
}
|
||||
private val stopReceiver =
|
||||
object : BroadcastReceiver() {
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
Log.d("AlarmModule", "Received stop broadcast intent")
|
||||
stop()
|
||||
}
|
||||
}
|
||||
|
||||
private val addReceiver = object : BroadcastReceiver() {
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
add()
|
||||
}
|
||||
}
|
||||
private val addReceiver =
|
||||
object : BroadcastReceiver() {
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
add()
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
reactApplicationContext.registerReceiver(stopReceiver, IntentFilter(STOP_BROADCAST))
|
||||
|
@ -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,19 +88,21 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
val manager = getManager()
|
||||
manager.cancel(AlarmService.NOTIFICATION_ID_DONE)
|
||||
manager.cancel(NOTIFICATION_ID_PENDING)
|
||||
val params = Arguments.createMap().apply {
|
||||
putString("minutes", "00")
|
||||
putString("seconds", "00")
|
||||
}
|
||||
val params =
|
||||
Arguments.createMap().apply {
|
||||
putString("minutes", "00")
|
||||
putString("seconds", "00")
|
||||
}
|
||||
reactApplicationContext
|
||||
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
||||
.emit("tick", params)
|
||||
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
||||
.emit("tick", params)
|
||||
}
|
||||
|
||||
@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)
|
||||
|
@ -112,7 +115,7 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
private fun getTimer(
|
||||
endMs: Int,
|
||||
endMs: Int,
|
||||
): CountDownTimer {
|
||||
val builder = getBuilder()
|
||||
return object : CountDownTimer(endMs.toLong(), 1000) {
|
||||
|
@ -120,34 +123,39 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
override fun onTick(current: Long) {
|
||||
currentMs = current
|
||||
val seconds =
|
||||
floor((current / 1000).toDouble() % 60).toInt().toString().padStart(2, '0')
|
||||
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)
|
||||
.setProgress(endMs, current.toInt(), false)
|
||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS).priority =
|
||||
NotificationCompat.PRIORITY_LOW
|
||||
floor((current / 1000).toDouble() / 60).toInt().toString().padStart(2, '0')
|
||||
builder.setContentText("$minutes:$seconds")
|
||||
.setAutoCancel(false)
|
||||
.setDefaults(0)
|
||||
.setProgress(endMs, current.toInt(), false)
|
||||
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
|
||||
.priority = NotificationCompat.PRIORITY_LOW
|
||||
val manager = getManager()
|
||||
manager.notify(NOTIFICATION_ID_PENDING, builder.build())
|
||||
val params = Arguments.createMap().apply {
|
||||
putString("minutes", minutes)
|
||||
putString("seconds", seconds)
|
||||
}
|
||||
val params =
|
||||
Arguments.createMap().apply {
|
||||
putString("minutes", minutes)
|
||||
putString("seconds", seconds)
|
||||
}
|
||||
reactApplicationContext
|
||||
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
||||
.emit("tick", params)
|
||||
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
||||
.emit("tick", params)
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun onFinish() {
|
||||
val context = reactApplicationContext
|
||||
context.startService(Intent(context, AlarmService::class.java))
|
||||
context
|
||||
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
||||
.emit("tick", Arguments.createMap().apply {
|
||||
putString("minutes", "00")
|
||||
putString("seconds", "00")
|
||||
})
|
||||
context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
||||
.emit(
|
||||
"tick",
|
||||
Arguments.createMap().apply {
|
||||
putString("minutes", "00")
|
||||
putString("seconds", "00")
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,32 +166,33 @@ class AlarmModule constructor(context: ReactApplicationContext?) :
|
|||
val 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)
|
||||
}
|
||||
PendingIntent.getActivity(context, 0, contentIntent, PendingIntent.FLAG_IMMUTABLE)
|
||||
val addBroadcast = Intent(ADD_BROADCAST).apply { setPackage(context.packageName) }
|
||||
val pendingAdd =
|
||||
PendingIntent.getBroadcast(context, 0, addBroadcast, PendingIntent.FLAG_MUTABLE)
|
||||
PendingIntent.getBroadcast(context, 0, addBroadcast, PendingIntent.FLAG_MUTABLE)
|
||||
val stopBroadcast = Intent(STOP_BROADCAST)
|
||||
stopBroadcast.setPackage(context.packageName)
|
||||
val pendingStop =
|
||||
PendingIntent.getBroadcast(context, 0, stopBroadcast, PendingIntent.FLAG_IMMUTABLE)
|
||||
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")
|
||||
.setContentIntent(pendingContent)
|
||||
.addAction(R.drawable.ic_baseline_stop_24, "Stop", pendingStop)
|
||||
.addAction(R.drawable.ic_baseline_stop_24, "Add 1 min", pendingAdd)
|
||||
.setDeleteIntent(pendingStop)
|
||||
.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)
|
||||
.setDeleteIntent(pendingStop)
|
||||
}
|
||||
|
||||
@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."
|
||||
notificationManager.createNotificationChannel(timersChannel)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "massive",
|
||||
"version": "2.10",
|
||||
"version": "2.11",
|
||||
"private": true,
|
||||
"license": "GPL-3.0-only",
|
||||
"scripts": {
|
||||
|
|
Loading…
Reference in New Issue