Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26e7dba0d0 | ||
|
|
00fe8039cc | ||
|
|
7526e80a40 | ||
|
|
6e1a2e0568 | ||
|
|
127500329b | ||
|
|
a81cf3b18f | ||
|
|
66f00d192f | ||
|
|
ad9502d3c7 | ||
|
|
380a15442a |
@@ -262,13 +262,13 @@ jobs:
|
||||
- name: Cache APT packages
|
||||
uses: awalsh128/cache-apt-pkgs-action@latest
|
||||
with:
|
||||
packages: clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev libasound2-dev libmpv-dev mpv
|
||||
packages: clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev libasound2-dev libmpv-dev mpv keybinder-3.0
|
||||
version: 1.0
|
||||
|
||||
- name: Install Linux dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev libasound2-dev libmpv-dev mpv
|
||||
sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev libasound2-dev libmpv-dev mpv keybinder-3.0
|
||||
|
||||
- name: Install dependencies
|
||||
run: flutter pub get
|
||||
|
||||
+7
-2
@@ -47,5 +47,10 @@ app.*.map.json
|
||||
# Code duplication reports
|
||||
duplication-report/
|
||||
|
||||
# Test credentials (do not commit!)
|
||||
.env.test
|
||||
.env.*
|
||||
.env
|
||||
!.env.example
|
||||
|
||||
**/fastlane/**/
|
||||
**/fastlane/report.xml
|
||||
maestro/**/*.png
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
require 'dotenv/load'
|
||||
Dotenv.load("../../.env")
|
||||
|
||||
default_platform(:android)
|
||||
|
||||
platform :android do
|
||||
desc "Deploy a new version to the Google Play"
|
||||
lane :deploy do
|
||||
gradle(task: "clean bundleRelease")
|
||||
|
||||
# Get version code from pubspec.yaml
|
||||
pubspec_path = "#{ENV['PWD']}/../pubspec.yaml"
|
||||
pubspec_content = File.read(pubspec_path)
|
||||
version_match = pubspec_content.match(/version:\s*(.+)\+(\d+)/)
|
||||
|
||||
if version_match
|
||||
version_code = version_match[2].to_i
|
||||
UI.message("Using version code: #{version_code}")
|
||||
else
|
||||
UI.user_error!("Could not extract version code from pubspec.yaml")
|
||||
end
|
||||
|
||||
upload_to_play_store(
|
||||
version_code: version_code,
|
||||
skip_upload_changelogs: true,
|
||||
skip_upload_metadata: true,
|
||||
skip_upload_images: true,
|
||||
skip_upload_screenshots: true
|
||||
)
|
||||
end
|
||||
|
||||
desc "Build release AAB"
|
||||
lane :build do
|
||||
# Navigate to Flutter project root and build
|
||||
sh("cd #{ENV['PWD']}/.. && flutter build appbundle")
|
||||
end
|
||||
|
||||
desc "Build and deploy to Google Play Store"
|
||||
lane :release do
|
||||
# Build the Flutter app
|
||||
sh("cd #{ENV['PWD']}/.. && flutter build appbundle")
|
||||
|
||||
# Get version code from pubspec.yaml
|
||||
pubspec_path = "#{ENV['PWD']}/../pubspec.yaml"
|
||||
pubspec_content = File.read(pubspec_path)
|
||||
version_match = pubspec_content.match(/version:\s*(.+)\+(\d+)/)
|
||||
|
||||
if version_match
|
||||
version_code = version_match[2].to_i
|
||||
UI.message("Using version code: #{version_code}")
|
||||
else
|
||||
UI.user_error!("Could not extract version code from pubspec.yaml")
|
||||
end
|
||||
|
||||
# Upload to Play Store
|
||||
upload_to_play_store(
|
||||
track: "internal",
|
||||
release_status: "draft",
|
||||
version_code: version_code,
|
||||
aab: "../build/app/outputs/bundle/release/app-release.aab"
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,49 @@
|
||||
require 'dotenv/load'
|
||||
Dotenv.load("../../.env")
|
||||
|
||||
default_platform(:ios)
|
||||
|
||||
platform :ios do
|
||||
desc "Push a new beta build to TestFlight"
|
||||
lane :beta do
|
||||
build_app(workspace: "Runner.xcworkspace", scheme: "Runner")
|
||||
upload_to_testflight
|
||||
end
|
||||
|
||||
desc "Push a new release build to the App Store"
|
||||
lane :release do
|
||||
build_app(workspace: "Runner.xcworkspace", scheme: "Runner")
|
||||
upload_to_app_store
|
||||
end
|
||||
|
||||
desc "Build release IPA"
|
||||
lane :build do
|
||||
# Navigate to Flutter project root and build
|
||||
sh("cd #{ENV['PWD']}/.. && flutter build ipa")
|
||||
end
|
||||
|
||||
desc "Build and deploy to TestFlight"
|
||||
lane :deploy_testflight do
|
||||
# Build the Flutter app
|
||||
sh("cd #{ENV['PWD']}/.. && flutter build ipa")
|
||||
|
||||
# Upload to TestFlight
|
||||
upload_to_testflight(
|
||||
skip_waiting_for_build_processing: true
|
||||
)
|
||||
end
|
||||
|
||||
desc "Build and deploy to App Store"
|
||||
lane :deploy_appstore do
|
||||
# Build the Flutter app
|
||||
sh("cd #{ENV['PWD']}/.. && flutter build ipa")
|
||||
|
||||
# Upload to App Store
|
||||
upload_to_app_store(
|
||||
ipa: "../build/ios/ipa/Plezy.ipa",
|
||||
force: true,
|
||||
submit_for_review: false,
|
||||
skip_screenshots: true, # https://github.com/fastlane/fastlane/issues/29735
|
||||
)
|
||||
end
|
||||
end
|
||||
+34
-15
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'dart:io' show Platform;
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
@@ -17,6 +16,7 @@ import 'providers/theme_provider.dart';
|
||||
import 'utils/language_codes.dart';
|
||||
import 'utils/app_logger.dart';
|
||||
import 'utils/provider_extensions.dart';
|
||||
import 'utils/orientation_helper.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -32,11 +32,7 @@ void main() async {
|
||||
// Initialize MediaKit
|
||||
MediaKit.ensureInitialized();
|
||||
|
||||
// Lock orientation to portrait for all screens except video player
|
||||
await SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
// Note: Orientation will be set dynamically based on device type in MainApp
|
||||
|
||||
await StorageService.getInstance();
|
||||
|
||||
@@ -76,7 +72,7 @@ class MainApp extends StatelessWidget {
|
||||
darkTheme: themeProvider.darkTheme,
|
||||
themeMode: themeProvider.materialThemeMode,
|
||||
navigatorObservers: [routeObserver],
|
||||
home: const SetupScreen(),
|
||||
home: const OrientationAwareSetup(),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -84,6 +80,30 @@ class MainApp extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class OrientationAwareSetup extends StatefulWidget {
|
||||
const OrientationAwareSetup({super.key});
|
||||
|
||||
@override
|
||||
State<OrientationAwareSetup> createState() => _OrientationAwareSetupState();
|
||||
}
|
||||
|
||||
class _OrientationAwareSetupState extends State<OrientationAwareSetup> {
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_setOrientationPreferences();
|
||||
}
|
||||
|
||||
void _setOrientationPreferences() {
|
||||
OrientationHelper.restoreDefaultOrientations(context);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const SetupScreen();
|
||||
}
|
||||
}
|
||||
|
||||
class SetupScreen extends StatefulWidget {
|
||||
const SetupScreen({super.key});
|
||||
|
||||
@@ -149,15 +169,14 @@ class _SetupScreenState extends State<SetupScreen> {
|
||||
if (mounted) {
|
||||
context.plexClient.setClient(result.client!);
|
||||
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MainScreen(
|
||||
client: result.client!,
|
||||
userProfile: result.userProfile,
|
||||
if (mounted) {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MainScreen(client: result.client!),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'plex_home_user.dart';
|
||||
class PlexHome {
|
||||
final int id;
|
||||
final String name;
|
||||
final int guestUserID;
|
||||
final int? guestUserID;
|
||||
final String guestUserUUID;
|
||||
final bool guestEnabled;
|
||||
final bool subscription;
|
||||
@@ -28,9 +28,9 @@ class PlexHome {
|
||||
.toList();
|
||||
|
||||
return PlexHome(
|
||||
id: json['id'] as int,
|
||||
id: (json['id'] as num?)?.toInt() ?? 0,
|
||||
name: json['name'] as String,
|
||||
guestUserID: json['guestUserID'] as int,
|
||||
guestUserID: (json['guestUserID'] as num?)?.toInt(),
|
||||
guestUserUUID: json['guestUserUUID'] as String,
|
||||
guestEnabled: json['guestEnabled'] as bool,
|
||||
subscription: json['subscription'] as bool,
|
||||
|
||||
@@ -8,7 +8,7 @@ class PlexHomeUser {
|
||||
final String thumb;
|
||||
final bool hasPassword;
|
||||
final bool restricted;
|
||||
final int updatedAt;
|
||||
final int? updatedAt;
|
||||
final bool admin;
|
||||
final bool guest;
|
||||
final bool protected;
|
||||
@@ -31,19 +31,19 @@ class PlexHomeUser {
|
||||
|
||||
factory PlexHomeUser.fromJson(Map<String, dynamic> json) {
|
||||
return PlexHomeUser(
|
||||
id: json['id'] as int,
|
||||
uuid: json['uuid'] as String,
|
||||
title: json['title'] as String,
|
||||
id: (json['id'] as num?)?.toInt() ?? 0,
|
||||
uuid: json['uuid'] as String? ?? '',
|
||||
title: json['title'] as String? ?? 'Unknown',
|
||||
username: json['username'] as String?,
|
||||
email: json['email'] as String?,
|
||||
friendlyName: json['friendlyName'] as String?,
|
||||
thumb: json['thumb'] as String,
|
||||
hasPassword: json['hasPassword'] as bool,
|
||||
restricted: json['restricted'] as bool,
|
||||
updatedAt: json['updatedAt'] as int,
|
||||
admin: json['admin'] as bool,
|
||||
guest: json['guest'] as bool,
|
||||
protected: json['protected'] as bool,
|
||||
thumb: json['thumb'] as String? ?? '',
|
||||
hasPassword: json['hasPassword'] as bool? ?? false,
|
||||
restricted: json['restricted'] as bool? ?? false,
|
||||
updatedAt: (json['updatedAt'] as num?)?.toInt(),
|
||||
admin: json['admin'] as bool? ?? false,
|
||||
guest: json['guest'] as bool? ?? false,
|
||||
protected: json['protected'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,16 +8,19 @@ class ThemeProvider extends ChangeNotifier {
|
||||
late Brightness _systemBrightness;
|
||||
|
||||
ThemeProvider() {
|
||||
_systemBrightness = WidgetsBinding.instance.platformDispatcher.platformBrightness;
|
||||
_systemBrightness =
|
||||
WidgetsBinding.instance.platformDispatcher.platformBrightness;
|
||||
_initializeSettings();
|
||||
|
||||
// Listen to system theme changes
|
||||
WidgetsBinding.instance.platformDispatcher.onPlatformBrightnessChanged = () {
|
||||
_systemBrightness = WidgetsBinding.instance.platformDispatcher.platformBrightness;
|
||||
if (_themeMode == settings.ThemeMode.system) {
|
||||
notifyListeners();
|
||||
}
|
||||
};
|
||||
WidgetsBinding.instance.platformDispatcher.onPlatformBrightnessChanged =
|
||||
() {
|
||||
_systemBrightness =
|
||||
WidgetsBinding.instance.platformDispatcher.platformBrightness;
|
||||
if (_themeMode == settings.ThemeMode.system) {
|
||||
notifyListeners();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Future<void> _initializeSettings() async {
|
||||
@@ -96,4 +99,4 @@ class ThemeProvider extends ChangeNotifier {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../models/plex_home.dart';
|
||||
import '../models/plex_home_user.dart';
|
||||
import '../models/plex_user_profile.dart';
|
||||
import '../services/plex_auth_service.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import '../utils/app_logger.dart';
|
||||
@@ -10,11 +11,13 @@ import 'plex_client_provider.dart';
|
||||
class UserProfileProvider extends ChangeNotifier {
|
||||
PlexHome? _home;
|
||||
PlexHomeUser? _currentUser;
|
||||
PlexUserProfile? _profileSettings;
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
|
||||
PlexHome? get home => _home;
|
||||
PlexHomeUser? get currentUser => _currentUser;
|
||||
PlexUserProfile? get profileSettings => _profileSettings;
|
||||
bool get isLoading => _isLoading;
|
||||
String? get error => _error;
|
||||
bool get hasMultipleUsers {
|
||||
@@ -66,6 +69,19 @@ class UserProfileProvider extends ChangeNotifier {
|
||||
// Don't set error here as it's not critical for app startup
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch fresh profile settings from API
|
||||
appLogger.d('UserProfileProvider: Fetching profile settings from API');
|
||||
try {
|
||||
await refreshProfileSettings();
|
||||
} catch (e) {
|
||||
appLogger.w(
|
||||
'UserProfileProvider: Failed to fetch profile settings during initialization',
|
||||
error: e,
|
||||
);
|
||||
// Don't set error here, cached profile (if any) was already loaded
|
||||
}
|
||||
|
||||
appLogger.d('UserProfileProvider: Initialization complete');
|
||||
} catch (e) {
|
||||
appLogger.e(
|
||||
@@ -98,9 +114,41 @@ class UserProfileProvider extends ChangeNotifier {
|
||||
_currentUser = _home!.getUserByUUID(currentUserUUID);
|
||||
}
|
||||
|
||||
// Profile settings are NOT cached - they will be fetched fresh from API
|
||||
// in refreshProfileSettings()
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Fetch the user's profile settings from the API
|
||||
Future<void> refreshProfileSettings() async {
|
||||
if (_authService == null || _storageService == null) {
|
||||
appLogger.w('refreshProfileSettings: Services not initialized, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
appLogger.d('Fetching user profile settings from Plex API');
|
||||
try {
|
||||
final currentToken = _storageService!.getPlexToken();
|
||||
if (currentToken == null) {
|
||||
appLogger.w(
|
||||
'refreshProfileSettings: No Plex token available, cannot fetch profile',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final profile = await _authService!.getUserProfile(currentToken);
|
||||
_profileSettings = profile;
|
||||
|
||||
appLogger.i('Successfully fetched user profile settings from API');
|
||||
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
appLogger.w('Failed to fetch user profile settings from API', error: e);
|
||||
// Don't set error state, profile will remain null or keep existing value
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadHomeUsers({bool forceRefresh = false}) async {
|
||||
appLogger.d('loadHomeUsers called - forceRefresh: $forceRefresh');
|
||||
|
||||
@@ -263,8 +311,17 @@ class UserProfileProvider extends ChangeNotifier {
|
||||
// Update current user
|
||||
_currentUser = user;
|
||||
|
||||
// Save user profile
|
||||
await _storageService!.saveUserProfile(switchResponse.profile.toJson());
|
||||
// Update user profile settings (fresh from API)
|
||||
_profileSettings = switchResponse.profile;
|
||||
appLogger.d(
|
||||
'Updated profile settings for user: ${user.displayName}',
|
||||
error: {
|
||||
'defaultAudioLanguage':
|
||||
_profileSettings?.defaultAudioLanguage ?? 'not set',
|
||||
'defaultSubtitleLanguage':
|
||||
_profileSettings?.defaultSubtitleLanguage ?? 'not set',
|
||||
},
|
||||
);
|
||||
|
||||
// Update PlexClient with proper server access token
|
||||
if (clientProvider != null) {
|
||||
@@ -322,6 +379,7 @@ class UserProfileProvider extends ChangeNotifier {
|
||||
// Clear user-specific provider state but keep services for future sign-ins
|
||||
_home = null;
|
||||
_currentUser = null;
|
||||
_profileSettings = null;
|
||||
_onDataInvalidationRequested = null;
|
||||
|
||||
_clearError();
|
||||
@@ -346,6 +404,7 @@ class UserProfileProvider extends ChangeNotifier {
|
||||
// Clear cached data from previous server (both memory and storage)
|
||||
_home = null;
|
||||
_currentUser = null;
|
||||
_profileSettings = null;
|
||||
_clearError();
|
||||
|
||||
// Re-initialize services with current storage state
|
||||
@@ -401,6 +460,15 @@ class UserProfileProvider extends ChangeNotifier {
|
||||
appLogger.w(
|
||||
'UserProfileProvider: Cannot perform complete profile switch - no context provided',
|
||||
);
|
||||
// Still try to fetch profile settings even without full switch
|
||||
try {
|
||||
await refreshProfileSettings();
|
||||
} catch (e) {
|
||||
appLogger.w(
|
||||
'UserProfileProvider: Failed to refresh profile settings for new server',
|
||||
error: e,
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
appLogger.w(
|
||||
|
||||
@@ -92,7 +92,6 @@ class _AboutScreenState extends State<AboutScreen> {
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
const SizedBox(height: 24),
|
||||
]),
|
||||
),
|
||||
@@ -101,5 +100,4 @@ class _AboutScreenState extends State<AboutScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../services/plex_auth_service.dart';
|
||||
@@ -110,6 +112,96 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
Future.delayed(const Duration(milliseconds: 100), _startAuthentication);
|
||||
}
|
||||
|
||||
void _handleDebugTap() {
|
||||
if (!kDebugMode) return;
|
||||
_showDebugTokenDialog();
|
||||
}
|
||||
|
||||
void _showDebugTokenDialog() {
|
||||
final tokenController = TextEditingController();
|
||||
String? errorMessage;
|
||||
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setDialogState) {
|
||||
return AlertDialog(
|
||||
title: const Text('Debug: Enter Plex Token'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextFormField(
|
||||
controller: tokenController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Plex Auth Token',
|
||||
hintText: 'Enter your Plex.tv token',
|
||||
errorText: errorMessage,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
obscureText: true,
|
||||
maxLines: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
final token = tokenController.text.trim();
|
||||
if (token.isEmpty) {
|
||||
setDialogState(() {
|
||||
errorMessage = 'Please enter a token';
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
final navigator = Navigator.of(context);
|
||||
|
||||
try {
|
||||
final isValid = await _authService.verifyToken(token);
|
||||
if (!isValid) {
|
||||
setDialogState(() {
|
||||
errorMessage = 'Invalid token';
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Store the token
|
||||
final storage = await StorageService.getInstance();
|
||||
await storage.savePlexToken(token);
|
||||
|
||||
// Close dialog and navigate
|
||||
if (mounted) {
|
||||
navigator.pop();
|
||||
navigator.pushReplacement(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ServerSelectionScreen(
|
||||
authService: _authService,
|
||||
plexToken: token,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
setDialogState(() {
|
||||
errorMessage = 'Failed to verify token: $e';
|
||||
});
|
||||
}
|
||||
},
|
||||
child: const Text('Authenticate'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -158,6 +250,24 @@ class _AuthScreenState extends State<AuthScreen> {
|
||||
),
|
||||
child: const Text('Sign in with Plex'),
|
||||
),
|
||||
if (kDebugMode) ...[
|
||||
const SizedBox(height: 12),
|
||||
OutlinedButton(
|
||||
onPressed: _handleDebugTap,
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
side: BorderSide(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.outline.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'Debug: Enter Token',
|
||||
style: TextStyle(fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (_errorMessage != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
|
||||
+371
-330
@@ -4,7 +4,6 @@ import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../client/plex_client.dart';
|
||||
import '../models/plex_metadata.dart';
|
||||
import '../models/plex_user_profile.dart';
|
||||
import '../providers/plex_client_provider.dart';
|
||||
import '../services/storage_service.dart';
|
||||
import '../services/plex_auth_service.dart';
|
||||
@@ -18,14 +17,13 @@ import '../mixins/refreshable.dart';
|
||||
import '../mixins/item_updatable.dart';
|
||||
import '../utils/app_logger.dart';
|
||||
import '../utils/provider_extensions.dart';
|
||||
import 'video_player_screen.dart';
|
||||
import '../utils/video_player_navigation.dart';
|
||||
import 'auth_screen.dart';
|
||||
|
||||
class DiscoverScreen extends StatefulWidget {
|
||||
final PlexUserProfile? userProfile;
|
||||
final VoidCallback? onBecameVisible;
|
||||
|
||||
const DiscoverScreen({super.key, this.userProfile, this.onBecameVisible});
|
||||
const DiscoverScreen({super.key, this.onBecameVisible});
|
||||
|
||||
@override
|
||||
State<DiscoverScreen> createState() => _DiscoverScreenState();
|
||||
@@ -45,6 +43,7 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
int _currentHeroIndex = 0;
|
||||
Timer? _autoScrollTimer;
|
||||
late AnimationController _indicatorAnimationController;
|
||||
bool _isAutoScrollPaused = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -67,9 +66,12 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
}
|
||||
|
||||
void _startAutoScroll() {
|
||||
if (_isAutoScrollPaused) return;
|
||||
|
||||
_indicatorAnimationController.forward(from: 0.0);
|
||||
_autoScrollTimer = Timer.periodic(const Duration(seconds: 5), (timer) {
|
||||
if (_onDeck.isEmpty || !_heroController.hasClients) return;
|
||||
if (_onDeck.isEmpty || !_heroController.hasClients || _isAutoScrollPaused)
|
||||
return;
|
||||
|
||||
final nextPage = (_currentHeroIndex + 1) % _onDeck.length;
|
||||
_heroController.animateToPage(
|
||||
@@ -79,7 +81,9 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
);
|
||||
// Wait for page transition to complete before resetting progress
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
_indicatorAnimationController.forward(from: 0.0);
|
||||
if (!_isAutoScrollPaused) {
|
||||
_indicatorAnimationController.forward(from: 0.0);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -89,6 +93,21 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
_startAutoScroll();
|
||||
}
|
||||
|
||||
void _pauseAutoScroll() {
|
||||
setState(() {
|
||||
_isAutoScrollPaused = true;
|
||||
});
|
||||
_autoScrollTimer?.cancel();
|
||||
_indicatorAnimationController.stop();
|
||||
}
|
||||
|
||||
void _resumeAutoScroll() {
|
||||
setState(() {
|
||||
_isAutoScrollPaused = false;
|
||||
});
|
||||
_startAutoScroll();
|
||||
}
|
||||
|
||||
Future<void> _loadContent() async {
|
||||
appLogger.d('Loading discover content');
|
||||
setState(() {
|
||||
@@ -211,8 +230,14 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
|
||||
if (confirm == true && mounted) {
|
||||
// Use comprehensive logout through UserProfileProvider
|
||||
final userProfileProvider = Provider.of<UserProfileProvider>(context, listen: false);
|
||||
final plexClientProvider = Provider.of<PlexClientProvider>(context, listen: false);
|
||||
final userProfileProvider = Provider.of<UserProfileProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
final plexClientProvider = Provider.of<PlexClientProvider>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
|
||||
// Clear all user data and provider states
|
||||
await userProfileProvider.logout();
|
||||
@@ -432,62 +457,85 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
return _buildHeroItem(_onDeck[index]);
|
||||
},
|
||||
),
|
||||
// Page indicators with animated progress
|
||||
// Page indicators with animated progress and pause/play button
|
||||
Positioned(
|
||||
bottom: 16,
|
||||
left: 0,
|
||||
left: -26,
|
||||
right: 0,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(_onDeck.length, (index) {
|
||||
final isActive = _currentHeroIndex == index;
|
||||
if (isActive) {
|
||||
// Animated progress indicator for active page
|
||||
return AnimatedBuilder(
|
||||
animation: _indicatorAnimationController,
|
||||
builder: (context, child) {
|
||||
// Fill width animates from 8px to 24px
|
||||
final fillWidth =
|
||||
8.0 + (16.0 * _indicatorAnimationController.value);
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
width: 24,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.4),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Container(
|
||||
width: fillWidth,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
children: [
|
||||
// Pause/Play button
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (_isAutoScrollPaused) {
|
||||
_resumeAutoScroll();
|
||||
} else {
|
||||
_pauseAutoScroll();
|
||||
}
|
||||
},
|
||||
child: Icon(
|
||||
_isAutoScrollPaused ? Icons.play_arrow : Icons.pause,
|
||||
color: Colors.white,
|
||||
size: 18,
|
||||
semanticLabel:
|
||||
'${_isAutoScrollPaused ? 'Play' : 'Pause'} auto-scroll',
|
||||
),
|
||||
),
|
||||
// Spacer to separate indicators from button
|
||||
const SizedBox(width: 8),
|
||||
// Page indicators
|
||||
...List.generate(_onDeck.length, (index) {
|
||||
final isActive = _currentHeroIndex == index;
|
||||
if (isActive) {
|
||||
// Animated progress indicator for active page
|
||||
return AnimatedBuilder(
|
||||
animation: _indicatorAnimationController,
|
||||
builder: (context, child) {
|
||||
// Fill width animates from 8px to 24px
|
||||
final fillWidth =
|
||||
8.0 +
|
||||
(16.0 * _indicatorAnimationController.value);
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
width: 24,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.4),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Container(
|
||||
width: fillWidth,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
// Static indicator for inactive pages
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.4),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
);
|
||||
}
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
// Static indicator for inactive pages
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.4),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
);
|
||||
}
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -507,182 +555,149 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
? 'Movie'
|
||||
: 'TV Show';
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
final clientProvider = context.plexClient;
|
||||
final client = clientProvider.client;
|
||||
if (client == null) return;
|
||||
return Semantics(
|
||||
label: "media-hero-${heroItem.ratingKey}",
|
||||
identifier: "media-hero-${heroItem.ratingKey}",
|
||||
button: true,
|
||||
hint: "Tap to play ${heroItem.title}",
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
final clientProvider = context.plexClient;
|
||||
final client = clientProvider.client;
|
||||
if (client == null) return;
|
||||
|
||||
appLogger.d('Navigating to VideoPlayerScreen for: ${heroItem.title}');
|
||||
Navigator.push<bool>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => VideoPlayerScreen(
|
||||
metadata: heroItem,
|
||||
userProfile: widget.userProfile,
|
||||
),
|
||||
appLogger.d('Navigating to VideoPlayerScreen for: ${heroItem.title}');
|
||||
navigateToVideoPlayer(context, metadata: heroItem);
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.3),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.3),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// Background Image with fade/zoom animation and parallax
|
||||
if (heroItem.art != null || heroItem.grandparentArt != null)
|
||||
AnimatedBuilder(
|
||||
animation: _scrollController,
|
||||
builder: (context, child) {
|
||||
final scrollOffset = _scrollController.hasClients
|
||||
? _scrollController.offset
|
||||
: 0.0;
|
||||
return Transform.translate(
|
||||
offset: Offset(0, scrollOffset * 0.3),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
child: TweenAnimationBuilder<double>(
|
||||
tween: Tween(begin: 0.0, end: 1.0),
|
||||
duration: const Duration(milliseconds: 800),
|
||||
curve: Curves.easeOut,
|
||||
builder: (context, value, child) {
|
||||
return Transform.scale(
|
||||
scale: 1.0 + (0.1 * (1 - value)),
|
||||
child: Opacity(opacity: value, child: child),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
// Background Image with fade/zoom animation and parallax
|
||||
if (heroItem.art != null || heroItem.grandparentArt != null)
|
||||
AnimatedBuilder(
|
||||
animation: _scrollController,
|
||||
builder: (context, child) {
|
||||
final scrollOffset = _scrollController.hasClients
|
||||
? _scrollController.offset
|
||||
: 0.0;
|
||||
return Transform.translate(
|
||||
offset: Offset(0, scrollOffset * 0.3),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
child: Consumer<PlexClientProvider>(
|
||||
builder: (context, clientProvider, child) {
|
||||
final client = clientProvider.client;
|
||||
if (client == null) {
|
||||
return Container(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
);
|
||||
}
|
||||
return CachedNetworkImage(
|
||||
imageUrl: client.getThumbnailUrl(
|
||||
heroItem.art ?? heroItem.grandparentArt,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
errorWidget: (context, url, error) => Container(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
child: TweenAnimationBuilder<double>(
|
||||
tween: Tween(begin: 0.0, end: 1.0),
|
||||
duration: const Duration(milliseconds: 800),
|
||||
curve: Curves.easeOut,
|
||||
builder: (context, value, child) {
|
||||
return Transform.scale(
|
||||
scale: 1.0 + (0.1 * (1 - value)),
|
||||
child: Opacity(opacity: value, child: child),
|
||||
);
|
||||
},
|
||||
child: Consumer<PlexClientProvider>(
|
||||
builder: (context, clientProvider, child) {
|
||||
final client = clientProvider.client;
|
||||
if (client == null) {
|
||||
return Container(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
);
|
||||
}
|
||||
return CachedNetworkImage(
|
||||
imageUrl: client.getThumbnailUrl(
|
||||
heroItem.art ?? heroItem.grandparentArt,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
errorWidget: (context, url, error) => Container(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
Container(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
|
||||
// Gradient Overlay
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.transparent,
|
||||
Colors.black.withValues(alpha: 0.7),
|
||||
Colors.black.withValues(alpha: 0.9),
|
||||
],
|
||||
stops: const [0.0, 0.5, 1.0],
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
Container(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
|
||||
// Gradient Overlay
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.transparent,
|
||||
Colors.black.withValues(alpha: 0.7),
|
||||
Colors.black.withValues(alpha: 0.9),
|
||||
],
|
||||
stops: const [0.0, 0.5, 1.0],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Content with responsive alignment
|
||||
Positioned(
|
||||
bottom: isLargeScreen ? 80 : 50,
|
||||
left: 0,
|
||||
right: isLargeScreen ? 200 : 0,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: isLargeScreen ? 40 : 16,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: isLargeScreen
|
||||
? CrossAxisAlignment.start
|
||||
: CrossAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Show logo or name/title
|
||||
if (heroItem.clearLogo != null)
|
||||
SizedBox(
|
||||
height: 120,
|
||||
width: 400,
|
||||
child: Consumer<PlexClientProvider>(
|
||||
builder: (context, clientProvider, child) {
|
||||
final client = clientProvider.client;
|
||||
if (client == null) {
|
||||
return Container();
|
||||
}
|
||||
return CachedNetworkImage(
|
||||
imageUrl: client.getThumbnailUrl(
|
||||
heroItem.clearLogo,
|
||||
),
|
||||
filterQuality: FilterQuality.medium,
|
||||
fit: BoxFit.contain,
|
||||
alignment: isLargeScreen
|
||||
? Alignment.bottomLeft
|
||||
: Alignment.bottomCenter,
|
||||
placeholder: (context, url) => Align(
|
||||
alignment: isLargeScreen
|
||||
? Alignment.centerLeft
|
||||
: Alignment.center,
|
||||
child: Text(
|
||||
showName,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.displaySmall
|
||||
?.copyWith(
|
||||
color: Colors.white.withValues(
|
||||
alpha: 0.3,
|
||||
),
|
||||
fontWeight: FontWeight.bold,
|
||||
shadows: [
|
||||
Shadow(
|
||||
color: Colors.black.withValues(
|
||||
alpha: 0.5,
|
||||
),
|
||||
blurRadius: 8,
|
||||
),
|
||||
],
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: isLargeScreen
|
||||
? TextAlign.left
|
||||
: TextAlign.center,
|
||||
// Content with responsive alignment
|
||||
Positioned(
|
||||
bottom: isLargeScreen ? 80 : 50,
|
||||
left: 0,
|
||||
right: isLargeScreen ? 200 : 0,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: isLargeScreen ? 40 : 16,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: isLargeScreen
|
||||
? CrossAxisAlignment.start
|
||||
: CrossAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Show logo or name/title
|
||||
if (heroItem.clearLogo != null)
|
||||
SizedBox(
|
||||
height: 120,
|
||||
width: 400,
|
||||
child: Consumer<PlexClientProvider>(
|
||||
builder: (context, clientProvider, child) {
|
||||
final client = clientProvider.client;
|
||||
if (client == null) {
|
||||
return Container();
|
||||
}
|
||||
return CachedNetworkImage(
|
||||
imageUrl: client.getThumbnailUrl(
|
||||
heroItem.clearLogo,
|
||||
),
|
||||
),
|
||||
errorWidget: (context, url, error) {
|
||||
// Fallback to text if logo fails to load
|
||||
return Align(
|
||||
filterQuality: FilterQuality.medium,
|
||||
fit: BoxFit.contain,
|
||||
alignment: isLargeScreen
|
||||
? Alignment.bottomLeft
|
||||
: Alignment.bottomCenter,
|
||||
placeholder: (context, url) => Align(
|
||||
alignment: isLargeScreen
|
||||
? Alignment.centerLeft
|
||||
: Alignment.center,
|
||||
@@ -692,7 +707,9 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
.textTheme
|
||||
.displaySmall
|
||||
?.copyWith(
|
||||
color: Colors.white,
|
||||
color: Colors.white.withValues(
|
||||
alpha: 0.3,
|
||||
),
|
||||
fontWeight: FontWeight.bold,
|
||||
shadows: [
|
||||
Shadow(
|
||||
@@ -709,111 +726,144 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
? TextAlign.left
|
||||
: TextAlign.center,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
else
|
||||
Text(
|
||||
showName,
|
||||
style: Theme.of(context).textTheme.displaySmall
|
||||
?.copyWith(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
shadows: [
|
||||
Shadow(
|
||||
color: Colors.black.withValues(alpha: 0.5),
|
||||
blurRadius: 8,
|
||||
),
|
||||
],
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: isLargeScreen
|
||||
? TextAlign.left
|
||||
: TextAlign.center,
|
||||
),
|
||||
|
||||
// Metadata as dot-separated text with content type
|
||||
if (heroItem.year != null ||
|
||||
heroItem.contentRating != null ||
|
||||
heroItem.rating != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
[
|
||||
contentTypeLabel,
|
||||
if (heroItem.rating != null)
|
||||
'★ ${(heroItem.rating! / 10).toStringAsFixed(1)}',
|
||||
if (heroItem.contentRating != null)
|
||||
heroItem.contentRating!,
|
||||
if (heroItem.year != null) heroItem.year.toString(),
|
||||
].join(' • '),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
textAlign: isLargeScreen
|
||||
? TextAlign.left
|
||||
: TextAlign.center,
|
||||
),
|
||||
],
|
||||
|
||||
// On small screens: show button before summary
|
||||
if (!isLargeScreen) ...[
|
||||
const SizedBox(height: 20),
|
||||
_buildSmartPlayButton(heroItem),
|
||||
],
|
||||
|
||||
// Summary with episode info (Apple TV style)
|
||||
if (heroItem.summary != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
RichText(
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: isLargeScreen
|
||||
? TextAlign.left
|
||||
: TextAlign.center,
|
||||
text: TextSpan(
|
||||
style: const TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 14,
|
||||
height: 1.4,
|
||||
errorWidget: (context, url, error) {
|
||||
// Fallback to text if logo fails to load
|
||||
return Align(
|
||||
alignment: isLargeScreen
|
||||
? Alignment.centerLeft
|
||||
: Alignment.center,
|
||||
child: Text(
|
||||
showName,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.displaySmall
|
||||
?.copyWith(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
shadows: [
|
||||
Shadow(
|
||||
color: Colors.black
|
||||
.withValues(alpha: 0.5),
|
||||
blurRadius: 8,
|
||||
),
|
||||
],
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: isLargeScreen
|
||||
? TextAlign.left
|
||||
: TextAlign.center,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
children: [
|
||||
if (isEpisode &&
|
||||
heroItem.parentIndex != null &&
|
||||
heroItem.index != null)
|
||||
TextSpan(
|
||||
text:
|
||||
'S${heroItem.parentIndex}, E${heroItem.index}: ',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
else
|
||||
Text(
|
||||
showName,
|
||||
style: Theme.of(context).textTheme.displaySmall
|
||||
?.copyWith(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
shadows: [
|
||||
Shadow(
|
||||
color: Colors.black.withValues(
|
||||
alpha: 0.5,
|
||||
),
|
||||
blurRadius: 8,
|
||||
),
|
||||
],
|
||||
),
|
||||
TextSpan(
|
||||
text: heroItem.summary?.isNotEmpty == true
|
||||
? heroItem.summary!
|
||||
: 'No description available',
|
||||
),
|
||||
],
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: isLargeScreen
|
||||
? TextAlign.left
|
||||
: TextAlign.center,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// On large screens: show button after summary
|
||||
if (isLargeScreen) ...[
|
||||
const SizedBox(height: 20),
|
||||
_buildSmartPlayButton(heroItem),
|
||||
// Metadata as dot-separated text with content type
|
||||
if (heroItem.year != null ||
|
||||
heroItem.contentRating != null ||
|
||||
heroItem.rating != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
[
|
||||
contentTypeLabel,
|
||||
if (heroItem.rating != null)
|
||||
'★ ${(heroItem.rating! / 10).toStringAsFixed(1)}',
|
||||
if (heroItem.contentRating != null)
|
||||
heroItem.contentRating!,
|
||||
if (heroItem.year != null)
|
||||
heroItem.year.toString(),
|
||||
].join(' • '),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
textAlign: isLargeScreen
|
||||
? TextAlign.left
|
||||
: TextAlign.center,
|
||||
),
|
||||
],
|
||||
|
||||
// On small screens: show button before summary
|
||||
if (!isLargeScreen) ...[
|
||||
const SizedBox(height: 20),
|
||||
_buildSmartPlayButton(heroItem),
|
||||
],
|
||||
|
||||
// Summary with episode info (Apple TV style)
|
||||
if (heroItem.summary != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
RichText(
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
textAlign: isLargeScreen
|
||||
? TextAlign.left
|
||||
: TextAlign.center,
|
||||
text: TextSpan(
|
||||
style: const TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 14,
|
||||
height: 1.4,
|
||||
),
|
||||
children: [
|
||||
if (isEpisode &&
|
||||
heroItem.parentIndex != null &&
|
||||
heroItem.index != null)
|
||||
TextSpan(
|
||||
text:
|
||||
'S${heroItem.parentIndex}, E${heroItem.index}: ',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
TextSpan(
|
||||
text: heroItem.summary?.isNotEmpty == true
|
||||
? heroItem.summary!
|
||||
: 'No description available',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// On large screens: show button after summary
|
||||
if (isLargeScreen) ...[
|
||||
const SizedBox(height: 20),
|
||||
_buildSmartPlayButton(heroItem),
|
||||
],
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -842,15 +892,7 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
if (client == null) return;
|
||||
|
||||
appLogger.d('Playing: ${heroItem.title}');
|
||||
Navigator.push<bool>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => VideoPlayerScreen(
|
||||
metadata: heroItem,
|
||||
userProfile: widget.userProfile,
|
||||
),
|
||||
),
|
||||
);
|
||||
navigateToVideoPlayer(context, metadata: heroItem);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
child: Container(
|
||||
@@ -947,7 +989,6 @@ class _DiscoverScreenState extends State<DiscoverScreen>
|
||||
width: cardWidth,
|
||||
height: cardHeight,
|
||||
onRefresh: updateItem,
|
||||
userProfile: widget.userProfile,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -4,7 +4,6 @@ import '../client/plex_client.dart';
|
||||
import '../models/plex_library.dart';
|
||||
import '../models/plex_metadata.dart';
|
||||
import '../models/plex_filter.dart';
|
||||
import '../models/plex_user_profile.dart';
|
||||
import '../providers/plex_client_provider.dart';
|
||||
import '../utils/provider_extensions.dart';
|
||||
import '../widgets/media_card.dart';
|
||||
@@ -16,9 +15,7 @@ import '../mixins/item_updatable.dart';
|
||||
import '../theme/theme_helper.dart';
|
||||
|
||||
class LibrariesScreen extends StatefulWidget {
|
||||
final PlexUserProfile? userProfile;
|
||||
|
||||
const LibrariesScreen({super.key, this.userProfile});
|
||||
const LibrariesScreen({super.key});
|
||||
|
||||
@override
|
||||
State<LibrariesScreen> createState() => _LibrariesScreenState();
|
||||
@@ -269,12 +266,15 @@ class _LibrariesScreenState extends State<LibrariesScreen>
|
||||
icon: Badge(
|
||||
label: Text('${_selectedFilters.length}'),
|
||||
isLabelVisible: _selectedFilters.isNotEmpty,
|
||||
child: const Icon(Icons.filter_list),
|
||||
child: const Icon(
|
||||
Icons.filter_list,
|
||||
semanticLabel: 'Filters',
|
||||
),
|
||||
),
|
||||
onPressed: _showFiltersBottomSheet,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
icon: const Icon(Icons.refresh, semanticLabel: 'Refresh'),
|
||||
onPressed: () => _loadLibraryContent(_selectedLibraryIndex),
|
||||
),
|
||||
],
|
||||
@@ -433,7 +433,6 @@ class _LibrariesScreenState extends State<LibrariesScreen>
|
||||
key: Key(item.ratingKey),
|
||||
item: item,
|
||||
onRefresh: updateItem,
|
||||
userProfile: widget.userProfile,
|
||||
);
|
||||
}, childCount: _items.length),
|
||||
),
|
||||
|
||||
@@ -67,9 +67,7 @@ class _LicensesScreenState extends State<LicensesScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_isLoading) {
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
return const Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
@@ -79,30 +77,29 @@ class _LicensesScreenState extends State<LicensesScreen> {
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
final mergedLicense = _mergedLicenses[index];
|
||||
final packageName = mergedLicense.packageName;
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
final mergedLicense = _mergedLicenses[index];
|
||||
final packageName = mergedLicense.packageName;
|
||||
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
child: ListTile(
|
||||
title: Text(
|
||||
packageName,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
child: ListTile(
|
||||
title: Text(
|
||||
packageName,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
subtitle: mergedLicense.licenseEntries.length > 1
|
||||
? Text('${mergedLicense.licenseEntries.length} licenses')
|
||||
: null,
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showLicenseDetail(mergedLicense),
|
||||
),
|
||||
);
|
||||
},
|
||||
childCount: _mergedLicenses.length,
|
||||
),
|
||||
subtitle: mergedLicense.licenseEntries.length > 1
|
||||
? Text(
|
||||
'${mergedLicense.licenseEntries.length} licenses',
|
||||
)
|
||||
: null,
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showLicenseDetail(mergedLicense),
|
||||
),
|
||||
);
|
||||
}, childCount: _mergedLicenses.length),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -114,9 +111,8 @@ class _LicensesScreenState extends State<LicensesScreen> {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _LicenseDetailScreen(
|
||||
mergedLicense: mergedLicense,
|
||||
),
|
||||
builder: (context) =>
|
||||
_LicenseDetailScreen(mergedLicense: mergedLicense),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -125,9 +121,7 @@ class _LicensesScreenState extends State<LicensesScreen> {
|
||||
class _LicenseDetailScreen extends StatelessWidget {
|
||||
final MergedLicenseEntry mergedLicense;
|
||||
|
||||
const _LicenseDetailScreen({
|
||||
required this.mergedLicense,
|
||||
});
|
||||
const _LicenseDetailScreen({required this.mergedLicense});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -137,10 +131,7 @@ class _LicenseDetailScreen extends StatelessWidget {
|
||||
return Scaffold(
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
CustomAppBar(
|
||||
title: Text(packageName),
|
||||
pinned: true,
|
||||
),
|
||||
CustomAppBar(title: Text(packageName), pinned: true),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
sliver: SliverList(
|
||||
@@ -155,9 +146,8 @@ class _LicenseDetailScreen extends StatelessWidget {
|
||||
children: [
|
||||
Text(
|
||||
'Related Packages',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: Theme.of(context).textTheme.titleMedium
|
||||
?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
@@ -186,10 +176,11 @@ class _LicenseDetailScreen extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
isMultipleLicenses ? 'License ${index + 1}' : 'License',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
isMultipleLicenses
|
||||
? 'License ${index + 1}'
|
||||
: 'License',
|
||||
style: Theme.of(context).textTheme.titleMedium
|
||||
?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
...license.paragraphs.map((paragraph) {
|
||||
@@ -198,7 +189,9 @@ class _LicenseDetailScreen extends StatelessWidget {
|
||||
child: SelectableText(
|
||||
paragraph.text,
|
||||
style: TextStyle(
|
||||
fontFamily: paragraph.indent > 0 ? 'monospace' : null,
|
||||
fontFamily: paragraph.indent > 0
|
||||
? 'monospace'
|
||||
: null,
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
@@ -220,4 +213,4 @@ class _LicenseDetailScreen extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../client/plex_client.dart';
|
||||
import '../models/plex_user_profile.dart';
|
||||
import '../utils/app_logger.dart';
|
||||
import '../utils/provider_extensions.dart';
|
||||
import '../main.dart';
|
||||
@@ -12,9 +11,8 @@ import 'settings_screen.dart';
|
||||
|
||||
class MainScreen extends StatefulWidget {
|
||||
final PlexClient client;
|
||||
final PlexUserProfile? userProfile;
|
||||
|
||||
const MainScreen({super.key, required this.client, this.userProfile});
|
||||
const MainScreen({super.key, required this.client});
|
||||
|
||||
@override
|
||||
State<MainScreen> createState() => _MainScreenState();
|
||||
@@ -36,11 +34,10 @@ class _MainScreenState extends State<MainScreen> with RouteAware {
|
||||
_screens = [
|
||||
DiscoverScreen(
|
||||
key: _discoverKey,
|
||||
userProfile: widget.userProfile,
|
||||
onBecameVisible: _onDiscoverBecameVisible,
|
||||
),
|
||||
LibrariesScreen(key: _librariesKey, userProfile: widget.userProfile),
|
||||
SearchScreen(key: _searchKey, userProfile: widget.userProfile),
|
||||
LibrariesScreen(key: _librariesKey),
|
||||
SearchScreen(key: _searchKey),
|
||||
SettingsScreen(key: _settingsKey),
|
||||
];
|
||||
|
||||
|
||||
@@ -2,26 +2,20 @@ import 'package:flutter/material.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../models/plex_metadata.dart';
|
||||
import '../models/plex_user_profile.dart';
|
||||
import '../providers/plex_client_provider.dart';
|
||||
import '../widgets/desktop_app_bar.dart';
|
||||
import '../widgets/app_bar_back_button.dart';
|
||||
import '../widgets/media_context_menu.dart';
|
||||
import '../utils/app_logger.dart';
|
||||
import '../utils/provider_extensions.dart';
|
||||
import '../utils/video_player_navigation.dart';
|
||||
import '../theme/theme_helper.dart';
|
||||
import 'season_detail_screen.dart';
|
||||
import 'video_player_screen.dart';
|
||||
|
||||
class MediaDetailScreen extends StatefulWidget {
|
||||
final PlexMetadata metadata;
|
||||
final PlexUserProfile? userProfile;
|
||||
|
||||
const MediaDetailScreen({
|
||||
super.key,
|
||||
required this.metadata,
|
||||
this.userProfile,
|
||||
});
|
||||
const MediaDetailScreen({super.key, required this.metadata});
|
||||
|
||||
@override
|
||||
State<MediaDetailScreen> createState() => _MediaDetailScreenState();
|
||||
@@ -214,15 +208,7 @@ class _MediaDetailScreenState extends State<MediaDetailScreen> {
|
||||
if (client == null) return;
|
||||
|
||||
appLogger.d('Playing first episode: ${firstEpisode.title}');
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => VideoPlayerScreen(
|
||||
metadata: firstEpisode,
|
||||
userProfile: widget.userProfile,
|
||||
),
|
||||
),
|
||||
);
|
||||
await navigateToVideoPlayer(context, metadata: firstEpisode);
|
||||
appLogger.d('Returned from playback, refreshing metadata');
|
||||
// Refresh metadata when returning from video player
|
||||
_loadFullMetadata();
|
||||
@@ -542,14 +528,9 @@ class _MediaDetailScreenState extends State<MediaDetailScreen> {
|
||||
appLogger.d(
|
||||
'Playing on deck episode: ${_onDeckEpisode!.title}',
|
||||
);
|
||||
await Navigator.push(
|
||||
await navigateToVideoPlayer(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => VideoPlayerScreen(
|
||||
metadata: _onDeckEpisode!,
|
||||
userProfile: widget.userProfile,
|
||||
),
|
||||
),
|
||||
metadata: _onDeckEpisode!,
|
||||
);
|
||||
appLogger.d(
|
||||
'Returned from playback, refreshing metadata',
|
||||
@@ -567,14 +548,9 @@ class _MediaDetailScreenState extends State<MediaDetailScreen> {
|
||||
|
||||
appLogger.d('Playing: ${metadata.title}');
|
||||
// For movies or episodes, play directly
|
||||
await Navigator.push(
|
||||
await navigateToVideoPlayer(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => VideoPlayerScreen(
|
||||
metadata: metadata,
|
||||
userProfile: widget.userProfile,
|
||||
),
|
||||
),
|
||||
metadata: metadata,
|
||||
);
|
||||
appLogger.d(
|
||||
'Returned from playback, refreshing metadata',
|
||||
@@ -772,120 +748,125 @@ class _MediaDetailScreenState extends State<MediaDetailScreen> {
|
||||
_updateWatchState();
|
||||
}
|
||||
},
|
||||
child: InkWell(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Row(
|
||||
children: [
|
||||
// Season poster
|
||||
if (season.thumb != null)
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Consumer<PlexClientProvider>(
|
||||
builder: (context, clientProvider, child) {
|
||||
final client = clientProvider.client;
|
||||
if (client == null) {
|
||||
return Container(
|
||||
width: 80,
|
||||
height: 120,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
child: const Icon(Icons.movie, size: 32),
|
||||
);
|
||||
}
|
||||
return CachedNetworkImage(
|
||||
imageUrl: client.getThumbnailUrl(season.thumb),
|
||||
width: 80,
|
||||
height: 120,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
width: 80,
|
||||
height: 120,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
errorWidget: (context, url, error) => Container(
|
||||
width: 80,
|
||||
height: 120,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
child: const Icon(Icons.movie, size: 32),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
else
|
||||
Container(
|
||||
width: 80,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
child: Semantics(
|
||||
label: "media-season-${season.ratingKey}",
|
||||
identifier: "media-season-${season.ratingKey}",
|
||||
button: true,
|
||||
hint: "Tap to view ${season.title}",
|
||||
child: InkWell(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Row(
|
||||
children: [
|
||||
// Season poster
|
||||
if (season.thumb != null)
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: const Icon(Icons.movie, size: 32),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// Season info
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
season.title,
|
||||
style: Theme.of(context).textTheme.titleMedium
|
||||
?.copyWith(fontWeight: FontWeight.bold),
|
||||
child: Consumer<PlexClientProvider>(
|
||||
builder: (context, clientProvider, child) {
|
||||
final client = clientProvider.client;
|
||||
if (client == null) {
|
||||
return Container(
|
||||
width: 80,
|
||||
height: 120,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
child: const Icon(Icons.movie, size: 32),
|
||||
);
|
||||
}
|
||||
return CachedNetworkImage(
|
||||
imageUrl: client.getThumbnailUrl(season.thumb),
|
||||
width: 80,
|
||||
height: 120,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
width: 80,
|
||||
height: 120,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
errorWidget: (context, url, error) => Container(
|
||||
width: 80,
|
||||
height: 120,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
child: const Icon(Icons.movie, size: 32),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
if (season.leafCount != null)
|
||||
)
|
||||
else
|
||||
Container(
|
||||
width: 80,
|
||||
height: 120,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: const Icon(Icons.movie, size: 32),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// Season info
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${season.leafCount} episodes',
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.bodyMedium?.copyWith(color: Colors.grey),
|
||||
season.title,
|
||||
style: Theme.of(context).textTheme.titleMedium
|
||||
?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (season.viewedLeafCount != null &&
|
||||
season.leafCount != null)
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 200,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: LinearProgressIndicator(
|
||||
value:
|
||||
season.viewedLeafCount! /
|
||||
season.leafCount!,
|
||||
backgroundColor: tokens(context).outline,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Theme.of(context).colorScheme.primary,
|
||||
const SizedBox(height: 4),
|
||||
if (season.leafCount != null)
|
||||
Text(
|
||||
'${season.leafCount} episodes',
|
||||
style: Theme.of(context).textTheme.bodyMedium
|
||||
?.copyWith(color: Colors.grey),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (season.viewedLeafCount != null &&
|
||||
season.leafCount != null)
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 200,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: LinearProgressIndicator(
|
||||
value:
|
||||
season.viewedLeafCount! /
|
||||
season.leafCount!,
|
||||
backgroundColor: tokens(context).outline,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
minHeight: 6,
|
||||
),
|
||||
minHeight: 6,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${season.viewedLeafCount}/${season.leafCount} watched',
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'${season.viewedLeafCount}/${season.leafCount} watched',
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const Icon(Icons.chevron_right),
|
||||
],
|
||||
const Icon(Icons.chevron_right),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -2,7 +2,6 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../client/plex_client.dart';
|
||||
import '../models/plex_metadata.dart';
|
||||
import '../models/plex_user_profile.dart';
|
||||
import '../utils/provider_extensions.dart';
|
||||
import '../widgets/media_card.dart';
|
||||
import '../widgets/desktop_app_bar.dart';
|
||||
@@ -10,9 +9,7 @@ import '../mixins/refreshable.dart';
|
||||
import '../mixins/item_updatable.dart';
|
||||
|
||||
class SearchScreen extends StatefulWidget {
|
||||
final PlexUserProfile? userProfile;
|
||||
|
||||
const SearchScreen({super.key, this.userProfile});
|
||||
const SearchScreen({super.key});
|
||||
|
||||
@override
|
||||
State<SearchScreen> createState() => _SearchScreenState();
|
||||
@@ -228,7 +225,6 @@ class _SearchScreenState extends State<SearchScreen>
|
||||
key: Key(item.ratingKey),
|
||||
item: item,
|
||||
onRefresh: updateItem,
|
||||
userProfile: widget.userProfile,
|
||||
);
|
||||
}, childCount: _searchResults.length),
|
||||
),
|
||||
|
||||
@@ -3,20 +3,18 @@ import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../client/plex_client.dart';
|
||||
import '../models/plex_metadata.dart';
|
||||
import '../models/plex_user_profile.dart';
|
||||
import '../providers/plex_client_provider.dart';
|
||||
import '../utils/provider_extensions.dart';
|
||||
import '../utils/video_player_navigation.dart';
|
||||
import '../widgets/desktop_app_bar.dart';
|
||||
import '../widgets/media_context_menu.dart';
|
||||
import '../mixins/item_updatable.dart';
|
||||
import '../theme/theme_helper.dart';
|
||||
import 'video_player_screen.dart';
|
||||
|
||||
class SeasonDetailScreen extends StatefulWidget {
|
||||
final PlexMetadata season;
|
||||
final PlexUserProfile? userProfile;
|
||||
|
||||
const SeasonDetailScreen({super.key, required this.season, this.userProfile});
|
||||
const SeasonDetailScreen({super.key, required this.season});
|
||||
|
||||
@override
|
||||
State<SeasonDetailScreen> createState() => _SeasonDetailScreenState();
|
||||
@@ -136,15 +134,7 @@ class _SeasonDetailScreenState extends State<SeasonDetailScreen>
|
||||
metadata: episode,
|
||||
onRefresh: updateItem,
|
||||
onTap: () async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => VideoPlayerScreen(
|
||||
metadata: episode,
|
||||
userProfile: widget.userProfile,
|
||||
),
|
||||
),
|
||||
);
|
||||
await navigateToVideoPlayer(context, metadata: episode);
|
||||
// Refresh episodes when returning from video player
|
||||
_loadEpisodes();
|
||||
},
|
||||
|
||||
@@ -22,8 +22,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
|
||||
bool _enableDebugLogging = false;
|
||||
bool _enableHardwareDecoding = true;
|
||||
int _videoBufferSize = 64;
|
||||
int _audioBufferSize = 8;
|
||||
int _bufferSize = 128;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -38,8 +37,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
setState(() {
|
||||
_enableDebugLogging = _settingsService.getEnableDebugLogging();
|
||||
_enableHardwareDecoding = _settingsService.getEnableHardwareDecoding();
|
||||
_videoBufferSize = _settingsService.getVideoBufferSize();
|
||||
_audioBufferSize = _settingsService.getAudioBufferSize();
|
||||
_bufferSize = _settingsService.getBufferSize();
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
@@ -47,9 +45,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_isLoading) {
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
return const Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
@@ -87,9 +83,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(
|
||||
'Appearance',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
Consumer<ThemeProvider>(
|
||||
@@ -117,9 +113,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(
|
||||
'Video Playback',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
SwitchListTile(
|
||||
@@ -136,17 +132,10 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.memory),
|
||||
title: const Text('Video Buffer Size'),
|
||||
subtitle: Text('${_videoBufferSize}MB'),
|
||||
title: const Text('Buffer Size'),
|
||||
subtitle: Text('${_bufferSize}MB'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showBufferSizeDialog(true),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.audiotrack),
|
||||
title: const Text('Audio Buffer Size'),
|
||||
subtitle: Text('${_audioBufferSize}MB'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showBufferSizeDialog(false),
|
||||
onTap: () => _showBufferSizeDialog(),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -162,9 +151,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(
|
||||
'Keyboard Shortcuts',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
@@ -179,7 +168,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildAdvancedSection() {
|
||||
return Card(
|
||||
child: Column(
|
||||
@@ -189,9 +177,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(
|
||||
'Advanced',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
SwitchListTile(
|
||||
@@ -242,7 +230,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void _showThemeDialog(ThemeProvider themeProvider) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -302,36 +289,28 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void _showBufferSizeDialog(bool isVideo) {
|
||||
final currentSize = isVideo ? _videoBufferSize : _audioBufferSize;
|
||||
final title = isVideo ? 'Video Buffer Size' : 'Audio Buffer Size';
|
||||
final options = isVideo ? [16, 32, 64, 128, 256] : [2, 4, 8, 16, 32];
|
||||
void _showBufferSizeDialog() {
|
||||
final options = [64, 128, 256, 512, 1024];
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text(title),
|
||||
title: const Text('Buffer Size'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: options.map((size) {
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
currentSize == size
|
||||
_bufferSize == size
|
||||
? Icons.radio_button_checked
|
||||
: Icons.radio_button_unchecked,
|
||||
),
|
||||
title: Text('${size}MB'),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
if (isVideo) {
|
||||
_videoBufferSize = size;
|
||||
_settingsService.setVideoBufferSize(size);
|
||||
} else {
|
||||
_audioBufferSize = size;
|
||||
_settingsService.setAudioBufferSize(size);
|
||||
}
|
||||
_bufferSize = size;
|
||||
_settingsService.setBufferSize(size);
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
@@ -353,9 +332,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => _KeyboardShortcutsScreen(
|
||||
keyboardService: _keyboardService,
|
||||
),
|
||||
builder: (context) =>
|
||||
_KeyboardShortcutsScreen(keyboardService: _keyboardService),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -417,7 +395,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
if (mounted) {
|
||||
navigator.pop();
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(content: Text('Settings reset successfully')),
|
||||
const SnackBar(
|
||||
content: Text('Settings reset successfully'),
|
||||
),
|
||||
);
|
||||
// Reload settings
|
||||
_loadSettings();
|
||||
@@ -430,7 +410,6 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class _KeyboardShortcutsScreen extends StatefulWidget {
|
||||
@@ -439,7 +418,8 @@ class _KeyboardShortcutsScreen extends StatefulWidget {
|
||||
const _KeyboardShortcutsScreen({required this.keyboardService});
|
||||
|
||||
@override
|
||||
State<_KeyboardShortcutsScreen> createState() => _KeyboardShortcutsScreenState();
|
||||
State<_KeyboardShortcutsScreen> createState() =>
|
||||
_KeyboardShortcutsScreenState();
|
||||
}
|
||||
|
||||
class _KeyboardShortcutsScreenState extends State<_KeyboardShortcutsScreen> {
|
||||
@@ -463,9 +443,7 @@ class _KeyboardShortcutsScreenState extends State<_KeyboardShortcutsScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_isLoading) {
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
return const Scaffold(body: Center(child: CircularProgressIndicator()));
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
@@ -482,7 +460,9 @@ class _KeyboardShortcutsScreenState extends State<_KeyboardShortcutsScreen> {
|
||||
await _loadHotkeys();
|
||||
if (mounted) {
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(content: Text('Shortcuts reset to defaults')),
|
||||
const SnackBar(
|
||||
content: Text('Shortcuts reset to defaults'),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -493,34 +473,38 @@ class _KeyboardShortcutsScreenState extends State<_KeyboardShortcutsScreen> {
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
final actions = _hotkeys.keys.toList();
|
||||
final action = actions[index];
|
||||
final hotkey = _hotkeys[action]!;
|
||||
delegate: SliverChildBuilderDelegate((context, index) {
|
||||
final actions = _hotkeys.keys.toList();
|
||||
final action = actions[index];
|
||||
final hotkey = _hotkeys[action]!;
|
||||
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
child: ListTile(
|
||||
title: Text(widget.keyboardService.getActionDisplayName(action)),
|
||||
subtitle: Text(action),
|
||||
trailing: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Theme.of(context).dividerColor),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
widget.keyboardService.formatHotkey(hotkey),
|
||||
style: const TextStyle(fontFamily: 'monospace'),
|
||||
),
|
||||
),
|
||||
onTap: () => _editHotkey(action, hotkey),
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
child: ListTile(
|
||||
title: Text(
|
||||
widget.keyboardService.getActionDisplayName(action),
|
||||
),
|
||||
);
|
||||
},
|
||||
childCount: _hotkeys.length,
|
||||
),
|
||||
subtitle: Text(action),
|
||||
trailing: Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 6,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Theme.of(context).dividerColor,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
widget.keyboardService.formatHotkey(hotkey),
|
||||
style: const TextStyle(fontFamily: 'monospace'),
|
||||
),
|
||||
),
|
||||
onTap: () => _editHotkey(action, hotkey),
|
||||
),
|
||||
);
|
||||
}, childCount: _hotkeys.length),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -540,12 +524,16 @@ class _KeyboardShortcutsScreenState extends State<_KeyboardShortcutsScreen> {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
|
||||
// Check for conflicts
|
||||
final existingAction = widget.keyboardService.getActionForHotkey(newHotkey);
|
||||
final existingAction = widget.keyboardService.getActionForHotkey(
|
||||
newHotkey,
|
||||
);
|
||||
if (existingAction != null && existingAction != action) {
|
||||
navigator.pop();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Shortcut already assigned to ${widget.keyboardService.getActionDisplayName(existingAction)}'),
|
||||
content: Text(
|
||||
'Shortcut already assigned to ${widget.keyboardService.getActionDisplayName(existingAction)}',
|
||||
),
|
||||
),
|
||||
);
|
||||
return;
|
||||
@@ -564,7 +552,9 @@ class _KeyboardShortcutsScreenState extends State<_KeyboardShortcutsScreen> {
|
||||
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Shortcut updated for ${widget.keyboardService.getActionDisplayName(action)}'),
|
||||
content: Text(
|
||||
'Shortcut updated for ${widget.keyboardService.getActionDisplayName(action)}',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -574,4 +564,4 @@ class _KeyboardShortcutsScreenState extends State<_KeyboardShortcutsScreen> {
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,16 @@ import '../utils/provider_extensions.dart';
|
||||
import '../widgets/plex_video_controls.dart';
|
||||
import '../utils/language_codes.dart';
|
||||
import '../utils/app_logger.dart';
|
||||
import '../services/settings_service.dart';
|
||||
import '../utils/orientation_helper.dart';
|
||||
import '../utils/video_player_navigation.dart';
|
||||
import '../utils/platform_detector.dart';
|
||||
|
||||
class VideoPlayerScreen extends StatefulWidget {
|
||||
final PlexMetadata metadata;
|
||||
final AudioTrack? preferredAudioTrack;
|
||||
final SubtitleTrack? preferredSubtitleTrack;
|
||||
final double? preferredPlaybackRate;
|
||||
final PlexUserProfile? userProfile;
|
||||
|
||||
const VideoPlayerScreen({
|
||||
super.key,
|
||||
@@ -24,7 +27,6 @@ class VideoPlayerScreen extends StatefulWidget {
|
||||
this.preferredAudioTrack,
|
||||
this.preferredSubtitleTrack,
|
||||
this.preferredPlaybackRate,
|
||||
this.userProfile,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -32,23 +34,22 @@ class VideoPlayerScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
late final Player player;
|
||||
late final VideoController controller;
|
||||
Player? player;
|
||||
VideoController? controller;
|
||||
bool _isPlayerInitialized = false;
|
||||
Timer? _progressTimer;
|
||||
PlexMetadata? _nextEpisode;
|
||||
PlexMetadata? _previousEpisode;
|
||||
bool _isLoadingNext = false;
|
||||
bool _showPlayNextDialog = false;
|
||||
PlexClientProvider? _cachedClientProvider;
|
||||
bool _isPhone = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
appLogger.d('VideoPlayerScreen initialized for: ${widget.metadata.title}');
|
||||
if (widget.userProfile != null) {
|
||||
appLogger.d('Using user profile for track selection');
|
||||
}
|
||||
if (widget.preferredAudioTrack != null) {
|
||||
appLogger.d(
|
||||
'Preferred audio track: ${widget.preferredAudioTrack!.title ?? widget.preferredAudioTrack!.id} (${widget.preferredAudioTrack!.language ?? "unknown"})',
|
||||
@@ -61,27 +62,8 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
appLogger.d('Preferred subtitle track: $subtitleDesc');
|
||||
}
|
||||
|
||||
// Create player and controller
|
||||
player = Player(configuration: PlayerConfiguration(libass: true));
|
||||
controller = VideoController(player);
|
||||
|
||||
// Get the video URL and start playback
|
||||
_startPlayback();
|
||||
|
||||
// Set fullscreen mode and landscape orientation
|
||||
_setLandscapeOrientation();
|
||||
|
||||
// Listen to playback state changes
|
||||
player.stream.playing.listen(_onPlayingStateChanged);
|
||||
|
||||
// Listen to completion
|
||||
player.stream.completed.listen(_onVideoCompleted);
|
||||
|
||||
// Start periodic progress updates
|
||||
_startProgressTracking();
|
||||
|
||||
// Load next/previous episodes
|
||||
_loadAdjacentEpisodes();
|
||||
// Initialize player asynchronously with buffer size from settings
|
||||
_initializePlayer();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -96,16 +78,74 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
_cachedClientProvider = null;
|
||||
}
|
||||
|
||||
// Ensure landscape orientation is set even after navigation
|
||||
_setLandscapeOrientation();
|
||||
// Cache device type for safe access in dispose()
|
||||
try {
|
||||
_isPhone = PlatformDetector.isPhone(context);
|
||||
} catch (e) {
|
||||
appLogger.w('Failed to determine device type', error: e);
|
||||
_isPhone = false; // Default to tablet/desktop (all orientations)
|
||||
}
|
||||
}
|
||||
|
||||
void _setLandscapeOrientation() {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.landscapeRight,
|
||||
]);
|
||||
OrientationHelper.setLandscapeOrientation();
|
||||
}
|
||||
|
||||
Future<void> _initializePlayer() async {
|
||||
try {
|
||||
// Load buffer size from settings
|
||||
final settingsService = await SettingsService.getInstance();
|
||||
final bufferSizeMB = settingsService.getBufferSize();
|
||||
final bufferSizeBytes = bufferSizeMB * 1024 * 1024;
|
||||
|
||||
// Create player with configuration
|
||||
player = Player(
|
||||
configuration: PlayerConfiguration(
|
||||
libass: true,
|
||||
bufferSize: bufferSizeBytes,
|
||||
),
|
||||
);
|
||||
controller = VideoController(player!);
|
||||
|
||||
// Notify that player is ready
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isPlayerInitialized = true;
|
||||
});
|
||||
}
|
||||
|
||||
// Get the video URL and start playback
|
||||
_startPlayback();
|
||||
|
||||
// Set fullscreen mode and landscape orientation
|
||||
if (mounted) {
|
||||
try {
|
||||
_setLandscapeOrientation();
|
||||
} catch (e) {
|
||||
appLogger.w('Failed to set landscape orientation', error: e);
|
||||
// Don't crash if orientation fails - video can still play
|
||||
}
|
||||
}
|
||||
|
||||
// Listen to playback state changes
|
||||
player!.stream.playing.listen(_onPlayingStateChanged);
|
||||
|
||||
// Listen to completion
|
||||
player!.stream.completed.listen(_onVideoCompleted);
|
||||
|
||||
// Start periodic progress updates
|
||||
_startProgressTracking();
|
||||
|
||||
// Load next/previous episodes
|
||||
_loadAdjacentEpisodes();
|
||||
} catch (e) {
|
||||
appLogger.e('Failed to initialize player', error: e);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isPlayerInitialized = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadAdjacentEpisodes() async {
|
||||
@@ -145,11 +185,11 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
|
||||
if (videoUrl != null) {
|
||||
// Open video without auto-playing
|
||||
await player.open(Media(videoUrl), play: false);
|
||||
await player!.open(Media(videoUrl), play: false);
|
||||
|
||||
// Wait for media to be ready (duration > 0)
|
||||
int attempts = 0;
|
||||
while (player.state.duration.inMilliseconds == 0 && attempts < 50) {
|
||||
while (player!.state.duration.inMilliseconds == 0 && attempts < 100) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
attempts++;
|
||||
}
|
||||
@@ -160,11 +200,11 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
final resumePosition = Duration(
|
||||
milliseconds: widget.metadata.viewOffset!,
|
||||
);
|
||||
await player.seek(resumePosition);
|
||||
await player!.seek(resumePosition);
|
||||
}
|
||||
|
||||
// Start playback after seeking
|
||||
await player.play();
|
||||
await player!.play();
|
||||
|
||||
// Wait for tracks to be loaded, then apply preferred tracks
|
||||
_waitForTracksAndApply();
|
||||
@@ -192,22 +232,38 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
// Send final stopped state
|
||||
_sendProgress('stopped');
|
||||
|
||||
// Restore system UI
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
// Restore portrait-only orientation
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
// Restore system UI and orientation preferences
|
||||
OrientationHelper.restoreSystemUI();
|
||||
|
||||
player.dispose();
|
||||
// Restore orientation based on cached device type (no context needed)
|
||||
try {
|
||||
if (_isPhone) {
|
||||
// Phone: portrait only
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
} else {
|
||||
// Tablet/Desktop: all orientations
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.landscapeRight,
|
||||
]);
|
||||
}
|
||||
} catch (e) {
|
||||
appLogger.w('Failed to restore orientation in dispose', error: e);
|
||||
}
|
||||
|
||||
player?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _startProgressTracking() {
|
||||
// Send progress update every 10 seconds
|
||||
_progressTimer = Timer.periodic(const Duration(seconds: 10), (timer) {
|
||||
if (player.state.playing) {
|
||||
if (player?.state.playing ?? false) {
|
||||
_sendProgress('playing');
|
||||
}
|
||||
});
|
||||
@@ -416,6 +472,9 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
Future<void> processTracks(Tracks tracks) async {
|
||||
appLogger.d('Starting track selection process');
|
||||
|
||||
// Get profile settings for track selection
|
||||
final profileSettings = context.profileSettings;
|
||||
|
||||
// Get real tracks (excluding auto and no)
|
||||
final realAudioTracks = tracks.audio
|
||||
.where((t) => t.id != 'auto' && t.id != 'no')
|
||||
@@ -462,11 +521,11 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
}
|
||||
|
||||
// Priority 2: If no preferred track matched, try user profile preferences
|
||||
if (trackToSelect == null && widget.userProfile != null) {
|
||||
if (trackToSelect == null && profileSettings != null) {
|
||||
appLogger.d('Priority 2: Checking user profile preferences');
|
||||
trackToSelect = _findAudioTrackByProfile(
|
||||
realAudioTracks,
|
||||
widget.userProfile!,
|
||||
profileSettings,
|
||||
);
|
||||
} else if (trackToSelect == null) {
|
||||
appLogger.d('Priority 2: No user profile available');
|
||||
@@ -488,7 +547,7 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
appLogger.i(
|
||||
'Final audio selection: ${trackToSelect.title ?? "Track ${trackToSelect.id}"} (${trackToSelect.language ?? "unknown"})',
|
||||
);
|
||||
player.setAudioTrack(trackToSelect);
|
||||
player!.setAudioTrack(trackToSelect);
|
||||
} else {
|
||||
appLogger.d('No audio tracks available');
|
||||
}
|
||||
@@ -524,12 +583,12 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
|
||||
// Priority 2: If no preferred match, apply user profile preferences
|
||||
if (subtitleToSelect == null &&
|
||||
widget.userProfile != null &&
|
||||
profileSettings != null &&
|
||||
realSubtitleTracks.isNotEmpty) {
|
||||
appLogger.d('Priority 2: Checking user profile preferences');
|
||||
subtitleToSelect = _findSubtitleTrackByProfile(
|
||||
realSubtitleTracks,
|
||||
widget.userProfile!,
|
||||
profileSettings,
|
||||
);
|
||||
} else if (subtitleToSelect == null && realSubtitleTracks.isNotEmpty) {
|
||||
appLogger.d('Priority 2: No user profile available');
|
||||
@@ -561,21 +620,21 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
? 'OFF'
|
||||
: '${subtitleToSelect.title ?? "Track ${subtitleToSelect.id}"} (${subtitleToSelect.language ?? "unknown"})';
|
||||
appLogger.i('Final subtitle selection: $finalSubtitle');
|
||||
player.setSubtitleTrack(subtitleToSelect);
|
||||
player!.setSubtitleTrack(subtitleToSelect);
|
||||
|
||||
// Set playback rate if preferred rate was provided
|
||||
if (widget.preferredPlaybackRate != null) {
|
||||
appLogger.d(
|
||||
'Setting preferred playback rate: ${widget.preferredPlaybackRate}x',
|
||||
);
|
||||
player.setRate(widget.preferredPlaybackRate!);
|
||||
player!.setRate(widget.preferredPlaybackRate!);
|
||||
}
|
||||
|
||||
appLogger.d('Track selection complete');
|
||||
}
|
||||
|
||||
// Check if tracks are already available in current state
|
||||
final currentTracks = player.state.tracks;
|
||||
final currentTracks = player!.state.tracks;
|
||||
if (currentTracks.audio.isNotEmpty || currentTracks.subtitle.isNotEmpty) {
|
||||
await processTracks(currentTracks);
|
||||
return;
|
||||
@@ -583,7 +642,7 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
|
||||
// If not, listen to tracks stream for when they become available
|
||||
bool applied = false;
|
||||
final subscription = player.stream.tracks.listen((tracks) async {
|
||||
final subscription = player!.stream.tracks.listen((tracks) async {
|
||||
// Check if tracks are loaded (have at least one track) and not yet applied
|
||||
if (!applied && (tracks.audio.isNotEmpty || tracks.subtitle.isNotEmpty)) {
|
||||
applied = true;
|
||||
@@ -603,8 +662,11 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
}
|
||||
|
||||
void _sendProgress(String state) {
|
||||
final position = player.state.position.inMilliseconds;
|
||||
final duration = player.state.duration.inMilliseconds;
|
||||
// Don't send misleading data if player isn't available
|
||||
if (player == null) return;
|
||||
|
||||
final position = player!.state.position.inMilliseconds;
|
||||
final duration = player!.state.duration.inMilliseconds;
|
||||
|
||||
if (duration > 0) {
|
||||
final clientProvider = _cachedClientProvider;
|
||||
@@ -650,39 +712,60 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
|
||||
/// Navigates to a new episode, preserving playback state and track selections
|
||||
Future<void> _navigateToEpisode(PlexMetadata episodeMetadata) async {
|
||||
// If player isn't available, navigate without preserving settings
|
||||
if (player == null) {
|
||||
if (mounted) {
|
||||
navigateToVideoPlayer(
|
||||
context,
|
||||
metadata: episodeMetadata,
|
||||
usePushReplacement: true,
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Capture current track selection BEFORE pausing
|
||||
final currentAudioTrack = player.state.track.audio;
|
||||
final currentSubtitleTrack = player.state.track.subtitle;
|
||||
final currentAudioTrack = player!.state.track.audio;
|
||||
final currentSubtitleTrack = player!.state.track.subtitle;
|
||||
|
||||
// Pause and stop current playback
|
||||
player.pause();
|
||||
player!.pause();
|
||||
_progressTimer?.cancel();
|
||||
_sendProgress('stopped');
|
||||
|
||||
// Navigate to the episode using pushReplacement to destroy current player
|
||||
if (mounted) {
|
||||
final currentRate = player.state.rate;
|
||||
Navigator.of(context).pushReplacement(
|
||||
PageRouteBuilder(
|
||||
pageBuilder: (context, animation, secondaryAnimation) =>
|
||||
VideoPlayerScreen(
|
||||
metadata: episodeMetadata,
|
||||
preferredAudioTrack: currentAudioTrack,
|
||||
preferredSubtitleTrack: currentSubtitleTrack,
|
||||
preferredPlaybackRate: currentRate,
|
||||
userProfile: widget.userProfile,
|
||||
),
|
||||
transitionDuration: Duration.zero,
|
||||
reverseTransitionDuration: Duration.zero,
|
||||
),
|
||||
final currentRate = player!.state.rate;
|
||||
navigateToVideoPlayer(
|
||||
context,
|
||||
metadata: episodeMetadata,
|
||||
preferredAudioTrack: currentAudioTrack,
|
||||
preferredSubtitleTrack: currentSubtitleTrack,
|
||||
preferredPlaybackRate: currentRate,
|
||||
usePushReplacement: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Show loading indicator while player initializes
|
||||
if (!_isPlayerInitialized || controller == null || player == null) {
|
||||
return const Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
body: Center(child: CircularProgressIndicator(color: Colors.white)),
|
||||
);
|
||||
}
|
||||
|
||||
return PopScope(
|
||||
canPop: true,
|
||||
canPop:
|
||||
false, // Disable swipe-back gesture to prevent interference with timeline scrubbing
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
// Allow programmatic back navigation from UI controls
|
||||
if (!didPop) {
|
||||
Navigator.of(context).pop(true);
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
body: Stack(
|
||||
@@ -690,9 +773,9 @@ class _VideoPlayerScreenState extends State<VideoPlayerScreen> {
|
||||
// Video player
|
||||
Center(
|
||||
child: Video(
|
||||
controller: controller,
|
||||
controller: controller!,
|
||||
controls: (state) => plexVideoControlsBuilder(
|
||||
player,
|
||||
player!,
|
||||
widget.metadata,
|
||||
onNext: _nextEpisode != null ? _playNext : null,
|
||||
onPrevious: _previousEpisode != null ? _playPrevious : null,
|
||||
|
||||
@@ -7,7 +7,8 @@ import 'settings_service.dart';
|
||||
class KeyboardShortcutsService {
|
||||
static KeyboardShortcutsService? _instance;
|
||||
late SettingsService _settingsService;
|
||||
Map<String, String> _shortcuts = {}; // Legacy string shortcuts for backward compatibility
|
||||
Map<String, String> _shortcuts =
|
||||
{}; // Legacy string shortcuts for backward compatibility
|
||||
Map<String, HotKey> _hotkeys = {}; // New HotKey objects
|
||||
|
||||
KeyboardShortcutsService._();
|
||||
@@ -24,7 +25,8 @@ class KeyboardShortcutsService {
|
||||
_settingsService = await SettingsService.getInstance();
|
||||
// Ensure settings service is fully initialized before loading data
|
||||
await Future.delayed(Duration.zero); // Allow event loop to complete
|
||||
_shortcuts = _settingsService.getKeyboardShortcuts(); // Keep for legacy compatibility
|
||||
_shortcuts = _settingsService
|
||||
.getKeyboardShortcuts(); // Keep for legacy compatibility
|
||||
_hotkeys = await _settingsService.getKeyboardHotkeys(); // Primary method
|
||||
}
|
||||
|
||||
@@ -135,8 +137,6 @@ class KeyboardShortcutsService {
|
||||
return modifiers.isEmpty ? keyName : '${modifiers.join(' + ')} + $keyName';
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Handle keyboard input for video player
|
||||
KeyEventResult handleVideoPlayerKeyEvent(
|
||||
KeyEvent event,
|
||||
@@ -207,8 +207,16 @@ class KeyboardShortcutsService {
|
||||
continue;
|
||||
}
|
||||
|
||||
_executeAction(action, player, onToggleFullscreen, onToggleSubtitles,
|
||||
onNextAudioTrack, onNextSubtitleTrack, onNextChapter, onPreviousChapter);
|
||||
_executeAction(
|
||||
action,
|
||||
player,
|
||||
onToggleFullscreen,
|
||||
onToggleSubtitles,
|
||||
onNextAudioTrack,
|
||||
onNextSubtitleTrack,
|
||||
onNextChapter,
|
||||
onPreviousChapter,
|
||||
);
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
}
|
||||
@@ -366,6 +374,6 @@ class KeyboardShortcutsService {
|
||||
final bModifiers = Set.from(b.modifiers ?? []);
|
||||
|
||||
return aModifiers.length == bModifiers.length &&
|
||||
aModifiers.every((modifier) => bModifiers.contains(modifier));
|
||||
aModifiers.every((modifier) => bModifiers.contains(modifier));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class ServerConnectionService {
|
||||
// Fetch user profile if requested
|
||||
PlexUserProfile? userProfile;
|
||||
if (fetchUserProfile && plexToken != null) {
|
||||
userProfile = await _fetchAndCacheUserProfile(plexToken);
|
||||
userProfile = await _fetchUserProfile(plexToken);
|
||||
}
|
||||
|
||||
// Return success result
|
||||
@@ -123,17 +123,15 @@ class ServerConnectionService {
|
||||
}
|
||||
}
|
||||
|
||||
/// Fetch user profile from Plex API and cache it locally
|
||||
static Future<PlexUserProfile?> _fetchAndCacheUserProfile(
|
||||
String plexToken,
|
||||
) async {
|
||||
/// Fetch user profile from Plex API
|
||||
static Future<PlexUserProfile?> _fetchUserProfile(String plexToken) async {
|
||||
appLogger.d('Fetching user profile from Plex API');
|
||||
try {
|
||||
final authService = await PlexAuthService.create();
|
||||
final profile = await authService.getUserProfile(plexToken);
|
||||
|
||||
appLogger.i(
|
||||
'Successfully fetched user profile',
|
||||
'Successfully fetched user profile from API',
|
||||
error: {
|
||||
'autoSelectAudio': profile.autoSelectAudio,
|
||||
'defaultAudioLanguage': profile.defaultAudioLanguage ?? 'not set',
|
||||
@@ -144,40 +142,9 @@ class ServerConnectionService {
|
||||
},
|
||||
);
|
||||
|
||||
// Cache the profile
|
||||
final storage = await StorageService.getInstance();
|
||||
await storage.saveUserProfile(profile.toJson());
|
||||
appLogger.d('User profile cached locally');
|
||||
|
||||
return profile;
|
||||
} catch (e) {
|
||||
appLogger.w(
|
||||
'Failed to fetch user profile from API, attempting to load from cache',
|
||||
error: e,
|
||||
);
|
||||
|
||||
// Failed to fetch profile, try to load from cache
|
||||
final storage = await StorageService.getInstance();
|
||||
final cachedProfile = storage.getUserProfile();
|
||||
if (cachedProfile != null) {
|
||||
final profile = PlexUserProfile.fromJson(cachedProfile);
|
||||
appLogger.i(
|
||||
'Loaded user profile from cache',
|
||||
error: {
|
||||
'autoSelectAudio': profile.autoSelectAudio,
|
||||
'defaultAudioLanguage': profile.defaultAudioLanguage ?? 'not set',
|
||||
'autoSelectSubtitle': profile.autoSelectSubtitle,
|
||||
'defaultSubtitleLanguage':
|
||||
profile.defaultSubtitleLanguage ?? 'not set',
|
||||
'defaultSubtitleForced': profile.defaultSubtitleForced,
|
||||
},
|
||||
);
|
||||
return profile;
|
||||
}
|
||||
|
||||
appLogger.w(
|
||||
'No cached user profile available, track selection will use defaults',
|
||||
);
|
||||
appLogger.w('Failed to fetch user profile from API', error: e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@ enum ThemeMode { system, light, dark }
|
||||
class SettingsService {
|
||||
static const String _keyThemeMode = 'theme_mode';
|
||||
static const String _keyEnableDebugLogging = 'enable_debug_logging';
|
||||
static const String _keyVideoBufferSize = 'video_buffer_size';
|
||||
static const String _keyAudioBufferSize = 'audio_buffer_size';
|
||||
static const String _keyBufferSize = 'buffer_size';
|
||||
static const String _keyKeyboardShortcuts = 'keyboard_shortcuts';
|
||||
static const String _keyKeyboardHotkeys = 'keyboard_hotkeys';
|
||||
static const String _keyEnableHardwareDecoding = 'enable_hardware_decoding';
|
||||
@@ -40,11 +39,12 @@ class SettingsService {
|
||||
|
||||
ThemeMode getThemeMode() {
|
||||
final modeString = _prefs.getString(_keyThemeMode);
|
||||
return ThemeMode.values
|
||||
.firstWhere((mode) => mode.name == modeString, orElse: () => ThemeMode.system);
|
||||
return ThemeMode.values.firstWhere(
|
||||
(mode) => mode.name == modeString,
|
||||
orElse: () => ThemeMode.system,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Debug Logging
|
||||
Future<void> setEnableDebugLogging(bool enabled) async {
|
||||
await _prefs.setBool(_keyEnableDebugLogging, enabled);
|
||||
@@ -54,22 +54,13 @@ class SettingsService {
|
||||
return _prefs.getBool(_keyEnableDebugLogging) ?? false;
|
||||
}
|
||||
|
||||
// Video Buffer Size (in MB)
|
||||
Future<void> setVideoBufferSize(int sizeInMB) async {
|
||||
await _prefs.setInt(_keyVideoBufferSize, sizeInMB);
|
||||
// Buffer Size (in MB)
|
||||
Future<void> setBufferSize(int sizeInMB) async {
|
||||
await _prefs.setInt(_keyBufferSize, sizeInMB);
|
||||
}
|
||||
|
||||
int getVideoBufferSize() {
|
||||
return _prefs.getInt(_keyVideoBufferSize) ?? 64; // Default 64MB
|
||||
}
|
||||
|
||||
// Audio Buffer Size (in MB)
|
||||
Future<void> setAudioBufferSize(int sizeInMB) async {
|
||||
await _prefs.setInt(_keyAudioBufferSize, sizeInMB);
|
||||
}
|
||||
|
||||
int getAudioBufferSize() {
|
||||
return _prefs.getInt(_keyAudioBufferSize) ?? 8; // Default 8MB
|
||||
int getBufferSize() {
|
||||
return _prefs.getInt(_keyBufferSize) ?? 128; // Default 128MB
|
||||
}
|
||||
|
||||
// Hardware Decoding
|
||||
@@ -78,7 +69,8 @@ class SettingsService {
|
||||
}
|
||||
|
||||
bool getEnableHardwareDecoding() {
|
||||
return _prefs.getBool(_keyEnableHardwareDecoding) ?? true; // Default enabled
|
||||
return _prefs.getBool(_keyEnableHardwareDecoding) ??
|
||||
true; // Default enabled
|
||||
}
|
||||
|
||||
// Preferred Video Codec
|
||||
@@ -130,13 +122,22 @@ class SettingsService {
|
||||
'volume_down': HotKey(key: PhysicalKeyboardKey.arrowDown),
|
||||
'seek_forward': HotKey(key: PhysicalKeyboardKey.arrowRight),
|
||||
'seek_backward': HotKey(key: PhysicalKeyboardKey.arrowLeft),
|
||||
'seek_forward_large': HotKey(key: PhysicalKeyboardKey.arrowRight, modifiers: [HotKeyModifier.shift]),
|
||||
'seek_backward_large': HotKey(key: PhysicalKeyboardKey.arrowLeft, modifiers: [HotKeyModifier.shift]),
|
||||
'seek_forward_large': HotKey(
|
||||
key: PhysicalKeyboardKey.arrowRight,
|
||||
modifiers: [HotKeyModifier.shift],
|
||||
),
|
||||
'seek_backward_large': HotKey(
|
||||
key: PhysicalKeyboardKey.arrowLeft,
|
||||
modifiers: [HotKeyModifier.shift],
|
||||
),
|
||||
'fullscreen_toggle': HotKey(key: PhysicalKeyboardKey.keyF),
|
||||
'mute_toggle': HotKey(key: PhysicalKeyboardKey.keyM),
|
||||
'subtitle_toggle': HotKey(key: PhysicalKeyboardKey.keyS),
|
||||
'audio_track_next': HotKey(key: PhysicalKeyboardKey.keyA),
|
||||
'subtitle_track_next': HotKey(key: PhysicalKeyboardKey.keyS, modifiers: [HotKeyModifier.shift]),
|
||||
'subtitle_track_next': HotKey(
|
||||
key: PhysicalKeyboardKey.keyS,
|
||||
modifiers: [HotKeyModifier.shift],
|
||||
),
|
||||
'chapter_next': HotKey(key: PhysicalKeyboardKey.keyN),
|
||||
'chapter_previous': HotKey(key: PhysicalKeyboardKey.keyP),
|
||||
'speed_increase': HotKey(key: PhysicalKeyboardKey.equal),
|
||||
@@ -156,7 +157,9 @@ class SettingsService {
|
||||
|
||||
try {
|
||||
final decoded = json.decode(jsonString) as Map<String, dynamic>;
|
||||
final shortcuts = decoded.map((key, value) => MapEntry(key, value.toString()));
|
||||
final shortcuts = decoded.map(
|
||||
(key, value) => MapEntry(key, value.toString()),
|
||||
);
|
||||
|
||||
// Merge with defaults to ensure all keys exist
|
||||
final defaults = getDefaultKeyboardShortcuts();
|
||||
@@ -252,28 +255,35 @@ class SettingsService {
|
||||
final keyString = data['key'] as String;
|
||||
final modifierNames = (data['modifiers'] as List<dynamic>).cast<String>();
|
||||
|
||||
final modifiers = modifierNames.map((name) {
|
||||
switch (name) {
|
||||
case 'alt':
|
||||
return HotKeyModifier.alt;
|
||||
case 'control':
|
||||
return HotKeyModifier.control;
|
||||
case 'shift':
|
||||
return HotKeyModifier.shift;
|
||||
case 'meta':
|
||||
return HotKeyModifier.meta;
|
||||
case 'capsLock':
|
||||
return HotKeyModifier.capsLock;
|
||||
case 'fn':
|
||||
return HotKeyModifier.fn;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}).where((m) => m != null).cast<HotKeyModifier>().toList();
|
||||
final modifiers = modifierNames
|
||||
.map((name) {
|
||||
switch (name) {
|
||||
case 'alt':
|
||||
return HotKeyModifier.alt;
|
||||
case 'control':
|
||||
return HotKeyModifier.control;
|
||||
case 'shift':
|
||||
return HotKeyModifier.shift;
|
||||
case 'meta':
|
||||
return HotKeyModifier.meta;
|
||||
case 'capsLock':
|
||||
return HotKeyModifier.capsLock;
|
||||
case 'fn':
|
||||
return HotKeyModifier.fn;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.where((m) => m != null)
|
||||
.cast<HotKeyModifier>()
|
||||
.toList();
|
||||
|
||||
final key = _findKeyByString(keyString);
|
||||
if (key != null) {
|
||||
return HotKey(key: key, modifiers: modifiers.isNotEmpty ? modifiers : null);
|
||||
return HotKey(
|
||||
key: key,
|
||||
modifiers: modifiers.isNotEmpty ? modifiers : null,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore deserialization errors
|
||||
@@ -283,7 +293,6 @@ class SettingsService {
|
||||
|
||||
// Helper method to find PhysicalKeyboardKey by string representation
|
||||
PhysicalKeyboardKey? _findKeyByString(String keyString) {
|
||||
|
||||
// Handle exact string matches first for better performance
|
||||
const keyMap = {
|
||||
'PhysicalKeyboardKey#0002c': PhysicalKeyboardKey.space,
|
||||
@@ -310,7 +319,9 @@ class SettingsService {
|
||||
// Alternative approach: extract USB HID usage code from the toString() output
|
||||
// Format: PhysicalKeyboardKey#ec9ed(usbHidUsage: "0x0007002c", debugName: "Space")
|
||||
try {
|
||||
final usbHidMatch = RegExp(r'usbHidUsage: "0x([0-9a-fA-F]+)"').firstMatch(keyString);
|
||||
final usbHidMatch = RegExp(
|
||||
r'usbHidUsage: "0x([0-9a-fA-F]+)"',
|
||||
).firstMatch(keyString);
|
||||
if (usbHidMatch != null) {
|
||||
final usbHidCode = usbHidMatch.group(1)!.toLowerCase();
|
||||
|
||||
@@ -434,18 +445,30 @@ class SettingsService {
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
if (keyString.contains('f$i') || keyString.contains('F$i')) {
|
||||
switch (i) {
|
||||
case 1: return PhysicalKeyboardKey.f1;
|
||||
case 2: return PhysicalKeyboardKey.f2;
|
||||
case 3: return PhysicalKeyboardKey.f3;
|
||||
case 4: return PhysicalKeyboardKey.f4;
|
||||
case 5: return PhysicalKeyboardKey.f5;
|
||||
case 6: return PhysicalKeyboardKey.f6;
|
||||
case 7: return PhysicalKeyboardKey.f7;
|
||||
case 8: return PhysicalKeyboardKey.f8;
|
||||
case 9: return PhysicalKeyboardKey.f9;
|
||||
case 10: return PhysicalKeyboardKey.f10;
|
||||
case 11: return PhysicalKeyboardKey.f11;
|
||||
case 12: return PhysicalKeyboardKey.f12;
|
||||
case 1:
|
||||
return PhysicalKeyboardKey.f1;
|
||||
case 2:
|
||||
return PhysicalKeyboardKey.f2;
|
||||
case 3:
|
||||
return PhysicalKeyboardKey.f3;
|
||||
case 4:
|
||||
return PhysicalKeyboardKey.f4;
|
||||
case 5:
|
||||
return PhysicalKeyboardKey.f5;
|
||||
case 6:
|
||||
return PhysicalKeyboardKey.f6;
|
||||
case 7:
|
||||
return PhysicalKeyboardKey.f7;
|
||||
case 8:
|
||||
return PhysicalKeyboardKey.f8;
|
||||
case 9:
|
||||
return PhysicalKeyboardKey.f9;
|
||||
case 10:
|
||||
return PhysicalKeyboardKey.f10;
|
||||
case 11:
|
||||
return PhysicalKeyboardKey.f11;
|
||||
case 12:
|
||||
return PhysicalKeyboardKey.f12;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -454,35 +477,63 @@ class SettingsService {
|
||||
for (int i = 0; i <= 9; i++) {
|
||||
if (keyString.contains('digit$i') || keyString.contains('Digit$i')) {
|
||||
switch (i) {
|
||||
case 0: return PhysicalKeyboardKey.digit0;
|
||||
case 1: return PhysicalKeyboardKey.digit1;
|
||||
case 2: return PhysicalKeyboardKey.digit2;
|
||||
case 3: return PhysicalKeyboardKey.digit3;
|
||||
case 4: return PhysicalKeyboardKey.digit4;
|
||||
case 5: return PhysicalKeyboardKey.digit5;
|
||||
case 6: return PhysicalKeyboardKey.digit6;
|
||||
case 7: return PhysicalKeyboardKey.digit7;
|
||||
case 8: return PhysicalKeyboardKey.digit8;
|
||||
case 9: return PhysicalKeyboardKey.digit9;
|
||||
case 0:
|
||||
return PhysicalKeyboardKey.digit0;
|
||||
case 1:
|
||||
return PhysicalKeyboardKey.digit1;
|
||||
case 2:
|
||||
return PhysicalKeyboardKey.digit2;
|
||||
case 3:
|
||||
return PhysicalKeyboardKey.digit3;
|
||||
case 4:
|
||||
return PhysicalKeyboardKey.digit4;
|
||||
case 5:
|
||||
return PhysicalKeyboardKey.digit5;
|
||||
case 6:
|
||||
return PhysicalKeyboardKey.digit6;
|
||||
case 7:
|
||||
return PhysicalKeyboardKey.digit7;
|
||||
case 8:
|
||||
return PhysicalKeyboardKey.digit8;
|
||||
case 9:
|
||||
return PhysicalKeyboardKey.digit9;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try letter keys A-Z (both upper and lower case patterns)
|
||||
const letterKeys = {
|
||||
'A': PhysicalKeyboardKey.keyA, 'B': PhysicalKeyboardKey.keyB, 'C': PhysicalKeyboardKey.keyC,
|
||||
'D': PhysicalKeyboardKey.keyD, 'E': PhysicalKeyboardKey.keyE, 'F': PhysicalKeyboardKey.keyF,
|
||||
'G': PhysicalKeyboardKey.keyG, 'H': PhysicalKeyboardKey.keyH, 'I': PhysicalKeyboardKey.keyI,
|
||||
'J': PhysicalKeyboardKey.keyJ, 'K': PhysicalKeyboardKey.keyK, 'L': PhysicalKeyboardKey.keyL,
|
||||
'M': PhysicalKeyboardKey.keyM, 'N': PhysicalKeyboardKey.keyN, 'O': PhysicalKeyboardKey.keyO,
|
||||
'P': PhysicalKeyboardKey.keyP, 'Q': PhysicalKeyboardKey.keyQ, 'R': PhysicalKeyboardKey.keyR,
|
||||
'S': PhysicalKeyboardKey.keyS, 'T': PhysicalKeyboardKey.keyT, 'U': PhysicalKeyboardKey.keyU,
|
||||
'V': PhysicalKeyboardKey.keyV, 'W': PhysicalKeyboardKey.keyW, 'X': PhysicalKeyboardKey.keyX,
|
||||
'Y': PhysicalKeyboardKey.keyY, 'Z': PhysicalKeyboardKey.keyZ,
|
||||
'A': PhysicalKeyboardKey.keyA,
|
||||
'B': PhysicalKeyboardKey.keyB,
|
||||
'C': PhysicalKeyboardKey.keyC,
|
||||
'D': PhysicalKeyboardKey.keyD,
|
||||
'E': PhysicalKeyboardKey.keyE,
|
||||
'F': PhysicalKeyboardKey.keyF,
|
||||
'G': PhysicalKeyboardKey.keyG,
|
||||
'H': PhysicalKeyboardKey.keyH,
|
||||
'I': PhysicalKeyboardKey.keyI,
|
||||
'J': PhysicalKeyboardKey.keyJ,
|
||||
'K': PhysicalKeyboardKey.keyK,
|
||||
'L': PhysicalKeyboardKey.keyL,
|
||||
'M': PhysicalKeyboardKey.keyM,
|
||||
'N': PhysicalKeyboardKey.keyN,
|
||||
'O': PhysicalKeyboardKey.keyO,
|
||||
'P': PhysicalKeyboardKey.keyP,
|
||||
'Q': PhysicalKeyboardKey.keyQ,
|
||||
'R': PhysicalKeyboardKey.keyR,
|
||||
'S': PhysicalKeyboardKey.keyS,
|
||||
'T': PhysicalKeyboardKey.keyT,
|
||||
'U': PhysicalKeyboardKey.keyU,
|
||||
'V': PhysicalKeyboardKey.keyV,
|
||||
'W': PhysicalKeyboardKey.keyW,
|
||||
'X': PhysicalKeyboardKey.keyX,
|
||||
'Y': PhysicalKeyboardKey.keyY,
|
||||
'Z': PhysicalKeyboardKey.keyZ,
|
||||
};
|
||||
|
||||
for (final entry in letterKeys.entries) {
|
||||
if (keyString.contains('key${entry.key}') || keyString.contains('Key${entry.key}')) {
|
||||
if (keyString.contains('key${entry.key}') ||
|
||||
keyString.contains('Key${entry.key}')) {
|
||||
return entry.value;
|
||||
}
|
||||
}
|
||||
@@ -491,14 +542,12 @@ class SettingsService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Reset all settings to defaults
|
||||
Future<void> resetAllSettings() async {
|
||||
await Future.wait([
|
||||
_prefs.remove(_keyThemeMode),
|
||||
_prefs.remove(_keyEnableDebugLogging),
|
||||
_prefs.remove(_keyVideoBufferSize),
|
||||
_prefs.remove(_keyAudioBufferSize),
|
||||
_prefs.remove(_keyBufferSize),
|
||||
_prefs.remove(_keyKeyboardShortcuts),
|
||||
_prefs.remove(_keyKeyboardHotkeys),
|
||||
_prefs.remove(_keyEnableHardwareDecoding),
|
||||
@@ -522,13 +571,14 @@ class SettingsService {
|
||||
return {
|
||||
'themeMode': getThemeMode().name,
|
||||
'enableDebugLogging': getEnableDebugLogging(),
|
||||
'videoBufferSize': getVideoBufferSize(),
|
||||
'audioBufferSize': getAudioBufferSize(),
|
||||
'bufferSize': getBufferSize(),
|
||||
'enableHardwareDecoding': getEnableHardwareDecoding(),
|
||||
'preferredVideoCodec': getPreferredVideoCodec(),
|
||||
'preferredAudioCodec': getPreferredAudioCodec(),
|
||||
'keyboardShortcuts': getKeyboardShortcuts(),
|
||||
'keyboardHotkeys': hotkeys.map((key, value) => MapEntry(key, _serializeHotKey(value))),
|
||||
'keyboardHotkeys': hotkeys.map(
|
||||
(key, value) => MapEntry(key, _serializeHotKey(value)),
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,10 +240,7 @@ class StorageService {
|
||||
|
||||
// Clear all user-related data (for logout)
|
||||
Future<void> clearUserData() async {
|
||||
await Future.wait([
|
||||
clearCredentials(),
|
||||
clearLibraryPreferences(),
|
||||
]);
|
||||
await Future.wait([clearCredentials(), clearLibraryPreferences()]);
|
||||
}
|
||||
|
||||
// Update current user after switching
|
||||
|
||||
@@ -11,14 +11,4 @@ import 'package:logger/logger.dart';
|
||||
/// appLogger.w('Warning message');
|
||||
/// appLogger.e('Error message', error: e, stackTrace: stackTrace);
|
||||
/// ```
|
||||
final appLogger = Logger(
|
||||
printer: PrettyPrinter(
|
||||
methodCount: 2,
|
||||
errorMethodCount: 8,
|
||||
lineLength: 120,
|
||||
colors: true,
|
||||
printEmojis: true,
|
||||
dateTimeFormat: DateTimeFormat.onlyTimeAndSinceStart,
|
||||
),
|
||||
level: Level.debug,
|
||||
);
|
||||
final appLogger = Logger(printer: SimplePrinter(), level: Level.debug);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'platform_detector.dart';
|
||||
|
||||
/// Helper class for managing device orientation preferences across the app.
|
||||
class OrientationHelper {
|
||||
/// Restores default orientation preferences based on device type.
|
||||
///
|
||||
/// For phones: Locks to portrait-only (up and down)
|
||||
/// For tablets/desktop: Allows all orientations
|
||||
///
|
||||
/// This should be called when leaving full-screen experiences like
|
||||
/// the video player to restore the app's default orientation behavior.
|
||||
static void restoreDefaultOrientations(BuildContext context) {
|
||||
final isPhone = PlatformDetector.isPhone(context);
|
||||
|
||||
if (isPhone) {
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
} else {
|
||||
// For tablets and desktop, allow all orientations
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.landscapeRight,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets orientation to landscape-only mode.
|
||||
///
|
||||
/// Used by the video player to force landscape orientation during playback.
|
||||
static void setLandscapeOrientation() {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
||||
SystemChrome.setPreferredOrientations([
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.landscapeRight,
|
||||
]);
|
||||
}
|
||||
|
||||
/// Restores edge-to-edge system UI mode.
|
||||
///
|
||||
/// Should be called when exiting full-screen mode.
|
||||
static void restoreSystemUI() {
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:math';
|
||||
|
||||
/// Utility class for platform detection
|
||||
class PlatformDetector {
|
||||
@@ -13,4 +14,24 @@ class PlatformDetector {
|
||||
static bool isDesktop(BuildContext context) {
|
||||
return !isMobile(context);
|
||||
}
|
||||
|
||||
/// Detects if the device is likely a tablet based on screen size
|
||||
/// Uses diagonal screen size to determine if device is a tablet
|
||||
static bool isTablet(BuildContext context) {
|
||||
final data = MediaQuery.of(context);
|
||||
final size = data.size;
|
||||
final diagonal = sqrt(size.width * size.width + size.height * size.height);
|
||||
final devicePixelRatio = data.devicePixelRatio;
|
||||
|
||||
// Convert diagonal from logical pixels to inches (assuming 160 DPI as baseline)
|
||||
final diagonalInches = diagonal / (devicePixelRatio * 160 / 2.54);
|
||||
|
||||
// Consider devices with diagonal >= 7 inches as tablets
|
||||
return diagonalInches >= 7.0;
|
||||
}
|
||||
|
||||
/// Detects if the device is a phone (mobile but not tablet)
|
||||
static bool isPhone(BuildContext context) {
|
||||
return isMobile(context) && !isTablet(context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
|
||||
import '../providers/plex_client_provider.dart';
|
||||
import '../providers/user_profile_provider.dart';
|
||||
import '../client/plex_client.dart';
|
||||
import '../models/plex_user_profile.dart';
|
||||
|
||||
extension ProviderExtensions on BuildContext {
|
||||
PlexClientProvider get plexClient =>
|
||||
@@ -22,4 +23,7 @@ extension ProviderExtensions on BuildContext {
|
||||
|
||||
// Null-safe client access
|
||||
PlexClient get clientSafe => plexClient.client!;
|
||||
|
||||
// Direct profile settings access (nullable)
|
||||
PlexUserProfile? get profileSettings => userProfile.profileSettings;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
import '../models/plex_metadata.dart';
|
||||
import '../screens/video_player_screen.dart';
|
||||
|
||||
/// Navigates to the VideoPlayerScreen with instant transitions to prevent white flash.
|
||||
///
|
||||
/// This utility function provides a consistent way to navigate to the video player
|
||||
/// across the app, using PageRouteBuilder with zero-duration transitions to eliminate
|
||||
/// the white flash that occurs with MaterialPageRoute.
|
||||
///
|
||||
/// Parameters:
|
||||
/// - [context]: The build context for navigation
|
||||
/// - [metadata]: The Plex metadata for the content to play
|
||||
/// - [preferredAudioTrack]: Optional audio track to select on playback start
|
||||
/// - [preferredSubtitleTrack]: Optional subtitle track to select on playback start
|
||||
/// - [preferredPlaybackRate]: Optional playback speed to set on playback start
|
||||
/// - [usePushReplacement]: If true, replaces current route instead of pushing;
|
||||
/// useful for episode-to-episode navigation. Defaults to false.
|
||||
///
|
||||
/// Returns a Future that completes with a boolean indicating whether the content
|
||||
/// was watched, or null if navigation was cancelled.
|
||||
Future<bool?> navigateToVideoPlayer(
|
||||
BuildContext context, {
|
||||
required PlexMetadata metadata,
|
||||
AudioTrack? preferredAudioTrack,
|
||||
SubtitleTrack? preferredSubtitleTrack,
|
||||
double? preferredPlaybackRate,
|
||||
bool usePushReplacement = false,
|
||||
}) async {
|
||||
final route = PageRouteBuilder<bool>(
|
||||
pageBuilder: (context, animation, secondaryAnimation) => VideoPlayerScreen(
|
||||
metadata: metadata,
|
||||
preferredAudioTrack: preferredAudioTrack,
|
||||
preferredSubtitleTrack: preferredSubtitleTrack,
|
||||
preferredPlaybackRate: preferredPlaybackRate,
|
||||
),
|
||||
transitionDuration: Duration.zero,
|
||||
reverseTransitionDuration: Duration.zero,
|
||||
);
|
||||
|
||||
if (usePushReplacement) {
|
||||
return Navigator.of(context).pushReplacement<bool, bool>(route);
|
||||
} else {
|
||||
return Navigator.push<bool>(context, route);
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ class _HotKeyRecorderWidgetState extends State<HotKeyRecorderWidget> {
|
||||
_recordedHotKey = widget.currentHotKey;
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
|
||||
+139
-88
@@ -2,12 +2,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../models/plex_metadata.dart';
|
||||
import '../models/plex_user_profile.dart';
|
||||
import '../providers/plex_client_provider.dart';
|
||||
import '../utils/provider_extensions.dart';
|
||||
import '../utils/video_player_navigation.dart';
|
||||
import '../screens/media_detail_screen.dart';
|
||||
import '../screens/season_detail_screen.dart';
|
||||
import '../screens/video_player_screen.dart';
|
||||
import '../theme/theme_helper.dart';
|
||||
import 'media_context_menu.dart';
|
||||
|
||||
@@ -16,7 +15,6 @@ class MediaCard extends StatefulWidget {
|
||||
final double? width;
|
||||
final double? height;
|
||||
final void Function(String ratingKey)? onRefresh;
|
||||
final PlexUserProfile? userProfile;
|
||||
|
||||
const MediaCard({
|
||||
super.key,
|
||||
@@ -24,7 +22,6 @@ class MediaCard extends StatefulWidget {
|
||||
this.width,
|
||||
this.height,
|
||||
this.onRefresh,
|
||||
this.userProfile,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -44,14 +41,9 @@ class _MediaCardState extends State<MediaCard>
|
||||
|
||||
// For episodes, start playback directly
|
||||
if (itemType == 'episode') {
|
||||
final result = await Navigator.push<bool>(
|
||||
final result = await navigateToVideoPlayer(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => VideoPlayerScreen(
|
||||
metadata: widget.item,
|
||||
userProfile: widget.userProfile,
|
||||
),
|
||||
),
|
||||
metadata: widget.item,
|
||||
);
|
||||
// Refresh parent screen if result indicates it's needed
|
||||
if (result == true) {
|
||||
@@ -62,10 +54,7 @@ class _MediaCardState extends State<MediaCard>
|
||||
await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => SeasonDetailScreen(
|
||||
season: widget.item,
|
||||
userProfile: widget.userProfile,
|
||||
),
|
||||
builder: (context) => SeasonDetailScreen(season: widget.item),
|
||||
),
|
||||
);
|
||||
// Season screen doesn't return a refresh flag, but we can refresh anyway
|
||||
@@ -75,10 +64,7 @@ class _MediaCardState extends State<MediaCard>
|
||||
final result = await Navigator.push<bool>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MediaDetailScreen(
|
||||
metadata: widget.item,
|
||||
userProfile: widget.userProfile,
|
||||
),
|
||||
builder: (context) => MediaDetailScreen(metadata: widget.item),
|
||||
),
|
||||
);
|
||||
// Refresh parent screen if result indicates it's needed
|
||||
@@ -97,72 +83,80 @@ class _MediaCardState extends State<MediaCard>
|
||||
metadata: widget.item,
|
||||
onRefresh: widget.onRefresh,
|
||||
onTap: () => _handleTap(context),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Poster
|
||||
if (widget.height != null)
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: widget.height,
|
||||
child: _buildPosterWithOverlay(context),
|
||||
)
|
||||
else
|
||||
Expanded(child: _buildPosterWithOverlay(context)),
|
||||
const SizedBox(height: 4),
|
||||
// Text content
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.item.displayTitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13,
|
||||
height: 1.1,
|
||||
),
|
||||
),
|
||||
if (widget.item.displaySubtitle != null)
|
||||
child: Semantics(
|
||||
label: "media-card-${widget.item.ratingKey}",
|
||||
identifier: "media-card-${widget.item.ratingKey}",
|
||||
button: true,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Poster
|
||||
if (widget.height != null)
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: widget.height,
|
||||
child: _buildPosterWithOverlay(context),
|
||||
)
|
||||
else
|
||||
Expanded(child: _buildPosterWithOverlay(context)),
|
||||
const SizedBox(height: 4),
|
||||
// Text content
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.item.displaySubtitle!,
|
||||
widget.item.displayTitle,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: tokens(context).textMuted,
|
||||
fontSize: 11,
|
||||
height: 1.1,
|
||||
),
|
||||
)
|
||||
else if (widget.item.parentTitle != null)
|
||||
Text(
|
||||
widget.item.parentTitle!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: tokens(context).textMuted,
|
||||
fontSize: 11,
|
||||
height: 1.1,
|
||||
),
|
||||
)
|
||||
else if (widget.item.year != null)
|
||||
Text(
|
||||
'${widget.item.year}',
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: tokens(context).textMuted,
|
||||
fontSize: 11,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13,
|
||||
height: 1.1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
if (widget.item.displaySubtitle != null)
|
||||
Text(
|
||||
widget.item.displaySubtitle!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(
|
||||
color: tokens(context).textMuted,
|
||||
fontSize: 11,
|
||||
height: 1.1,
|
||||
),
|
||||
)
|
||||
else if (widget.item.parentTitle != null)
|
||||
Text(
|
||||
widget.item.parentTitle!,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(
|
||||
color: tokens(context).textMuted,
|
||||
fontSize: 11,
|
||||
height: 1.1,
|
||||
),
|
||||
)
|
||||
else if (widget.item.year != null)
|
||||
Text(
|
||||
'${widget.item.year}',
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(
|
||||
color: tokens(context).textMuted,
|
||||
fontSize: 11,
|
||||
height: 1.1,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -188,9 +182,10 @@ class _MediaCardState extends State<MediaCard>
|
||||
builder: (context, clientProvider, child) {
|
||||
final client = clientProvider.client;
|
||||
if (client == null) {
|
||||
return Container(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
child: const Center(child: Icon(Icons.movie, size: 40)),
|
||||
return const SkeletonLoader(
|
||||
child: Center(
|
||||
child: Icon(Icons.movie, size: 40, color: Colors.white54),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -201,9 +196,7 @@ class _MediaCardState extends State<MediaCard>
|
||||
height: double.infinity,
|
||||
filterQuality: FilterQuality.medium,
|
||||
fadeInDuration: const Duration(milliseconds: 300),
|
||||
placeholder: (context, url) => Container(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
),
|
||||
placeholder: (context, url) => const SkeletonLoader(),
|
||||
errorWidget: (context, url, error) => Container(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
child: const Center(child: Icon(Icons.broken_image, size: 40)),
|
||||
@@ -212,9 +205,10 @@ class _MediaCardState extends State<MediaCard>
|
||||
},
|
||||
);
|
||||
} else {
|
||||
return Container(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest,
|
||||
child: const Center(child: Icon(Icons.movie, size: 40)),
|
||||
return const SkeletonLoader(
|
||||
child: Center(
|
||||
child: Icon(Icons.movie, size: 40, color: Colors.white54),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -278,3 +272,60 @@ class _PosterOverlay extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Skeleton loader widget with subtle opacity pulse animation
|
||||
class SkeletonLoader extends StatefulWidget {
|
||||
final Widget? child;
|
||||
final BorderRadius? borderRadius;
|
||||
|
||||
const SkeletonLoader({super.key, this.child, this.borderRadius});
|
||||
|
||||
@override
|
||||
State<SkeletonLoader> createState() => _SkeletonLoaderState();
|
||||
}
|
||||
|
||||
class _SkeletonLoaderState extends State<SkeletonLoader>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _animationController;
|
||||
late Animation<double> _animation;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_animationController = AnimationController(
|
||||
duration: const Duration(milliseconds: 1500),
|
||||
vsync: this,
|
||||
);
|
||||
_animation = Tween<double>(begin: 0.3, end: 0.7).animate(
|
||||
CurvedAnimation(parent: _animationController, curve: Curves.easeInOut),
|
||||
);
|
||||
_animationController.repeat(reverse: true);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedBuilder(
|
||||
animation: _animation,
|
||||
builder: (context, child) {
|
||||
return Semantics(
|
||||
label: "skeleton-loader",
|
||||
identifier: "skeleton-loader",
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surfaceContainerHighest
|
||||
.withValues(alpha: _animation.value),
|
||||
borderRadius: widget.borderRadius ?? BorderRadius.circular(8),
|
||||
),
|
||||
child: widget.child,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,7 +333,6 @@ class _PlexVideoControlsState extends State<PlexVideoControls>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isMobile = PlatformDetector.isMobile(context);
|
||||
@@ -688,10 +687,7 @@ class _PlexVideoControlsState extends State<PlexVideoControls>
|
||||
final isMacOS = Platform.isMacOS;
|
||||
|
||||
final topBar = Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: leftPadding,
|
||||
right: 16,
|
||||
),
|
||||
padding: EdgeInsets.only(left: leftPadding, right: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
AppBarBackButton(
|
||||
@@ -1100,7 +1096,11 @@ class _PlexVideoControlsState extends State<PlexVideoControls>
|
||||
stream: widget.player.stream.track,
|
||||
initialData: widget.player.state.track,
|
||||
builder: (context, selectedSnapshot) {
|
||||
final selectedTrack = selectedSnapshot.data?.audio;
|
||||
// Use snapshot data or fall back to current state
|
||||
final currentTrack =
|
||||
selectedSnapshot.data ??
|
||||
widget.player.state.track;
|
||||
final selectedTrack = currentTrack.audio;
|
||||
final selectedId = selectedTrack?.id;
|
||||
|
||||
return ListView.builder(
|
||||
@@ -1222,7 +1222,11 @@ class _PlexVideoControlsState extends State<PlexVideoControls>
|
||||
stream: widget.player.stream.track,
|
||||
initialData: widget.player.state.track,
|
||||
builder: (context, selectedSnapshot) {
|
||||
final selectedTrack = selectedSnapshot.data?.subtitle;
|
||||
// Use snapshot data or fall back to current state
|
||||
final currentTrack =
|
||||
selectedSnapshot.data ??
|
||||
widget.player.state.track;
|
||||
final selectedTrack = currentTrack.subtitle;
|
||||
final selectedId = selectedTrack?.id;
|
||||
final isOffSelected = selectedId == 'no';
|
||||
|
||||
@@ -1233,9 +1237,13 @@ class _PlexVideoControlsState extends State<PlexVideoControls>
|
||||
// First item is "Off"
|
||||
if (index == 0) {
|
||||
return ListTile(
|
||||
title: const Text(
|
||||
title: Text(
|
||||
'Off',
|
||||
style: TextStyle(color: Colors.white),
|
||||
style: TextStyle(
|
||||
color: isOffSelected
|
||||
? Colors.blue
|
||||
: Colors.white,
|
||||
),
|
||||
),
|
||||
trailing: isOffSelected
|
||||
? const Icon(
|
||||
|
||||
@@ -19,66 +19,84 @@ class ServerListTile extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final isOnline = server.isOnline;
|
||||
|
||||
return ListTile(
|
||||
leading: Icon(
|
||||
Icons.dns,
|
||||
color: isOnline
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.5),
|
||||
),
|
||||
title: Text(server.name),
|
||||
subtitle: Row(
|
||||
children: [
|
||||
Icon(
|
||||
isOnline ? Icons.circle : Icons.circle_outlined,
|
||||
size: 10,
|
||||
color: isOnline ? Colors.green : Colors.grey,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
isOnline ? 'Online' : 'Offline',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isOnline ? Colors.green : Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'•',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
server.owned ? 'Owned' : 'Shared',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: isCurrentServer
|
||||
? Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
'CURRENT',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 0.5,
|
||||
return Semantics(
|
||||
selected: isCurrentServer,
|
||||
identifier: server.name,
|
||||
label: server.name,
|
||||
child: ListTile(
|
||||
key: ValueKey(server.name),
|
||||
leading: Icon(
|
||||
Icons.dns,
|
||||
color: isOnline
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).colorScheme.onSurface.withValues(alpha: 0.5),
|
||||
semanticLabel: 'Server',
|
||||
),
|
||||
title: Text(server.name),
|
||||
subtitle: Semantics(
|
||||
label:
|
||||
'${isOnline ? 'Online' : 'Offline'}, ${server.owned ? 'Owned' : 'Shared'}',
|
||||
excludeSemantics: true,
|
||||
child: Row(
|
||||
children: [
|
||||
Semantics(
|
||||
excludeSemantics: true,
|
||||
child: Icon(
|
||||
isOnline ? Icons.circle : Icons.circle_outlined,
|
||||
size: 10,
|
||||
color: isOnline ? Colors.green : Colors.grey,
|
||||
),
|
||||
),
|
||||
)
|
||||
: (showTrailingIcon ? const Icon(Icons.chevron_right) : null),
|
||||
onTap: isCurrentServer ? null : onTap,
|
||||
enabled: !isCurrentServer,
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
isOnline ? 'Online' : 'Offline',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isOnline ? Colors.green : Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Semantics(
|
||||
excludeSemantics: true,
|
||||
child: Text(
|
||||
'•',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(
|
||||
context,
|
||||
).colorScheme.onSurface.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
server.owned ? 'Owned' : 'Shared',
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
trailing: isCurrentServer
|
||||
? Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
'CURRENT',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
)
|
||||
: (showTrailingIcon ? const Icon(Icons.chevron_right) : null),
|
||||
onTap: isCurrentServer ? null : onTap,
|
||||
enabled: !isCurrentServer,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
appId: com.edde746.plezy
|
||||
---
|
||||
- tapOn: "Debug: Enter Token"
|
||||
- tapOn: "Plex Auth Token"
|
||||
- inputText: ${MAESTRO_PLEX_TOKEN}
|
||||
- tapOn: "Authenticate"
|
||||
- tapOn: ${MAESTRO_PLEX_SERVER_NAME}
|
||||
@@ -0,0 +1,49 @@
|
||||
appId: com.edde746.plezy
|
||||
env:
|
||||
PREFIX: ./${maestro.platform}/
|
||||
---
|
||||
- evalScript: ${output.suffix = '-' + Date.now().toString()}
|
||||
- launchApp:
|
||||
clearState: true
|
||||
stopApp: false
|
||||
- runFlow: auth.yaml
|
||||
- assertVisible:
|
||||
id: "media-hero-${MAESTRO_EPISODE}"
|
||||
- tapOn: "Pause auto-scroll"
|
||||
- waitForAnimationToEnd
|
||||
- tapOn:
|
||||
text: "Play auto-scroll"
|
||||
waitToSettleTimeoutMs: 800
|
||||
- takeScreenshot: "${PREFIX}1-home${output.suffix}"
|
||||
- tapOn: "Libraries.*"
|
||||
- tapOn:
|
||||
text: "TV Shows"
|
||||
waitToSettleTimeoutMs: 200
|
||||
- runFlow:
|
||||
when:
|
||||
true: ${MAESTRO_COLLECTION != ""}
|
||||
commands:
|
||||
- tapOn: "Filters"
|
||||
- tapOn: "Collection"
|
||||
- tapOn: "${MAESTRO_COLLECTION}"
|
||||
- repeat:
|
||||
while:
|
||||
visible: "skeleton-loader"
|
||||
commands:
|
||||
- assertNotVisible: "skeleton-loader"
|
||||
|
||||
- takeScreenshot: "${PREFIX}2-library${output.suffix}"
|
||||
- scrollUntilVisible:
|
||||
element:
|
||||
id: "media-card-${MAESTRO_SHOW}"
|
||||
- tapOn:
|
||||
id: "media-card-${MAESTRO_SHOW}"
|
||||
- waitForAnimationToEnd:
|
||||
timeout: 5000
|
||||
- takeScreenshot: "${PREFIX}3-media-card${output.suffix}"
|
||||
- scrollUntilVisible:
|
||||
element:
|
||||
id: "media-season-.*"
|
||||
- tapOn:
|
||||
id: "media-season-.*"
|
||||
- takeScreenshot: "${PREFIX}4-season${output.suffix}"
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
name: plezy
|
||||
description: "A beautiful Plex client for Flutter"
|
||||
publish_to: "none"
|
||||
version: 1.2.0+6
|
||||
version: 1.2.2+8
|
||||
|
||||
environment:
|
||||
sdk: ^3.8.1
|
||||
|
||||
Executable
+396
@@ -0,0 +1,396 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Android Screenshot Automation Script
|
||||
# Starts emulators, runs Flutter app, executes maestro tests, and organizes screenshots
|
||||
|
||||
set -e # Exit on any error
|
||||
|
||||
# Configuration
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
MAESTRO_DIR="$PROJECT_ROOT/maestro"
|
||||
FASTLANE_IMAGES_DIR="$PROJECT_ROOT/android/fastlane/metadata/android/en-GB/images"
|
||||
ENV_FILE="$PROJECT_ROOT/.env"
|
||||
|
||||
# Source common screenshot functions
|
||||
source "${SCRIPT_DIR}/screenshot_common.sh"
|
||||
|
||||
# Check if required tools are installed
|
||||
check_dependencies() {
|
||||
# Check common dependencies first
|
||||
if ! check_common_dependencies; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "Checking Android-specific dependencies..."
|
||||
|
||||
# Try to find emulator binary
|
||||
if ! command -v emulator &> /dev/null; then
|
||||
# Try common Android SDK locations
|
||||
POSSIBLE_PATHS=(
|
||||
"$ANDROID_HOME/emulator/emulator"
|
||||
"$ANDROID_SDK_ROOT/emulator/emulator"
|
||||
"~/Android/Sdk/emulator/emulator"
|
||||
"~/Library/Android/sdk/emulator/emulator"
|
||||
)
|
||||
|
||||
EMULATOR_PATH=""
|
||||
for path in "${POSSIBLE_PATHS[@]}"; do
|
||||
if [ -f "$path" ]; then
|
||||
EMULATOR_PATH="$path"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$EMULATOR_PATH" ]; then
|
||||
log_error "Android emulator not found. Please ensure Android SDK is installed and ANDROID_HOME is set."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create an alias for emulator
|
||||
alias emulator="$EMULATOR_PATH"
|
||||
fi
|
||||
|
||||
log_success "All dependencies found"
|
||||
}
|
||||
|
||||
# Get list of available AVDs
|
||||
get_avds() {
|
||||
# Parse flutter emulators output to get Android emulator IDs
|
||||
flutter emulators 2>/dev/null | grep "android$" | awk '{print $1}'
|
||||
}
|
||||
|
||||
# Stop all running emulators
|
||||
stop_emulators() {
|
||||
log_info "Stopping any running emulators..."
|
||||
|
||||
# Get list of running emulators
|
||||
local running_emulators=$(adb devices | grep emulator | cut -f1)
|
||||
|
||||
if [ -n "$running_emulators" ]; then
|
||||
for emulator in $running_emulators; do
|
||||
log_info "Stopping emulator $emulator"
|
||||
adb -s "$emulator" emu kill 2>/dev/null || true
|
||||
done
|
||||
|
||||
# Wait for emulators to fully stop - check periodically
|
||||
log_info "Waiting for emulators to fully shut down..."
|
||||
local timeout=30 # 30 seconds timeout
|
||||
local elapsed=0
|
||||
|
||||
while [ $elapsed -lt $timeout ]; do
|
||||
local still_running=$(adb devices | grep emulator | cut -f1)
|
||||
if [ -z "$still_running" ]; then
|
||||
log_success "All emulators stopped"
|
||||
return 0
|
||||
fi
|
||||
sleep 2
|
||||
elapsed=$((elapsed + 2))
|
||||
|
||||
# Show progress every 6 seconds
|
||||
if [ $((elapsed % 6)) -eq 0 ]; then
|
||||
log_info "Still waiting for emulators to stop... (${elapsed}s elapsed)"
|
||||
fi
|
||||
done
|
||||
|
||||
log_warning "Timeout waiting for emulators to stop completely"
|
||||
else
|
||||
log_info "No emulators are currently running"
|
||||
fi
|
||||
}
|
||||
|
||||
# Start emulator and wait for it to be ready
|
||||
start_emulator() {
|
||||
local avd_name="$1"
|
||||
local device_type="$2"
|
||||
|
||||
log_info "Starting $device_type emulator: $avd_name"
|
||||
|
||||
# Double-check if any emulator is still running
|
||||
local running_emulators=$(adb devices | grep emulator | cut -f1)
|
||||
if [ -n "$running_emulators" ]; then
|
||||
log_warning "Emulator still running: $running_emulators"
|
||||
log_info "Forcing stop before starting new emulator..."
|
||||
stop_emulators
|
||||
fi
|
||||
|
||||
# Start emulator in background with proper output redirection
|
||||
log_info "Launching emulator..."
|
||||
flutter emulators --launch "$avd_name" > /dev/null 2>&1 &
|
||||
local emulator_pid=$!
|
||||
|
||||
log_info "Waiting for $device_type emulator to boot..."
|
||||
|
||||
# Wait for emulator to appear in adb devices
|
||||
local timeout=120 # 2 minutes timeout
|
||||
local elapsed=0
|
||||
|
||||
while [ $elapsed -lt $timeout ]; do
|
||||
if adb devices | grep -q "emulator.*device"; then
|
||||
log_success "$device_type emulator is ready"
|
||||
return 0
|
||||
fi
|
||||
sleep 2
|
||||
elapsed=$((elapsed + 2))
|
||||
|
||||
# Show progress every 10 seconds
|
||||
if [ $((elapsed % 10)) -eq 0 ]; then
|
||||
log_info "Still waiting... (${elapsed}s elapsed)"
|
||||
fi
|
||||
done
|
||||
|
||||
log_error "Timeout waiting for $device_type emulator to start"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Detect device type based on screen size
|
||||
detect_device_type() {
|
||||
local device_id="$1"
|
||||
|
||||
# Get screen density and size
|
||||
local density=$(adb -s "$device_id" shell wm density | cut -d: -f2 | tr -d ' ')
|
||||
local size=$(adb -s "$device_id" shell wm size | cut -d: -f2 | tr -d ' ')
|
||||
|
||||
# Extract width and height
|
||||
local width=$(echo "$size" | cut -d'x' -f1)
|
||||
local height=$(echo "$size" | cut -d'x' -f2)
|
||||
|
||||
# Calculate diagonal in inches (approximate)
|
||||
local diagonal_pixels=$(echo "sqrt($width*$width + $height*$height)" | bc -l)
|
||||
local diagonal_inches=$(echo "$diagonal_pixels / $density" | bc -l)
|
||||
|
||||
# Convert to integer for comparison
|
||||
local diagonal_int=$(echo "$diagonal_inches" | cut -d'.' -f1)
|
||||
|
||||
if [ "$diagonal_int" -ge 9 ]; then
|
||||
echo "tablet"
|
||||
else
|
||||
echo "phone"
|
||||
fi
|
||||
}
|
||||
|
||||
# Run Flutter app on specified device
|
||||
run_flutter_app() {
|
||||
local device_id="$1"
|
||||
local device_type="$2"
|
||||
|
||||
log_info "Running Flutter app on $device_type ($device_id)"
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
flutter run -d "$device_id" --hot &
|
||||
local flutter_pid=$!
|
||||
|
||||
# Wait for app to be installed and launched
|
||||
sleep 30
|
||||
|
||||
# Check if app is running
|
||||
if adb -s "$device_id" shell pm list packages | grep -q "com.edde746.plezy"; then
|
||||
log_success "Flutter app is running on $device_type"
|
||||
return 0
|
||||
else
|
||||
log_error "Failed to start Flutter app on $device_type"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Detect device type based on image dimensions
|
||||
detect_device_type() {
|
||||
local image_path="$1"
|
||||
|
||||
local dimensions=$(get_image_dimensions "$image_path")
|
||||
if [ -z "$dimensions" ]; then
|
||||
log_warning "Could not get dimensions for $image_path"
|
||||
echo "phone" # Default to phone
|
||||
return
|
||||
fi
|
||||
|
||||
local width=$(echo "$dimensions" | cut -d',' -f1)
|
||||
local height=$(echo "$dimensions" | cut -d',' -f2)
|
||||
|
||||
# Determine shorter and longer sides
|
||||
local shorter_side=$((width < height ? width : height))
|
||||
local longer_side=$((width > height ? width : height))
|
||||
|
||||
# Calculate diagonal using shell arithmetic (approximate)
|
||||
# For simplicity, we'll use the shorter side as the main criteria
|
||||
# Tablets typically have shorter side >= 1200px
|
||||
# Phones typically have shorter side < 1200px
|
||||
|
||||
if [ "$shorter_side" -ge 1200 ]; then
|
||||
echo "tablet"
|
||||
else
|
||||
echo "phone"
|
||||
fi
|
||||
}
|
||||
|
||||
# Organize screenshots into correct fastlane folders
|
||||
organize_screenshots() {
|
||||
log_info "Organizing screenshots using ffprobe analysis..."
|
||||
|
||||
# Create directories if they don't exist
|
||||
mkdir -p "$FASTLANE_IMAGES_DIR/phoneScreenshots"
|
||||
mkdir -p "$FASTLANE_IMAGES_DIR/sevenInchScreenshots"
|
||||
mkdir -p "$FASTLANE_IMAGES_DIR/tenInchScreenshots"
|
||||
|
||||
# Find all screenshot files generated by maestro
|
||||
local android_screenshots_dir="$MAESTRO_DIR/android"
|
||||
if [ ! -d "$android_screenshots_dir" ]; then
|
||||
log_warning "No Android screenshots directory found at $android_screenshots_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local screenshots=($(find "$android_screenshots_dir" -name "*.png" | sort))
|
||||
|
||||
if [ ${#screenshots[@]} -eq 0 ]; then
|
||||
log_warning "No Android screenshots found in $android_screenshots_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_info "Found ${#screenshots[@]} screenshots"
|
||||
|
||||
# Group screenshots by device type
|
||||
local phone_screenshots=()
|
||||
local tablet_screenshots=()
|
||||
|
||||
for screenshot in "${screenshots[@]}"; do
|
||||
local device_type=$(detect_device_type "$screenshot")
|
||||
log_image_info "$screenshot" "$device_type"
|
||||
|
||||
if [ "$device_type" = "tablet" ]; then
|
||||
tablet_screenshots+=("$screenshot")
|
||||
else
|
||||
phone_screenshots+=("$screenshot")
|
||||
fi
|
||||
done
|
||||
|
||||
# Copy and rename phone screenshots
|
||||
local phone_count=1
|
||||
for screenshot in "${phone_screenshots[@]}"; do
|
||||
if [ $phone_count -gt 4 ]; then
|
||||
break # Limit to 4 screenshots
|
||||
fi
|
||||
|
||||
local target_name="${phone_count}_en-GB.png"
|
||||
|
||||
# Copy to phone directory
|
||||
cp "$screenshot" "$FASTLANE_IMAGES_DIR/phoneScreenshots/$target_name"
|
||||
|
||||
# Copy to seven inch directory (phone screenshots go here too)
|
||||
cp "$screenshot" "$FASTLANE_IMAGES_DIR/sevenInchScreenshots/$target_name"
|
||||
|
||||
log_success "Copied phone screenshot $phone_count: $(basename "$screenshot")"
|
||||
phone_count=$((phone_count + 1))
|
||||
done
|
||||
|
||||
# Copy and rename tablet screenshots
|
||||
local tablet_count=1
|
||||
for screenshot in "${tablet_screenshots[@]}"; do
|
||||
if [ $tablet_count -gt 4 ]; then
|
||||
break # Limit to 4 screenshots
|
||||
fi
|
||||
|
||||
local target_name="${tablet_count}_en-GB.png"
|
||||
cp "$screenshot" "$FASTLANE_IMAGES_DIR/tenInchScreenshots/$target_name"
|
||||
|
||||
log_success "Copied tablet screenshot $tablet_count: $(basename "$screenshot")"
|
||||
tablet_count=$((tablet_count + 1))
|
||||
done
|
||||
|
||||
log_success "Organized $((phone_count-1)) phone screenshots and $((tablet_count-1)) tablet screenshots"
|
||||
}
|
||||
|
||||
# Cleanup function
|
||||
cleanup() {
|
||||
log_info "Cleaning up..."
|
||||
|
||||
# Kill any running Flutter processes
|
||||
pkill -f "flutter run" 2>/dev/null || true
|
||||
|
||||
# Stop emulators using our function
|
||||
stop_emulators
|
||||
|
||||
log_success "Cleanup completed"
|
||||
}
|
||||
|
||||
# Main execution
|
||||
main() {
|
||||
log_info "Starting Android screenshot automation..."
|
||||
|
||||
# Set up cleanup trap
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
# Clean up old screenshots at the very beginning
|
||||
clean_old_screenshots "android ios"
|
||||
|
||||
# Check dependencies
|
||||
check_dependencies
|
||||
|
||||
# Stop any running emulators first
|
||||
stop_emulators
|
||||
|
||||
# Get available AVDs
|
||||
log_info "Getting available Android Virtual Devices..."
|
||||
|
||||
# Store AVDs in an array, handling potential spaces in names
|
||||
local avds_raw=$(get_avds)
|
||||
if [ -z "$avds_raw" ]; then
|
||||
log_error "No Android Virtual Devices found. Please create AVDs first."
|
||||
log_info "Create AVDs using: flutter emulators --create"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Convert to array (each line is an AVD)
|
||||
IFS=$'\n' read -d '' -r -a avds <<< "$avds_raw" || true
|
||||
|
||||
log_info "Found ${#avds[@]} Android AVD(s): ${avds[*]}"
|
||||
|
||||
# For now, we'll use the first two AVDs as phone and tablet
|
||||
# In a real scenario, you'd want to specify which AVDs to use
|
||||
local phone_avd="${avds[0]}"
|
||||
local tablet_avd="${avds[1]:-${avds[0]}}" # Use first AVD if only one available
|
||||
|
||||
if [ ${#avds[@]} -eq 1 ]; then
|
||||
log_warning "Only one AVD available. Using it for both phone and tablet tests."
|
||||
fi
|
||||
|
||||
# Start phone emulator
|
||||
start_emulator "$phone_avd" "phone"
|
||||
|
||||
# Get device ID for phone
|
||||
local phone_device=$(adb devices | grep emulator | head -n1 | cut -f1)
|
||||
|
||||
# Run Flutter app on phone
|
||||
run_flutter_app "$phone_device" "phone"
|
||||
|
||||
# Run maestro tests for phone
|
||||
MAESTRO_DEVICE="$phone_device" run_maestro_tests
|
||||
|
||||
# If we have a different tablet AVD, start it
|
||||
if [ "$phone_avd" != "$tablet_avd" ]; then
|
||||
# Stop phone emulator
|
||||
log_info "Switching from phone to tablet emulator"
|
||||
stop_emulators
|
||||
|
||||
# Start tablet emulator
|
||||
start_emulator "$tablet_avd" "tablet"
|
||||
|
||||
# Get device ID for tablet
|
||||
local tablet_device=$(adb devices | grep emulator | head -n1 | cut -f1)
|
||||
|
||||
# Run Flutter app on tablet
|
||||
run_flutter_app "$tablet_device" "tablet"
|
||||
|
||||
# Run maestro tests for tablet
|
||||
MAESTRO_DEVICE="$tablet_device" run_maestro_tests
|
||||
fi
|
||||
|
||||
# Organize screenshots
|
||||
organize_screenshots
|
||||
|
||||
log_success "Android screenshot automation completed successfully!"
|
||||
}
|
||||
|
||||
# Run main function if script is executed directly
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
main "$@"
|
||||
fi
|
||||
Executable
+421
@@ -0,0 +1,421 @@
|
||||
#!/bin/bash
|
||||
|
||||
# iOS Screenshot Automation Script
|
||||
# Starts simulators, runs Flutter app, executes maestro tests, and organizes screenshots
|
||||
|
||||
set -e # Exit on any error
|
||||
|
||||
# Configuration
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
MAESTRO_DIR="$PROJECT_ROOT/maestro"
|
||||
FASTLANE_SCREENSHOTS_DIR="$PROJECT_ROOT/ios/fastlane/screenshots/en-US"
|
||||
ENV_FILE="$PROJECT_ROOT/.env"
|
||||
|
||||
# Source common screenshot functions
|
||||
source "${SCRIPT_DIR}/screenshot_common.sh"
|
||||
|
||||
# Check if required tools are installed
|
||||
check_dependencies() {
|
||||
# Check common dependencies first
|
||||
if ! check_common_dependencies; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "Checking iOS-specific dependencies..."
|
||||
|
||||
if ! command -v xcrun &> /dev/null; then
|
||||
log_error "xcrun is not installed - Xcode is required"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_success "All dependencies found"
|
||||
}
|
||||
|
||||
# Get list of available iOS simulators
|
||||
get_simulators() {
|
||||
xcrun simctl list devices available -j | python3 -c "
|
||||
import sys, json
|
||||
data = json.load(sys.stdin)
|
||||
for runtime, devices in data['devices'].items():
|
||||
if 'iOS' in runtime and devices:
|
||||
for device in devices:
|
||||
if device['isAvailable']:
|
||||
print(f\"{device['udid']}|{device['name']}\")
|
||||
" 2>/dev/null || echo ""
|
||||
}
|
||||
|
||||
# Stop all running simulators
|
||||
stop_simulators() {
|
||||
log_info "Stopping any running simulators..."
|
||||
|
||||
# Get list of running simulators
|
||||
local running_simulators=$(xcrun simctl list devices | grep "Booted" | grep -oE "[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}" || echo "")
|
||||
|
||||
if [ -n "$running_simulators" ]; then
|
||||
while IFS= read -r simulator; do
|
||||
log_info "Stopping simulator $simulator"
|
||||
xcrun simctl shutdown "$simulator" 2>/dev/null || true
|
||||
done <<< "$running_simulators"
|
||||
|
||||
# Wait for simulators to fully stop
|
||||
log_info "Waiting for simulators to fully shut down..."
|
||||
sleep 3
|
||||
log_success "All simulators stopped"
|
||||
else
|
||||
log_info "No simulators are currently running"
|
||||
fi
|
||||
}
|
||||
|
||||
# Start simulator and wait for it to be ready
|
||||
start_simulator() {
|
||||
local simulator_udid="$1"
|
||||
local simulator_name="$2"
|
||||
local device_type="$3"
|
||||
|
||||
log_info "Starting $device_type simulator: $simulator_name"
|
||||
|
||||
# Double-check if any simulator is still running
|
||||
local running_simulators=$(xcrun simctl list devices | grep "Booted" | grep -oE "[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}" || echo "")
|
||||
if [ -n "$running_simulators" ]; then
|
||||
log_warning "Simulator still running"
|
||||
log_info "Forcing stop before starting new simulator..."
|
||||
stop_simulators
|
||||
fi
|
||||
|
||||
# Start simulator
|
||||
log_info "Launching simulator..."
|
||||
xcrun simctl boot "$simulator_udid" 2>/dev/null || log_warning "Simulator may already be booting"
|
||||
|
||||
log_info "Waiting for $device_type simulator to be ready..."
|
||||
|
||||
# Wait for simulator to boot
|
||||
local timeout=120 # 2 minutes timeout
|
||||
local elapsed=0
|
||||
|
||||
while [ $elapsed -lt $timeout ]; do
|
||||
local state=$(xcrun simctl list devices | grep "$simulator_udid" | grep -oE "(Booted|Shutdown)")
|
||||
if [ "$state" = "Booted" ]; then
|
||||
# Give it a bit more time to fully initialize
|
||||
sleep 5
|
||||
log_success "$device_type simulator is ready"
|
||||
return 0
|
||||
fi
|
||||
sleep 2
|
||||
elapsed=$((elapsed + 2))
|
||||
|
||||
# Show progress every 10 seconds
|
||||
if [ $((elapsed % 10)) -eq 0 ]; then
|
||||
log_info "Still waiting... (${elapsed}s elapsed)"
|
||||
fi
|
||||
done
|
||||
|
||||
log_error "Timeout waiting for $device_type simulator to start"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Rotate simulator to landscape
|
||||
rotate_simulator_landscape() {
|
||||
local simulator_udid="$1"
|
||||
|
||||
log_info "Rotating simulator to landscape orientation..."
|
||||
|
||||
# Open Simulator app and bring it to front
|
||||
open -a Simulator
|
||||
sleep 2
|
||||
|
||||
# Use AppleScript to send rotation keyboard shortcut (Cmd+Left arrow rotates counterclockwise)
|
||||
# Key code 123 is left arrow
|
||||
osascript -e 'tell application "Simulator" to activate' \
|
||||
-e 'tell application "System Events" to key code 123 using command down'
|
||||
|
||||
sleep 2
|
||||
log_success "Simulator rotated to landscape"
|
||||
}
|
||||
|
||||
# Detect device type based on image dimensions for iOS
|
||||
detect_ios_device_type() {
|
||||
local image_path="$1"
|
||||
|
||||
local dimensions=$(get_image_dimensions "$image_path")
|
||||
if [ -z "$dimensions" ]; then
|
||||
log_warning "Could not get dimensions for $image_path"
|
||||
echo "iphone_6_5" # Default
|
||||
return
|
||||
fi
|
||||
|
||||
local width=$(echo "$dimensions" | cut -d',' -f1)
|
||||
local height=$(echo "$dimensions" | cut -d',' -f2)
|
||||
|
||||
# Determine shorter and longer sides (for portrait orientation)
|
||||
local shorter_side=$((width < height ? width : height))
|
||||
local longer_side=$((width > height ? width : height))
|
||||
|
||||
# iOS App Store screenshot sizes (based on shorter side in portrait)
|
||||
# Reference: https://help.apple.com/app-store-connect/#/devd274dd925
|
||||
|
||||
# iPad Pro 12.9" (3rd gen and later): 2048 x 2732
|
||||
if [ "$shorter_side" -ge 2000 ] && [ "$longer_side" -ge 2700 ]; then
|
||||
echo "ipad_pro_12_9_3rd_gen"
|
||||
# iPad Pro 12.9" (2nd gen): 2048 x 2732
|
||||
elif [ "$shorter_side" -ge 2000 ] && [ "$longer_side" -ge 2700 ]; then
|
||||
echo "ipad_pro_12_9_2nd_gen"
|
||||
# iPhone 6.9" display (iPhone Air Pro Max, 16 Pro Max, etc.): 1320 x 2868
|
||||
elif [ "$shorter_side" -ge 1300 ] && [ "$longer_side" -ge 2800 ]; then
|
||||
echo "iphone_6_9"
|
||||
# iPhone 6.7" display (iPhone 14 Pro Max, etc.): 1290 x 2796
|
||||
elif [ "$shorter_side" -ge 1250 ] && [ "$longer_side" -ge 2700 ]; then
|
||||
echo "iphone_6_7"
|
||||
# iPhone 6.3" display (iPhone 17, 16 Pro, 15 Pro, 14 Pro): 1206 x 2622
|
||||
elif [ "$shorter_side" -ge 1200 ] && [ "$shorter_side" -lt 1242 ] && [ "$longer_side" -ge 2600 ] && [ "$longer_side" -lt 2688 ]; then
|
||||
echo "iphone_6_3"
|
||||
# iPhone 6.5" display (iPhone 14 Plus, 13 Pro Max, 11 Pro Max, XS Max, etc.): 1242 x 2688 or 1284 x 2778
|
||||
elif [ "$shorter_side" -ge 1200 ] && [ "$longer_side" -ge 2600 ]; then
|
||||
echo "iphone_6_5"
|
||||
# iPhone 5.5" display (iPhone 8 Plus, etc.): 1242 x 2208
|
||||
elif [ "$shorter_side" -ge 1200 ] && [ "$longer_side" -ge 2200 ]; then
|
||||
echo "iphone_5_5"
|
||||
else
|
||||
# Default to 6.5" for unknown iPhone sizes
|
||||
echo "iphone_6_5"
|
||||
fi
|
||||
}
|
||||
|
||||
# Run Flutter app on specified device
|
||||
run_flutter_app() {
|
||||
local device_id="$1"
|
||||
local device_type="$2"
|
||||
|
||||
log_info "Running Flutter app on $device_type ($device_id)"
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
flutter run -d "$device_id" --hot &
|
||||
local flutter_pid=$!
|
||||
|
||||
# Wait for app to be installed and launched
|
||||
log_info "Waiting for Flutter app to launch..."
|
||||
sleep 40 # iOS typically takes longer to launch
|
||||
|
||||
# Check if simulator is still running
|
||||
local state=$(xcrun simctl list devices | grep "$device_id" | grep -oE "(Booted|Shutdown)")
|
||||
if [ "$state" = "Booted" ]; then
|
||||
log_success "Flutter app should be running on $device_type"
|
||||
return 0
|
||||
else
|
||||
log_error "Simulator not running anymore"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Map device type to fastlane naming convention
|
||||
get_fastlane_device_name() {
|
||||
local device_type="$1"
|
||||
|
||||
case "$device_type" in
|
||||
ipad_pro_12_9_3rd_gen|ipad_pro_12_9_2nd_gen)
|
||||
echo "IPAD_PRO_3GEN_129"
|
||||
;;
|
||||
iphone_6_9)
|
||||
echo "IPHONE_69"
|
||||
;;
|
||||
iphone_6_7)
|
||||
echo "IPHONE_67"
|
||||
;;
|
||||
iphone_6_5)
|
||||
echo "IPHONE_65"
|
||||
;;
|
||||
iphone_6_3)
|
||||
echo "IPHONE_63"
|
||||
;;
|
||||
iphone_5_5)
|
||||
echo "IPHONE_55"
|
||||
;;
|
||||
*)
|
||||
echo "IPHONE_67" # Default to 6.7"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Organize screenshots into correct fastlane folders
|
||||
organize_screenshots() {
|
||||
log_info "Organizing screenshots using ffprobe analysis..."
|
||||
|
||||
# Ensure target directory exists
|
||||
mkdir -p "$FASTLANE_SCREENSHOTS_DIR"
|
||||
|
||||
# Find all screenshot files generated by maestro
|
||||
local ios_screenshots_dir="$MAESTRO_DIR/ios"
|
||||
if [ ! -d "$ios_screenshots_dir" ]; then
|
||||
log_warning "No iOS screenshots directory found at $ios_screenshots_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local screenshots=($(find "$ios_screenshots_dir" -name "*.png" | sort))
|
||||
|
||||
if [ ${#screenshots[@]} -eq 0 ]; then
|
||||
log_warning "No iOS screenshots found in $ios_screenshots_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_info "Found ${#screenshots[@]} screenshots"
|
||||
|
||||
# First pass: detect and log all device types
|
||||
local device_types=()
|
||||
for screenshot in "${screenshots[@]}"; do
|
||||
local device_type=$(detect_ios_device_type "$screenshot")
|
||||
log_image_info "$screenshot" "$device_type"
|
||||
|
||||
# Add to device_types if not already present
|
||||
local found=0
|
||||
for dt in "${device_types[@]}"; do
|
||||
if [ "$dt" = "$device_type" ]; then
|
||||
found=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ $found -eq 0 ]; then
|
||||
device_types+=("$device_type")
|
||||
fi
|
||||
done
|
||||
|
||||
# Second pass: copy and rename screenshots for each device type
|
||||
for device_type in "${device_types[@]}"; do
|
||||
local fastlane_name=$(get_fastlane_device_name "$device_type")
|
||||
local count=0
|
||||
|
||||
for screenshot in "${screenshots[@]}"; do
|
||||
local detected_type=$(detect_ios_device_type "$screenshot")
|
||||
|
||||
# Only process screenshots matching this device type
|
||||
if [ "$detected_type" = "$device_type" ]; then
|
||||
# Format: {index}_APP_{DEVICE_TYPE}_{index}.png
|
||||
local target_name="${count}_APP_${fastlane_name}_${count}.png"
|
||||
cp "$screenshot" "$FASTLANE_SCREENSHOTS_DIR/$target_name"
|
||||
|
||||
log_success "Copied $device_type screenshot: $(basename "$screenshot") -> $target_name"
|
||||
count=$((count + 1))
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
log_success "Screenshot organization completed"
|
||||
}
|
||||
|
||||
# Cleanup function
|
||||
cleanup() {
|
||||
log_info "Cleaning up..."
|
||||
|
||||
# Kill any running Flutter processes
|
||||
pkill -f "flutter run" 2>/dev/null || true
|
||||
|
||||
# Stop simulators
|
||||
stop_simulators
|
||||
|
||||
log_success "Cleanup completed"
|
||||
}
|
||||
|
||||
# Main execution
|
||||
main() {
|
||||
log_info "Starting iOS screenshot automation..."
|
||||
|
||||
# Set up cleanup trap
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
# Clean up old screenshots at the very beginning
|
||||
clean_old_screenshots "ios"
|
||||
|
||||
# Clean up old fastlane screenshots to prevent mixing old/new with different naming
|
||||
log_info "Cleaning old fastlane screenshots..."
|
||||
if [ -d "$FASTLANE_SCREENSHOTS_DIR" ]; then
|
||||
rm -rf "$FASTLANE_SCREENSHOTS_DIR"/*
|
||||
log_success "Fastlane screenshots directory cleaned"
|
||||
fi
|
||||
|
||||
# Check dependencies
|
||||
check_dependencies
|
||||
|
||||
# Stop any running simulators first
|
||||
stop_simulators
|
||||
|
||||
# Get available simulators
|
||||
log_info "Getting available iOS Simulators..."
|
||||
|
||||
local simulators_raw=$(get_simulators)
|
||||
if [ -z "$simulators_raw" ]; then
|
||||
log_error "No iOS Simulators found. Please install simulators via Xcode."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Parse simulators into arrays
|
||||
declare -a simulator_udids
|
||||
declare -a simulator_names
|
||||
|
||||
while IFS='|' read -r udid name; do
|
||||
simulator_udids+=("$udid")
|
||||
simulator_names+=("$name")
|
||||
done <<< "$simulators_raw"
|
||||
|
||||
log_info "Found ${#simulator_udids[@]} iOS Simulator(s)"
|
||||
|
||||
# Find iPhone Air and iPad Pro 13" simulators
|
||||
local iphone_idx=-1
|
||||
local ipad_idx=-1
|
||||
|
||||
for i in "${!simulator_names[@]}"; do
|
||||
if [[ "${simulator_names[$i]}" =~ iPhone\ Air ]] && [ $iphone_idx -eq -1 ]; then
|
||||
iphone_idx=$i
|
||||
log_info "Found iPhone Air: ${simulator_names[$i]}"
|
||||
elif [[ "${simulator_names[$i]}" =~ iPad.*13 ]] && [ $ipad_idx -eq -1 ]; then
|
||||
ipad_idx=$i
|
||||
log_info "Found iPad Pro 13\": ${simulator_names[$i]}"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $iphone_idx -eq -1 ]; then
|
||||
log_error "iPhone Air simulator not found. Please create it in Xcode."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $ipad_idx -eq -1 ]; then
|
||||
log_error "iPad Pro 13\" simulator not found. Please create it in Xcode."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "Using iPhone: ${simulator_names[$iphone_idx]}"
|
||||
log_info "Using iPad: ${simulator_names[$ipad_idx]}"
|
||||
|
||||
# Start iPhone Air simulator
|
||||
start_simulator "${simulator_udids[$iphone_idx]}" "${simulator_names[$iphone_idx]}" "iPhone Air"
|
||||
|
||||
# Run Flutter app on iPhone Air
|
||||
run_flutter_app "${simulator_udids[$iphone_idx]}" "iPhone Air"
|
||||
|
||||
# Run maestro tests for iPhone Air
|
||||
run_maestro_tests "${simulator_udids[$iphone_idx]}"
|
||||
|
||||
# Stop iPhone simulator and switch to iPad
|
||||
log_info "Switching from iPhone Air to iPad Pro 13\" simulator"
|
||||
stop_simulators
|
||||
|
||||
# Start iPad Pro 13" simulator
|
||||
start_simulator "${simulator_udids[$ipad_idx]}" "${simulator_names[$ipad_idx]}" "iPad Pro 13\""
|
||||
|
||||
# Rotate iPad to landscape
|
||||
# rotate_simulator_landscape "${simulator_udids[$ipad_idx]}"
|
||||
|
||||
# Run Flutter app on iPad
|
||||
run_flutter_app "${simulator_udids[$ipad_idx]}" "iPad Pro 13\""
|
||||
|
||||
# Run maestro tests for iPad
|
||||
run_maestro_tests "${simulator_udids[$ipad_idx]}"
|
||||
|
||||
# Organize screenshots
|
||||
organize_screenshots
|
||||
|
||||
log_success "iOS screenshot automation completed successfully!"
|
||||
}
|
||||
|
||||
# Run main function if script is executed directly
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
main "$@"
|
||||
fi
|
||||
Executable
+135
@@ -0,0 +1,135 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Plezy Release Automation Script
|
||||
# This script automates the release process for both iOS and Android
|
||||
|
||||
set -e
|
||||
|
||||
# Get the script's directory
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
PROJECT_ROOT="$SCRIPT_DIR/.."
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Load environment variables from .env
|
||||
if [ -f "$PROJECT_ROOT/.env" ]; then
|
||||
# Export variables without executing the file
|
||||
set -a
|
||||
source "$PROJECT_ROOT/.env"
|
||||
set +a
|
||||
echo -e "${GREEN}✅ Loaded environment variables from .env${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ Error: .env file not found${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to show help
|
||||
show_help() {
|
||||
echo -e "${BLUE}Plezy Release Automation${NC}"
|
||||
echo ""
|
||||
echo "Usage: ./scripts/release.sh <command>"
|
||||
echo ""
|
||||
echo "Available commands:"
|
||||
echo " sync - Sync iOS release notes to Android changelog"
|
||||
echo " android - Build and release to Google Play Store"
|
||||
echo " ios - Build and release to App Store"
|
||||
echo " all - Sync changelogs and release to both platforms"
|
||||
echo " clean - Clean build artifacts"
|
||||
echo " help - Show this help message"
|
||||
echo ""
|
||||
echo "Prerequisites:"
|
||||
echo " - .env file must be configured with credentials"
|
||||
echo " - iOS release notes updated in ios/fastlane/metadata/en-US/release_notes.txt"
|
||||
echo " - Version bumped in pubspec.yaml"
|
||||
echo ""
|
||||
echo "Example:"
|
||||
echo " ./scripts/release.sh all"
|
||||
}
|
||||
|
||||
# Function to sync changelogs
|
||||
sync_changelogs() {
|
||||
echo -e "${YELLOW}📝 Syncing changelogs...${NC}"
|
||||
"$SCRIPT_DIR/sync_changelogs.sh"
|
||||
}
|
||||
|
||||
# Function to release Android
|
||||
release_android() {
|
||||
echo -e "${GREEN}🤖 Building and releasing Android app...${NC}"
|
||||
cd "$PROJECT_ROOT/android"
|
||||
fastlane release
|
||||
cd "$PROJECT_ROOT"
|
||||
}
|
||||
|
||||
# Function to release iOS
|
||||
release_ios() {
|
||||
echo -e "${GREEN}🍎 Building and releasing iOS app...${NC}"
|
||||
cd "$PROJECT_ROOT/ios"
|
||||
fastlane deploy_appstore
|
||||
cd "$PROJECT_ROOT"
|
||||
}
|
||||
|
||||
# Function to release all
|
||||
release_all() {
|
||||
sync_changelogs
|
||||
echo ""
|
||||
release_android
|
||||
echo ""
|
||||
release_ios
|
||||
echo ""
|
||||
echo -e "${GREEN}✅ Release complete for both platforms!${NC}"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Next steps:${NC}"
|
||||
echo " 1. Check Google Play Console for the draft release"
|
||||
echo " 2. Check App Store Connect for the uploaded build"
|
||||
echo " 3. Submit for review when ready"
|
||||
}
|
||||
|
||||
# Function to clean build artifacts
|
||||
clean() {
|
||||
echo -e "${YELLOW}🧹 Cleaning build artifacts...${NC}"
|
||||
cd "$PROJECT_ROOT/android"
|
||||
./gradlew clean 2>/dev/null || true
|
||||
cd "$PROJECT_ROOT/ios"
|
||||
xcodebuild clean -workspace Runner.xcworkspace -scheme Runner 2>/dev/null || true
|
||||
cd "$PROJECT_ROOT"
|
||||
flutter clean
|
||||
echo -e "${GREEN}✅ Clean complete!${NC}"
|
||||
}
|
||||
|
||||
# Main script logic
|
||||
if [ $# -eq 0 ]; then
|
||||
show_help
|
||||
exit 0
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
sync)
|
||||
sync_changelogs
|
||||
;;
|
||||
android)
|
||||
release_android
|
||||
;;
|
||||
ios)
|
||||
release_ios
|
||||
;;
|
||||
all)
|
||||
release_all
|
||||
;;
|
||||
clean)
|
||||
clean
|
||||
;;
|
||||
help|--help|-h)
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
echo -e "${RED}❌ Unknown command: $1${NC}"
|
||||
echo ""
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Executable
+184
@@ -0,0 +1,184 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Screenshot Automation Common Functions
|
||||
# Shared functionality between Android and iOS screenshot scripts
|
||||
|
||||
# This script should be sourced, not executed directly
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
echo "This script should be sourced, not executed directly"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Configuration - these should be set before sourcing this file, but defaults provided
|
||||
SCRIPT_DIR="${SCRIPT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
|
||||
PROJECT_ROOT="${PROJECT_ROOT:-$(dirname "$SCRIPT_DIR")}"
|
||||
MAESTRO_DIR="${MAESTRO_DIR:-$PROJECT_ROOT/maestro}"
|
||||
ENV_FILE="${ENV_FILE:-$PROJECT_ROOT/.env}"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Logging functions
|
||||
log_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
log_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Check common dependencies (flutter, maestro, dotenv, ffprobe)
|
||||
check_common_dependencies() {
|
||||
log_info "Checking common dependencies..."
|
||||
|
||||
local all_found=true
|
||||
|
||||
if ! command -v flutter &> /dev/null; then
|
||||
log_error "Flutter is not installed or not in PATH"
|
||||
all_found=false
|
||||
fi
|
||||
|
||||
if ! command -v maestro &> /dev/null; then
|
||||
log_error "Maestro is not installed or not in PATH"
|
||||
all_found=false
|
||||
fi
|
||||
|
||||
if ! command -v dotenv &> /dev/null; then
|
||||
log_error "dotenv is not installed or not in PATH"
|
||||
all_found=false
|
||||
fi
|
||||
|
||||
if ! command -v ffprobe &> /dev/null; then
|
||||
log_error "ffprobe is not installed or not in PATH (part of ffmpeg)"
|
||||
all_found=false
|
||||
fi
|
||||
|
||||
if [ "$all_found" = false ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_success "Common dependencies found"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Get image dimensions using ffprobe
|
||||
get_image_dimensions() {
|
||||
local image_path="$1"
|
||||
ffprobe -v quiet -select_streams v:0 -show_entries stream=width,height -of csv=p=0 "$image_path" 2>/dev/null
|
||||
}
|
||||
|
||||
# Log image information for debugging
|
||||
log_image_info() {
|
||||
local image_path="$1"
|
||||
local device_type="$2"
|
||||
|
||||
local dimensions=$(get_image_dimensions "$image_path")
|
||||
local filename=$(basename "$image_path")
|
||||
|
||||
if [ -n "$dimensions" ]; then
|
||||
local width=$(echo "$dimensions" | cut -d',' -f1)
|
||||
local height=$(echo "$dimensions" | cut -d',' -f2)
|
||||
log_info "Screenshot: $filename - ${width}x${height} - $device_type"
|
||||
else
|
||||
log_warning "Could not analyze: $filename - assuming $device_type"
|
||||
fi
|
||||
}
|
||||
|
||||
# Clean up old maestro screenshots for specified platform(s)
|
||||
# Usage: clean_old_screenshots "android" or clean_old_screenshots "ios" or clean_old_screenshots "android ios"
|
||||
clean_old_screenshots() {
|
||||
local platforms="$1"
|
||||
|
||||
log_info "Cleaning up old screenshots..."
|
||||
|
||||
for platform in $platforms; do
|
||||
local platform_dir="$MAESTRO_DIR/$platform"
|
||||
|
||||
if [ -d "$platform_dir" ]; then
|
||||
local old_count=$(find "$platform_dir" -name "*.png" 2>/dev/null | wc -l)
|
||||
if [ "$old_count" -gt 0 ]; then
|
||||
log_info "Removing $old_count old screenshot(s) from maestro/$platform/"
|
||||
rm -f "$platform_dir"/*.png
|
||||
else
|
||||
log_info "No old screenshots found in maestro/$platform/"
|
||||
fi
|
||||
else
|
||||
log_info "No $platform screenshot directory found"
|
||||
fi
|
||||
done
|
||||
|
||||
log_success "Screenshot cleanup completed"
|
||||
}
|
||||
|
||||
# Execute maestro tests
|
||||
# Usage: run_maestro_tests [device_id]
|
||||
run_maestro_tests() {
|
||||
local device_id="${1:-}"
|
||||
|
||||
if [ -n "$device_id" ]; then
|
||||
log_info "Running maestro screenshot tests on device $device_id..."
|
||||
else
|
||||
log_info "Running maestro screenshot tests..."
|
||||
fi
|
||||
|
||||
# Check if .env file exists
|
||||
if [ ! -f "$ENV_FILE" ]; then
|
||||
log_error "Environment file not found at $ENV_FILE"
|
||||
log_info "Please create a .env file with required Maestro variables"
|
||||
return 1
|
||||
fi
|
||||
|
||||
log_info "Using environment file: $ENV_FILE"
|
||||
cd "$MAESTRO_DIR"
|
||||
|
||||
# Run maestro tests with optional device specification
|
||||
if [ -n "$device_id" ]; then
|
||||
log_info "Executing: MAESTRO_DEVICE=$device_id dotenv -f $ENV_FILE run maestro test screenshots.yaml"
|
||||
MAESTRO_DEVICE="$device_id" dotenv -f "$ENV_FILE" run maestro test screenshots.yaml
|
||||
else
|
||||
log_info "Executing: dotenv -f $ENV_FILE run maestro test screenshots.yaml"
|
||||
dotenv -f "$ENV_FILE" run maestro test screenshots.yaml
|
||||
fi
|
||||
|
||||
local maestro_exit_code=$?
|
||||
if [ $maestro_exit_code -eq 0 ]; then
|
||||
log_success "Maestro tests completed successfully"
|
||||
return 0
|
||||
else
|
||||
log_error "Maestro tests failed with exit code $maestro_exit_code"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Run Flutter app on specified device
|
||||
# Platform-specific validation should be done in the calling script
|
||||
run_flutter_app() {
|
||||
local device_id="$1"
|
||||
local device_type="$2"
|
||||
local wait_time="${3:-30}" # Optional wait time, default 30s
|
||||
|
||||
log_info "Running Flutter app on $device_type ($device_id)"
|
||||
|
||||
cd "$PROJECT_ROOT"
|
||||
flutter run -d "$device_id" --hot &
|
||||
local flutter_pid=$!
|
||||
|
||||
# Wait for app to be installed and launched
|
||||
log_info "Waiting for Flutter app to launch..."
|
||||
sleep "$wait_time"
|
||||
|
||||
log_success "Flutter app should be running on $device_type"
|
||||
return 0
|
||||
}
|
||||
Executable
+59
@@ -0,0 +1,59 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Sync changelogs between iOS and Android
|
||||
# This script copies the iOS release notes to the Android changelog for the current version
|
||||
|
||||
set -e
|
||||
|
||||
# Get the script's directory
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
PROJECT_ROOT="$SCRIPT_DIR/.."
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
echo -e "${GREEN}📝 Syncing changelogs between iOS and Android${NC}"
|
||||
|
||||
# Extract version code from pubspec.yaml
|
||||
PUBSPEC_PATH="$PROJECT_ROOT/pubspec.yaml"
|
||||
if [ ! -f "$PUBSPEC_PATH" ]; then
|
||||
echo -e "${RED}Error: pubspec.yaml not found at $PUBSPEC_PATH${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VERSION_CODE=$(grep -E "version:\s*(.+)\+(\d+)" "$PUBSPEC_PATH" | sed -E 's/.*\+([0-9]+).*/\1/')
|
||||
|
||||
if [ -z "$VERSION_CODE" ]; then
|
||||
echo -e "${RED}Error: Could not extract version code from pubspec.yaml${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "${YELLOW}Current version code: $VERSION_CODE${NC}"
|
||||
|
||||
# Define paths
|
||||
IOS_RELEASE_NOTES="$PROJECT_ROOT/ios/fastlane/metadata/en-US/release_notes.txt"
|
||||
ANDROID_CHANGELOG="$PROJECT_ROOT/android/fastlane/metadata/android/en-GB/changelogs/$VERSION_CODE.txt"
|
||||
|
||||
# Check if iOS release notes exist
|
||||
if [ ! -f "$IOS_RELEASE_NOTES" ]; then
|
||||
echo -e "${RED}Error: iOS release notes not found at $IOS_RELEASE_NOTES${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create Android changelogs directory if it doesn't exist
|
||||
ANDROID_CHANGELOGS_DIR="$(dirname "$ANDROID_CHANGELOG")"
|
||||
mkdir -p "$ANDROID_CHANGELOGS_DIR"
|
||||
|
||||
# Copy iOS release notes to Android changelog
|
||||
cp "$IOS_RELEASE_NOTES" "$ANDROID_CHANGELOG"
|
||||
|
||||
echo -e "${GREEN}✅ Successfully synced changelog!${NC}"
|
||||
echo -e " iOS release notes → Android changelog ($VERSION_CODE.txt)"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Next steps:${NC}"
|
||||
echo "1. Review the changelog at: $ANDROID_CHANGELOG"
|
||||
echo "2. Commit the changes"
|
||||
echo "3. Run fastlane to deploy"
|
||||
Reference in New Issue
Block a user