π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Small refactor
laurenspriem2d3cb7c39123
diff --git a/mobile/apps/photos/lib/services/update_service.dart b/mobile/apps/photos/lib/services/update_service.dartindex e992a0ec97..12c6eb4647 100644--- a/mobile/apps/photos/lib/services/update_service.dart+++ b/mobile/apps/photos/lib/services/update_service.dart@@ -1,4 +1,5 @@import 'dart:io';+import 'dart:ui';import 'package:flutter/foundation.dart';import 'package:logging/logging.dart';@@ -7,10 +8,17 @@ import 'package:photos/core/constants.dart';import 'package:photos/core/network/network.dart';import "package:photos/services/language_service.dart";import 'package:photos/services/notification_service.dart';+import 'package:photos/ui/notification/update/change_log_strings.dart';import 'package:shared_preferences/shared_preferences.dart';import 'package:tuple/tuple.dart';import 'package:url_launcher/url_launcher_string.dart';+enum ChangeLogAction {+ skip,+ consumeWithoutShowing,+ show,+}+class UpdateService {static const kUpdateAvailableShownTimeKey = "update_available_shown_time_key";static const changeLogVersionKey = "update_change_log_key";@@ -27,12 +35,33 @@ class UpdateService {debugPrint("UpdateService constructor");}- Future<bool> showChangeLog() async {+ Future<bool> shouldShowChangeLog() async {// fetch the change log version which was last shown to user.final lastShownAtVersion = _prefs.getInt(changeLogVersionKey) ?? 0;return lastShownAtVersion < currentChangeLogVersion;}+ Future<ChangeLogAction> getChangeLogAction({+ required Locale locale,+ required bool isOffline,+ required bool isSignedIn,+ }) async {+ if (!await shouldShowChangeLog()) {+ return ChangeLogAction.skip;+ }++ if (!(isOffline || isSignedIn)) {+ return ChangeLogAction.skip;+ }++ return ChangeLogStrings.hasContentForLocale(+ locale,+ isOffline: isOffline,+ )+ ? ChangeLogAction.show+ : ChangeLogAction.consumeWithoutShowing;+ }+Future<bool> hideChangeLog() async {return _prefs.setInt(changeLogVersionKey, currentChangeLogVersion);}diff --git a/mobile/apps/photos/lib/ui/notification/update/change_log_page.dart b/mobile/apps/photos/lib/ui/notification/update/change_log_page.dartindex 79759b98c3..f7d07afbdf 100644--- a/mobile/apps/photos/lib/ui/notification/update/change_log_page.dart+++ b/mobile/apps/photos/lib/ui/notification/update/change_log_page.dart@@ -70,8 +70,7 @@ class _ChangeLogPageState extends State<ChangeLogPage> {labelText: AppLocalizations.of(context).continueLabel,icon: Icons.arrow_forward_outlined,onTap: () async {- await updateService.hideChangeLog();- if (mounted && Navigator.of(context).canPop()) {+ if (Navigator.of(context).canPop()) {Navigator.of(context).pop();}},diff --git a/mobile/apps/photos/lib/ui/notification/update/change_log_strings.dart b/mobile/apps/photos/lib/ui/notification/update/change_log_strings.dartindex 89124ca9d0..6fe8ed3373 100644--- a/mobile/apps/photos/lib/ui/notification/update/change_log_strings.dart+++ b/mobile/apps/photos/lib/ui/notification/update/change_log_strings.dart@@ -49,6 +49,17 @@ class ChangeLogStrings {return strings;}+ static bool hasContentForLocale(+ Locale locale, {+ bool isOffline = false,+ }) {+ return maybeForLocale(+ locale,+ isOffline: isOffline,+ ) !=+ null;+ }+static const Map<String, ChangeLogStrings> _translations = {'en': ChangeLogStrings(title1: 'Better People Suggestions',diff --git a/mobile/apps/photos/lib/ui/tabs/home_widget.dart b/mobile/apps/photos/lib/ui/tabs/home_widget.dartindex 879bfb4dbe..14cfe82835 100644--- a/mobile/apps/photos/lib/ui/tabs/home_widget.dart+++ b/mobile/apps/photos/lib/ui/tabs/home_widget.dart@@ -53,6 +53,7 @@ import "package:photos/services/people_home_widget_service.dart";import "package:photos/services/sync/diff_fetcher.dart";import "package:photos/services/sync/local_sync_service.dart";import "package:photos/services/sync/remote_sync_service.dart";+import "package:photos/services/update_service.dart";import "package:photos/states/user_details_state.dart";import "package:photos/theme/colors.dart";import "package:photos/theme/ente_theme.dart";@@ -72,7 +73,6 @@ import "package:photos/ui/home/landing_page_widget.dart";import "package:photos/ui/home/loading_photos_widget.dart";import "package:photos/ui/home/start_backup_hook_widget.dart";import "package:photos/ui/notification/update/change_log_page.dart";-import "package:photos/ui/notification/update/change_log_strings.dart";import "package:photos/ui/rituals/ritual_camera_page.dart";import "package:photos/ui/rituals/ritual_page.dart";import "package:photos/ui/rituals/ritual_privacy.dart";@@ -1090,20 +1090,15 @@ class _HomeWidgetState extends State<HomeWidget> {}_isShowingChangeLog = true;try {- final bool show = await updateService.showChangeLog();- if (!mounted || !show) {- return;- }- final bool canShow = isOfflineMode || Configuration.instance.isLoggedIn();- final hasContent = ChangeLogStrings.maybeForLocale(- Localizations.localeOf(context),- isOffline: isOfflineMode,- ) !=- null;- if (!canShow) {+ final action = await updateService.getChangeLogAction(+ locale: Localizations.localeOf(context),+ isOffline: isOfflineMode,+ isSignedIn: Configuration.instance.isLoggedIn(),+ );+ if (!mounted || action == ChangeLogAction.skip) {return;}- if (!hasContent) {+ if (action == ChangeLogAction.consumeWithoutShowing) {updateService.hideChangeLog().ignore();return;}