| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,65 @@ |
| 1 |
+/* |
|
| 2 |
+ * Copyright (c) 2023 Samson Achiaga |
|
| 3 |
+ * |
|
| 4 |
+ * Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 5 |
+ * you may not use this file except in compliance with the License. |
|
| 6 |
+ * You may obtain a copy of the License at |
|
| 7 |
+ * |
|
| 8 |
+ * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 9 |
+ * |
|
| 10 |
+ * Unless required by applicable law or agreed to in writing, software |
|
| 11 |
+ * distributed under the License is distributed on an "AS IS" BASIS, |
|
| 12 |
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 13 |
+ * See the License for the specific language governing permissions and |
|
| 14 |
+ * limitations under the License. |
|
| 15 |
+ */ |
|
| 16 |
+ |
|
| 17 |
+package com.certified.audionote.ui |
|
| 18 |
+ |
|
| 19 |
+import android.content.BroadcastReceiver |
|
| 20 |
+import android.content.Context |
|
| 21 |
+import android.content.Intent |
|
| 22 |
+import androidx.work.Data |
|
| 23 |
+import androidx.work.ExistingWorkPolicy |
|
| 24 |
+import androidx.work.OneTimeWorkRequestBuilder |
|
| 25 |
+import androidx.work.WorkManager |
|
| 26 |
+import com.certified.audionote.utils.NotificationWorker |
|
| 27 |
+import java.util.concurrent.TimeUnit |
|
| 28 |
+ |
|
| 29 |
+class AlertReceiver : BroadcastReceiver() {
|
|
| 30 |
+ override fun onReceive(context: Context, intent: Intent) {
|
|
| 31 |
+ |
|
| 32 |
+ val noteId = intent.getIntExtra("noteId", 0)
|
|
| 33 |
+ val noteTitle = intent.getStringExtra("noteTitle")
|
|
| 34 |
+ val noteDescription = intent.getStringExtra("noteDescription")
|
|
| 35 |
+ val noteColor = intent.getIntExtra("noteColor", -1)
|
|
| 36 |
+ val noteLastModificationDate = intent.getLongExtra("noteLastModificationDate", -1L)
|
|
| 37 |
+ val noteSize = intent.getStringExtra("noteSize")
|
|
| 38 |
+ val noteAudioLength = intent.getLongExtra("noteAudioLength", 0L)
|
|
| 39 |
+ val noteFilePath = intent.getStringExtra("noteFilePath")
|
|
| 40 |
+ val noteStarted = intent.getBooleanExtra("noteStarted", false)
|
|
| 41 |
+ val noteReminder = intent.getLongExtra("noteReminder", -1L)
|
|
| 42 |
+ |
|
| 43 |
+ val data = Data.Builder() |
|
| 44 |
+ data.apply {
|
|
| 45 |
+ putInt("noteId", noteId)
|
|
| 46 |
+ putString("noteTitle", noteTitle)
|
|
| 47 |
+ putString("noteDescription", noteDescription)
|
|
| 48 |
+ putInt("noteColor", noteColor)
|
|
| 49 |
+ putLong("noteLastModificationDate", noteLastModificationDate)
|
|
| 50 |
+ putString("noteSize", noteSize)
|
|
| 51 |
+ putLong("noteAudioLength", noteAudioLength)
|
|
| 52 |
+ putString("noteFilePath", noteFilePath)
|
|
| 53 |
+ putBoolean("noteStarted", noteStarted)
|
|
| 54 |
+ putLong("noteReminder", noteReminder)
|
|
| 55 |
+ } |
|
| 56 |
+ val notificationRequest = OneTimeWorkRequestBuilder<NotificationWorker>() |
|
| 57 |
+ notificationRequest |
|
| 58 |
+ .setInitialDelay(10000, TimeUnit.MILLISECONDS).setInputData(data.build()) |
|
| 59 |
+ WorkManager.getInstance(context).beginUniqueWork( |
|
| 60 |
+ "Audio Notes notification work", |
|
| 61 |
+ ExistingWorkPolicy.REPLACE, |
|
| 62 |
+ notificationRequest.build() |
|
| 63 |
+ ).enqueue() |
|
| 64 |
+ } |
|
| 65 |
+} |
|
| 0 | 66 |
\ No newline at end of file |