💚 End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] In-app change log for local gallery (#9913)
Neeraj9769420556d0
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/home/landing_page_widget.dart b/mobile/apps/photos/lib/ui/home/landing_page_widget.dartindex a47bcd1630..f987f45f75 100644--- a/mobile/apps/photos/lib/ui/home/landing_page_widget.dart+++ b/mobile/apps/photos/lib/ui/home/landing_page_widget.dart@@ -300,7 +300,6 @@ class _LandingPageWidgetState extends State<LandingPageWidget> {}Future<void> _navigateWithoutAccount() async {- updateService.hideChangeLog().ignore();await Navigator.of(context).push(MaterialPageRoute(builder: (_) => const HomeWidget(startWithoutAccount: true),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 c92151500d..85c04a39b6 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@@ -49,7 +49,7 @@ class _ChangeLogPageState extends State<ChangeLogPage> {const SizedBox(height: 24,),- Flexible(child: _getChangeLog(context)),+ Flexible(child: _getChangeLog()),const DividerWidget(dividerType: DividerType.solid,),@@ -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();}},@@ -97,8 +96,14 @@ class _ChangeLogPageState extends State<ChangeLogPage> {);}- Widget _getChangeLog(BuildContext ctx) {- final strings = ChangeLogStrings.forLocale(Localizations.localeOf(context));+ Widget _getChangeLog() {+ final strings = ChangeLogStrings.maybeForLocale(+ Localizations.localeOf(context),+ isOffline: isOfflineMode,+ );+ if (strings == null) {+ return const SizedBox.shrink();+ }final items = <ChangeLogEntry>[ChangeLogEntry(strings.title1,@@ -119,6 +124,11 @@ class _ChangeLogPageState extends State<ChangeLogPage> {description: strings.desc3,isFeature: true,),+ ChangeLogEntry(+ strings.title4,+ description: strings.desc4,+ isFeature: true,+ ),].where((entry) =>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 238886668b..936833afd2 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@@ -9,26 +9,61 @@ class ChangeLogStrings {final String desc2;final String title3;final String desc3;+ final String title4;+ final String desc4;const ChangeLogStrings({required this.title1,required this.desc1,- required this.desc1Item1,- required this.desc1Item2,- required this.title2,- required this.desc2,- required this.title3,- required this.desc3,+ this.desc1Item1 = '',+ this.desc1Item2 = '',+ this.title2 = '',+ this.desc2 = '',+ this.title3 = '',+ this.desc3 = '',+ this.title4 = '',+ this.desc4 = '',});- static ChangeLogStrings forLocale(Locale locale) {+ bool get hasVisibleEntries =>+ title1.trim().isNotEmpty ||+ desc1.trim().isNotEmpty ||+ desc1Item1.trim().isNotEmpty ||+ desc1Item2.trim().isNotEmpty ||+ title2.trim().isNotEmpty ||+ desc2.trim().isNotEmpty ||+ title3.trim().isNotEmpty ||+ desc3.trim().isNotEmpty ||+ title4.trim().isNotEmpty ||+ desc4.trim().isNotEmpty;++ static ChangeLogStrings? maybeForLocale(+ Locale locale, {+ bool isOffline = false,+ }) {final key = locale.countryCode != null && locale.countryCode!.isNotEmpty? '${locale.languageCode}_${locale.countryCode}': locale.languageCode;+ final translations = isOffline ? _offlineTranslations : _translations;+ final strings = translations[key] ??+ translations[locale.languageCode] ??+ translations['en'];++ if (strings == null || !strings.hasVisibleEntries) {+ return null;+ }+ return strings;+ }- return _translations[key] ??- _translations[locale.languageCode] ??- _translations['en']!;+ static bool hasContentForLocale(+ Locale locale, {+ bool isOffline = false,+ }) {+ return maybeForLocale(+ locale,+ isOffline: isOffline,+ ) !=+ null;}static const Map<String, ChangeLogStrings> _translations = {@@ -266,4 +301,17 @@ class ChangeLogStrings {'我们让帮助与支持页面变得更易用,你可以在那里报告问题、提出疑问或提交功能请求。我们还新增了一个版块,带你前往常见问题页面,方便你快速找到答案。',),};++ static const Map<String, ChangeLogStrings> _offlineTranslations = {+ 'en': ChangeLogStrings(+ title1: '',+ desc1: '',+ desc1Item1: '',+ desc1Item2: '',+ title2: '',+ desc2: '',+ title3: '',+ desc3: '',+ ),+ };}diff --git a/mobile/apps/photos/lib/ui/tabs/home_widget.dart b/mobile/apps/photos/lib/ui/tabs/home_widget.dartindex 77ee174e63..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";@@ -124,6 +125,7 @@ class _HomeWidgetState extends State<HomeWidget> {bool _showShowBackupHook = false;bool _personSyncTriggered = false;bool _collectionsSyncTriggered = false;+ bool _isShowingChangeLog = false;final isOnSearchTabNotifier = ValueNotifier<bool>(false);final ValueNotifier<bool> _swipeToSelectInProgressNotifier =ValueNotifier<bool>(false);@@ -222,6 +224,9 @@ class _HomeWidgetState extends State<HomeWidget> {Bus.instance.on<AppModeChangedEvent>().listen((event) async {if (mounted) {setState(() {});+ _scheduleChangeLogCheck(+ delay: const Duration(milliseconds: 250),+ );}});_firstImportEvent =@@ -294,13 +299,8 @@ class _HomeWidgetState extends State<HomeWidget> {// For sharing images coming from outside the app_initMediaShareSubscription();- WidgetsBinding.instance.addPostFrameCallback(- (_) => Future.delayed(- const Duration(seconds: 1),- () => {- if (mounted) {showChangeLog(context)},- },- ),+ _scheduleChangeLogCheck(+ delay: const Duration(seconds: 1),);if (Platform.isAndroid &&@@ -343,6 +343,18 @@ class _HomeWidgetState extends State<HomeWidget> {await MemoryHomeWidgetService.instance.checkPendingMemorySync();}+ void _scheduleChangeLogCheck({+ required Duration delay,+ }) {+ WidgetsBinding.instance.addPostFrameCallback((_) {+ Future.delayed(delay, () {+ if (mounted) {+ showChangeLog(context);+ }+ });+ });+ }+final Map<Uri, (bool, int)> _linkedPublicAlbums = {};Future<void> _handlePublicAlbumLink(Uri uri, String via) async {if (!mounted) {@@ -1073,31 +1085,48 @@ class _HomeWidgetState extends State<HomeWidget> {}showChangeLog(BuildContext context) async {- final bool show = await updateService.showChangeLog();- if (!show || !Configuration.instance.isLoggedIn()) {+ if (_isShowingChangeLog) {return;}- final colorScheme = getEnteColorScheme(context);- await showBarModalBottomSheet(- topControl: const SizedBox.shrink(),- shape: const RoundedRectangleBorder(- borderRadius: BorderRadius.only(- topLeft: Radius.circular(5),- topRight: Radius.circular(5),+ _isShowingChangeLog = true;+ try {+ final action = await updateService.getChangeLogAction(+ locale: Localizations.localeOf(context),+ isOffline: isOfflineMode,+ isSignedIn: Configuration.instance.isLoggedIn(),+ );+ if (!mounted || action == ChangeLogAction.skip) {+ return;+ }+ if (action == ChangeLogAction.consumeWithoutShowing) {+ updateService.hideChangeLog().ignore();+ return;+ }+ final colorScheme = getEnteColorScheme(context);+ await showBarModalBottomSheet(+ topControl: const SizedBox.shrink(),+ shape: const RoundedRectangleBorder(+ borderRadius: BorderRadius.only(+ topLeft: Radius.circular(5),+ topRight: Radius.circular(5),+ ),),- ),- backgroundColor: colorScheme.backgroundElevated,- enableDrag: false,- barrierColor: backdropFaintDark,- context: context,- builder: (BuildContext context) {- return Padding(- padding:- EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),- child: const ChangeLogPage(),- );- },- );+ backgroundColor: colorScheme.backgroundElevated,+ enableDrag: false,+ barrierColor: backdropFaintDark,+ context: context,+ builder: (BuildContext context) {+ return Padding(+ padding: EdgeInsets.only(+ bottom: MediaQuery.of(context).viewInsets.bottom,+ ),+ child: const ChangeLogPage(),+ );+ },+ );+ } finally {+ _isShowingChangeLog = false;+ }// Do not show change dialog againupdateService.hideChangeLog().ignore();}