Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Add ReadMeABook integration in admin and settings

Barnabasc024915e6e7b
diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb
index f9efdb1f..36dcd641 100644
--- a/lib/l10n/app_en.arb
+++ b/lib/l10n/app_en.arb
@@ -555,6 +555,21 @@
"adminBackupCreated": "Backup created",
"adminBackupFailed": "Backup failed",
"adminCachePurged": "Cache purged",
+ "adminRmab": "ReadMeABook",
+ "adminRmabSubtitle": "Open in app",
+ "adminRmabAdd": "Add ReadMeABook integration",
+ "adminRmabUrlTitle": "ReadMeABook URL",
+ "adminRmabUrlHelp": "Paste your URL with login token. Generate one in RMAB, Admin, Users.",
+ "adminRmabUrlHint": "https://rmab.example.com/?token=...",
+ "adminRmabInvalidUrl": "Enter a valid http(s) URL",
+ "adminRmabSaved": "ReadMeABook saved",
+ "adminRmabRemoved": "ReadMeABook removed",
+ "adminRmabReload": "Reload",
+ "adminRmabLoadFailed": "Couldn't load ReadMeABook. Check your URL.",
+ "adminRmabConnected": "Connected",
+ "adminRmabAskAdmin": "Get a login URL from your server admin",
+ "adminRmabUrlHelpUser": "Get a login URL from your server admin. They generate one in RMAB > Admin > Users.",
+ "adminRmabSettingsInfo": "ReadMeABook is a self-hosted service for requesting and downloading audiobooks. It must be installed and set up by your server admin.",
"narratedBy": "Narrated by {narrator}",
"@narratedBy": { "placeholders": { "narrator": { "type": "String" } } },
@@ -718,6 +733,7 @@
"surround": "Surround",
"loudness": "Loudness",
"monoAudio": "Mono Audio",
+ "skipSilence": "Skip Silence",
"resetAll": "Reset All",
"collectionNotFound": "Collection not found",
diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart
index a232cce5..e8e5da97 100644
--- a/lib/l10n/app_localizations.dart
+++ b/lib/l10n/app_localizations.dart
@@ -2996,6 +2996,96 @@ abstract class AppLocalizations {
/// **'Cache purged'**
String get adminCachePurged;
+ /// No description provided for @adminRmab.
+ ///
+ /// In en, this message translates to:
+ /// **'ReadMeABook'**
+ String get adminRmab;
+
+ /// No description provided for @adminRmabSubtitle.
+ ///
+ /// In en, this message translates to:
+ /// **'Open in app'**
+ String get adminRmabSubtitle;
+
+ /// No description provided for @adminRmabAdd.
+ ///
+ /// In en, this message translates to:
+ /// **'Add ReadMeABook integration'**
+ String get adminRmabAdd;
+
+ /// No description provided for @adminRmabUrlTitle.
+ ///
+ /// In en, this message translates to:
+ /// **'ReadMeABook URL'**
+ String get adminRmabUrlTitle;
+
+ /// No description provided for @adminRmabUrlHelp.
+ ///
+ /// In en, this message translates to:
+ /// **'Paste your URL with login token. Generate one in RMAB, Admin, Users.'**
+ String get adminRmabUrlHelp;
+
+ /// No description provided for @adminRmabUrlHint.
+ ///
+ /// In en, this message translates to:
+ /// **'https://rmab.example.com/?token=...'**
+ String get adminRmabUrlHint;
+
+ /// No description provided for @adminRmabInvalidUrl.
+ ///
+ /// In en, this message translates to:
+ /// **'Enter a valid http(s) URL'**
+ String get adminRmabInvalidUrl;
+
+ /// No description provided for @adminRmabSaved.
+ ///
+ /// In en, this message translates to:
+ /// **'ReadMeABook saved'**
+ String get adminRmabSaved;
+
+ /// No description provided for @adminRmabRemoved.
+ ///
+ /// In en, this message translates to:
+ /// **'ReadMeABook removed'**
+ String get adminRmabRemoved;
+
+ /// No description provided for @adminRmabReload.
+ ///
+ /// In en, this message translates to:
+ /// **'Reload'**
+ String get adminRmabReload;
+
+ /// No description provided for @adminRmabLoadFailed.
+ ///
+ /// In en, this message translates to:
+ /// **'Couldn\'t load ReadMeABook. Check your URL.'**
+ String get adminRmabLoadFailed;
+
+ /// No description provided for @adminRmabConnected.
+ ///
+ /// In en, this message translates to:
+ /// **'Connected'**
+ String get adminRmabConnected;
+
+ /// No description provided for @adminRmabAskAdmin.
+ ///
+ /// In en, this message translates to:
+ /// **'Get a login URL from your server admin'**
+ String get adminRmabAskAdmin;
+
+ /// No description provided for @adminRmabUrlHelpUser.
+ ///
+ /// In en, this message translates to:
+ /// **'Get a login URL from your server admin. They generate one in RMAB > Admin > Users.'**
+ String get adminRmabUrlHelpUser;
+
+ /// No description provided for @adminRmabSettingsInfo.
+ ///
+ /// In en, this message translates to:
+ /// **'ReadMeABook is a self-hosted service for requesting and downloading audiobooks. It must be installed and set up by your server admin.'**
+ String get adminRmabSettingsInfo;
+
/// No description provided for @narratedBy.
///
/// In en, this message translates to:
@@ -3854,6 +3944,12 @@ abstract class AppLocalizations {
/// **'Mono Audio'**
String get monoAudio;
+ /// No description provided for @skipSilence.
+ ///
+ /// In en, this message translates to:
+ /// **'Skip Silence'**
+ String get skipSilence;
+
/// No description provided for @resetAll.
///
/// In en, this message translates to:
diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart
index e36c1a99..5f2ef354 100644
--- a/lib/l10n/app_localizations_en.dart
+++ b/lib/l10n/app_localizations_en.dart
@@ -1619,6 +1619,55 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get adminCachePurged => 'Cache purged';
+ @override
+ String get adminRmab => 'ReadMeABook';
+
+ @override
+ String get adminRmabSubtitle => 'Open in app';
+
+ @override
+ String get adminRmabAdd => 'Add ReadMeABook integration';
+
+ @override
+ String get adminRmabUrlTitle => 'ReadMeABook URL';
+
+ @override
+ String get adminRmabUrlHelp =>
+ 'Paste your URL with login token. Generate one in RMAB, Admin, Users.';
+
+ @override
+ String get adminRmabUrlHint => 'https://rmab.example.com/?token=...';
+
+ @override
+ String get adminRmabInvalidUrl => 'Enter a valid http(s) URL';
+
+ @override
+ String get adminRmabSaved => 'ReadMeABook saved';
+
+ @override
+ String get adminRmabRemoved => 'ReadMeABook removed';
+
+ @override
+ String get adminRmabReload => 'Reload';
+
+ @override
+ String get adminRmabLoadFailed =>
+ 'Couldn\'t load ReadMeABook. Check your URL.';
+
+ @override
+ String get adminRmabConnected => 'Connected';
+
+ @override
+ String get adminRmabAskAdmin => 'Get a login URL from your server admin';
+
+ @override
+ String get adminRmabUrlHelpUser =>
+ 'Get a login URL from your server admin. They generate one in RMAB > Admin > Users.';
+
+ @override
+ String get adminRmabSettingsInfo =>
+ 'ReadMeABook is a self-hosted service for requesting and downloading audiobooks. It must be installed and set up by your server admin.';
+
@override
String narratedBy(String narrator) {
return 'Narrated by $narrator';
@@ -2082,6 +2131,9 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get monoAudio => 'Mono Audio';
+ @override
+ String get skipSilence => 'Skip Silence';
+
@override
String get resetAll => 'Reset All';
diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart
index 4b912bec..97d56ff1 100644
--- a/lib/l10n/app_localizations_zh.dart
+++ b/lib/l10n/app_localizations_zh.dart
@@ -1560,6 +1560,53 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get adminCachePurged => '缓存已清除';
+ @override
+ String get adminRmab => 'ReadMeABook';
+
+ @override
+ String get adminRmabSubtitle => '在应用中打开';
+
+ @override
+ String get adminRmabAdd => '添加 ReadMeABook 集成';
+
+ @override
+ String get adminRmabUrlTitle => 'ReadMeABook URL';
+
+ @override
+ String get adminRmabUrlHelp => '粘贴包含登录令牌的 URL。在 RMAB 的管理 -> 用户中生成。';
+
+ @override
+ String get adminRmabUrlHint => 'https://rmab.example.com/?token=...';
+
+ @override
+ String get adminRmabInvalidUrl => '请输入有效的 http(s) URL';
+
+ @override
+ String get adminRmabSaved => '已保存 ReadMeABook';
+
+ @override
+ String get adminRmabRemoved => '已移除 ReadMeABook';
+
+ @override
+ String get adminRmabReload => '重新加载';
+
+ @override
+ String get adminRmabLoadFailed => '无法加载 ReadMeABook,请检查 URL。';
+
+ @override
+ String get adminRmabConnected => '已连接';
+
+ @override
+ String get adminRmabAskAdmin => '请向您的服务器管理员获取登录 URL';
+
+ @override
+ String get adminRmabUrlHelpUser =>
+ '请向您的服务器管理员获取登录 URL,管理员可在 RMAB 的管理 -> 用户中生成。';
+
+ @override
+ String get adminRmabSettingsInfo =>
+ 'ReadMeABook 是一个用于请求和下载有声书的自托管服务,需要由您的服务器管理员安装和设置。';
+
@override
String narratedBy(String narrator) {
return '朗读者: $narrator';
@@ -2013,6 +2060,9 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get monoAudio => '单声道音频';
+ @override
+ String get skipSilence => 'Skip Silence';
+
@override
String get resetAll => '全部重置';
diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb
index 93524cc5..a5502240 100644
--- a/lib/l10n/app_zh.arb
+++ b/lib/l10n/app_zh.arb
@@ -555,6 +555,21 @@
"adminBackupCreated": "备份已创建",
"adminBackupFailed": "备份失败",
"adminCachePurged": "缓存已清除",
+ "adminRmab": "ReadMeABook",
+ "adminRmabSubtitle": "在应用中打开",
+ "adminRmabAdd": "添加 ReadMeABook 集成",
+ "adminRmabUrlTitle": "ReadMeABook URL",
+ "adminRmabUrlHelp": "粘贴包含登录令牌的 URL。在 RMAB 的管理 -> 用户中生成。",
+ "adminRmabUrlHint": "https://rmab.example.com/?token=...",
+ "adminRmabInvalidUrl": "请输入有效的 http(s) URL",
+ "adminRmabSaved": "已保存 ReadMeABook",
+ "adminRmabRemoved": "已移除 ReadMeABook",
+ "adminRmabReload": "重新加载",
+ "adminRmabLoadFailed": "无法加载 ReadMeABook,请检查 URL。",
+ "adminRmabConnected": "已连接",
+ "adminRmabAskAdmin": "请向您的服务器管理员获取登录 URL",
+ "adminRmabUrlHelpUser": "请向您的服务器管理员获取登录 URL,管理员可在 RMAB 的管理 -> 用户中生成。",
+ "adminRmabSettingsInfo": "ReadMeABook 是一个用于请求和下载有声书的自托管服务,需要由您的服务器管理员安装和设置。",
"narratedBy": "朗读者: {narrator}",
"@narratedBy": { "placeholders": { "narrator": { "type": "String" } } },
@@ -718,6 +733,7 @@
"surround": "环绕声",
"loudness": "响度",
"monoAudio": "单声道音频",
+ "skipSilence": "Skip Silence",
"resetAll": "全部重置",
"collectionNotFound": "未找到收藏集",
diff --git a/lib/screens/admin_rmab_screen.dart b/lib/screens/admin_rmab_screen.dart
new file mode 100644
index 00000000..6f59686e
--- /dev/null
+++ b/lib/screens/admin_rmab_screen.dart
@@ -0,0 +1,97 @@
+import 'package:flutter/material.dart';
+import 'package:webview_flutter/webview_flutter.dart';
+import '../l10n/app_localizations.dart';
+
+class AdminRmabScreen extends StatefulWidget {
+ final String url;
+ const AdminRmabScreen({super.key, required this.url});
+
+ @override
+ State<AdminRmabScreen> createState() => _AdminRmabScreenState();
+}
+
+class _AdminRmabScreenState extends State<AdminRmabScreen> {
+ late final WebViewController _controller;
+ int _progress = 0;
+ bool _failed = false;
+
+ @override
+ void initState() {
+ super.initState();
+ _controller = WebViewController()
+ ..setJavaScriptMode(JavaScriptMode.unrestricted)
+ ..setBackgroundColor(Theme.of(context).colorScheme.surface)
+ ..setNavigationDelegate(NavigationDelegate(
+ onProgress: (p) => mounted ? setState(() => _progress = p) : null,
+ onPageStarted: (_) => mounted ? setState(() => _failed = false) : null,
+ onWebResourceError: (e) {
+ if (e.isForMainFrame == true && mounted) {
+ setState(() => _failed = true);
+ }
+ },
+ ))
+ ..loadRequest(Uri.parse(widget.url));
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final cs = Theme.of(context).colorScheme;
+ final l = AppLocalizations.of(context)!;
+
+ return Scaffold(
+ backgroundColor: cs.surface,
+ appBar: AppBar(
+ backgroundColor: cs.surface,
+ title: Text(l.adminRmab),
+ leading: IconButton(
+ icon: const Icon(Icons.close_rounded),
+ onPressed: () => Navigator.pop(context),
+ ),
+ actions: [
+ IconButton(
+ icon: const Icon(Icons.refresh_rounded),
+ tooltip: l.adminRmabReload,
+ onPressed: () => _controller.reload(),
+ ),
+ ],
+ bottom: _progress > 0 && _progress < 100
+ ? PreferredSize(
+ preferredSize: const Size.fromHeight(2),
+ child: LinearProgressIndicator(
+ value: _progress / 100,
+ minHeight: 2,
+ backgroundColor: Colors.transparent,
+ valueColor: AlwaysStoppedAnimation(cs.primary),
+ ),
+ )
+ : null,
+ ),
+ body: _failed
+ ? Center(
+ child: Padding(
+ padding: const EdgeInsets.all(24),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(Icons.error_outline_rounded,
+ size: 40, color: cs.onSurfaceVariant),
+ const SizedBox(height: 12),
+ Text(l.adminRmabLoadFailed,
+ textAlign: TextAlign.center,
+ style: Theme.of(context).textTheme.bodyMedium),
+ const SizedBox(height: 16),
+ TextButton(
+ onPressed: () {
+ setState(() => _failed = false);
+ _controller.reload();
+ },
+ child: Text(l.adminRmabReload),
+ ),
+ ],
+ ),
+ ),
+ )
+ : WebViewWidget(controller: _controller),
+ );
+ }
+}
diff --git a/lib/screens/admin_screen.dart b/lib/screens/admin_screen.dart
index 516ed56a..492af5ff 100644
--- a/lib/screens/admin_screen.dart
+++ b/lib/screens/admin_screen.dart
@@ -1,10 +1,14 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/auth_provider.dart';
+import '../services/scoped_prefs.dart';
import '../widgets/absorb_page_header.dart';
import '../l10n/app_localizations.dart';
import 'admin_users_screen.dart';
import 'admin_podcasts_screen.dart';
+import 'admin_rmab_screen.dart';
+
+const _kRmabUrlKey = 'rmab_url';
class AdminScreen extends StatefulWidget {
const AdminScreen({super.key});
@@ -20,6 +24,7 @@ class _AdminScreenState extends State<AdminScreen> {
List<dynamic> _sessions = [];
final Map<String, Map<String, dynamic>> _libraryStats = {};
String? _serverVersion;
+ String? _rmabUrl;
final Set<String> _scanningLibraries = {};
final Set<String> _matchingLibraries = {};
@@ -51,9 +56,12 @@ class _AdminScreenState extends State<AdminScreen> {
if (stats != null) _libraryStats[id] = stats;
}
}
+ _rmabUrl = await ScopedPrefs.getString(_kRmabUrlKey);
if (mounted) setState(() => _loading = false);
}
+ bool get _hasRmab => (_rmabUrl ?? '').isNotEmpty;
+
bool get _hasPodcastLibrary => _libraries.any((l) => l['mediaType'] == 'podcast');
List<dynamic> get _activeSessions => _sessions.where((s) {
@@ -143,6 +151,8 @@ class _AdminScreenState extends State<AdminScreen> {
}
},
),
+ if (_hasPodcastLibrary) const SizedBox(height: 10),
+ if (_hasRmab) _rmabTile(cs, tt) else _rmabAddRow(cs, tt),
]),
),
const SizedBox(height: 28),
@@ -202,6 +212,119 @@ class _AdminScreenState extends State<AdminScreen> {
Icon(Icons.chevron_right_rounded, color: cs.onSurface.withValues(alpha: 0.15)),
])));
+ // ─── ReadMeABook Integration ────────────────────────────────
+
+ Widget _rmabTile(ColorScheme cs, TextTheme tt) {
+ final l = AppLocalizations.of(context)!;
+ return GestureDetector(
+ onTap: () => Navigator.push(context, MaterialPageRoute(
+ builder: (_) => AdminRmabScreen(url: _rmabUrl!))),
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
+ decoration: _cardDeco(cs),
+ child: Row(children: [
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 6),
+ child: Icon(Icons.menu_book_rounded, color: cs.primary, size: 22),
+ ),
+ const SizedBox(width: 14),
+ Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(l.adminRmab, style: tt.titleSmall?.copyWith(fontWeight: FontWeight.w600, color: cs.onSurface)),
+ Text(l.adminRmabSubtitle, style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant.withValues(alpha: 0.6))),
+ ])),
+ PopupMenuButton<String>(
+ icon: Icon(Icons.more_vert_rounded, color: cs.onSurface.withValues(alpha: 0.4), size: 20),
+ tooltip: '',
+ onSelected: (v) {
+ if (v == 'edit') _showRmabUrlDialog();
+ if (v == 'remove') _clearRmab();
+ },
+ itemBuilder: (_) => [
+ PopupMenuItem(value: 'edit', child: Text(l.edit)),
+ PopupMenuItem(value: 'remove', child: Text(l.remove)),
+ ],
+ ),
+ ]),
+ ),
+ );
+ }
+
+ Widget _rmabAddRow(ColorScheme cs, TextTheme tt) {
+ final l = AppLocalizations.of(context)!;
+ return Align(
+ alignment: Alignment.centerLeft,
+ child: TextButton.icon(
+ onPressed: _showRmabUrlDialog,
+ style: TextButton.styleFrom(
+ foregroundColor: cs.onSurfaceVariant.withValues(alpha: 0.6),
+ padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 0),
+ minimumSize: const Size(0, 32),
+ tapTargetSize: MaterialTapTargetSize.shrinkWrap,
+ ),
+ icon: const Icon(Icons.add_rounded, size: 16),
+ label: Text(l.adminRmabAdd, style: tt.labelMedium),
+ ),
+ );
+ }
+
+ Future<void> _showRmabUrlDialog() async {
+ final l = AppLocalizations.of(context)!;
+ final controller = TextEditingController(text: _rmabUrl ?? '');
+ String? err;
+
+ final saved = await showDialog<String?>(
+ context: context,
+ builder: (ctx) => StatefulBuilder(builder: (ctx, setLocal) => AlertDialog(
+ title: Text(l.adminRmabUrlTitle),
+ content: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(l.adminRmabUrlHelp, style: Theme.of(ctx).textTheme.bodySmall),
+ const SizedBox(height: 12),
+ TextField(
+ controller: controller,
+ autofocus: true,
+ keyboardType: TextInputType.url,
+ autocorrect: false,
+ decoration: InputDecoration(
+ hintText: l.adminRmabUrlHint,
+ errorText: err,
+ border: const OutlineInputBorder(),
+ ),
+ ),
+ ]),
+ actions: [
+ TextButton(onPressed: () => Navigator.pop(ctx, null), child: Text(l.cancel)),
+ TextButton(
+ onPressed: () {
+ final v = controller.text.trim();
+ if (v.isEmpty) { setLocal(() => err = l.adminRmabInvalidUrl); return; }
+ final u = Uri.tryParse(v);
+ if (u == null || !(u.scheme == 'http' || u.scheme == 'https') || u.host.isEmpty) {
+ setLocal(() => err = l.adminRmabInvalidUrl);
+ return;
+ }
+ Navigator.pop(ctx, v);
+ },
+ child: Text(l.save),
+ ),
+ ],
+ )),
+ );
+
+ if (saved == null) return;
+ await ScopedPrefs.setString(_kRmabUrlKey, saved);
+ if (!mounted) return;
+ setState(() => _rmabUrl = saved);
+ _msg(l.adminRmabSaved);
+ }
+
+ Future<void> _clearRmab() async {
+ final l = AppLocalizations.of(context)!;
+ await ScopedPrefs.remove(_kRmabUrlKey);
+ if (!mounted) return;
+ setState(() => _rmabUrl = null);
+ _msg(l.adminRmabRemoved);
+ }
+
// ─── Library Card ───────────────────────────────────────────
Widget _libraryCard(ColorScheme cs, TextTheme tt, dynamic lib) {
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index 81cdba47..157d369d 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -16,10 +16,12 @@ import '../services/sleep_timer_service.dart';
import '../services/user_account_service.dart';
import '../services/backup_service.dart';
import '../services/log_service.dart';
+import '../services/scoped_prefs.dart';
import '../screens/login_screen.dart';
import '../screens/app_shell.dart';
import '../services/update_checker_service.dart';
import '../screens/admin_screen.dart';
+import '../screens/admin_rmab_screen.dart';
import '../screens/downloads_screen.dart';
import '../screens/bookmarks_screen.dart';
import '../main.dart' show applyThemeMode, applyTrustAllCerts, oledNotifier, snappyTransitionsNotifier;
@@ -92,6 +94,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
late final TextEditingController _localServerController;
bool _trustAllCerts = false;
bool _includePreReleases = false;
+ String? _rmabUrl;
bool _loaded = false;
String _downloadLocationLabel = 'App Internal Storage (Default)';
bool _canPickDownloadLocation = false;
@@ -247,7 +250,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
final chime = results[43] as bool;
final chimeVol = results[44] as double;
final shakeSens = results[45] as String;
+ final rmabUrl = await ScopedPrefs.getString('rmab_url');
if (mounted) setState(() {
+ _rmabUrl = rmabUrl;
_rewindSettings = s;
_defaultSpeed = speed;
_wifiOnlyDownloads = wifiOnly;
@@ -1990,6 +1995,38 @@ class _SettingsScreenState extends State<SettingsScreen> {
} : null,
),
],
+ const Divider(height: 1, indent: 16, endIndent: 16),
+ ListTile(
+ leading: Icon(Icons.menu_book_rounded, color: cs.primary),
+ title: Row(children: [
+ Flexible(child: Text(l.adminRmab)),
+ _infoIcon(l.adminRmab, l.adminRmabSettingsInfo),
+ ]),
+ subtitle: Text(
+ (_rmabUrl ?? '').isNotEmpty ? l.adminRmabConnected : l.adminRmabAskAdmin,
+ style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant)),
+ trailing: (_rmabUrl ?? '').isNotEmpty
+ ? PopupMenuButton<String>(
+ icon: Icon(Icons.more_vert_rounded, color: cs.onSurfaceVariant),
+ onSelected: (v) {
+ if (v == 'edit') _showRmabSettingsDialog();
+ if (v == 'remove') _clearRmabSettings();
+ },
+ itemBuilder: (_) => [
+ PopupMenuItem(value: 'edit', child: Text(l.edit)),
+ PopupMenuItem(value: 'remove', child: Text(l.remove)),
+ ],
+ )
+ : Icon(Icons.chevron_right_rounded, color: cs.onSurfaceVariant.withValues(alpha: 0.5)),
+ onTap: () {
+ if ((_rmabUrl ?? '').isNotEmpty) {
+ Navigator.push(context, MaterialPageRoute(
+ builder: (_) => AdminRmabScreen(url: _rmabUrl!)));
+ } else {
+ _showRmabSettingsDialog();
+ }
+ },
+ ),
],
),
const SizedBox(height: 16),
@@ -2778,6 +2815,72 @@ class _SettingsScreenState extends State<SettingsScreen> {
}
}
+ Future<void> _showRmabSettingsDialog() async {
+ final l = AppLocalizations.of(context)!;
+ final controller = TextEditingController(text: _rmabUrl ?? '');
+ String? err;
+
+ final saved = await showDialog<String?>(
+ context: context,
+ builder: (ctx) => StatefulBuilder(builder: (ctx, setLocal) => AlertDialog(
+ title: Text(l.adminRmabUrlTitle),
+ content: Column(mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [
+ Text(l.adminRmabUrlHelpUser, style: Theme.of(ctx).textTheme.bodySmall),
+ const SizedBox(height: 12),
+ TextField(
+ controller: controller,
+ autofocus: true,
+ keyboardType: TextInputType.url,
+ autocorrect: false,
+ decoration: InputDecoration(
+ hintText: l.adminRmabUrlHint,
+ errorText: err,
+ border: const OutlineInputBorder(),
+ ),
+ ),
+ ]),
+ actions: [
+ TextButton(onPressed: () => Navigator.pop(ctx, null), child: Text(l.cancel)),
+ TextButton(
+ onPressed: () {
+ final v = controller.text.trim();
+ if (v.isEmpty) { setLocal(() => err = l.adminRmabInvalidUrl); return; }
+ final u = Uri.tryParse(v);
+ if (u == null || !(u.scheme == 'http' || u.scheme == 'https') || u.host.isEmpty) {
+ setLocal(() => err = l.adminRmabInvalidUrl);
+ return;
+ }
+ Navigator.pop(ctx, v);
+ },
+ child: Text(l.save),
+ ),
+ ],
+ )),
+ );
+
+ if (saved == null) return;
+ await ScopedPrefs.setString('rmab_url', saved);
+ if (!mounted) return;
+ setState(() => _rmabUrl = saved);
+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(
+ content: Text(l.adminRmabSaved),
+ behavior: SnackBarBehavior.floating,
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
+ ));
+ }
+
+ Future<void> _clearRmabSettings() async {
+ final l = AppLocalizations.of(context)!;
+ await ScopedPrefs.remove('rmab_url');
+ if (!mounted) return;
+ setState(() => _rmabUrl = null);
+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(
+ content: Text(l.adminRmabRemoved),
+ behavior: SnackBarBehavior.floating,
+ shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
+ ));
+ }
+
void _confirmLogout(BuildContext context) {
final cs = Theme.of(context).colorScheme;
final l = AppLocalizations.of(context)!;