Skip to content

Commit

Permalink
feat: add promotion consent
Browse files Browse the repository at this point in the history
  • Loading branch information
sparcscasio committed Jan 9, 2025
1 parent ff9edb4 commit 445e286
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 7 deletions.
15 changes: 13 additions & 2 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"all_selected": "All Selected",
"num_selected": " Selected",
"close": "Close",
"coming": "Coming Soon"
"coming": "Coming Soon",
"confirm": "Confirm"
},
"semester": {
"spring": "Spring",
Expand Down Expand Up @@ -165,11 +166,21 @@
"send_error_log_desc": "Automatically collect logs without user reporting",
"send_anonymously": "Send anonymously",
"send_anonymously_desc": "Not including user ID in error logs",
"receive_promotion": "Promotion consent",
"receive_promotion_desc": "Receive promotional notifications",
"reset_all": "Reset all settings",
"dialog": {
"reset": "Reset",
"reset_settings": "Reset settings",
"reset_settings_desc": "Are you really want to reset all data? However, it will be reset except for login data."
"reset_settings_desc": "Are you really want to reset all data? However, it will be reset except for login data.",
"disable_promotion" : "Refusal to Receive Promotional Information",
"promotion_desc" : "You can change your consent to receive promotional information in Settings > [Promoiton Consent].",
"enable_promotion" : "Consent to Receive Promotional Information",
"date" : "Date",
"user_name" : "Name",
"detail" : "Detail",
"disable" : "decline",
"enable" : "agree"
},
"throw_test": "Throw Test Exception",
"throw_test_desc": "for testing firebase crashlytics",
Expand Down
16 changes: 14 additions & 2 deletions assets/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"all_selected": "전체 선택됨",
"num_selected": "개 선택됨",
"close": "닫기",
"coming": "준비 중입니다."
"coming": "준비 중입니다.",
"confirm": "확인"
},
"semester": {
"spring": "",
Expand Down Expand Up @@ -164,12 +165,23 @@
"send_error_log": "오류 로그 전송",
"send_error_log_desc": "사용자의 제보 없이 자동으로 오류를 수집합니다.",
"send_anonymously": "익명으로 전송",
"receive_promotion": "광고성 정보 수신 동의",
"receive_promotion_desc": "광고성 정보에 대한 푸시 알림 수신에 동의합니다.",
"send_anonymously_desc": "오류 로그에 사용자 ID를 포함하지 않고 익명으로 전송합니다.",
"reset_all": "모든 설정 데이터 초기화",
"dialog": {
"reset": "초기화",
"yes": "확인",
"reset_settings": "설정 초기화",
"reset_settings_desc": "정말 모든 설정 데이터를 초기화하시겠습니까? 단, 로그인 정보는 제외하고 초기화됩니다."
"reset_settings_desc": "정말 모든 설정 데이터를 초기화하시겠습니까? 단, 로그인 정보는 제외하고 초기화됩니다.",
"disable_promotion": "광고성 정보 수신 거부 처리 결과",
"enable_promotion" : "광고성 정보 수신 동의 처리 결과",
"promotion_desc" : "광고성 정보 수신동의는 설정 > [광고성 정보 수신 동의] 에서 변경 가능합니다.",
"date" : "일시",
"user_name" : "전송자",
"detail" : "내용",
"disable" : "거부",
"enable" : "동의"
},
"throw_test": "테스트 오류 발생",
"throw_test_desc": "Firebase crashlytics 테스트용",
Expand Down
3 changes: 3 additions & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void main() {
);

final token = await FirebaseMessaging.instance.getToken();
debugPrint('firebase token : ${token}');

Check warning on line 52 in lib/main.dart

View check run for this annotation

Codecov / codecov/patch

lib/main.dart#L52

Added line #L52 was not covered by tests

FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;

Expand Down
20 changes: 20 additions & 0 deletions lib/pages/settings_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart';
import 'package:otlplus/constants/color.dart';
import 'package:otlplus/constants/text_styles.dart';
import 'package:otlplus/constants/url.dart';
import 'package:otlplus/providers/info_model.dart';
import 'package:otlplus/providers/settings_model.dart';
import 'package:otlplus/widgets/dropdown.dart';
import 'package:otlplus/widgets/otl_dialog.dart';
Expand All @@ -18,6 +19,7 @@ class SettingsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isEn = EasyLocalization.of(context)?.currentLocale == Locale('en');
final user = context.watch<InfoModel>().user;

return OTLScaffold(
child: OTLLayout(
Expand Down Expand Up @@ -84,6 +86,24 @@ class SettingsPage extends StatelessWidget {
),
],
),
_buildListTile(
title: "settings.receive_promotion".tr(),
subtitle: "settings.receive_promotion_desc".tr(),
trailing: CupertinoSwitch(
value: context.watch<SettingsModel>().getReceivePromotion(),
onChanged: (value) {
context.read<SettingsModel>().setReceivePromotion(value);
OTLNavigator.pushDialog(

Check warning on line 96 in lib/pages/settings_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/settings_page.dart#L89-L96

Added lines #L89 - L96 were not covered by tests
context: context,
builder: (_) => OTLDialog(

Check warning on line 98 in lib/pages/settings_page.dart

View check run for this annotation

Codecov / codecov/patch

lib/pages/settings_page.dart#L98

Added line #L98 was not covered by tests
type: value
? OTLDialogType.enablePromotion
: OTLDialogType.disablePromotion,
),
);
},
),
),
_buildListTile(
title: "settings.send_error_log".tr(),
subtitle: "settings.send_error_log_desc".tr(),
Expand Down
17 changes: 17 additions & 0 deletions lib/providers/settings_model.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

final _kSendCrashlytics = 'sendCrashlytics';
final _kSendCrashlyticsAnonymously = 'sendCrashlyticsAnonymously';
final _kShowsChannelTalkButton = 'showsChannelTalkButton';
final _kReceivePromotion = 'receivePromoiton';

class SettingsModel extends ChangeNotifier {
late bool _sendCrashlytics;
late bool _sendCrashlyticsAnonymously;
late bool _showsChannelTalkButton;
late bool _receivePromotion;

bool getSendCrashlytics() => _sendCrashlytics;
void setSendCrashlytics(bool newValue) {
Expand All @@ -34,6 +37,17 @@ class SettingsModel extends ChangeNotifier {
(instance) => instance.setBool(_kShowsChannelTalkButton, newValue));
}

bool getReceivePromotion() => _receivePromotion;
Future<void> setReceivePromotion(bool newValue) async {
_receivePromotion = newValue;
notifyListeners();
SharedPreferences.getInstance()
.then((instance) => instance.setBool(_kReceivePromotion, newValue));

Check warning on line 45 in lib/providers/settings_model.dart

View check run for this annotation

Codecov / codecov/patch

lib/providers/settings_model.dart#L40-L45

Added lines #L40 - L45 were not covered by tests
newValue
? await FirebaseMessaging.instance.subscribeToTopic("promotion")
: await FirebaseMessaging.instance.unsubscribeFromTopic("promotion");

Check warning on line 48 in lib/providers/settings_model.dart

View check run for this annotation

Codecov / codecov/patch

lib/providers/settings_model.dart#L47-L48

Added lines #L47 - L48 were not covered by tests
}

SettingsModel({bool forTest = false}) {
SharedPreferences.getInstance().then((instance) {
getAllValues(instance);
Expand All @@ -43,6 +57,7 @@ class SettingsModel extends ChangeNotifier {
_sendCrashlytics = true;
_sendCrashlyticsAnonymously = false;
_showsChannelTalkButton = true;
_receivePromotion = true;
}
}

Expand All @@ -52,6 +67,8 @@ class SettingsModel extends ChangeNotifier {
instance.getBool(_kSendCrashlyticsAnonymously) ?? false;
_showsChannelTalkButton =
instance.getBool(_kShowsChannelTalkButton) ?? true;
_receivePromotion = instance.getBool(_kReceivePromotion) ?? false;

notifyListeners();
}

Expand Down
83 changes: 80 additions & 3 deletions lib/widgets/otl_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:otlplus/constants/color.dart';
import 'package:otlplus/constants/text_styles.dart';
import 'package:otlplus/constants/url.dart';
import 'package:otlplus/models/user.dart';
import 'package:otlplus/providers/info_model.dart';
import 'package:otlplus/utils/navigator.dart';
import 'package:otlplus/widgets/responsive_button.dart';
import 'package:provider/provider.dart';

enum OTLDialogType {
/// namedArgs: 'lecture'
Expand Down Expand Up @@ -37,6 +40,10 @@ enum OTLDialogType {

resetSettings,

disablePromotion,

enablePromotion,

about,
}

Expand Down Expand Up @@ -133,7 +140,21 @@ extension OTLDialogTypeExt on OTLDialogType {
title: 'settings.dialog.reset_settings',
content: 'settings.dialog.reset_settings_desc',
icon: 'alert',
posText: 'settings.dialog.reset',
posText: '.dialog.reset',
),
OTLDialogType.disablePromotion: _OTLDialogData(

Check warning on line 145 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L145

Added line #L145 was not covered by tests
title: 'settings.dialog.disable_promotion',
content: 'settings.dialog.reset_settings_desc',
icon: 'OTL',
negText: 'common.close',
btnStyle: BtnStyle.one,
),
OTLDialogType.enablePromotion: _OTLDialogData(

Check warning on line 152 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L152

Added line #L152 was not covered by tests
title: 'settings.dialog.enable_promotion',
content: 'settings.dialog.reset_settings_desc',
icon: 'OTL',
negText: 'common.close',
btnStyle: BtnStyle.one,
),
OTLDialogType.about: _OTLDialogData(
title: 'Online Timeplanner with Lectures Plus @ KAIST',
Expand Down Expand Up @@ -169,6 +190,8 @@ class OTLDialog extends StatelessWidget {

@override
Widget build(BuildContext context) {
final user = context.watch<InfoModel>().user;

Check warning on line 193 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L193

Added line #L193 was not covered by tests

return Center(
child: Container(
width: 256,
Expand Down Expand Up @@ -200,7 +223,7 @@ class OTLDialog extends StatelessWidget {
children: [
Text(type.title.tr(), style: titleBold),
const SizedBox(height: 8),
_buildContent(),
_buildContent(user: user),

Check warning on line 226 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L226

Added line #L226 was not covered by tests
],
),
),
Expand Down Expand Up @@ -259,8 +282,11 @@ class OTLDialog extends StatelessWidget {
);
}

Widget _buildContent() {
Widget _buildContent({User? user}) {

Check warning on line 285 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L285

Added line #L285 was not covered by tests
final content = type.content.tr(namedArgs: namedArgs);

user ?? null;

switch (type) {
case OTLDialogType.addLecture:
case OTLDialogType.addLectureWithTab:
Expand All @@ -275,6 +301,57 @@ class OTLDialog extends StatelessWidget {
content,
style: bodyRegular,
);

case OTLDialogType.disablePromotion:
return Column(
children: [
Container(

Check warning on line 308 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L305-L308

Added lines #L305 - L308 were not covered by tests
width: 200,
child: Column(
children: [
Text(
'${'settings.dialog.date'.tr(namedArgs: namedArgs)} : ${DateFormat('yyyy-MM-dd').format(DateTime.now())}'),
Text(
'${'settings.dialog.user_name'.tr(namedArgs: namedArgs)} : ${user!.firstName} ${user!.lastName}'),
Text(
'${'settings.dialog.detail'.tr(namedArgs: namedArgs)} : ${'settings.dialog.disable'.tr(namedArgs: namedArgs)}'),

Check warning on line 317 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L310-L317

Added lines #L310 - L317 were not covered by tests
],
),
color: OTLColor.grayE,
),
SizedBox(

Check warning on line 322 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L322

Added line #L322 was not covered by tests
height: 5,
),
Text(
'${'settings.dialog.promotion_desc'.tr(namedArgs: namedArgs)}'),

Check warning on line 326 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L325-L326

Added lines #L325 - L326 were not covered by tests
],
);

case OTLDialogType.enablePromotion:
return Column(
children: [
Container(

Check warning on line 333 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L330-L333

Added lines #L330 - L333 were not covered by tests
width: 200,
child: Column(
children: [
Text(
'${'settings.dialog.date'.tr(namedArgs: namedArgs)} : ${DateFormat('yyyy-MM-dd').format(DateTime.now())}'),
Text(
'${'settings.dialog.user_name'.tr(namedArgs: namedArgs)} : ${user!.firstName} ${user!.lastName}'),
Text(
'${'settings.dialog.detail'.tr(namedArgs: namedArgs)} : ${'settings.dialog.enable'.tr(namedArgs: namedArgs)}'),

Check warning on line 342 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L335-L342

Added lines #L335 - L342 were not covered by tests
],
),
color: OTLColor.grayE,
),
SizedBox(

Check warning on line 347 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L347

Added line #L347 was not covered by tests
height: 5,
),
Text(
'${'settings.dialog.promotion_desc'.tr(namedArgs: namedArgs)}'),

Check warning on line 351 in lib/widgets/otl_dialog.dart

View check run for this annotation

Codecov / codecov/patch

lib/widgets/otl_dialog.dart#L350-L351

Added lines #L350 - L351 were not covered by tests
],
);

case OTLDialogType.addOverlappingLecture:
case OTLDialogType.addOverlappingLectureWithTab:
return Text.rich(TextSpan(
Expand Down

0 comments on commit 445e286

Please sign in to comment.