Skip to content

Commit cd3ea84

Browse files
authored
Merge pull request #119 from akaMrNagar/dev
Minor changes and bug fixes
2 parents 4c2a1bc + 6164925 commit cd3ea84

File tree

53 files changed

+1240
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1240
-434
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<!-- ____________________________________________________________________________________ -->
1717
<!-- ________________________________ PERMISSIONS _______________________________________ -->
1818
<!-- ____________________________________________________________________________________ -->
19+
<uses-permission android:name="android.permission.VIBRATE" />
1920
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
2021
<uses-permission android:name="android.permission.WAKE_LOCK" />
2122
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />

android/app/src/main/java/com/mindful/android/helpers/device/NotificationHelper.kt

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ object NotificationHelper {
4040
private const val TAG = "Mindful.NotificationHelper"
4141

4242
// Notification channel IDs
43-
const val NOTIFICATION_CRITICAL_CHANNEL_ID: String = "mindful.notification.channel.CRITICAL"
44-
const val NOTIFICATION_FOCUS_CHANNEL_ID: String = "mindful.notification.channel.FOCUS"
45-
const val NOTIFICATION_BEDTIME_CHANNEL_ID: String = "mindful.notification.channel.BEDTIME"
46-
private const val NOTIFICATION_SERVICE_CHANNEL_ID: String =
43+
const val CRITICAL_CHANNEL_ID: String = "mindful.notification.channel.CRITICAL"
44+
const val FOCUS_CHANNEL_ID: String = "mindful.notification.channel.FOCUS"
45+
const val BEDTIME_CHANNEL_ID: String = "mindful.notification.channel.BEDTIME"
46+
const val NOTIFICATION_BATCHING_CHANNEL_ID: String =
47+
"mindful.notification.channel.NOTIFICATION_BATCHING"
48+
private const val SERVICE_CHANNEL_ID: String =
4749
"mindful.notification.channel.SERVICE"
4850

4951
/**
@@ -56,31 +58,39 @@ object NotificationHelper {
5658
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
5759
// Create channels
5860
val criticalChannel = NotificationChannel(
59-
NOTIFICATION_CRITICAL_CHANNEL_ID,
61+
CRITICAL_CHANNEL_ID,
6062
"Critical Alerts",
6163
NotificationManager.IMPORTANCE_HIGH
6264
)
6365
criticalChannel.description =
6466
"These notifications include crucial updates regarding the essential system operations to ensure Mindful runs smoothly."
6567

6668
val focusChannel = NotificationChannel(
67-
NOTIFICATION_FOCUS_CHANNEL_ID,
69+
FOCUS_CHANNEL_ID,
6870
"Focus Sessions",
6971
NotificationManager.IMPORTANCE_HIGH
7072
)
7173
focusChannel.description =
7274
"These notifications include updates regarding focus sessions to help you stay on track."
7375

7476
val bedtimeChannel = NotificationChannel(
75-
NOTIFICATION_BEDTIME_CHANNEL_ID,
77+
BEDTIME_CHANNEL_ID,
7678
"Bedtime Routine",
7779
NotificationManager.IMPORTANCE_DEFAULT
7880
)
7981
bedtimeChannel.description =
8082
"These notifications include updates regarding bedtime routine to help you get a peaceful sleep."
8183

84+
val notificationBatchingChannel = NotificationChannel(
85+
FOCUS_CHANNEL_ID,
86+
"Notification Batch",
87+
NotificationManager.IMPORTANCE_DEFAULT
88+
)
89+
notificationBatchingChannel.description =
90+
"These notifications include summaries or all batched notifications from your scheduled notification batches."
91+
8292
val serviceChannel = NotificationChannel(
83-
NOTIFICATION_SERVICE_CHANNEL_ID,
93+
SERVICE_CHANNEL_ID,
8494
"Running Services",
8595
NotificationManager.IMPORTANCE_LOW
8696
)
@@ -109,7 +119,7 @@ object NotificationHelper {
109119
* @return A Notification object representing the foreground service notification.
110120
*/
111121
fun buildFgServiceNotification(context: Context, content: String?): Notification {
112-
return NotificationCompat.Builder(context, NOTIFICATION_SERVICE_CHANNEL_ID)
122+
return NotificationCompat.Builder(context, SERVICE_CHANNEL_ID)
113123
.setSmallIcon(R.drawable.ic_mindful)
114124
.setOngoing(true)
115125
.setAutoCancel(true)
@@ -142,7 +152,7 @@ object NotificationHelper {
142152
AppConstants.OVERLAY_SERVICE_NOTIFICATION_ID,
143153
NotificationCompat.Builder(
144154
context,
145-
NOTIFICATION_CRITICAL_CHANNEL_ID
155+
CRITICAL_CHANNEL_ID
146156
)
147157
.setSmallIcon(R.drawable.ic_mindful)
148158
.setAutoCancel(true)

android/app/src/main/java/com/mindful/android/models/AppRestriction.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ data class AppRestriction(
3131
*/
3232
val activePeriodEnd: Int = 0,
3333

34+
/**
35+
* Flag denoting if to show usage reminders while using timed app.
36+
*/
37+
val usageReminders: Boolean = true,
38+
3439
/**
3540
* ID of the restriction group this app belongs to (nullable).
3641
*/
@@ -48,6 +53,7 @@ data class AppRestriction(
4853
launchLimit = jsonObject.optInt("launchLimit", 0),
4954
activePeriodStart = jsonObject.optInt("activePeriodStart", 0),
5055
activePeriodEnd = jsonObject.optInt("activePeriodEnd", 0),
56+
usageReminders = jsonObject.optBoolean("usageReminders", true),
5157
associatedGroupId = if (jsonObject.isNull("associatedGroupId")) null else jsonObject.optInt(
5258
"associatedGroupId"
5359
),

android/app/src/main/java/com/mindful/android/models/RestrictionState.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ data class RestrictionState(
1818

1919
/** The timer limit for screen time in SECONDS **/
2020
val totalScreenTimer: Long = -1L,
21+
22+
/** Flag indicating if to show usage reminders or not **/
23+
val showUsageReminders: Boolean = false,
2124
)

android/app/src/main/java/com/mindful/android/receivers/alarm/BedtimeRoutineReceiver.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class BedtimeRoutineReceiver : BroadcastReceiver() {
166166
AppConstants.BEDTIME_ROUTINE_NOTIFICATION_ID,
167167
NotificationCompat.Builder(
168168
context,
169-
NotificationHelper.NOTIFICATION_BEDTIME_CHANNEL_ID
169+
NotificationHelper.BEDTIME_CHANNEL_ID
170170
)
171171
.setSmallIcon(R.drawable.ic_mindful)
172172
.setOngoing(false)

android/app/src/main/java/com/mindful/android/receivers/alarm/NotificationBatchReceiver.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class NotificationBatchReceiver : BroadcastReceiver() {
106106
)
107107
val notification = NotificationCompat.Builder(
108108
context,
109-
NotificationHelper.NOTIFICATION_CRITICAL_CHANNEL_ID
109+
NotificationHelper.NOTIFICATION_BATCHING_CHANNEL_ID
110110
)
111111
.setSmallIcon(R.drawable.ic_mindful)
112112
.setAutoCancel(true)
@@ -174,12 +174,14 @@ class NotificationBatchReceiver : BroadcastReceiver() {
174174

175175
val notification = NotificationCompat.Builder(
176176
context,
177-
NotificationHelper.NOTIFICATION_CRITICAL_CHANNEL_ID
177+
NotificationHelper.CRITICAL_CHANNEL_ID
178178
)
179179
.setSmallIcon(R.drawable.ic_mindful)
180180
.setLargeIcon(appIcon)
181181
.setContentTitle(appName)
182182
.setGroup(packageName)
183+
.setGroupSummary(false)
184+
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
183185
.setStyle(messagingStyle)
184186
.setAutoCancel(true)
185187
.setContentIntent(pendingIntent)
@@ -208,13 +210,13 @@ class NotificationBatchReceiver : BroadcastReceiver() {
208210

209211
val summaryNotification = NotificationCompat.Builder(
210212
context,
211-
NotificationHelper.NOTIFICATION_CRITICAL_CHANNEL_ID
213+
NotificationHelper.NOTIFICATION_BATCHING_CHANNEL_ID
212214
)
213215
.setSmallIcon(R.drawable.ic_mindful)
214216
.setStyle(summaryStyle)
215217
.setGroup(packageName)
216-
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY)
217218
.setGroupSummary(true)
219+
.setAutoCancel(true)
218220
.build()
219221

220222
notificationManager.notify(packageName.hashCode(), summaryNotification)

android/app/src/main/java/com/mindful/android/services/accessibility/MindfulAccessibilityService.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ class MindfulAccessibilityService : AccessibilityService(), OnSharedPreferenceCh
149149

150150
// submit event for tracking if window or it's state changes
151151
val packageName = event.packageName.toString()
152-
if (event.eventType != TYPE_VIEW_SCROLLED) {
153-
executorService.submit { trackingManager.onNewEvent(packageName) }
154-
}
152+
executorService.submit { trackingManager.onNewEvent(packageName) }
155153

156154
// If no reason to process event then just return
157155
if (!shouldBlockContent()) return

android/app/src/main/java/com/mindful/android/services/notification/MindfulNotificationListenerService.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package com.mindful.android.services.notification
1313

1414
import android.app.PendingIntent
15+
import android.content.ComponentName
1516
import android.content.Intent
1617
import android.os.IBinder
1718
import android.service.notification.NotificationListenerService
@@ -61,7 +62,13 @@ class MindfulNotificationListenerService : NotificationListenerService() {
6162
override fun onListenerDisconnected() {
6263
isListenerActive = false
6364
Log.d(TAG, "onListenerConnected: Notifications listener DIS-CONNECTED")
65+
6466
super.onListenerDisconnected()
67+
// Try to rebind again
68+
runCatching {
69+
val listener = ComponentName(this, MindfulNotificationListenerService::class.java)
70+
requestRebind(listener)
71+
}
6572
}
6673

6774
override fun onNotificationPosted(sbn: StatusBarNotification) {

android/app/src/main/java/com/mindful/android/services/timer/EmergencyPauseService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import com.mindful.android.AppConstants.EMERGENCY_PAUSE_SERVICE_NOTIFICATION_ID
1919
import com.mindful.android.R
2020
import com.mindful.android.generics.SafeServiceConnection
2121
import com.mindful.android.generics.ServiceBinder
22-
import com.mindful.android.helpers.device.NotificationHelper.NOTIFICATION_CRITICAL_CHANNEL_ID
22+
import com.mindful.android.helpers.device.NotificationHelper.CRITICAL_CHANNEL_ID
2323
import com.mindful.android.helpers.storage.SharedPrefsHelper
2424
import com.mindful.android.services.tracking.MindfulTrackerService
2525
import com.mindful.android.utils.AppUtils
@@ -40,7 +40,7 @@ class EmergencyPauseService : Service() {
4040
title = getString(R.string.emergency_pause_notification_title),
4141
timerDurationSeconds = DEFAULT_EMERGENCY_PASS_PERIOD_SECONDS,
4242
notificationId = EMERGENCY_PAUSE_SERVICE_NOTIFICATION_ID,
43-
notificationChannelId = NOTIFICATION_CRITICAL_CHANNEL_ID,
43+
notificationChannelId = CRITICAL_CHANNEL_ID,
4444
onTicked = { remainingTime ->
4545
getString(
4646
R.string.emergency_pause_notification_info,

android/app/src/main/java/com/mindful/android/services/timer/FocusSessionService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import com.mindful.android.enums.DndWakeLock
2323
import com.mindful.android.generics.SafeServiceConnection
2424
import com.mindful.android.generics.ServiceBinder
2525
import com.mindful.android.helpers.device.NotificationHelper
26-
import com.mindful.android.helpers.device.NotificationHelper.NOTIFICATION_FOCUS_CHANNEL_ID
26+
import com.mindful.android.helpers.device.NotificationHelper.FOCUS_CHANNEL_ID
2727
import com.mindful.android.helpers.storage.SharedPrefsHelper
2828
import com.mindful.android.models.FocusSession
2929
import com.mindful.android.services.quickTiles.FocusQuickTileService
@@ -136,7 +136,7 @@ class FocusSessionService : Service() {
136136
timerDurationSeconds = timerDuration,
137137
alreadyElapsedTimeSecond = max(0, elapsedTimeMs / 1000L),
138138
notificationId = FOCUS_SESSION_SERVICE_NOTIFICATION_ID,
139-
notificationChannelId = NOTIFICATION_FOCUS_CHANNEL_ID,
139+
notificationChannelId = FOCUS_CHANNEL_ID,
140140
onTicked = { remainingTime ->
141141
getString(
142142
if (isFiniteSession) R.string.focus_session_notification_info

0 commit comments

Comments
 (0)