Skip to content

Commit

Permalink
flutter: Popup Privacy Policy dialog when first run
Browse files Browse the repository at this point in the history
  • Loading branch information
calcitem committed May 22, 2021
1 parent d9c8c69 commit 3086897
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/ui/flutter_app/lib/common/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import 'settings.dart';
class Config {
static bool settingsLoaded = false;

static bool isPrivacyPolicyAccepted = false;

// Preferences
static bool toneEnabled = true;
static bool aiMovesFirst = false;
static bool aiIsLazy = false;
Expand Down Expand Up @@ -72,6 +75,10 @@ class Config {

final settings = await Settings.instance();

Config.isPrivacyPolicyAccepted =
settings['IsPrivacyPolicyAccepted'] ?? false;

// Preferences
Config.toneEnabled = settings['ToneEnabled'] ?? true;
Config.aiMovesFirst = settings['AiMovesFirst'] ?? false;
Config.aiIsLazy = settings['AiIsLazy'] ?? false;
Expand Down Expand Up @@ -140,6 +147,9 @@ class Config {
static Future<bool> save() async {
final settings = await Settings.instance();

settings['IsPrivacyPolicyAccepted'] = Config.isPrivacyPolicyAccepted;

// Preferences
settings['ToneEnabled'] = Config.toneEnabled;
settings['AiMovesFirst'] = Config.aiMovesFirst;
settings['AiIsLazy'] = Config.aiIsLazy;
Expand Down
12 changes: 12 additions & 0 deletions src/ui/flutter_app/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,18 @@
"@privacyPolicy": {
"description": "Privacy Policy"
},
"privacyPolicy_Detail_1": "Please read carefully and make sure you fully understand and agree with this ",
"@privacyPolicy_Detail_1": {
"description": "Privacy Policy Detail 1"
},
"privacyPolicy_Detail_2": ". If you do not agree to this Policy, please do not use this App. Using the App implies that you accept these terms. We do occasionally update these terms so please refer back to them in the future.",
"@privacyPolicy_Detail_2": {
"description": "Privacy Policy Detail 2"
},
"accept": "Accept",
"@accept": {
"description": "Accept"
},
"undo": "Undo",
"@undo": {
"description": "Undo"
Expand Down
3 changes: 3 additions & 0 deletions src/ui/flutter_app/lib/l10n/intl_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@
"cannotRemoveFromMill": "不能吃三连中的子。",
"left": "剩余",
"privacyPolicy": "隐私政策",
"privacyPolicy_Detail_1": "请您务必审慎阅读、充分理解《隐私政策》各条款,包括但不限于:\n为了改善我们向您提供的服务,基于您的明示授权,我们可能会获取您的设备型号、诊断数据、电子邮件地址等信息,您有权拒绝或取消授权。我们将在每次请求发送诊断数据前,通过弹窗形式征得您的明示同意。\n您可阅读《",
"privacyPolicy_Detail_2": "》了解详细信息。如您同意,请点击“同意”开始接受我们的服务。",
"accept": "同意",
"undo": "悔棋",
"undoOption": "悔棋",
"undoOption_Detail": "允许悔棋",
Expand Down
99 changes: 98 additions & 1 deletion src/ui/flutter_app/lib/widgets/game_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
*/

import 'dart:async';
import 'dart:io';

import 'package:devicelocale/devicelocale.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:sanmill/common/config.dart';
Expand All @@ -31,7 +34,9 @@ import 'package:sanmill/mill/rule.dart';
import 'package:sanmill/mill/types.dart';
import 'package:sanmill/services/audios.dart';
import 'package:sanmill/style/app_theme.dart';
import 'package:sanmill/widgets/game_settings_page.dart';
import 'package:stack_trace/stack_trace.dart';
import 'package:url_launcher/url_launcher.dart';

import 'board.dart';
import 'game_settings_page.dart';
Expand Down Expand Up @@ -80,6 +85,10 @@ class _GamePageState extends State<GamePage> with RouteAware {
setState(() {});
isReady = true;
timer.cancel();

if (!Config.isPrivacyPolicyAccepted) {
onShowPrivacyDialog();
}
}
}

Expand Down Expand Up @@ -674,7 +683,6 @@ class _GamePageState extends State<GamePage> with RouteAware {

onInfoButtonPressed() {
final analyzeText = getInfoText();

showDialog(
context: context,
barrierDismissible: true,
Expand All @@ -695,6 +703,84 @@ class _GamePageState extends State<GamePage> with RouteAware {
);
}

setPrivacyPolicyAccepted(bool value) async {
setState(() {
Config.isPrivacyPolicyAccepted = value;
});

print("[config] isPrivacyPolicyAccepted: $value");

Config.save();
}

onShowPrivacyDialog() async {
String? locale = "en_US";
late String privacyPolicyURL;
if (!Platform.isWindows) {
locale = await Devicelocale.currentLocale;
}

print("[about] local = $locale");
if (locale != null && locale.startsWith("zh_")) {
privacyPolicyURL =
'https://gitee.com/calcitem/Sanmill/wikis/privacy_policy_zh';
} else {
privacyPolicyURL =
'https://github.com/calcitem/Sanmill/wiki/privacy_policy';
}

final ThemeData themeData = Theme.of(context);
final TextStyle? aboutTextStyle = themeData.textTheme.bodyText1;
final TextStyle linkStyle =
themeData.textTheme.bodyText1!.copyWith(color: themeData.accentColor);

showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: Text(
S.of(context).privacyPolicy,
),
content: RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(
style: aboutTextStyle,
text: S.of(context).privacyPolicy_Detail_1,
),
_LinkTextSpan(
style: linkStyle,
text: S.of(context).privacyPolicy,
url: privacyPolicyURL,
),
TextSpan(
style: aboutTextStyle,
text: S.of(context).privacyPolicy_Detail_2,
),
],
),
),
actions: <Widget>[
TextButton(
child: Text(S.of(context).accept),
onPressed: () {
setPrivacyPolicyAccepted(true);
Navigator.of(context).pop();
}),
Platform.isAndroid
? TextButton(
child: Text(S.of(context).exit),
onPressed: () {
setPrivacyPolicyAccepted(false);
SystemChannels.platform
.invokeMethod('SystemNavigator.pop');
},
)
: Container(height: 0.0, width: 0.0),
],
));
}

String getGameOverReasonString(GameOverReason? reason, String? winner) {
//String winnerStr =
// winner == Color.white ? S.of(context).white : S.of(context).black;
Expand Down Expand Up @@ -1180,3 +1266,14 @@ class _GamePageState extends State<GamePage> with RouteAware {
print('$tag Game Page didPop route: $route');
}
}

class _LinkTextSpan extends TextSpan {
_LinkTextSpan({TextStyle? style, required String url, String? text})
: super(
style: style,
text: text ?? url,
recognizer: TapGestureRecognizer()
..onTap = () {
launch(url, forceSafariVC: false);
});
}

0 comments on commit 3086897

Please sign in to comment.