-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Add App Message feature for displaying static backend message #530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ahmed-tarek-salem
wants to merge
7
commits into
develop
Choose a base branch
from
feature/add-in-app-messages
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
58767f8
refactor: remove unused code from SettingsStore
ahmed-tarek-salem ee46abc
feat: add maintenance screen and related app message handling
ahmed-tarek-salem cf90571
feat: add localization
ahmed-tarek-salem 5098254
docs: update readme file to include app message feature
ahmed-tarek-salem ab4f8a9
refactor: rename AppMessageModel to AppMessageDto
ahmed-tarek-salem 832c3d8
fix: correct JSON key names for startDate and endDate in AppMessageDto
ahmed-tarek-salem 9e9378c
feat: add disabled optional field
ahmed-tarek-salem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| class AppMessageDto { | ||
| final String? id; | ||
| final String title; | ||
| final String message; | ||
| final bool blocking; | ||
| final String platform; // e.g. "all", "ios", "android" | ||
| final DateTime? startDate; | ||
| final DateTime? endDate; | ||
| final bool disabled; | ||
|
|
||
| AppMessageDto({ | ||
| required this.id, | ||
| required this.title, | ||
| required this.message, | ||
| required this.blocking, | ||
| required this.platform, | ||
| this.startDate, | ||
| this.endDate, | ||
| this.disabled = false, | ||
| }); | ||
|
|
||
| factory AppMessageDto.fromJson(Map<String, dynamic> json) { | ||
| return AppMessageDto( | ||
| id: json['id'], | ||
| title: json['title'] ?? '', | ||
| message: json['message'] ?? '', | ||
| blocking: json['blocking'] ?? false, | ||
| platform: json['platform'] ?? 'all', | ||
| startDate: | ||
| json['startDate'] == null ? null : _parseDate(json['startDate']), | ||
| endDate: json['endDate'] == null ? null : _parseDate(json['endDate']), | ||
| disabled: json['disabled'] ?? false, | ||
| ); | ||
| } | ||
|
|
||
| /// Check if the message is currently active | ||
| bool get isActive { | ||
| final now = DateTime.now().toUtc(); | ||
| if (startDate != null && now.isBefore(startDate!)) return false; | ||
| if (endDate != null && now.isAfter(endDate!)) return false; | ||
| return true; | ||
| } | ||
|
|
||
| /// Check if message applies to current platform | ||
| bool appliesToPlatform(String currentPlatform) { | ||
| final lowerPlatform = platform.toLowerCase(); | ||
| return lowerPlatform == 'all' || | ||
| lowerPlatform == currentPlatform.toLowerCase(); | ||
| } | ||
|
|
||
| bool isValid(String currentPlatform) { | ||
| return isActive && appliesToPlatform(currentPlatform) && !disabled; | ||
| } | ||
|
|
||
| static DateTime? _parseDate(dynamic value) { | ||
| if (value == null) return null; | ||
| try { | ||
| return DateTime.parse(value).toUtc(); | ||
| } catch (_) { | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_mobx/flutter_mobx.dart'; | ||
| import 'package:flutter_svg/flutter_svg.dart'; | ||
| import 'package:qubic_wallet/di.dart'; | ||
| import 'package:qubic_wallet/dtos/app_message_dto.dart'; | ||
| import 'package:qubic_wallet/flutter_flow/theme_paddings.dart'; | ||
| import 'package:qubic_wallet/l10n/l10n.dart'; | ||
| import 'package:qubic_wallet/stores/app_message_store.dart'; | ||
| import 'package:qubic_wallet/styles/app_icons.dart'; | ||
| import 'package:qubic_wallet/styles/text_styles.dart'; | ||
| import 'package:qubic_wallet/styles/themed_controls.dart'; | ||
|
|
||
| class MaintenanceScreen extends StatelessWidget { | ||
| final AppMessageDto? appMessage; | ||
| const MaintenanceScreen({super.key, this.appMessage}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final l10n = l10nOf(context); | ||
| return PopScope( | ||
| canPop: false, | ||
| child: Scaffold( | ||
| body: Center( | ||
| child: Padding( | ||
| padding: const EdgeInsets.symmetric( | ||
| horizontal: ThemePaddings.normalPadding), | ||
| child: Column( | ||
| mainAxisAlignment: MainAxisAlignment.center, | ||
| children: [ | ||
| SvgPicture.asset( | ||
| AppIcons.maintenance, | ||
| height: 100, | ||
| colorFilter: const ColorFilter.mode( | ||
| LightThemeColors.primary40, BlendMode.srcIn), | ||
| ), | ||
| ThemedControls.spacerVerticalNormal(), | ||
| Text(appMessage?.title ?? "", | ||
| style: TextStyles.alertHeader, textAlign: TextAlign.center), | ||
| ThemedControls.spacerVerticalSmall(), | ||
| Text(appMessage?.message ?? "", | ||
| style: TextStyles.alertText, textAlign: TextAlign.center), | ||
| ThemedControls.spacerVerticalNormal(), | ||
| Observer(builder: (context) { | ||
| bool isLoading = getIt<AppMessageStore>().isLoading; | ||
| return ThemedControls.primaryButtonSmall( | ||
| onPressed: () async { | ||
| final navigator = Navigator.of(context); | ||
| final message = | ||
| await getIt<AppMessageStore>().getAppMessage(); | ||
| if (message == null) { | ||
| navigator.pop(); | ||
| } | ||
| }, | ||
| text: isLoading ? "" : l10n.maintenanceRefreshButton, | ||
| icon: isLoading | ||
| ? const SizedBox( | ||
| height: 20, | ||
| width: 20, | ||
| child: CircularProgressIndicator( | ||
| strokeWidth: 2, | ||
| color: LightThemeColors.background), | ||
| ) | ||
| : null); | ||
| }), | ||
| ], | ||
| ), | ||
| )), | ||
| ), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahmed-tarek-salem how localised message would be handled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahmed-tarek-salem
i.e android_os_version: <13
"Since beginning of next year, our app will only run on devices with Android 13 or upper."