Skip to content

Commit

Permalink
Merge branch 'master' into proxy-session
Browse files Browse the repository at this point in the history
  • Loading branch information
inetic committed Sep 13, 2024
2 parents 81e8df5 + a551b1f commit cb172aa
Show file tree
Hide file tree
Showing 16 changed files with 454 additions and 98 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jobs:
uses: nttld/setup-ndk@v1
with:
ndk-version: ${{ matrix.ndk.version }}
link-to-sdk: true
if: matrix.ndk.version != ''

- name: Set NDK ABI filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import android.content.Intent
import android.os.Bundle
import android.os.Environment
import android.util.Log
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel

class MainActivity: FlutterActivity() {
class MainActivity: FlutterFragmentActivity() {
companion object {
private val CHANNEL = "org.equalitie.ouisync/native"
}
Expand Down
26 changes: 18 additions & 8 deletions lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,30 @@ class _OuisyncAppState extends State<OuisyncApp> with AppLogger {
// After this, just show the regular home page.

if (!_onboarded) {
final onboardingPages = <Widget>[];

if (widget.settings.getShowOnboarding()) {
await Navigator.of(context).push(MaterialPageRoute(
builder: (_) => OnboardingPage(
settings: widget.settings,
),
));
onboardingPages.add(OnboardingPage(settings: widget.settings));
}

if (!widget.settings.getEqualitieValues()) {
await Navigator.of(context).push(MaterialPageRoute(
builder: (_) => AcceptEqualitieValuesTermsPrivacyPage(
// If this is the first time the onboarding page was displayed, even
// though the setting is already set to true by the time we get to the
// eQ values page, we can allow the user to navigate back to the
// onboarding using the back button in Android.
final canNavigateBack = widget.settings.getShowOnboarding();

onboardingPages.add(
AcceptEqualitieValuesTermsPrivacyPage(
settings: widget.settings,
canNavigateToOnboarding: canNavigateBack,
),
));
);
}

for (var page in onboardingPages) {
await Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => page));
}

if (_onboarded) {
Expand Down
47 changes: 41 additions & 6 deletions lib/app/pages/accept_eq_values_terms_privacy_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ import 'dart:io';
import 'package:flutter/material.dart';

import '../../generated/l10n.dart';
import '../utils/click_counter.dart';
import '../utils/utils.dart';
import '../widgets/widgets.dart';
import 'pages.dart';

class AcceptEqualitieValuesTermsPrivacyPage extends StatefulWidget {
const AcceptEqualitieValuesTermsPrivacyPage({
required this.settings,
required this.canNavigateToOnboarding,
});

final Settings settings;
final bool canNavigateToOnboarding;

@override
State<AcceptEqualitieValuesTermsPrivacyPage> createState() =>
Expand All @@ -20,20 +24,51 @@ class AcceptEqualitieValuesTermsPrivacyPage extends StatefulWidget {

class _AcceptEqualitieValuesTermsPrivacyPageState
extends State<AcceptEqualitieValuesTermsPrivacyPage> {
final exitClickCounter = ClickCounter(timeoutMs: 3000);

@override
Widget build(BuildContext context) => SafeArea(
child: Scaffold(
body: ContentWithStickyFooterState(
content: _buildContent(context),
footer: Fields.dialogActions(
context,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
buttons: _buildActions(context),
body: PopScope<Object?>(
canPop: false,
onPopInvokedWithResult: _onBackPressed,
child: ContentWithStickyFooterState(
content: _buildContent(context),
footer: Fields.dialogActions(
context,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
buttons: _buildActions(context),
),
),
),
),
);

Future<void> _onBackPressed(bool didPop, Object? result) async {
if (didPop) return;

if (widget.canNavigateToOnboarding) {
await Navigator.of(context).push(MaterialPageRoute(
builder: (_) => OnboardingPage(
settings: widget.settings,
wasSeen: true,
)));
return;
}

int clickCount = exitClickCounter.registerClick();
if (clickCount <= 1) {
final snackBar = SnackBar(
content: Text(S.current.messageExitOuiSync),
showCloseIcon: true,
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
} else {
exitClickCounter.reset();
exit(0);
}
}

Column _buildContent(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
Expand Down
8 changes: 4 additions & 4 deletions lib/app/pages/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class _MainPageState extends State<MainPage>
@override
Widget build(BuildContext context) => Scaffold(
appBar: _buildOuiSyncBar(),
body: PopScope(
body: PopScope<Object?>(
// Don't pop => don't exit
//
// We don't want to do the pop because that would destroy the current Isolate's execution
Expand All @@ -476,7 +476,7 @@ class _MainPageState extends State<MainPage>
// user at that point tried to open the app again, this widget would try to reinitialize
// all those variables without previously properly closing them.
canPop: false,
onPopInvoked: _onBackPressed,
onPopInvokedWithResult: _onBackPressed,
child: Stack(
alignment: AlignmentDirectional.bottomEnd,
children: <Widget>[
Expand All @@ -493,7 +493,7 @@ class _MainPageState extends State<MainPage>
bottomSheet: modalBottomSheet(),
);

Future<void> _onBackPressed(bool didPop) async {
Future<void> _onBackPressed(bool didPop, Object? result) async {
final currentRepo = _currentRepo;

if (currentRepo != null) {
Expand All @@ -512,7 +512,7 @@ class _MainPageState extends State<MainPage>
int clickCount = exitClickCounter.registerClick();

if (clickCount <= 1) {
showSnackBar(S.current.messageExitOuiSync);
showSnackBar(S.current.messageExitOuiSync, context: context);
} else {
exitClickCounter.reset();
await MoveToBackground.moveTaskToBack();
Expand Down
129 changes: 89 additions & 40 deletions lib/app/pages/onboarding_page.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:introduction_screen/introduction_screen.dart';

import '../../generated/l10n.dart';
import '../utils/click_counter.dart';
import '../utils/utils.dart';

const int totalPages = 3;

class OnboardingPage extends StatefulWidget {
const OnboardingPage({
required this.settings,
this.wasSeen = false,
});

final Settings settings;
final bool wasSeen;

@override
State<OnboardingPage> createState() => _OnboardingPageState();
Expand All @@ -18,10 +25,21 @@ class OnboardingPage extends StatefulWidget {
class _OnboardingPageState extends State<OnboardingPage> {
final introKey = GlobalKey<IntroductionScreenState>();

int _currentPageIndex = 0;
final exitClickCounter = ClickCounter(timeoutMs: 3000);

final buttonStyle = TextStyle(fontWeight: FontWeight.w600);

double _imageWidth = 0;

@override
void initState() {
if (widget.wasSeen) {
_currentPageIndex = totalPages - 1;
}
super.initState();
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
Expand All @@ -38,48 +56,79 @@ class _OnboardingPageState extends State<OnboardingPage> {
bodyPadding: EdgeInsets.fromLTRB(16.0, 0.0, 16.0, 16.0),
imagePadding: EdgeInsets.zero);

return IntroductionScreen(
key: introKey,
globalBackgroundColor: Colors.white,
pages: [
PageViewModel(
title: S.current.titleOnboardingShare,
body: S.current.messageOnboardingShare,
image: _buildImage(Constants.onboardingShareImage),
decoration: pageDecoration,
),
PageViewModel(
title: S.current.titleOnboardingPermissions,
body: S.current.messageOnboardingPermissions,
image: _buildImage(Constants.onboardingPermissionsImage),
decoration: pageDecoration,
),
PageViewModel(
title: S.current.titleOnboardingAccess,
body: S.current.messageOnboardingAccess,
image: _buildImage(Constants.onboardingAccessImage),
decoration: pageDecoration,
return PopScope<Object?>(
canPop: false,
onPopInvokedWithResult: _onBackPressed,
child: Stack(
children: [
IntroductionScreen(
key: introKey,
initialPage: _currentPageIndex,
globalBackgroundColor: Colors.white,
pages: [
PageViewModel(
title: S.current.titleOnboardingShare,
body: S.current.messageOnboardingShare,
image: _buildImage(Constants.onboardingShareImage),
decoration: pageDecoration,
),
PageViewModel(
title: S.current.titleOnboardingPermissions,
body: S.current.messageOnboardingPermissions,
image: _buildImage(Constants.onboardingPermissionsImage),
decoration: pageDecoration,
),
PageViewModel(
title: S.current.titleOnboardingAccess,
body: S.current.messageOnboardingAccess,
image: _buildImage(Constants.onboardingAccessImage),
decoration: pageDecoration,
),
],
onChange: (index) => setState(() => _currentPageIndex = index),
onDone: () async => await _onIntroEnd(context),
onSkip: () async => await _onIntroEnd(context),
skipOrBackFlex: 0,
nextFlex: 0,
showBackButton: true,
rtl: Directionality.of(context) == TextDirection.rtl,
back: _buildButton(S.current.actionBack),
next: _buildButton(S.current.actionNext),
done: _buildButton(S.current.actionDone),
curve: Curves.fastLinearToSlowEaseIn,
dotsDecorator: DotsDecorator(
size: Size(10.0, 10.0),
color: Theme.of(context).colorScheme.surfaceDim,
activeSize: Size(22.0, 10.0),
activeShape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(25.0)),
),
),
),
],
onDone: () async => await _onIntroEnd(context),
onSkip: () async =>
await _onIntroEnd(context), // You can override onSkip callback
skipOrBackFlex: 0,
nextFlex: 0,
showBackButton: true,
rtl: Directionality.of(context) == TextDirection.rtl,
back: _buildButton(S.current.actionBack),
next: _buildButton(S.current.actionNext),
done: _buildButton(S.current.actionDone),
curve: Curves.fastLinearToSlowEaseIn,
dotsDecorator: DotsDecorator(
size: Size(10.0, 10.0),
color: Theme.of(context).colorScheme.surfaceDim,
activeSize: Size(22.0, 10.0),
activeShape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(25.0)),
),
));
),
);
}

Future<void> _onBackPressed(bool didPop, Object? result) async {
if (didPop) return;

if (_currentPageIndex > 0) {
introKey.currentState?.previous();
return;
}

int clickCount = exitClickCounter.registerClick();
if (clickCount <= 1) {
final snackBar = SnackBar(
content: Text(S.current.messageExitOuiSync),
showCloseIcon: true,
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
} else {
exitClickCounter.reset();
exit(0);
}
}

Future<void> _onIntroEnd(context) async {
Expand Down
Loading

0 comments on commit cb172aa

Please sign in to comment.