-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add broadcast reciver to reschedule reminders on device reboot or tim…
…e change Signed-off-by: starry-shivam <krshivam24@proton.me>
- Loading branch information
1 parent
44e9440
commit 926819e
Showing
9 changed files
with
145 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/starry/greenstash/reminder/DateTimeChangeReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.starry.greenstash.reminder | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.compose.animation.ExperimentalAnimationApi | ||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import com.starry.greenstash.database.goal.GoalDao | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@ExperimentalMaterial3Api | ||
@ExperimentalAnimationApi | ||
@ExperimentalComposeUiApi | ||
@ExperimentalFoundationApi | ||
@ExperimentalMaterialApi | ||
@AndroidEntryPoint | ||
class DateTimeChangeReceiver : BroadcastReceiver() { | ||
|
||
@Inject | ||
lateinit var goalDao: GoalDao | ||
|
||
override fun onReceive(context: Context, intent: Intent?) { | ||
if (intent?.action == Intent.ACTION_TIME_CHANGED | ||
|| intent?.action == Intent.ACTION_TIMEZONE_CHANGED | ||
|| intent?.action == Intent.ACTION_DATE_CHANGED | ||
) { | ||
val coroutineScope = CoroutineScope(Dispatchers.IO) | ||
coroutineScope.launch { | ||
val allGoals = goalDao.getAllGoals() | ||
val reminderManager = ReminderManager(context) | ||
reminderManager.scheduleReminderForAllGoals(allGoals) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#000000" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
<vector android:height="24dp" android:tint="#000000" | ||
android:viewportHeight="24" android:viewportWidth="24" | ||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<path android:fillColor="@android:color/white" android:pathData="M19.83,7.5l-2.27,-2.27c0.07,-0.42 0.18,-0.81 0.32,-1.15C17.96,3.9 18,3.71 18,3.5C18,2.67 17.33,2 16.5,2c-1.64,0 -3.09,0.79 -4,2l-5,0C4.46,4 2,6.46 2,9.5S4.5,21 4.5,21l5.5,0v-2h2v2l5.5,0l1.68,-5.59L22,14.47V7.5H19.83zM13,9H8V7h5V9zM16,11c-0.55,0 -1,-0.45 -1,-1c0,-0.55 0.45,-1 1,-1s1,0.45 1,1C17,10.55 16.55,11 16,11z"/> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#000000" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M19.83,7.5l-2.27,-2.27c0.07,-0.42 0.18,-0.81 0.32,-1.15C17.96,3.9 18,3.71 18,3.5C18,2.67 17.33,2 16.5,2c-1.64,0 -3.09,0.79 -4,2l-5,0C4.46,4 2,6.46 2,9.5S4.5,21 4.5,21l5.5,0v-2h2v2l5.5,0l1.68,-5.59L22,14.47V7.5H19.83zM13,9H8V7h5V9zM16,11c-0.55,0 -1,-0.45 -1,-1c0,-0.55 0.45,-1 1,-1s1,0.45 1,1C17,10.55 16.55,11 16,11z" /> | ||
</vector> |