Skip to content

A cross platform Audiobookshelf client for Android and iOS

Dart

Fix custom download location permissions, add Audible reviews WebView

Nathan Poulsonde178b8822ca
diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro
index bef5cc96..9777f2f5 100644
--- a/android/app/proguard-rules.pro
+++ b/android/app/proguard-rules.pro
@@ -18,7 +18,8 @@
# flutter_local_notifications + Gson generic signatures
-keep class com.dexterous.flutterlocalnotifications.** { *; }
--keep class * extends com.google.gson.reflect.TypeToken
+-keep class com.google.gson.reflect.TypeToken { *; }
+-keep class * extends com.google.gson.reflect.TypeToken { *; }
# Prevent stripping of native methods
-keepclasseswithmembernames class * {
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 74914155..b8781c56 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -13,6 +13,9 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="29"/>
+ <!-- Full file access for custom download locations (Android 11+) -->
+ <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
+
<!-- Block permissions pulled in by dependencies -->
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" tools:node="remove"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" tools:node="remove"/>
diff --git a/lib/screens/settings_screen.dart b/lib/screens/settings_screen.dart
index 6ddfeeac..8b8b6589 100644
--- a/lib/screens/settings_screen.dart
+++ b/lib/screens/settings_screen.dart
@@ -1883,11 +1883,16 @@ class _SettingsScreenState extends State<SettingsScreen> {
label: const Text('Choose folder'),
onPressed: () async {
Navigator.pop(ctx);
- // Request storage permission (needed on Android 9 and below).
- // On Android 10+, this permission is deprecated - we skip blocking
- // and let the write test below catch any actual access issues.
if (Platform.isAndroid) {
- final status = await Permission.storage.status;
+ // Android 11+ needs MANAGE_EXTERNAL_STORAGE for custom paths.
+ // Android 9-10 use WRITE_EXTERNAL_STORAGE.
+ // If manageExternalStorage is restricted, the OS doesn't
+ // support it (Android 10 or below) so fall back to storage.
+ final manageStatus = await Permission.manageExternalStorage.status;
+ final Permission perm = manageStatus == PermissionStatus.restricted
+ ? Permission.storage
+ : Permission.manageExternalStorage;
+ final status = await perm.status;
if (status.isPermanentlyDenied) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
@@ -1904,14 +1909,46 @@ class _SettingsScreenState extends State<SettingsScreen> {
return;
}
if (!status.isGranted) {
- await Permission.storage.request();
- // Don't block - proceed regardless
+ final result = await perm.request();
+ if (!result.isGranted) {
+ if (mounted) {
+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(
+ content: const Text('Storage permission is required for custom download locations'),
+ behavior: SnackBarBehavior.floating,
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(12)),
+ ));
+ }
+ return;
+ }
}
}
final result = await FilePicker.platform.getDirectoryPath(
dialogTitle: 'Choose download folder',
);
if (result != null) {
+ // Write test - verify we can actually create files here
+ try {
+ final testDir = Directory(result);
+ if (!testDir.existsSync()) testDir.createSync(recursive: true);
+ final testFile = File('${testDir.path}/.absorb_write_test');
+ testFile.writeAsStringSync('test');
+ testFile.deleteSync();
+ } catch (e) {
+ if (mounted) {
+ ScaffoldMessenger.of(context).showSnackBar(SnackBar(
+ content: Text('Cannot write to that folder - choose another location or grant file access in system settings'),
+ behavior: SnackBarBehavior.floating,
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(12)),
+ action: SnackBarAction(
+ label: 'Open Settings',
+ onPressed: openAppSettings,
+ ),
+ ));
+ }
+ return;
+ }
await dl.setCustomDownloadPath(result);
final label = await dl.downloadLocationLabel;
if (mounted) {
diff --git a/lib/services/api_service.dart b/lib/services/api_service.dart
index 6a76fa9c..2c35a402 100644
--- a/lib/services/api_service.dart
+++ b/lib/services/api_service.dart
@@ -902,7 +902,7 @@ class ApiService {
}
/// Fetch Audible rating from Audnexus API using ASIN.
- /// Returns { rating } or null.
+ /// Returns { rating, asin } or null.
static Future<Map<String, dynamic>?> getAudibleRating(String asin) async {
try {
final response = await http.get(
@@ -915,6 +915,7 @@ class ApiService {
if (rating != null) {
return {
'rating': double.tryParse(rating) ?? 0.0,
+ 'asin': asin,
};
}
}
diff --git a/lib/services/download_service.dart b/lib/services/download_service.dart
index ee1fc7f7..ad183109 100644
--- a/lib/services/download_service.dart
+++ b/lib/services/download_service.dart
@@ -787,7 +787,9 @@ class DownloadService extends ChangeNotifier {
final isStorageFull = e.toString().contains('No space left') ||
e.toString().contains('ENOSPC');
final isPermissionDenied = e.toString().contains('Permission denied') ||
- e.toString().contains('error = 13');
+ e.toString().contains('Operation not permitted') ||
+ e.toString().contains('error = 13') ||
+ e.toString().contains('errno = 1');
final errorMsg = isStorageFull
? 'Not enough storage space'
: isPermissionDenied
diff --git a/lib/widgets/book_detail_sheet.dart b/lib/widgets/book_detail_sheet.dart
index d82c8610..ecb90ce2 100644
--- a/lib/widgets/book_detail_sheet.dart
+++ b/lib/widgets/book_detail_sheet.dart
@@ -9,6 +9,7 @@ import 'package:path_provider/path_provider.dart';
import 'package:file_picker/file_picker.dart';
import 'package:http/http.dart' as http;
import 'package:url_launcher/url_launcher.dart';
+import 'package:webview_flutter/webview_flutter.dart';
import '../providers/auth_provider.dart';
import '../providers/library_provider.dart';
import '../services/audio_player_service.dart';
@@ -48,6 +49,7 @@ class _BookDetailSheetContent extends StatefulWidget {
class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {
Map<String, dynamic>? _item;
Map<String, dynamic>? _rating;
+ String? _asin;
bool _isLoading = true;
bool _chaptersExpanded = false;
bool _isAbsorbing = false;
@@ -106,7 +108,10 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {
}
}
if (rating != null && mounted) {
- setState(() => _rating = rating);
+ setState(() {
+ _rating = rating;
+ _asin = rating?['asin'] as String? ?? asin;
+ });
}
return;
}
@@ -225,19 +230,30 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {
Text('Narrated by $narrator', textAlign: TextAlign.center, style: tt.bodySmall?.copyWith(color: cs.onSurfaceVariant))],
// ─── AUDIBLE RATING (space always reserved) ─────────
const SizedBox(height: 8),
- SizedBox(
- height: 20,
- child: (_rating != null && (_rating!['rating'] as num).toDouble() > 0)
- ? Row(mainAxisAlignment: MainAxisAlignment.center, children: [
- ..._buildStars((_rating!['rating'] as num).toDouble(), cs),
- const SizedBox(width: 6),
- Text((_rating!['rating'] as num).toStringAsFixed(1),
- style: tt.labelLarge?.copyWith(fontWeight: FontWeight.w600, color: cs.onSurface.withValues(alpha: 0.7))),
- const SizedBox(width: 4),
- Text('on Audible', style: tt.labelSmall?.copyWith(color: cs.onSurfaceVariant)),
- ])
- : null,
- ),
+ if (_rating != null && (_rating!['rating'] as num).toDouble() > 0)
+ Center(
+ child: GestureDetector(
+ onTap: _asin != null ? () => _showAudibleReviews(context) : null,
+ child: Container(
+ padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
+ decoration: BoxDecoration(
+ color: cs.onSurface.withValues(alpha: 0.06),
+ borderRadius: BorderRadius.circular(20),
+ border: Border.all(color: cs.onSurface.withValues(alpha: 0.08)),
+ ),
+ child: Row(mainAxisSize: MainAxisSize.min, children: [
+ ..._buildStars((_rating!['rating'] as num).toDouble(), cs),
+ const SizedBox(width: 6),
+ Text((_rating!['rating'] as num).toStringAsFixed(1),
+ style: TextStyle(fontSize: 11, fontWeight: FontWeight.w600, color: cs.onSurfaceVariant)),
+ const SizedBox(width: 4),
+ Text('on Audible', style: TextStyle(fontSize: 11, color: cs.onSurfaceVariant)),
+ ]),
+ ),
+ ),
+ )
+ else
+ const SizedBox(height: 20),
const SizedBox(height: 12),
if (progress > 0 && !isFinished) ...[
ClipRRect(borderRadius: BorderRadius.circular(3),
@@ -559,6 +575,58 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {
return stars;
}
+ void _showAudibleReviews(BuildContext context) {
+ final asin = _asin;
+ if (asin == null) return;
+ final url = 'https://www.audible.com/pd/$asin#customer-reviews';
+ final cs = Theme.of(context).colorScheme;
+
+ final controller = WebViewController()
+ ..setJavaScriptMode(JavaScriptMode.unrestricted)
+ ..setBackgroundColor(cs.surface)
+ ..loadRequest(Uri.parse(url));
+
+ showModalBottomSheet(
+ context: context,
+ isScrollControlled: true,
+ useSafeArea: true,
+ backgroundColor: Colors.transparent,
+ enableDrag: false,
+ builder: (ctx) => FractionallySizedBox(
+ heightFactor: 0.92,
+ child: Container(
+ clipBehavior: Clip.hardEdge,
+ decoration: BoxDecoration(
+ color: cs.surface,
+ borderRadius: const BorderRadius.vertical(top: Radius.circular(20)),
+ ),
+ child: Column(children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(16, 8, 8, 0),
+ child: Row(children: [
+ const Spacer(),
+ Container(width: 32, height: 4,
+ decoration: BoxDecoration(
+ color: cs.onSurface.withValues(alpha: 0.24),
+ borderRadius: BorderRadius.circular(2))),
+ const Spacer(),
+ IconButton(
+ icon: Icon(Icons.close_rounded, color: cs.onSurfaceVariant),
+ onPressed: () => Navigator.pop(ctx),
+ ),
+ ]),
+ ),
+ Expanded(
+ child: SizedBox.expand(
+ child: WebViewWidget(controller: controller),
+ ),
+ ),
+ ]),
+ ),
+ ),
+ );
+ }
+
Future<void> _openSeries(BuildContext context, String? seriesId, String seriesName) async {
if (seriesId == null) return;
final auth = context.read<AuthProvider>();
@@ -937,3 +1005,4 @@ class _BookDetailSheetContentState extends State<_BookDetailSheetContent> {
}
}
}
+
diff --git a/pubspec.lock b/pubspec.lock
index 432ece08..66d7854e 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -1092,6 +1092,38 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.1"
+ webview_flutter:
+ dependency: "direct main"
+ description:
+ name: webview_flutter
+ sha256: a3da219916aba44947d3a5478b1927876a09781174b5a2b67fa5be0555154bf9
+ url: "https://pub.dev"
+ source: hosted
+ version: "4.13.1"
+ webview_flutter_android:
+ dependency: transitive
+ description:
+ name: webview_flutter_android
+ sha256: "2a03df01df2fd30b075d1e7f24c28aee593f2e5d5ac4c3c4283c5eda63717b24"
+ url: "https://pub.dev"
+ source: hosted
+ version: "4.10.13"
+ webview_flutter_platform_interface:
+ dependency: transitive
+ description:
+ name: webview_flutter_platform_interface
+ sha256: "63d26ee3aca7256a83ccb576a50272edd7cfc80573a4305caa98985feb493ee0"
+ url: "https://pub.dev"
+ source: hosted
+ version: "2.14.0"
+ webview_flutter_wkwebview:
+ dependency: transitive
+ description:
+ name: webview_flutter_wkwebview
+ sha256: "2df8fd9ada04d699b9db8e79aa783a16e5d89b69e5b74009b87e16b59912cf98"
+ url: "https://pub.dev"
+ source: hosted
+ version: "3.24.0"
win32:
dependency: transitive
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index a1ca594d..9abead88 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,7 +1,7 @@
name: absorb
description: A Material 3 Audiobookshelf client.
publish_to: 'none'
-version: 1.8.9+40
+version: 1.8.10+40
environment:
sdk: '>=3.1.0 <4.0.0'
@@ -75,6 +75,7 @@ dependencies:
# Splash screen (preserve during init)
flutter_native_splash: ^2.4.4
vibration: ^3.1.8
+ webview_flutter: ^4.13.1
dev_dependencies:
flutter_test: