Skip to content

Commit fd794c6

Browse files
authored
Merge pull request #176 from akaMrNagar/dev
Added swipe to start session and minor improvements
2 parents 4f51774 + 247c559 commit fd794c6

File tree

13 files changed

+142
-68
lines changed

13 files changed

+142
-68
lines changed

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
@@ -8,6 +8,9 @@ data class RestrictionState(
88
/** The type of restriction that this state represents **/
99
val type: RestrictionType,
1010

11+
/** The group name if this restriction belongs to a group **/
12+
val groupName: String? = null,
13+
1114
/** Time left in milliseconds before the restriction starts **/
1215
val timeLeftMillis: Long = -1,
1316

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package com.mindful.android.services.accessibility
22

33
import android.content.Context
44
import android.content.Intent
5-
import android.net.Uri
65
import android.os.Handler
76
import android.os.Looper
87
import android.provider.Browser
98
import android.util.Log
109
import android.view.accessibility.AccessibilityNodeInfo
1110
import android.widget.Toast
11+
import androidx.core.net.toUri
1212
import com.mindful.android.R
1313
import com.mindful.android.models.Wellbeing
1414
import com.mindful.android.utils.NsfwDomains
@@ -74,7 +74,7 @@ class BrowserManager(
7474
* @param hostDomain The resolved host name for the provided url.
7575
*/
7676
private fun applySafeSearch(browserPackage: String, url: String, hostDomain: String) {
77-
val query = runCatching { Uri.parse(url) }.getOrNull()
77+
val query = runCatching { url.toUri() }.getOrNull()
7878
?.getQueryParameter("q")?.lowercase() ?: url
7979

8080
// Apply safe search if searching maybe nsfw
@@ -116,7 +116,7 @@ class BrowserManager(
116116

117117
// Post to the main thread
118118
ThreadUtils.runOnMainThread {
119-
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(Utils.validateHttpsProtocol(url)))
119+
val intent = Intent(Intent.ACTION_VIEW, Utils.validateHttpsProtocol(url).toUri())
120120
.apply {
121121
putExtra(Browser.EXTRA_APPLICATION_ID, browserPackage)
122122
setPackage(browserPackage)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class MindfulAccessibilityService : AccessibilityService(), OnSharedPreferenceCh
6969

7070
// Fixed thread pool for parallel event processing
7171
private val executorService: ExecutorService = Executors.newFixedThreadPool(4)
72-
private val throttler: Throttler = Throttler(250L)
72+
private val throttler: Throttler = Throttler(500L)
7373
private val deviceAppsChangedReceiver: DeviceAppsChangedReceiver =
7474
DeviceAppsChangedReceiver(onAppsChanged = { refreshServiceConfig() })
7575

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,10 @@ object OverlayBuilder {
224224
return appName to appIcon
225225
}
226226

227-
private fun getRestrictionInfo(context: Context, state: RestrictionState): String {
227+
private fun getRestrictionInfo(
228+
context: Context,
229+
state: RestrictionState,
230+
): String {
228231
val isLimitExhausted = state.screenTimeUsed >= state.screenTimeLimit
229232

230233
return when (state.type) {
@@ -245,11 +248,17 @@ object OverlayBuilder {
245248
context.getString(R.string.app_paused_reason_app_active_period_over)
246249

247250
RestrictionType.GROUP_TIMER ->
248-
if (isLimitExhausted) context.getString(R.string.app_paused_reason_group_timer_out)
249-
else context.getString(R.string.app_paused_reason_group_timer_left)
251+
if (isLimitExhausted) context.getString(
252+
R.string.app_paused_reason_group_timer_out,
253+
state.groupName
254+
)
255+
else context.getString(R.string.app_paused_reason_group_timer_left, state.groupName)
250256

251257
RestrictionType.GROUP_ACTIVE_PERIOD ->
252-
context.getString(R.string.app_paused_reason_group_active_period_over)
258+
context.getString(
259+
R.string.app_paused_reason_group_active_period_over,
260+
state.groupName
261+
)
253262
}
254263
}
255264
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ class RestrictionManager(
158158
/// Check group's active period
159159
restrictionGroups[restriction.associatedGroupId]?.let {
160160
if (it.activePeriodStart != it.activePeriodEnd) {
161-
val state = RestrictionState(type = RestrictionType.GROUP_ACTIVE_PERIOD)
161+
val state = RestrictionState(
162+
type = RestrictionType.GROUP_ACTIVE_PERIOD,
163+
groupName = it.groupName,
164+
)
162165
/// Outside active period
163166
if (DateTimeUtils.isTimeOutsideTODs(it.activePeriodStart, it.activePeriodEnd)) {
164167
Log.d(
@@ -235,6 +238,7 @@ class RestrictionManager(
235238
screenTimeUsed = groupScreenTimeSec,
236239
screenTimeLimit = group.timerSec.toLong(),
237240
reminderType = restriction.reminderType,
241+
groupName = group.groupName,
238242
)
239243

240244
alreadyRestrictedGroups[group.id] = state
@@ -249,6 +253,7 @@ class RestrictionManager(
249253
screenTimeUsed = groupScreenTimeSec,
250254
screenTimeLimit = group.timerSec.toLong(),
251255
reminderType = restriction.reminderType,
256+
groupName = group.groupName,
252257
)
253258
)
254259
}

android/app/src/main/java/com/mindful/android/utils/NsfwDomains.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14961,7 +14961,6 @@ object NsfwDomains {
1496114961
"nxt-comics.com",
1496214962
"nxtcomics.me",
1496314963
"nxtcomicsclub.com",
14964-
"nyaa.si",
1496514964
"nyllover.com",
1496614965
"nylon-erotic.com",
1496714966
"nylon-milf.com",

lib/core/extensions/ext_build_context.dart

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85,37 +85,38 @@ extension ExtBuildContext on BuildContext {
8585
}) {
8686
try {
8787
if (mounted) {
88-
ScaffoldMessenger.of(this).clearSnackBars();
89-
ScaffoldMessenger.of(this).showSnackBar(
90-
SnackBar(
91-
key: UniqueKey(),
92-
dismissDirection: DismissDirection.horizontal,
93-
shape: const RoundedRectangleBorder(
94-
borderRadius: BorderRadius.vertical(top: Radius.circular(18)),
88+
ScaffoldMessenger.of(this)
89+
..clearSnackBars()
90+
..showSnackBar(
91+
SnackBar(
92+
key: UniqueKey(),
93+
dismissDirection: DismissDirection.horizontal,
94+
shape: const RoundedRectangleBorder(
95+
borderRadius: BorderRadius.vertical(top: Radius.circular(18)),
96+
),
97+
backgroundColor: bgColor,
98+
content: Row(
99+
children: [
100+
Icon(icon, color: fgColor),
101+
12.hBox,
102+
Expanded(
103+
child: StyledText(
104+
info,
105+
color: fgColor,
106+
fontSize: 14,
107+
fontWeight: FontWeight.w500,
108+
),
109+
)
110+
],
111+
),
95112
),
96-
backgroundColor: bgColor,
97-
content: Row(
98-
children: [
99-
Icon(icon, color: fgColor),
100-
12.hBox,
101-
Expanded(
102-
child: StyledText(
103-
info,
104-
color: fgColor,
105-
fontSize: 14,
106-
fontWeight: FontWeight.w500,
107-
),
108-
)
109-
],
113+
snackBarAnimationStyle: AnimationStyle(
114+
curve: Curves.easeOutBack,
115+
reverseCurve: Curves.easeOutBack.flipped,
116+
duration: 300.ms,
117+
reverseDuration: 300.ms,
110118
),
111-
),
112-
snackBarAnimationStyle: AnimationStyle(
113-
curve: Curves.easeOutBack,
114-
reverseCurve: Curves.easeOutBack.flipped,
115-
duration: 300.ms,
116-
reverseDuration: 300.ms,
117-
),
118-
);
119+
);
119120
}
120121
} catch (e) {
121122
debugPrint("ExtBuildContext._showSnackBar(): Exception $e");

lib/ui/common/default_fab_button.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ class DefaultFabButton extends StatelessWidget {
3737
style: const ButtonStyle().copyWith(
3838
padding: const WidgetStatePropertyAll(EdgeInsets.all(16)),
3939
shape: WidgetStatePropertyAll(
40-
RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
40+
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
4141
),
4242
),
4343
),
4444
).animate().scale(
4545
duration: AppConstants.defaultAnimDuration,
4646
curve: Curves.easeOutBack,
47+
alignment: Alignment.bottomRight,
4748
);
4849
}
4950
}

lib/ui/screens/focus/focus_mode/start_session_fab.dart

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,79 @@ import 'package:fluentui_system_icons/fluentui_system_icons.dart';
1212
import 'package:flutter/material.dart';
1313
import 'package:flutter_animate/flutter_animate.dart';
1414
import 'package:flutter_riverpod/flutter_riverpod.dart';
15+
import 'package:mindful/config/app_constants.dart';
1516
import 'package:mindful/config/navigation/app_routes.dart';
1617
import 'package:mindful/core/extensions/ext_build_context.dart';
1718
import 'package:mindful/config/hero_tags.dart';
1819
import 'package:mindful/providers/focus/focus_mode_provider.dart';
19-
import 'package:mindful/ui/common/default_fab_button.dart';
20+
import 'package:mindful/ui/common/rounded_container.dart';
21+
import 'package:mindful/ui/common/styled_text.dart';
22+
import 'package:mindful/ui/transitions/default_hero.dart';
23+
import 'package:slide_action/slide_action.dart';
2024

2125
class StartSessionFAB extends ConsumerWidget {
2226
const StartSessionFAB({super.key});
2327

2428
@override
2529
Widget build(BuildContext context, WidgetRef ref) {
26-
return DefaultFabButton(
27-
heroTag: HeroTags.focusModeFABTag,
28-
icon: FluentIcons.target_arrow_20_filled,
29-
label: context.locale.focus_session_start_fab_button,
30-
onPressed: () => _startFocusSession(context, ref),
30+
return Column(
31+
mainAxisAlignment: MainAxisAlignment.end,
32+
crossAxisAlignment: CrossAxisAlignment.end,
33+
children: [
34+
FractionallySizedBox(
35+
widthFactor: 0.5,
36+
child: DefaultHero(
37+
tag: HeroTags.focusModeFABTag,
38+
child: SlideAction(
39+
trackHeight: 52,
40+
actionSnapThreshold: 0.9,
41+
trackBuilder: (context, currentState) => RoundedContainer(
42+
color: Theme.of(context).colorScheme.primary,
43+
circularRadius: 16,
44+
child: Padding(
45+
padding: const EdgeInsets.only(left: 40),
46+
child: StyledText(
47+
context.locale.focus_session_start_fab_button,
48+
color: Theme.of(context).colorScheme.onPrimary,
49+
fontSize: 14,
50+
fontWeight: FontWeight.w600,
51+
),
52+
),
53+
),
54+
thumbBuilder: (context, currentState) => RoundedContainer(
55+
color: Theme.of(context).colorScheme.primaryContainer,
56+
margin: EdgeInsets.all(4),
57+
circularRadius: 14,
58+
child: Icon(
59+
FluentIcons.chevron_right_20_filled,
60+
color: Theme.of(context).colorScheme.onPrimaryContainer,
61+
),
62+
),
63+
action: () => _startFocusSession(context, ref),
64+
).animate().scale(
65+
duration: AppConstants.defaultAnimDuration,
66+
curve: Curves.easeOutBack,
67+
alignment: Alignment.bottomRight,
68+
),
69+
),
70+
),
71+
],
3172
);
3273
}
3374

3475
void _startFocusSession(BuildContext context, WidgetRef ref) async {
35-
final focusModeModel = ref.read(focusModeProvider);
76+
final focusMode = ref.read(focusModeProvider);
3677

3778
/// If another focus session is already active
38-
if (focusModeModel.activeSession.value != null) {
79+
if (focusMode.activeSession.value != null) {
3980
context.showSnackAlert(
4081
context.locale.focus_session_already_active_snack_alert,
4182
);
4283
return;
4384
}
4485

4586
// If no distracting apps selected
46-
if (focusModeModel.focusProfile.distractingApps.isEmpty) {
87+
if (focusMode.focusProfile.distractingApps.isEmpty) {
4788
context.showSnackAlert(
4889
context.locale.focus_session_minimum_apps_snack_alert,
4990
);

lib/ui/screens/restriction_groups/restriction_group_card.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class RestrictionGroupCard extends ConsumerWidget {
9797
value: progress > 0 ? progress : 1,
9898
color: timeSpent > 0 &&
9999
group.timerSec > 0 &&
100-
progress <= 0
100+
progress >= 1
101101
? Theme.of(context).colorScheme.error
102102
: null,
103103
),

0 commit comments

Comments
 (0)