Skip to content

Commit

Permalink
Merge pull request #138 from sparcs-kaist/feat@delete-account
Browse files Browse the repository at this point in the history
Add feature that deleting account temporally (only iOS)
  • Loading branch information
sboh1214 authored Aug 17, 2023
2 parents c142f93 + 2aa4c35 commit 5580c88
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 101 deletions.
9 changes: 7 additions & 2 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"unselect_all": "Unselect All",
"no_info": "No information",
"all_selected": "All Selected",
"num_selected": " Selected"
"num_selected": " Selected",
"close": "Close"
},
"semester": {
"spring": "Spring",
Expand Down Expand Up @@ -121,7 +122,11 @@
"major": "Major",
"my_review": "My Reviews",
"liked_review": "Liked Reviews",
"logout": "Logout"
"logout": "Logout",
"delete_account": "Delete Account",
"ask_delete_account": "Are you sure you want to delete your account?",
"account_deleted": "Account Deleted",
"deleted_account": "This is the deleted account."
},
"settings": {
"send_error_log": "Send error log",
Expand Down
9 changes: 7 additions & 2 deletions assets/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"unselect_all": "모두 해제",
"no_info": "정보 없음",
"all_selected": "전체 선택됨",
"num_selected": "개 선택됨"
"num_selected": "개 선택됨",
"close": "닫기"
},
"semester": {
"spring": "",
Expand Down Expand Up @@ -121,7 +122,11 @@
"major": "전공",
"my_review": "내가 들은 과목",
"liked_review": "좋아요한 후기",
"logout": "로그아웃"
"logout": "로그아웃",
"delete_account": "계정 삭제",
"ask_delete_account": "계정을 정말 삭제하시겠습니까?",
"account_deleted": "계정 삭제됨",
"deleted_account": "삭제된 계정입니다."
},
"settings": {
"send_error_log": "오류 로그 전송",
Expand Down
35 changes: 35 additions & 0 deletions lib/pages/login_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import 'dart:io';

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:otlplus/constants/color.dart';
import 'package:otlplus/utils/responsive_button.dart';
import 'package:provider/provider.dart';
import 'package:otlplus/constants/url.dart';
import 'package:otlplus/providers/auth_model.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:webview_flutter/webview_flutter.dart';

class LoginPage extends StatefulWidget {
Expand All @@ -16,6 +21,36 @@ class LoginPage extends StatefulWidget {
class _LoginPageState extends State<LoginPage> {
bool _isVisible = true;

@override
void initState() {
super.initState();

WidgetsBinding.instance.addPostFrameCallback(
(_) async {
if (!((await SharedPreferences.getInstance()).getBool('hasAccount') ??
true)) {
await showDialog(
context: context,
builder: (context) => AlertDialog(
title: Text('user.account_deleted'.tr()),
content: Text('user.deleted_account'.tr()),
actions: [
IconTextButton(
padding: EdgeInsets.all(12),
text: 'common.close'.tr(),
color: OTLColor.pinksMain,
onTap: () {
SystemNavigator.pop();
},
),
],
),
);
}
},
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down
84 changes: 10 additions & 74 deletions lib/pages/timetable_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:otlplus/utils/build_page_route.dart';
import 'package:otlplus/providers/lecture_search_model.dart';
import 'package:otlplus/utils/responsive_button.dart';
import 'package:otlplus/widgets/delete_dialog.dart';
import 'package:otlplus/widgets/lecture_search.dart';
import 'package:otlplus/widgets/map_view.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -254,8 +255,15 @@ class _TimetablePageState extends State<TimetablePage> {
barrierDismissible: true,
barrierLabel:
MaterialLocalizations.of(context).modalBarrierDismissLabel,
pageBuilder: (context, _, __) =>
_buildDeleteDialog(context, timetableModel.selectedIndex),
pageBuilder: (context, _, __) => DeleteDialog(
text: 'timetable.ask_delete_tab'.tr(args: [
'timetable.tab'
.tr(args: [timetableModel.selectedIndex.toString()])
]),
onDelete: () {
context.read<TimetableModel>().deleteTimetable();
},
),
);
},
onExportTap: (type) {
Expand All @@ -265,76 +273,4 @@ class _TimetablePageState extends State<TimetablePage> {
},
);
}

Widget _buildDeleteDialog(BuildContext context, int i) {
return Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Material(
child: IntrinsicWidth(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.fromLTRB(16, 19, 16, 20),
alignment: Alignment.center,
color: Colors.white,
child: Text(
'timetable.ask_delete_tab'.tr(args: [
'timetable.tab'.tr(args: [i.toString()])
]),
style: TextStyle(
fontSize: 12,
),
),
),
Row(
children: [
Expanded(
child: GestureDetector(
onTap: () => Navigator.pop(context),
child: Container(
height: 40,
alignment: Alignment.center,
color: OTLColor.grayE,
child: Text(
'common.cancel'.tr(),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
),
),
),
),
),
Expanded(
child: GestureDetector(
onTap: () {
context.read<TimetableModel>().deleteTimetable();
Navigator.pop(context);
},
child: Container(
height: 40,
alignment: Alignment.center,
color: OTLColor.pinksMain,
child: Text(
'common.delete'.tr(),
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w700,
),
),
),
),
),
],
)
],
),
),
),
),
);
}
}
61 changes: 47 additions & 14 deletions lib/pages/user_page.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'dart:io';

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:otlplus/constants/text_styles.dart';
import 'package:otlplus/providers/auth_model.dart';
import 'package:otlplus/utils/build_app_bar.dart';
import 'package:otlplus/utils/build_page_route.dart';
import 'package:otlplus/utils/responsive_button.dart';
import 'package:otlplus/widgets/delete_dialog.dart';
import 'package:provider/provider.dart';
import 'package:otlplus/constants/color.dart';
import 'package:otlplus/providers/info_model.dart';
Expand Down Expand Up @@ -57,22 +60,37 @@ class UserPage extends StatelessWidget {
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: _buildDivider(),
),
Align(
alignment: Alignment.centerLeft,
child: IconTextButton(
icon: 'assets/icons/logout.svg',
onTap: () {
context.read<AuthModel>().logout();
context.read<InfoModel>().logout();
Navigator.pop(context);
_buildAccount(
'assets/icons/logout.svg',
() {
context.read<AuthModel>().logout();
context.read<InfoModel>().logout();
Navigator.pop(context);
},
'user.logout'.tr(),
),
if (Platform.isIOS)
_buildAccount(
Icons.highlight_off,
() async {
showGeneralDialog(
context: context,
barrierColor: Colors.black.withOpacity(0.2),
barrierDismissible: true,
barrierLabel: MaterialLocalizations.of(context)
.modalBarrierDismissLabel,
pageBuilder: (context, _, __) => DeleteDialog(
text: 'user.ask_delete_account'.tr(),
onDelete: () {
context.read<AuthModel>().logout();
context.read<InfoModel>().deleteAccount();
Navigator.pop(context);
},
),
);
},
text: 'user.logout'.tr(),
color: OTLColor.pinksMain,
textStyle: bodyBold,
spaceBetween: 8.0,
padding: EdgeInsets.symmetric(horizontal: 16.0),
'user.delete_account'.tr(),
),
),
],
),
),
Expand Down Expand Up @@ -150,4 +168,19 @@ class UserPage extends StatelessWidget {
onTap: onTap,
);
}

Widget _buildAccount(dynamic icon, void Function()? onTap, String? text) {
return Align(
alignment: Alignment.centerLeft,
child: IconTextButton(
icon: icon,
onTap: onTap,
text: text,
color: OTLColor.pinksMain,
textStyle: bodyBold,
spaceBetween: 8.0,
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 6.0),
),
);
}
}
25 changes: 16 additions & 9 deletions lib/providers/info_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:otlplus/dio_provider.dart';
import 'package:otlplus/extensions/semester.dart';
import 'package:otlplus/models/semester.dart';
import 'package:otlplus/models/user.dart';
import 'package:shared_preferences/shared_preferences.dart';

const USED_SCHEDULE_FIELDS = [
"beginning",
Expand Down Expand Up @@ -77,16 +78,15 @@ class InfoModel extends ChangeNotifier {
}

Future<void> getInfo() async {
// try {
_semesters = await getSemesters();
_years = _semesters.map((semester) => semester.year).toSet();
_user = await getUser();
_currentSchedule = getCurrentSchedule();
_hasData = true;
if ((await SharedPreferences.getInstance()).getBool('hasAccount') ??
true) {
_semesters = await getSemesters();
_years = _semesters.map((semester) => semester.year).toSet();
_user = await getUser();
_currentSchedule = getCurrentSchedule();
_hasData = true;
}
notifyListeners();
// } catch (exception) {
// print(exception);
// }
}

Future<List<Semester>> getSemesters() async {
Expand Down Expand Up @@ -120,4 +120,11 @@ class InfoModel extends ChangeNotifier {
return schedules.firstWhere((e) => e!["time"].isAfter(now),
orElse: () => null);
}

Future<void> deleteAccount() async {
final pref = await SharedPreferences.getInstance();
pref.setBool('hasAccount', false);
_hasData = false;
notifyListeners();
}
}
Loading

0 comments on commit 5580c88

Please sign in to comment.