diff --git a/lib/logic/automation/radarr/api.dart b/lib/logic/automation/radarr/api.dart index 51a0d9b5..8a53acfd 100644 --- a/lib/logic/automation/radarr/api.dart +++ b/lib/logic/automation/radarr/api.dart @@ -808,6 +808,39 @@ class RadarrAPI { return false; } + static Future automaticSearchMovie(int id) async { + List values = Values.radarrValues; + if(values[0] == false) { + return false; + } + try { + String uri = '${values[1]}/api/command?apikey=${values[2]}'; + http.Response response = await http.post( + Uri.encodeFull(uri), + headers: { + 'Content-Type': 'application/json', + }, + body: json.encode({ + 'name': 'MoviesSearch', + 'movieIds': [id], + }), + ); + if(response.statusCode == 201) { + Map body = json.decode(response.body); + if(body.containsKey('status')) { + return true; + } + } else { + logError('automaticSearchMovie', ' HTTP Status Code (${response.statusCode})', null); + } + } catch (e) { + logError('automaticSearchMovie', 'Failed to automatically search for movie releases ($id)', e); + return null; + } + logWarning('automaticSearchMovie', 'Failed to automatically search for movie releases ($id)'); + return null; + } + static Future> searchMovies(String search) async { List values = Values.radarrValues; if(values[0] == false) { diff --git a/lib/pages/radarr/subpages/details/movie.dart b/lib/pages/radarr/subpages/details/movie.dart index 22b67c07..df9a01c5 100644 --- a/lib/pages/radarr/subpages/details/movie.dart +++ b/lib/pages/radarr/subpages/details/movie.dart @@ -182,6 +182,7 @@ class _State extends State { buildOverview(entry, context), RadarrReleases( entry: entry, + scaffoldKey: _scaffoldKey, ), buildFiles(entry, _scaffoldKey, _refreshData, context), ], diff --git a/lib/pages/radarr/subpages/details/tabs/releases.dart b/lib/pages/radarr/subpages/details/tabs/releases.dart index fdf7d5bd..ac1ea8eb 100644 --- a/lib/pages/radarr/subpages/details/tabs/releases.dart +++ b/lib/pages/radarr/subpages/details/tabs/releases.dart @@ -6,11 +6,13 @@ import 'package:lunasea/system/functions.dart'; import 'package:lunasea/system/ui.dart'; class RadarrReleases extends StatefulWidget { + final GlobalKey scaffoldKey; final RadarrCatalogueEntry entry; RadarrReleases({ Key key, @required this.entry, + @required this.scaffoldKey, }): super(key: key); State createState() { @@ -20,7 +22,6 @@ class RadarrReleases extends StatefulWidget { class _State extends State { final _searchController = TextEditingController(); - final _scaffoldKey = GlobalKey(); bool _searched = false; List _entries; String _message = 'Please Search for Releases'; @@ -34,14 +35,10 @@ class _State extends State { @override Widget build(BuildContext context) { - return Scaffold( - key: _scaffoldKey, - body: _buildReleases(), - floatingActionButton: _buildFloatingActionButton(), - ); + return _buildReleases(); } - Future _startSearch() async { + Future _startManualSearch() async { if(mounted) { setState(() { _message = 'Searching...'; @@ -57,27 +54,40 @@ class _State extends State { } } - Widget _buildFloatingActionButton() { - return FloatingActionButton( - heroTag: null, - tooltip: 'Search', - child: Elements.getIcon(Icons.search), - onPressed: _startSearch, - ); + Future _startAutomaticSearch() async { + if(await RadarrAPI.automaticSearchMovie(widget.entry.movieID)) { + Notifications.showSnackBar(widget.scaffoldKey, 'Searching for ${widget.entry.title}...'); + } else { + Notifications.showSnackBar(widget.scaffoldKey, 'Failed to search for ${widget.entry.title}...'); + } + } + + Widget _buildAutomaticSearchButton() { + return Elements.getButton('Automatic Search', () async { + _startAutomaticSearch(); + }); + } + + Widget _buildManualSearchButton() { + return Elements.getButton('Manual Search', () async { + _startManualSearch(); + }, backgroundColor: Colors.orange); } Widget _buildReleases() { return Scrollbar( child: ListView.builder( - itemCount: _entries == null || _entries.length == 0 ? _searched ? 3 : 1 : _entries.length+2, + itemCount: _entries == null || _entries.length == 0 ? _searched ? 5 : 3 : _entries.length+4, itemBuilder: (context, index) { switch(index) { case 0: return _buildSearchBar(); - case 1: return Elements.getDivider(); + case 1: return _buildAutomaticSearchButton(); + case 2: return _buildManualSearchButton(); + case 3: return Elements.getDivider(); } return _entries == null || _entries.length == 0 ? Notifications.centeredMessage(_message) : - _buildEntry(_entries[index-2]); + _buildEntry(_entries[index-4]); }, padding: Elements.getListViewPadding(extraBottom: true), ), @@ -108,9 +118,9 @@ class _State extends State { onPressed: () async { if(release.approved) { if(await _startDownload(release.guid, release.indexerId)) { - Notifications.showSnackBar(_scaffoldKey, 'Download starting...'); + Notifications.showSnackBar(widget.scaffoldKey, 'Download starting...'); } else { - Notifications.showSnackBar(_scaffoldKey, 'Failed to start download'); + Notifications.showSnackBar(widget.scaffoldKey, 'Failed to start download'); } } else { await _showWarnings(release); @@ -122,9 +132,9 @@ class _State extends State { List values = await RadarrDialogs.showDownloadWarningPrompt(context); if(values[0]) { if(await _startDownload(release.guid, release.indexerId)) { - Notifications.showSnackBar(_scaffoldKey, 'Download starting...'); + Notifications.showSnackBar(widget.scaffoldKey, 'Download starting...'); } else { - Notifications.showSnackBar(_scaffoldKey, 'Failed to start download'); + Notifications.showSnackBar(widget.scaffoldKey, 'Failed to start download'); } } } diff --git a/lib/system/ui/elements.dart b/lib/system/ui/elements.dart index 9bd72674..8398938e 100644 --- a/lib/system/ui/elements.dart +++ b/lib/system/ui/elements.dart @@ -86,7 +86,7 @@ class Elements { ); } - static Row getButton(String text, Function onTapHandler) { + static Row getButton(String text, Function onTapHandler, { Color backgroundColor, Color textColor = Colors.white} ) { return Row( children: [ Expanded( @@ -95,14 +95,14 @@ class Elements { title: Text( text, style: TextStyle( - color: Colors.white, + color: textColor, fontWeight: FontWeight.bold, ), textAlign: TextAlign.center, ), onTap: onTapHandler, ), - color: Color(Constants.ACCENT_COLOR), + color: backgroundColor == null ? Color(Constants.ACCENT_COLOR) : backgroundColor, margin: getCardMargin(), elevation: 4.0, ),