π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Update the design for apply referral
Neeraj Guptad3e308f5bfdc
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arbindex d52c5b52c8..cc1d712a96 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -306,6 +306,7 @@"enterCodeDescription": "Enter the code provided by your friend to claim free storage for both of you","apply": "Apply","failedToApplyCode": "Failed to apply code",+ "invalidReferralCode": "Invalid code","enterReferralCode": "Enter referral code","codeAppliedPageTitle": "Code applied","changeYourReferralCode": "Change your code",diff --git a/mobile/apps/photos/lib/ui/growth/apply_code_sheet.dart b/mobile/apps/photos/lib/ui/growth/apply_code_sheet.dartnew file mode 100644index 0000000000..6ef3dd2792--- /dev/null+++ b/mobile/apps/photos/lib/ui/growth/apply_code_sheet.dart@@ -0,0 +1,205 @@+import "package:dio/dio.dart";+import "package:ente_pure_utils/ente_pure_utils.dart";+import "package:flutter/material.dart";+import "package:logging/logging.dart";+import "package:photos/generated/l10n.dart";+import "package:photos/models/api/storage_bonus/storage_bonus.dart";+import "package:photos/models/user_details.dart";+import "package:photos/service_locator.dart";+import "package:photos/theme/ente_theme.dart";+import "package:photos/ui/components/base_bottom_sheet.dart";+import "package:photos/ui/growth/code_success_screen.dart";++Future<bool?> showApplyCodeSheet(+ BuildContext context, {+ required ReferralView referralView,+ required UserDetails userDetails,+}) {+ return showBaseBottomSheet<bool>(+ context,+ title: AppLocalizations.of(context).applyCodeTitle,+ headerSpacing: 20,+ child: _ApplyCodeContent(+ referralView: referralView,+ userDetails: userDetails,+ ),+ );+}++class _ApplyCodeContent extends StatefulWidget {+ final ReferralView referralView;+ final UserDetails userDetails;++ const _ApplyCodeContent({+ required this.referralView,+ required this.userDetails,+ });++ @override+ State<_ApplyCodeContent> createState() => _ApplyCodeContentState();+}++class _ApplyCodeContentState extends State<_ApplyCodeContent> {+ late TextEditingController _controller;+ bool _isLoading = false;+ String? _errorMessage;++ @override+ void initState() {+ super.initState();+ _controller = TextEditingController();+ _controller.addListener(_onTextChanged);+ }++ @override+ void dispose() {+ _controller.removeListener(_onTextChanged);+ _controller.dispose();+ super.dispose();+ }++ void _onTextChanged() {+ setState(() {+ _errorMessage = null;+ });+ }++ bool get _isValid => _controller.text.trim().length >= 4;++ Future<void> _applyCode() async {+ final code = _controller.text.trim();+ if (code.length < 4) {+ return;+ }++ setState(() {+ _isLoading = true;+ _errorMessage = null;+ });++ try {+ await storageBonusService.applyCode(code);+ if (mounted) {+ Navigator.of(context).pop(true);+ // Navigate to success screen+ await Navigator.of(context).push(+ MaterialPageRoute(+ builder: (context) => CodeSuccessScreen(+ widget.referralView,+ widget.userDetails,+ ),+ ),+ );+ }+ } catch (e) {+ Logger("ApplyCodeSheet").severe("Failed to apply code", e);+ if (mounted) {+ String errorMessage = AppLocalizations.of(context).failedToApplyCode;+ if (e is DioException &&+ e.response != null &&+ e.response!.data != null) {+ final code = e.response!.data["code"];+ if (code == "INVALID_CODE") {+ errorMessage = AppLocalizations.of(context).invalidReferralCode;+ } else if (code != null) {+ errorMessage =+ "${AppLocalizations.of(context).failedToApplyCode}: $code";+ }+ }+ setState(() {+ _errorMessage = errorMessage;+ });+ }+ } finally {+ if (mounted) {+ setState(() {+ _isLoading = false;+ });+ }+ }+ }++ @override+ Widget build(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ final textTheme = getEnteTextTheme(context);+ final isDarkMode = Theme.of(context).brightness == Brightness.dark;++ final inputBackgroundColor =+ isDarkMode ? const Color(0xFF1C1C1C) : const Color(0xFFFAFAFA);++ const greenColor = Color(0xFF08C225);+ const warningRedColor = Color(0xFFF63A3A);++ return Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ // Text input field+ Container(+ decoration: BoxDecoration(+ color: inputBackgroundColor,+ borderRadius: BorderRadius.circular(16),+ ),+ child: TextField(+ controller: _controller,+ inputFormatters: [UpperCaseTextFormatter()],+ textCapitalization: TextCapitalization.characters,+ style: textTheme.body,+ decoration: InputDecoration(+ border: InputBorder.none,+ contentPadding: const EdgeInsets.symmetric(+ horizontal: 16,+ vertical: 20,+ ),+ hintText: AppLocalizations.of(context).enterReferralCode,+ hintStyle: textTheme.body.copyWith(color: colorScheme.textMuted),+ ),+ ),+ ),+ const SizedBox(height: 9),+ // Helper/error text+ Text(+ _errorMessage ?? AppLocalizations.of(context).enterCodeDescription,+ style: textTheme.mini.copyWith(+ color: _errorMessage != null ? warningRedColor : colorScheme.textMuted,+ ),+ ),+ const SizedBox(height: 20),+ // Apply button+ SizedBox(+ width: double.infinity,+ height: 56,+ child: ElevatedButton(+ onPressed: _isLoading || !_isValid ? null : _applyCode,+ style: ElevatedButton.styleFrom(+ backgroundColor: _isValid ? greenColor : colorScheme.fillMuted,+ foregroundColor: Colors.white,+ disabledBackgroundColor: colorScheme.fillMuted,+ disabledForegroundColor: colorScheme.textMuted,+ shape: RoundedRectangleBorder(+ borderRadius: BorderRadius.circular(20),+ ),+ elevation: 0,+ ),+ child: _isLoading+ ? SizedBox(+ width: 24,+ height: 24,+ child: CircularProgressIndicator(+ strokeWidth: 2,+ color: colorScheme.textMuted,+ ),+ )+ : Text(+ AppLocalizations.of(context).apply,+ style: textTheme.bodyBold.copyWith(+ color: _isValid ? Colors.white : colorScheme.textMuted,+ ),+ ),+ ),+ ),+ ],+ );+ }+}diff --git a/mobile/apps/photos/lib/ui/growth/change_referral_code_sheet.dart b/mobile/apps/photos/lib/ui/growth/change_referral_code_sheet.dartindex d3ad2fb95c..f04af954a6 100644--- a/mobile/apps/photos/lib/ui/growth/change_referral_code_sheet.dart+++ b/mobile/apps/photos/lib/ui/growth/change_referral_code_sheet.dart@@ -64,7 +64,7 @@ class _ChangeReferralCodeContentState}bool get _hasChanges =>- _controller.text.trim().isNotEmpty &&+ _controller.text.trim().length >= 4 &&_controller.text.trim() != widget.currentCode;Future<void> _saveCode() async {diff --git a/mobile/apps/photos/lib/ui/growth/referral_screen.dart b/mobile/apps/photos/lib/ui/growth/referral_screen.dartindex 5d2d33b79f..6f09707ad7 100644--- a/mobile/apps/photos/lib/ui/growth/referral_screen.dart+++ b/mobile/apps/photos/lib/ui/growth/referral_screen.dart@@ -11,7 +11,7 @@ import "package:photos/theme/text_style.dart";import "package:photos/ui/common/loading_widget.dart";import "package:photos/ui/common/web_page.dart";import "package:photos/ui/components/menu_item_widget/menu_item_widget_new.dart";-import "package:photos/ui/growth/apply_code_screen.dart";+import "package:photos/ui/growth/apply_code_sheet.dart";import "package:photos/ui/growth/referral_code_widget.dart";import "package:photos/ui/growth/storage_details_screen.dart";import "package:photos/utils/share_util.dart";@@ -226,11 +226,14 @@ class ReferralWidget extends StatelessWidget {trailingIcon: Icons.chevron_right_outlined,trailingIconIsMuted: true,onTap: () async {- await routeToPage(+ final result = await showApplyCodeSheet(context,- ApplyCodeScreen(referralView, userDetails),+ referralView: referralView,+ userDetails: userDetails,);- notifyParent();+ if (result == true) {+ notifyParent();+ }},),const SizedBox(height: 8),diff --git a/mobile/apps/photos/scripts/internal_changes.txt b/mobile/apps/photos/scripts/internal_changes.txtindex ad38070ef1..0198c358ec 100644--- a/mobile/apps/photos/scripts/internal_changes.txt+++ b/mobile/apps/photos/scripts/internal_changes.txt@@ -1,3 +1,5 @@+- Neeraj: Referral screen redesign+- Neeraj: Settings screen redesign- Ashil: QOL: Fix home gallery getting cut on the right end on landscape mode (affects tablets)- Ashil: QOL: Fix uncategorized page not updating after move- Ashil: QOL: Pause video when using jump to date@@ -13,3 +15,4 @@- Prateek: Add "Start with latest backups" (last 7 days onwards) (20% rollout)- Prateek: Stop streaming if not 75% processed for upload and thermal change- Prateek: Stop streaming immediately on log-out+