Skip to content

Commit a5c997f

Browse files
authored
Merge pull request #68 from akaMrNagar/dev
Major improvement and new features
2 parents b04459d + d698ae4 commit a5c997f

File tree

78 files changed

+3703
-1018
lines changed

Some content is hidden

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

78 files changed

+3703
-1018
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@ Your feedback is invaluable to us! If you have suggestions, encounter issues, or
8484

8585
### Translation
8686

87-
1. Japanese by [*Riikun*](https://github.com/akaMrNagar/Mindful?tab=readme-ov-file#donate)
87+
1. Japanese by [*Riikun*](https://crowdin.com/profile/riikun)
88+
2. Turkish by [*Kerem*](https://crowdin.com/profile/keremk)

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<activity
5353
android:name=".MainActivity"
5454
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
55-
android:enableOnBackInvokedCallback="false"
55+
android:enableOnBackInvokedCallback="true"
5656
android:exported="true"
5757
android:hardwareAccelerated="true"
5858
android:launchMode="singleTop"

android/app/src/main/java/com/mindful/android/FgMethodCallHandler.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,28 @@ class FgMethodCallHandler(
4343
) : MethodCallHandler {
4444

4545
private val focusServiceConn =
46-
SafeServiceConnection(FocusSessionService::class.java, context)
46+
SafeServiceConnection(
47+
context = context,
48+
serviceClass = FocusSessionService::class.java
49+
)
4750

4851
private val trackerServiceConn =
49-
SafeServiceConnection(MindfulTrackerService::class.java, context)
52+
SafeServiceConnection(
53+
context = context,
54+
serviceClass = MindfulTrackerService::class.java
55+
)
5056

5157
private val vpnServiceConn =
52-
SafeServiceConnection(MindfulVpnService::class.java, context)
58+
SafeServiceConnection(
59+
context = context,
60+
serviceClass = MindfulVpnService::class.java
61+
)
5362

5463
private val notificationServiceConn =
55-
SafeServiceConnection(MindfulNotificationListenerService::class.java, context)
64+
SafeServiceConnection(
65+
context = context,
66+
serviceClass = MindfulNotificationListenerService::class.java
67+
)
5668

5769

5870
init {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.mindful.android.enums
2+
3+
/**
4+
* Enum representing short-form content features
5+
*/
6+
enum class ShortsPlatformFeatures {
7+
INSTAGRAM_REELS,
8+
INSTAGRAM_EXPLORE,
9+
SNAPCHAT_SPOTLIGHT,
10+
SNAPCHAT_DISCOVER,
11+
FACEBOOK_REELS,
12+
REDDIT_SHORTS,
13+
YOUTUBE_SHORTS,
14+
}

android/app/src/main/java/com/mindful/android/generics/SafeServiceConnection.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,24 @@ import com.mindful.android.utils.Utils
2828
* @param <T> The type of Service this class is designed to connect to.</T>
2929
*/
3030
class SafeServiceConnection<T : Service>(
31-
private val serviceClass: Class<T>,
3231
private val context: Context,
32+
private val serviceClass: Class<T>,
3333
) : ServiceConnection {
3434

3535
var service: T? = null
3636
val isActive: Boolean get() = service != null
3737

3838
private var mIsBound = false
39-
private var mOnConnectedCallback: ((service: T) -> Unit)? = null;
39+
private var mOnServiceConnected: ((service: T) -> Unit)? = null
4040

4141
override fun onServiceConnected(name: ComponentName, binder: IBinder) {
4242
try {
43-
service = (binder as ServiceBinder<T>?)?.service
43+
val binderService = (binder as ServiceBinder<T>?)?.service
4444

45-
if (service != null) {
45+
binderService?.let {
46+
service = it
4647
mIsBound = true
47-
mOnConnectedCallback?.invoke(service!!)
48+
mOnServiceConnected?.invoke(it)
4849
}
4950
} catch (ignored: Exception) {
5051
}
@@ -125,6 +126,6 @@ class SafeServiceConnection<T : Service>(
125126
* @param callback The callback to be triggered upon successful connection.
126127
*/
127128
fun setOnConnectedCallback(callback: ((service: T) -> Unit)) {
128-
mOnConnectedCallback = callback
129+
mOnServiceConnected = callback
129130
}
130131
}

android/app/src/main/java/com/mindful/android/helpers/AlarmTasksSchedulingHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ object AlarmTasksSchedulingHelper {
170170

171171
// Let service know
172172
if (Utils.isServiceRunning(context, MindfulTrackerService::class.java)) {
173-
val conn = SafeServiceConnection(MindfulTrackerService::class.java, context)
173+
val conn = SafeServiceConnection(context, MindfulTrackerService::class.java)
174174
conn.setOnConnectedCallback { service ->
175175
service.getRestrictionManager.updateBedtimeApps(
176176
null

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

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,14 @@
1111
*/
1212
package com.mindful.android.models
1313

14+
import android.util.Log
15+
import com.mindful.android.enums.ShortsPlatformFeatures
1416
import org.json.JSONObject
1517

1618
/**
1719
* Represents the settings related to user well-being in the application.
1820
*/
1921
data class WellBeingSettings(private val jsonObject: JSONObject) {
20-
/**
21-
* Flag indicating whether to block Instagram Reels.
22-
*/
23-
val blockInstaReels: Boolean = jsonObject.optBoolean("blockInstaReels", false)
24-
25-
/**
26-
* Flag indicating whether to block YouTube Shorts.
27-
*/
28-
val blockYtShorts: Boolean = jsonObject.optBoolean("blockYtShorts", false)
29-
30-
/**
31-
* Flag indicating whether to block Snapchat Spotlight.
32-
*/
33-
val blockSnapSpotlight: Boolean = jsonObject.optBoolean("blockSnapSpotlight", false)
34-
35-
/**
36-
* Flag indicating whether to block Facebook Reels.
37-
*/
38-
val blockFbReels: Boolean = jsonObject.optBoolean("blockFbReels", false)
39-
40-
/**
41-
* Flag indicating whether to block Reddit Shorts.
42-
*/
43-
val blockRedditShorts: Boolean = jsonObject.optBoolean("blockRedditShorts", false)
44-
4522
/**
4623
* Flag indicating whether to block NSFW or adult websites.
4724
* This is used to determine if the accessibility service is filtering websites.
@@ -56,31 +33,42 @@ data class WellBeingSettings(private val jsonObject: JSONObject) {
5633
jsonObject.optInt("allowedShortsTimeSec", 30 * 60) * 1000L
5734

5835
/**
59-
* List of website hosts that are blocked.
36+
* List of blocked short-form features (stored as enum indexes)
6037
*/
61-
val blockedWebsites: MutableList<String>
38+
val blockedShortsPlatformFeatures: Set<ShortsPlatformFeatures>
6239

40+
/**
41+
* List of website hosts that are blocked including custom nsfw websites.
42+
*/
43+
val blockedWebsites: Set<String>
6344

6445
init {
65-
val allWebsites = mutableListOf<String>()
6646

67-
// Deserialize blocked websites
68-
val websitesJsonArray = jsonObject.optJSONArray("blockedWebsites")
69-
if (websitesJsonArray != null) {
70-
for (i in 0 until websitesJsonArray.length()) {
71-
allWebsites.add(websitesJsonArray.getString(i))
47+
val blockedFeatures = mutableSetOf<ShortsPlatformFeatures>()
48+
// Deserialize blocked shorts platform features
49+
jsonObject.optJSONArray("blockedShortsPlatformFeatures")?.let { featuresArray ->
50+
for (i in 0 until featuresArray.length()) {
51+
blockedFeatures.add(ShortsPlatformFeatures.values()[featuresArray.getInt(i)])
7252
}
7353
}
54+
this.blockedShortsPlatformFeatures = blockedFeatures
7455

75-
// Deserialize nsfw websites
76-
val nsfwSitesJsonArray = jsonObject.optJSONArray("nsfwWebsites")
77-
if (nsfwSitesJsonArray != null) {
78-
for (i in 0 until nsfwSitesJsonArray.length()) {
79-
allWebsites.add(nsfwSitesJsonArray.getString(i))
56+
57+
val blockedWebsites = mutableSetOf<String>()
58+
// Deserialize blocked websites
59+
jsonObject.optJSONArray("blockedWebsites")?.let { websitesArray ->
60+
for (i in 0 until websitesArray.length()) {
61+
blockedWebsites.add(websitesArray.getString(i))
8062
}
8163
}
8264

8365

84-
this.blockedWebsites = allWebsites
66+
// Deserialize nsfw websites
67+
jsonObject.optJSONArray("nsfwWebsites")?.let { nsfwSitesArray ->
68+
for (i in 0 until nsfwSitesArray.length()) {
69+
blockedWebsites.add(nsfwSitesArray.getString(i))
70+
}
71+
}
72+
this.blockedWebsites = blockedWebsites
8573
}
8674
}

android/app/src/main/java/com/mindful/android/receivers/DeviceBootReceiver.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import android.util.Log
1818
import androidx.work.Data
1919
import androidx.work.ExistingWorkPolicy
2020
import androidx.work.OneTimeWorkRequest
21+
import androidx.work.OutOfQuotaPolicy
2122
import androidx.work.WorkManager
2223
import com.mindful.android.helpers.AlarmTasksSchedulingHelper
2324
import com.mindful.android.helpers.device.NotificationHelper
@@ -57,6 +58,7 @@ class DeviceBootReceiver : BroadcastReceiver() {
5758
TAG, ExistingWorkPolicy.KEEP,
5859
OneTimeWorkRequest
5960
.Builder(FlutterBgExecutionWorker::class.java)
61+
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
6062
.setInputData(
6163
Data.Builder().putString(FLUTTER_TASK_ID, "onBootOrAppUpdate")
6264
.build()

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class BedtimeRoutineReceiver : BroadcastReceiver() {
7272
bedtimeSettings.scheduleDays[Utils.zeroIndexedDayOfWeek()]
7373

7474
private val trackerServiceConn = SafeServiceConnection(
75-
MindfulTrackerService::class.java, context
75+
context = context,
76+
serviceClass = MindfulTrackerService::class.java
7677
)
7778

7879

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import android.util.Log
1818
import androidx.work.Data
1919
import androidx.work.ExistingWorkPolicy
2020
import androidx.work.OneTimeWorkRequest
21+
import androidx.work.OutOfQuotaPolicy
2122
import androidx.work.WorkManager
2223
import androidx.work.Worker
2324
import androidx.work.WorkerParameters
@@ -46,6 +47,7 @@ class MidnightResetReceiver : BroadcastReceiver() {
4647
ExistingWorkPolicy.KEEP,
4748
OneTimeWorkRequest
4849
.Builder(FlutterBgExecutionWorker::class.java)
50+
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
4951
.setInputData(
5052
Data.Builder().putString(FLUTTER_TASK_ID, "onMidnightReset")
5153
.build()
@@ -59,7 +61,8 @@ class MidnightResetReceiver : BroadcastReceiver() {
5961
params: WorkerParameters,
6062
) : Worker(context, params) {
6163
private val mTrackerServiceConn = SafeServiceConnection(
62-
MindfulTrackerService::class.java, context
64+
context = context,
65+
serviceClass = MindfulTrackerService::class.java,
6366
)
6467

6568

0 commit comments

Comments
 (0)