diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n.dart b/.dart_tool/flutter_gen/gen_l10n/l10n.dart index da7ae6dd8..adfd04e42 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n.dart @@ -182,6 +182,12 @@ abstract class S { /// **'Auto'** String get auto; + /// No description provided for @autoBackupConflict. + /// + /// In en, this message translates to: + /// **'Only one automatic backup can be turned on at the same time.'** + String get autoBackupConflict; + /// No description provided for @autoCheckUpdate. /// /// In en, this message translates to: @@ -1574,6 +1580,12 @@ abstract class S { /// **'No paired Apple Watch'** String get watchNotPaired; + /// No description provided for @webdavSettingEmpty. + /// + /// In en, this message translates to: + /// **'Webdav setting is empty'** + String get webdavSettingEmpty; + /// No description provided for @whenOpenApp. /// /// In en, this message translates to: diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n_de.dart b/.dart_tool/flutter_gen/gen_l10n/l10n_de.dart index 95539b9c1..da93796d8 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n_de.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n_de.dart @@ -48,6 +48,9 @@ class SDe extends S { @override String get auto => 'System folgen'; + @override + String get autoBackupConflict => 'Es kann nur eine automatische Sicherung gleichzeitig aktiviert werden.'; + @override String get autoCheckUpdate => 'Aktualisierung automatisch prüfen'; @@ -782,6 +785,9 @@ class SDe extends S { @override String get watchNotPaired => 'Keine gekoppelte Apple Watch'; + @override + String get webdavSettingEmpty => 'Webdav-Einstellungen sind leer'; + @override String get whenOpenApp => 'Beim Öffnen der App'; diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart b/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart index bea6d8ea1..357c28210 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart @@ -48,6 +48,9 @@ class SEn extends S { @override String get auto => 'Auto'; + @override + String get autoBackupConflict => 'Only one automatic backup can be turned on at the same time.'; + @override String get autoCheckUpdate => 'Auto check update'; @@ -782,6 +785,9 @@ class SEn extends S { @override String get watchNotPaired => 'No paired Apple Watch'; + @override + String get webdavSettingEmpty => 'Webdav setting is empty'; + @override String get whenOpenApp => 'When opening the app'; diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n_id.dart b/.dart_tool/flutter_gen/gen_l10n/l10n_id.dart index e50027f83..33cbace95 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n_id.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n_id.dart @@ -48,6 +48,9 @@ class SId extends S { @override String get auto => 'Auto'; + @override + String get autoBackupConflict => 'Hanya satu pencadangan otomatis yang dapat diaktifkan pada saat yang bersamaan.'; + @override String get autoCheckUpdate => 'Periksa pembaruan otomatis'; @@ -782,6 +785,9 @@ class SId extends S { @override String get watchNotPaired => 'Tidak ada Apple Watch yang dipasangkan'; + @override + String get webdavSettingEmpty => 'Pengaturan webdav kosong'; + @override String get whenOpenApp => 'Saat membuka aplikasi'; diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n_zh.dart b/.dart_tool/flutter_gen/gen_l10n/l10n_zh.dart index bd2c0203e..12367d09a 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n_zh.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n_zh.dart @@ -48,6 +48,9 @@ class SZh extends S { @override String get auto => '自动'; + @override + String get autoBackupConflict => '只能同时开启一个自动备份'; + @override String get autoCheckUpdate => '自动检查更新'; @@ -782,6 +785,9 @@ class SZh extends S { @override String get watchNotPaired => '没有已配对的 Apple Watch'; + @override + String get webdavSettingEmpty => 'Webdav 设置项为空'; + @override String get whenOpenApp => '当打开 App 时'; @@ -840,6 +846,9 @@ class SZhTw extends SZh { @override String get auto => '自動'; + @override + String get autoBackupConflict => '只能同時開啓壹個自動備份'; + @override String get autoCheckUpdate => '自動檢查更新'; @@ -1574,6 +1583,9 @@ class SZhTw extends SZh { @override String get watchNotPaired => '沒有已配對的 Apple Watch'; + @override + String get webdavSettingEmpty => 'Webdav 設置項爲空'; + @override String get whenOpenApp => '當打開 App 時'; diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 01033bf75..fbe57621d 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -14,6 +14,7 @@ "attention": "Achtung", "authRequired": "Autorisierung erforderlich", "auto": "System folgen", + "autoBackupConflict": "Es kann nur eine automatische Sicherung gleichzeitig aktiviert werden.", "autoCheckUpdate": "Aktualisierung automatisch prüfen", "autoConnect": "Automatisch verbinden", "autoUpdateHomeWidget": "Home-Widget automatisch aktualisieren", @@ -246,6 +247,7 @@ "virtKeyHelpSFTP": "Aktuelles Verzeichnis in SFTP öffnen.", "waitConnection": "Bitte warte, bis die Verbindung hergestellt wurde.", "watchNotPaired": "Keine gekoppelte Apple Watch", + "webdavSettingEmpty": "Webdav-Einstellungen sind leer", "whenOpenApp": "Beim Öffnen der App", "willTakEeffectImmediately": "Wird sofort angewendet", "write": "Schreiben" diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 5e10a1e1f..619bed870 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -14,6 +14,7 @@ "attention": "Attention", "authRequired": "Auth required", "auto": "Auto", + "autoBackupConflict": "Only one automatic backup can be turned on at the same time.", "autoCheckUpdate": "Auto check update", "autoConnect": "Auto connect", "autoUpdateHomeWidget": "Auto update home widget", @@ -246,6 +247,7 @@ "virtKeyHelpSFTP": "Open current directory in SFTP.", "waitConnection": "Please wait for the connection to be established.", "watchNotPaired": "No paired Apple Watch", + "webdavSettingEmpty": "Webdav setting is empty", "whenOpenApp": "When opening the app", "willTakEeffectImmediately": "Will take effect immediately", "write": "Write" diff --git a/lib/l10n/app_id.arb b/lib/l10n/app_id.arb index 249ae33e2..faaa1f16e 100644 --- a/lib/l10n/app_id.arb +++ b/lib/l10n/app_id.arb @@ -14,6 +14,7 @@ "attention": "Perhatian", "authRequired": "Auth diperlukan", "auto": "Auto", + "autoBackupConflict": "Hanya satu pencadangan otomatis yang dapat diaktifkan pada saat yang bersamaan.", "autoCheckUpdate": "Periksa pembaruan otomatis", "autoConnect": "Hubungkan otomatis", "autoUpdateHomeWidget": "Widget Rumah Pembaruan Otomatis", @@ -246,6 +247,7 @@ "virtKeyHelpSFTP": "Buka direktori saat ini di SFTP.", "waitConnection": "Harap tunggu koneksi akan dibuat.", "watchNotPaired": "Tidak ada Apple Watch yang dipasangkan", + "webdavSettingEmpty": "Pengaturan webdav kosong", "whenOpenApp": "Saat membuka aplikasi", "willTakEeffectImmediately": "Akan segera berlaku", "write": "Tulis" diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index e053b6fdd..ec0b95a2e 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -14,6 +14,7 @@ "attention": "注意", "authRequired": "需要认证", "auto": "自动", + "autoBackupConflict": "只能同时开启一个自动备份", "autoCheckUpdate": "自动检查更新", "autoConnect": "自动连接", "autoUpdateHomeWidget": "自动更新桌面小部件", @@ -246,6 +247,7 @@ "virtKeyHelpSFTP": "在 SFTP 中打开当前路径。", "waitConnection": "请等待连接建立", "watchNotPaired": "没有已配对的 Apple Watch", + "webdavSettingEmpty": "Webdav 设置项为空", "whenOpenApp": "当打开 App 时", "willTakEeffectImmediately": "更改将会立即生效", "write": "写" diff --git a/lib/l10n/app_zh_tw.arb b/lib/l10n/app_zh_tw.arb index b9c348fc8..ff95fe205 100644 --- a/lib/l10n/app_zh_tw.arb +++ b/lib/l10n/app_zh_tw.arb @@ -14,6 +14,7 @@ "attention": "注意", "authRequired": "需要認證", "auto": "自動", + "autoBackupConflict": "只能同時開啓壹個自動備份", "autoCheckUpdate": "自動檢查更新", "autoConnect": "自動連接", "autoUpdateHomeWidget": "自動更新桌面小部件", @@ -246,6 +247,7 @@ "virtKeyHelpSFTP": "在 SFTP 中打開當前路徑。", "waitConnection": "請等待連接建立", "watchNotPaired": "沒有已配對的 Apple Watch", + "webdavSettingEmpty": "Webdav 設置項爲空", "whenOpenApp": "當打開 App 時", "willTakEeffectImmediately": "更改將會立即生效", "write": "写" diff --git a/lib/view/page/backup.dart b/lib/view/page/backup.dart index 5bbbf36cc..ced7cb195 100644 --- a/lib/view/page/backup.dart +++ b/lib/view/page/backup.dart @@ -150,7 +150,14 @@ class BackupPage extends StatelessWidget { title: Text(l10n.auto), trailing: StoreSwitch( prop: Stores.setting.icloudSync, - func: (val) async { + validator: (p0) { + if (p0 && Stores.setting.webdavSync.fetch()) { + context.showSnackBar(l10n.autoBackupConflict); + return false; + } + return true; + }, + callback: (val) async { if (val) { icloudLoading.value = true; await ICloud.sync(); @@ -273,24 +280,20 @@ class BackupPage extends StatelessWidget { }, child: Text(l10n.ok), ), - TextButton( - onPressed: () async { - final result = await Webdav.test( - urlCtrl.text, - userCtrl.text, - pwdCtrl.text, - ); - if (result == null) { - context.showSnackBar(l10n.success); - } else { - context.showSnackBar(result); - } - }, - child: Text(l10n.test), - ), ], ); if (result == true) { + final result = await Webdav.test( + urlCtrl.text, + userCtrl.text, + pwdCtrl.text, + ); + if (result == null) { + context.showSnackBar(l10n.success); + } else { + context.showSnackBar(result); + return; + } Webdav.changeClient( urlCtrl.text, userCtrl.text, @@ -306,7 +309,22 @@ class BackupPage extends StatelessWidget { title: Text(l10n.auto), trailing: StoreSwitch( prop: Stores.setting.webdavSync, - func: (val) async { + validator: (p0) { + if (p0) { + if (Stores.setting.webdavUrl.fetch().isEmpty || + Stores.setting.webdavUser.fetch().isEmpty || + Stores.setting.webdavPwd.fetch().isEmpty) { + context.showSnackBar(l10n.webdavSettingEmpty); + return false; + } + } + if (Stores.setting.icloudSync.fetch()) { + context.showSnackBar(l10n.autoBackupConflict); + return false; + } + return true; + }, + callback: (val) async { if (val) { webdavLoading.value = true; await Webdav.sync(); diff --git a/lib/view/page/setting/entry.dart b/lib/view/page/setting/entry.dart index 9c53931fd..42b3e164f 100644 --- a/lib/view/page/setting/entry.dart +++ b/lib/view/page/setting/entry.dart @@ -339,7 +339,7 @@ class _SettingPageState extends State { title: Text(l10n.followSystem), trailing: StoreSwitch( prop: _setting.useSystemPrimaryColor, - func: (_) => setState(() {}), + callback: (_) => setState(() {}), ), ) ]; @@ -747,7 +747,7 @@ class _SettingPageState extends State { title: Text(l10n.fullScreen), trailing: StoreSwitch( prop: _setting.fullScreen, - func: (_) => RebuildNodes.app.rebuild(), + callback: (_) => RebuildNodes.app.rebuild(), ), ); } diff --git a/lib/view/page/setting/platform_pub.dart b/lib/view/page/setting/platform_pub.dart index 906702fc4..109a0979e 100644 --- a/lib/view/page/setting/platform_pub.dart +++ b/lib/view/page/setting/platform_pub.dart @@ -30,7 +30,7 @@ class PlatformPublicSettings { trailing: can == true ? StoreSwitch( prop: Stores.setting.useBioAuth, - func: (val) async { + callback: (val) async { if (val) { Stores.setting.useBioAuth.put(false); return; diff --git a/lib/view/widget/store_switch.dart b/lib/view/widget/store_switch.dart index 0f9f3a607..39b0ef8ba 100644 --- a/lib/view/widget/store_switch.dart +++ b/lib/view/widget/store_switch.dart @@ -4,9 +4,19 @@ import '../../core/persistant_store.dart'; class StoreSwitch extends StatelessWidget { final StorePropertyBase prop; - final void Function(bool)? func; - const StoreSwitch({super.key, required this.prop, this.func}); + /// Exec before make change, after validator. + final void Function(bool)? callback; + + /// If return false, the switch will not change. + final bool Function(bool)? validator; + + const StoreSwitch({ + super.key, + required this.prop, + this.callback, + this.validator, + }); @override Widget build(BuildContext context) { @@ -16,7 +26,8 @@ class StoreSwitch extends StatelessWidget { return Switch( value: value, onChanged: (value) { - func?.call(value); + if (validator != null && validator?.call(value) != true) return; + callback?.call(value); prop.put(value); }, );