Skip to content

Commit

Permalink
Отображение диалога с изменениями (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
KriseevM authored May 11, 2024
1 parent 9011133 commit 72fe5c7
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 45 deletions.
4 changes: 4 additions & 0 deletions lib/core/constants/changelog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const String changelogString = '''Версия 0.2.2:
- Добавлена зачётная книжка
- Добавлена возможность поставить реакцию к посту
- Исправлены некоторые баги''';
3 changes: 1 addition & 2 deletions lib/core/misc/app_open_tracker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ class AppOpenTracker {
_lastVisitedVersion ??= await _storage.read(
key: _AppOpenTrackerProviderKeys._firstAppOpen,
);
appVersion == _lastVisitedVersion;
final isFirstAppOpenForVersion =
_lastVisitedVersion == null || appVersion == _lastVisitedVersion;
_lastVisitedVersion == null || appVersion != _lastVisitedVersion;

if (isFirstAppOpenForVersion) {
await _storage.write(
Expand Down
40 changes: 40 additions & 0 deletions lib/core/misc/custom_bb_tags.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';
import 'package:unn_mobile/core/misc/hex_color.dart';
import 'package:flutter_bbcode/flutter_bbcode.dart';
import 'package:bbob_dart/bbob_dart.dart' as bbob;
import 'package:unn_mobile/ui/widgets/spoiler_display.dart';
import 'package:url_launcher/url_launcher.dart';

class PTag extends StyleTag {
PTag() : super('p');
Expand Down Expand Up @@ -339,3 +341,41 @@ class UserTag extends StyleTag {
return oldStyle;
}
}

BBStylesheet getBBStyleSheet() {
return defaultBBStylesheet()
.replaceTag(
UrlTag(
onTap: (url) async {
if (!await launchUrl(Uri.parse(url))) {
FirebaseCrashlytics.instance.log('Could not launch url $url');
}
},
),
)
.addTag(PTag())
.addTag(SizeTag())
.addTag(
VideoTag(
onTap: (url) async {
if (!await launchUrl(
Uri.parse(url),
mode: LaunchMode.platformDefault,
)) {
FirebaseCrashlytics.instance.log('Could not launch url $url');
}
},
),
)
.addTag(JustifyAlignTag())
.addTag(FontTag())
.addTag(CodeTag())
.addTag(DiskTag())
.addTag(TableTag())
.addTag(TRTag())
.addTag(TDTag())
.addTag(UserTag())
.replaceTag(ColorTag())
.replaceTag(ImgTag())
.replaceTag(SpoilerTag());
}
16 changes: 16 additions & 0 deletions lib/ui/views/auth_page/auth_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import 'dart:math' as math;

import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:injector/injector.dart';
import 'package:unn_mobile/core/misc/app_open_tracker.dart';
import 'package:unn_mobile/core/viewmodels/auth_page_view_model.dart';
import 'package:unn_mobile/core/viewmodels/base_view_model.dart';
import 'package:unn_mobile/ui/router.dart';
import 'package:unn_mobile/ui/views/base_view.dart';
import 'package:unn_mobile/ui/widgets/dialogs/changelog_dialog.dart';
import 'package:unn_mobile/ui/widgets/text_field_with_shadow.dart';

const _accentColor = Color(0xFF1A63B7);
Expand Down Expand Up @@ -34,6 +37,19 @@ class AuthPageWithState extends State<AuthPage> {

_loginTextController.addListener(stateUpdater);
_passwordTextController.addListener(stateUpdater);

WidgetsBinding.instance.addPostFrameCallback((_) async {
if (await Injector.appInstance
.get<AppOpenTracker>()
.isFirstTimeOpenOnVersion()) {
if (mounted) {
await showDialog(
context: context,
builder: (context) => const ChangelogDialog(),
);
}
}
});
}

@override
Expand Down
42 changes: 1 addition & 41 deletions lib/ui/views/main_page/feed/feed.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bbcode/flutter_bbcode.dart';
import 'package:html_unescape/html_unescape.dart';
import 'package:intl/intl.dart';
import 'package:unn_mobile/core/misc/custom_bb_tags.dart' as custom_tags;
import 'package:unn_mobile/core/misc/custom_bb_tags.dart';
import 'package:unn_mobile/core/misc/user_functions.dart';
import 'package:unn_mobile/core/models/post_with_loaded_info.dart';
import 'package:unn_mobile/core/models/user_data.dart';
Expand All @@ -12,7 +11,6 @@ import 'package:unn_mobile/ui/unn_mobile_colors.dart';
import 'package:unn_mobile/ui/views/base_view.dart';
import 'package:unn_mobile/ui/views/main_page/feed/widgets/attached_file.dart';
import 'package:unn_mobile/ui/views/main_page/feed/widgets/comments_page.dart';
import 'package:url_launcher/url_launcher.dart';

class FeedScreenView extends StatelessWidget {
const FeedScreenView({super.key});
Expand Down Expand Up @@ -223,44 +221,6 @@ class FeedScreenView extends StatelessWidget {
);
}

static BBStylesheet getBBStyleSheet() {
return defaultBBStylesheet()
.replaceTag(
UrlTag(
onTap: (url) async {
if (!await launchUrl(Uri.parse(url))) {
FirebaseCrashlytics.instance.log('Could not launch url $url');
}
},
),
)
.addTag(custom_tags.PTag())
.addTag(custom_tags.SizeTag())
.addTag(
custom_tags.VideoTag(
onTap: (url) async {
if (!await launchUrl(
Uri.parse(url),
mode: LaunchMode.platformDefault,
)) {
FirebaseCrashlytics.instance.log('Could not launch url $url');
}
},
),
)
.addTag(custom_tags.JustifyAlignTag())
.addTag(custom_tags.FontTag())
.addTag(custom_tags.CodeTag())
.addTag(custom_tags.DiskTag())
.addTag(custom_tags.TableTag())
.addTag(custom_tags.TRTag())
.addTag(custom_tags.TDTag())
.addTag(custom_tags.UserTag())
.replaceTag(custom_tags.ColorTag())
.replaceTag(custom_tags.ImgTag())
.replaceTag(custom_tags.SpoilerTag());
}

static CircleAvatar _circleAvatar(ThemeData theme, UserData? userData) {
final userAvatar = getUserAvatar(userData);
return CircleAvatar(
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/views/main_page/feed/widgets/comments_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bbcode/flutter_bbcode.dart';
import 'package:html_unescape/html_unescape.dart';
import 'package:unn_mobile/core/misc/custom_bb_tags.dart';
import 'package:unn_mobile/core/misc/user_functions.dart';
import 'package:unn_mobile/core/models/blog_post_comment_with_loaded_info.dart';
import 'package:unn_mobile/core/models/post_with_loaded_info.dart';
Expand Down Expand Up @@ -150,7 +151,7 @@ class CommentsPage extends StatelessWidget {
const EdgeInsets.only(left: 16, bottom: 10, right: 10, top: 16),
child: BBCodeText(
data: unescaper.convert(comment.comment.message),
stylesheet: FeedScreenView.getBBStyleSheet(),
stylesheet: getBBStyleSheet(),
),
),
for (final file in comment.files)
Expand Down
22 changes: 22 additions & 0 deletions lib/ui/views/main_page/main_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:injector/injector.dart';
import 'package:unn_mobile/core/misc/app_open_tracker.dart';
import 'package:unn_mobile/ui/views/main_page/feed/feed.dart';
import 'package:unn_mobile/ui/views/main_page/grades/grades.dart';
import 'package:unn_mobile/ui/views/main_page/main_page_tab_state.dart';
import 'package:unn_mobile/ui/views/main_page/settings/settings.dart';
import 'package:unn_mobile/ui/widgets/dialogs/changelog_dialog.dart';
import 'package:unn_mobile/ui/widgets/placeholder.dart' as placeholder;
import 'package:flutter/material.dart';
import 'package:unn_mobile/core/viewmodels/main_page_view_model.dart';
Expand Down Expand Up @@ -41,6 +44,25 @@ class _MainPageState extends State<MainPage> {
];

final drawerIdOffset = 10;

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

WidgetsBinding.instance.addPostFrameCallback((_) async {
if (await Injector.appInstance
.get<AppOpenTracker>()
.isFirstTimeOpenOnVersion()) {
if (mounted) {
await showDialog(
context: context,
builder: (context) => const ChangelogDialog(),
);
}
}
});
}

@override
Widget build(BuildContext context) {
return BaseView<MainPageViewModel>(
Expand Down
39 changes: 39 additions & 0 deletions lib/ui/widgets/dialogs/changelog_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'package:flutter_bbcode/flutter_bbcode.dart';
import 'package:unn_mobile/core/constants/changelog.dart';
import 'package:unn_mobile/core/misc/custom_bb_tags.dart';
import 'package:unn_mobile/ui/widgets/adaptive_dialog_action.dart';

class ChangelogDialog extends StatelessWidget {
const ChangelogDialog({super.key});

@override
Widget build(BuildContext context) {
return AlertDialog.adaptive(
title: const Text('Список изменений: '),
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
const Flexible(
child: SingleChildScrollView(
child: Text(changelogString),
),
),
const Divider(),
BBCodeText(
data:
'Также, подписывайтесь на наш [URL=https://t.me/unn_mobile]Telegram-канал[/URL]',
stylesheet: getBBStyleSheet(),
),
],
),
actions: [
AdaptiveDialogAction(
onPressed: () => Navigator.of(context).pop(),
child: const Text('OK'),
),
],
);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: unn_mobile
description: A mobile application for UNN Portal website
publish_to: 'none'

version: 0.2.1+192
version: 0.2.2+193

environment:
sdk: '>=3.1.2 <4.0.0'
Expand Down

0 comments on commit 72fe5c7

Please sign in to comment.