Skip to content

Commit a964348

Browse files
authored
Merge pull request #211 from akaMrNagar/patch
Minor bug fixes and improvements
2 parents 97869b8 + 9e195e7 commit a964348

File tree

10 files changed

+274
-263
lines changed

10 files changed

+274
-263
lines changed

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.mindful.android.helpers.device
33
import android.content.Context
44
import android.content.Intent
55
import android.content.pm.ApplicationInfo
6-
import android.content.pm.PackageManager
76
import com.mindful.android.AppConstants
87
import com.mindful.android.AppConstants.REMOVED_APP_NAME
98
import com.mindful.android.AppConstants.REMOVED_PACKAGE
@@ -35,21 +34,20 @@ object DeviceAppsHelper {
3534
val launchableApps = packageManager.queryIntentActivities(
3635
Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER),
3736
0
38-
).map { it.activityInfo.packageName }.toSet()
39-
40-
// Fetch package info of installed apps on device
41-
val installedApps =
42-
packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
37+
)
4338

4439

45-
val deviceAppsMapList: MutableList<Map<String, Any>> = installedApps
46-
.filter { launchableApps.contains(it.packageName) }
47-
.map { app ->
40+
val deviceAppsMapList: MutableList<Map<String, Any>> = launchableApps
41+
.map { appInfo ->
4842
getAppInfoMap(
49-
name = app.loadLabel(packageManager).toString(),
50-
packageName = app.packageName,
51-
isImpSysApp = impSystemApps.contains(app.packageName),
52-
appIcon = AppUtils.getEncodedAppIcon(packageManager.getApplicationIcon(app)),
43+
name = appInfo.loadLabel(packageManager).toString(),
44+
packageName = appInfo.activityInfo.packageName,
45+
isImpSysApp = impSystemApps.contains(appInfo.activityInfo.packageName),
46+
appIcon = AppUtils.getEncodedAppIcon(
47+
packageManager.getApplicationIcon(
48+
appInfo.activityInfo.applicationInfo
49+
)
50+
),
5351
)
5452
}.toMutableList()
5553

android/app/src/main/java/com/mindful/android/helpers/usages/AppsUsageHelper.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import android.app.usage.NetworkStatsManager
55
import android.app.usage.UsageStatsManager
66
import android.content.Context
77
import android.content.Intent
8-
import android.content.pm.PackageManager
98
import com.mindful.android.AppConstants.REMOVED_PACKAGE
109
import com.mindful.android.AppConstants.TETHERING_PACKAGE
1110

@@ -77,17 +76,12 @@ object AppsUsageHelper {
7776
val launchableApps = packageManager.queryIntentActivities(
7877
Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER),
7978
0
80-
).map { it.activityInfo.packageName }.toSet()
81-
82-
// Fetch package info of installed apps on device
83-
val installedApps =
84-
packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
79+
)
8580

86-
val appsUsageMapList: MutableList<Map<String, Any>> = installedApps
87-
.filter { launchableApps.contains(it.packageName) }
88-
.mapNotNull { appInfo ->
89-
val packageName = appInfo.packageName
90-
val uid = appInfo.uid
81+
val appsUsageMapList: MutableList<Map<String, Any>> = launchableApps
82+
.mapNotNull { info ->
83+
val packageName = info.activityInfo.packageName
84+
val uid = info.activityInfo.applicationInfo.uid
9185
val screenTime = screenUsage.getOrDefault(packageName, 0L)
9286
val mobileData = mobileDataUsage.getOrDefault(uid, 0L)
9387
val wifiData = wifiDataUsage.getOrDefault(uid, 0L)

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
@@ -130,20 +130,22 @@ class NotificationBatchReceiver : BroadcastReceiver() {
130130
context,
131131
"com.mindful.android://open/notifications"
132132
)
133+
val packageManager = context.packageManager
133134
val notificationManager =
134135
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
135136

136137
// Group notifications by app package
137138
val appGroupedNotifications = notifications.groupBy { it.packageName }
138139
for ((packageName, appNotifications) in appGroupedNotifications) {
139-
val appInfo = context.packageManager.getApplicationInfo(packageName, 0)
140-
val appName = context.packageManager.getApplicationLabel(appInfo).toString()
141-
val appIcon = context.packageManager.getApplicationIcon(appInfo).toBitmap()
140+
141+
val appInfo = packageManager.getApplicationInfo(packageName, 0)
142+
val appName = packageManager.getApplicationLabel(appInfo).toString()
143+
val appIcon = packageManager.getApplicationIcon(appInfo).toBitmap()
142144
val appIntent = runCatching {
143145
PendingIntent.getActivity(
144146
context,
145147
0,
146-
context.packageManager.getLaunchIntentForPackage(packageName),
148+
packageManager.getLaunchIntentForPackage(packageName),
147149
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
148150
)
149151
}.getOrNull()

android/app/src/main/java/com/mindful/android/services/tracking/OverlayBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ object OverlayBuilder {
218218
): Pair<String, Drawable> {
219219
val packageManager = context.packageManager
220220
val info = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
221-
val appName = info.loadLabel(packageManager).toString()
221+
val appName = packageManager.getApplicationLabel(info).toString()
222222
val appIcon = packageManager.getApplicationIcon(info)
223223

224224
return appName to appIcon

android/app/src/main/java/com/mindful/android/services/tracking/OverlayManager.kt

Lines changed: 64 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -73,50 +73,55 @@ class OverlayManager(
7373
if (overlays.isNotEmpty()) return
7474

7575
ThreadUtils.runOnMainThread {
76-
// Notify, stop and return if don't have overlay permission
77-
if (!haveOverlayPermission(context)) {
78-
return@runOnMainThread
79-
}
80-
81-
// Build overlay
82-
val sheetOverlay = OverlayBuilder.buildFullScreenOverlay(
83-
context = context,
84-
packageName = packageName,
85-
state = restrictionState,
86-
dismissOverlay = ::dismissSheetOverlay,
87-
addReminderDelay = addReminderWithDelay,
88-
).apply {
89-
// TODO: Fix the deprecated logic
90-
// Full screen edge to edge view
91-
systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
92-
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
93-
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
94-
}
95-
96-
Log.d(TAG, "showFullScreenOverlay: Showing full screen overlay for $packageName")
97-
sheetOverlay.also {
98-
windowManager.addView(it, sheetLayoutParams)
99-
overlays.push(it)
100-
Utils.vibrateDevice(context, 50L)
76+
runCatching {
10177

102-
// Get views
103-
val bg = sheetOverlay.findViewById<View>(R.id.overlay_background)
104-
val quote = sheetOverlay.findViewById<View>(R.id.overlay_sheet_quote_panel)
105-
val sheet = sheetOverlay.findViewById<LinearLayout>(R.id.overlay_sheet)
78+
// Notify, stop and return if don't have overlay permission
79+
if (!haveOverlayPermission(context)) {
80+
return@runOnMainThread
81+
}
10682

107-
// Set initial
108-
bg.alpha = 0f
109-
quote.alpha = 0f
110-
sheet.translationY = SLIDE_UP_START_Y
83+
// Build overlay
84+
val sheetOverlay = OverlayBuilder.buildFullScreenOverlay(
85+
context = context,
86+
packageName = packageName,
87+
state = restrictionState,
88+
dismissOverlay = ::dismissSheetOverlay,
89+
addReminderDelay = addReminderWithDelay,
90+
).apply {
91+
// TODO: Fix the deprecated logic
92+
// Full screen edge to edge view
93+
systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
94+
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
95+
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
96+
}
11197

112-
// Animate
113-
bg.animate().alpha(1f).setDuration(400).start()
114-
quote.animate().alpha(1f).setDuration(400).start()
115-
sheet.animate()
116-
.translationY(0f)
117-
.setInterpolator(OvershootInterpolator(1.5f))
118-
.setDuration(500)
119-
.start()
98+
Log.d(TAG, "showFullScreenOverlay: Showing full screen overlay for $packageName")
99+
sheetOverlay.also {
100+
windowManager.addView(it, sheetLayoutParams)
101+
overlays.push(it)
102+
Utils.vibrateDevice(context, 50L)
103+
104+
// Get views
105+
val bg = sheetOverlay.findViewById<View>(R.id.overlay_background)
106+
val quote = sheetOverlay.findViewById<View>(R.id.overlay_sheet_quote_panel)
107+
val sheet = sheetOverlay.findViewById<LinearLayout>(R.id.overlay_sheet)
108+
109+
// Set initial
110+
bg.alpha = 0f
111+
quote.alpha = 0f
112+
sheet.translationY = SLIDE_UP_START_Y
113+
114+
// Animate
115+
bg.animate().alpha(1f).setDuration(400).start()
116+
quote.animate().alpha(1f).setDuration(400).start()
117+
sheet.animate()
118+
.translationY(0f)
119+
.setInterpolator(OvershootInterpolator(1.5f))
120+
.setDuration(500)
121+
.start()
122+
}
123+
}.getOrElse {
124+
SharedPrefsHelper.insertCrashLogToPrefs(context, it)
120125
}
121126
}
122127
}
@@ -127,27 +132,27 @@ class OverlayManager(
127132
screenTimeUsedInMins: Int,
128133
) {
129134
ThreadUtils.runOnMainThread {
130-
// Notify, stop and return if don't have overlay permission
131-
if (!haveOverlayPermission(context)) return@runOnMainThread
132-
133-
// Build view
134-
val toastView = OverlayBuilder.buildToastOverlay(
135-
context,
136-
packageName,
137-
screenTimeUsedInMins
138-
)
135+
runCatching {
136+
// Notify, stop and return if don't have overlay permission
137+
if (!haveOverlayPermission(context)) return@runOnMainThread
138+
139+
// Build view
140+
val toastView = OverlayBuilder.buildToastOverlay(
141+
context,
142+
packageName,
143+
screenTimeUsedInMins
144+
)
139145

140-
Log.d(TAG, "Showing toast overlay for $packageName")
141-
windowManager.addView(toastView, toastLayoutParams)
146+
Log.d(TAG, "Showing toast overlay for $packageName")
147+
windowManager.addView(toastView, toastLayoutParams)
142148

143-
// Fade-in
144-
toastView.animate()
145-
.alpha(1f)
146-
.setDuration(500)
147-
.start()
149+
// Fade-in
150+
toastView.animate()
151+
.alpha(1f)
152+
.setDuration(500)
153+
.start()
148154

149-
// Fade-out and remove after delay
150-
runCatching {
155+
// Fade-out and remove after delay
151156
Handler(Looper.getMainLooper()).let {
152157
it.postDelayed({
153158
toastView.animate()

android/app/src/main/java/com/mindful/android/widgets/AggregatedUsageWidgetProvider.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import android.appwidget.AppWidgetProvider
99
import android.content.ComponentName
1010
import android.content.Context
1111
import android.content.Intent
12-
import android.content.pm.PackageManager
1312
import android.net.ConnectivityManager
1413
import android.util.Log
1514
import android.widget.RemoteViews
@@ -108,27 +107,30 @@ class AggregatedUsageWidgetProvider : AppWidgetProvider() {
108107

109108
// Fetch package info of installed apps on device
110109
val packageManager = context.packageManager
111-
val deviceApps = packageManager.getInstalledPackages(PackageManager.GET_META_DATA)
112110
val excludedApps = SharedPrefsHelper.getSetExcludedApps(context, null)
113111

114112

115113
var wifiUsageKbs = 0L
116114
var mobileUsageKbs = 0L
117115
var screenTimeSec = 0L
118116

119-
for (app in deviceApps) {
120-
// Only include apps which are launchable
121-
if (packageManager.getLaunchIntentForPackage(app.packageName) != null) {
122-
val appUid = app.applicationInfo?.uid
123-
mobileUsageKbs += mobileUsageOneDay.getOrDefault(appUid, 0L)
124-
wifiUsageKbs += wifiUsageOneDay.getOrDefault(appUid, 0L)
125-
126-
// skip excluded apps
127-
if (excludedApps.contains(app.packageName)) continue
128-
screenTimeSec += screenUsageOneDay.getOrDefault(app.packageName, 0L)
117+
// Fetch set of all launchable apps
118+
val launchableApps = packageManager.queryIntentActivities(
119+
Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER),
120+
0
121+
).forEach { appInfo ->
122+
val appUid = appInfo.activityInfo.applicationInfo?.uid
123+
mobileUsageKbs += mobileUsageOneDay.getOrDefault(appUid, 0L)
124+
wifiUsageKbs += wifiUsageOneDay.getOrDefault(appUid, 0L)
125+
126+
// skip excluded apps
127+
val packageName = appInfo.activityInfo.packageName
128+
if (!excludedApps.contains(packageName)) {
129+
screenTimeSec += screenUsageOneDay.getOrDefault(packageName, 0L)
129130
}
130131
}
131132

133+
132134
// Also include tethering hotspot and removed app's data usage
133135
wifiUsageKbs += wifiUsageOneDay.getOrDefault(
134136
NetworkStats.Bucket.UID_TETHERING,

lib/l10n/generated/app_localizations_ar.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class AppLocalizationsAr extends AppLocalizations {
99
AppLocalizationsAr([String locale = 'ar']) : super(locale);
1010

1111
@override
12-
String get mindful_tagline => 'ركز على ما يهم حقا';
12+
String get mindful_tagline => 'Focus on what truly Matters';
1313

1414
@override
1515
String get unlock_button_label => 'فتح';

lib/l10n/generated/app_localizations_el.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class AppLocalizationsEl extends AppLocalizations {
278278

279279
@override
280280
String get exit_without_saving_dialog_info =>
281-
'Are you sure you want to exit without saving?';
281+
'Σίγουρα θες να βγεις χωρίς αποθήκευση;';
282282

283283
@override
284284
String get development_dialog_info =>
@@ -351,43 +351,43 @@ class AppLocalizationsEl extends AppLocalizations {
351351

352352
@override
353353
String get accessibility_tip =>
354-
'Want smarter, more battery-friendly blocking? Enable Accessibility permission for Mindful.';
354+
'Θέλετε έναν πιο έξυπνο, πιο φιλικό προς την μπαταρία αποκλεισμό; Ενεργοποίησε την άδεια προσβασιμότητας για Mindful.';
355355

356356
@override
357357
String get battery_optimization_tip =>
358-
'Mindful not working? Allow \'Ignore Battery Optimization\' in Settings to keep it running smoothly.';
358+
'Το Mindful δεν λειτουργεί; Επιτρέψτε την \'Αγνόηση Βελτιστοποίησης Μπαταρίας\' στις Ρυθμίσεις για να συνεχίσει να λειτουργεί ομαλά.';
359359

360360
@override
361361
String get invincible_mode_tip =>
362-
'Accidentally removed restrictions? Use Invincible Mode to lock them until the next day or adjustment window.';
362+
'Περιορισμοί που αφαιρέθηκαν τυχαία; Χρησιμοποιήστε τη Άτρωτη λειτουργία για να τους κλειδώσετε μέχρι την επόμενη μέρα ή το παράθυρο ρύθμισης.';
363363

364364
@override
365365
String get glance_usage_tip =>
366-
'Want insights? Check the Glance section to view your usage patterns and screen time.';
366+
'Θέλετε πληροφορίες; Ελέγξτε την ενότητα Ματιά για να δείτε τα μοτίβα χρήσης και την ώρα επί οθόνης.';
367367

368368
@override
369369
String get tamper_protection_tip =>
370-
'Uninstalling Mindful? Enable the Uninstall Window to safely disable tamper protection first.';
370+
'Απεγκατάσταση του Mindful; Ενεργοποιήστε το Παράθυρο Απεγκατάστασης για να απενεργοποιήσετε με ασφάλεια την προστασία παραβίασης πρώτα.';
371371

372372
@override
373373
String get notification_blocking_tip =>
374-
'Want to reduce distractions? Use Notification Blocking to silence selected apps.';
374+
'Θέλετε να μειώσετε τους περισπασμούς; Χρησιμοποιήστε το Μπλοκάρισμα Ειδοποιήσεων για σίγαση επιλεγμένων εφαρμογών.';
375375

376376
@override
377377
String get usage_history_tip =>
378-
'Want to reflect on your habits? Check Usage History to see past patterns.';
378+
'Θέλετε να συλλογιστείτε τις συνήθειές σας; Ελέγξτε το ιστορικό χρήσης για να δείτε τα προηγούμενα μοτίβα.';
379379

380380
@override
381381
String get focus_mode_tip =>
382-
'Need deep focus? Turn on Focus Mode to block apps and notifications during tasks.';
382+
'Χρειάζεστε βαθιά συγκέντρωση; Ενεργοποιήστε τη λειτουργία εστίασης για να μπλοκάρετε εφαρμογές και ειδοποιήσεις κατά τη διάρκεια εργασιών.';
383383

384384
@override
385385
String get bedtime_reminder_tip =>
386-
'Want to improve your sleep? Set a Bedtime Reminder to wind down nightly.';
386+
'Θέλετε να βελτιώσετε τον ύπνο σας; Ρυθμίστε μια Υπενθύμιση Ύπνου για να χαλαρώσετε.';
387387

388388
@override
389389
String get custom_blocking_tip =>
390-
'Need a custom experience? Create app blocking rules that fit your needs.';
390+
'Χρειάζεσαι μια προσαρμοσμένη εμπερία; Δημιούργησε κανόνες αποκλεισμού εφαρμογών που ταιριάζουν στις ανάγκες σου.';
391391

392392
@override
393393
String get session_timeline_tip =>

0 commit comments

Comments
 (0)