Skip to content

Commit

Permalink
feat(radarr): support moving files when editing the storage path
Browse files Browse the repository at this point in the history
  • Loading branch information
JagandeepBrar committed Sep 26, 2022
1 parent cfbfb2b commit c9bd02b
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 18 deletions.
5 changes: 5 additions & 0 deletions assets/localization/en.json
Expand Up @@ -78,6 +78,7 @@
"lunasea.Months": "{} Months",
"lunasea.MonthsAgo": "{} Months Ago",
"lunasea.New": "New",
"lunasea.No": "No",
"lunasea.NotSet": "Not Set",
"lunasea.NoModulesEnabled": "No Modules Enabled",
"lunasea.OneDay": "1 Day",
Expand Down Expand Up @@ -127,6 +128,7 @@
"lunasea.Website": "Website",
"lunasea.Years": "{} Years",
"lunasea.YearsAgo": "{} Years Ago",
"lunasea.Yes": "Yes",
"overseerr.Audio": "Audio",
"overseerr.Approved": "Approved",
"overseerr.Available": "Available",
Expand Down Expand Up @@ -172,6 +174,7 @@
"radarr.Codec": "Codec",
"radarr.Configure": "Configure",
"radarr.Copy": "Copy",
"radarr.CopyFiles": "Hardlink/Copy Files",
"radarr.CopyFull": "Hardlink/Copy Files",
"radarr.CutoffUnmet": "Cutoff Unmet",
"radarr.DateAdded": "Date Added",
Expand Down Expand Up @@ -208,6 +211,8 @@
"radarr.MonitorMovie": "Monitor Movie",
"radarr.More": "More",
"radarr.Move": "Move",
"radarr.MoveFiles": "Move Files",
"radarr.MoveFilesDescription": "Would you like to move the files?",
"radarr.MoveFull": "Move Files",
"radarr.Movie": "Movie",
"radarr.Movies": "Movies",
Expand Down
11 changes: 9 additions & 2 deletions lib/api/radarr/commands/movie.dart
Expand Up @@ -29,8 +29,15 @@ class RadarrCommandHandlerMovie {
///
/// Required Parameters:
/// - `movie`: [RadarrMovie] object with the updated information
Future<RadarrMovie> update({required RadarrMovie movie}) async =>
_commandUpdateMovie(_client, movie: movie);
Future<RadarrMovie> update({
required RadarrMovie movie,
bool moveFiles = false,
}) async =>
_commandUpdateMovie(
_client,
movie: movie,
moveFiles: moveFiles,
);

/// Handler for [movie/{id}](https://radarr.video/docs/api/#/Movie/deleteMovie).
///
Expand Down
9 changes: 8 additions & 1 deletion lib/api/radarr/commands/movie/update_movie.dart
Expand Up @@ -3,7 +3,14 @@ part of radarr_commands;
Future<RadarrMovie> _commandUpdateMovie(
Dio client, {
required RadarrMovie movie,
required bool moveFiles,
}) async {
Response response = await client.put('movie', data: movie.toJson());
Response response = await client.put(
'movie',
data: movie.toJson(),
queryParameters: {
'moveFiles': moveFiles,
},
);
return RadarrMovie.fromJson(response.data);
}
3 changes: 2 additions & 1 deletion lib/modules/radarr/core/api_helper.dart
Expand Up @@ -260,14 +260,15 @@ class RadarrAPIHelper {
Future<bool> updateMovie({
required BuildContext context,
required RadarrMovie movie,
required bool moveFiles,
bool showSnackbar = true,
}) async {
if (context.read<RadarrState>().enabled) {
return await context
.read<RadarrState>()
.api!
.movie
.update(movie: movie)
.update(movie: movie, moveFiles: moveFiles)
.then((_) async {
return await context
.read<RadarrState>()
Expand Down
27 changes: 27 additions & 0 deletions lib/modules/radarr/core/dialogs.dart
Expand Up @@ -702,4 +702,31 @@ class RadarrDialogs {
contentPadding: LunaDialog.listDialogContentPadding(),
);
}

Future<bool> moveFiles() async {
bool _flag = false;

void _setValues(bool flag) {
_flag = flag;
Navigator.of(LunaState.context, rootNavigator: true).pop();
}

await LunaDialog.dialog(
context: LunaState.context,
title: 'radarr.MoveFiles'.tr(),
contentPadding: LunaDialog.textDialogContentPadding(),
cancelButtonText: 'lunasea.No'.tr(),
buttons: [
LunaDialog.button(
text: 'lunasea.Yes'.tr(),
onPressed: () => _setValues(true),
),
],
content: [
LunaDialog.textContent(text: 'radarr.MoveFilesDescription'.tr()),
],
);

return _flag;
}
}
27 changes: 15 additions & 12 deletions lib/modules/radarr/routes/edit_movie/widgets/bottom_action_bar.dart
Expand Up @@ -24,19 +24,22 @@ class RadarrEditMovieActionBar extends StatelessWidget {
}

Future<void> _updateOnTap(BuildContext context) async {
if (context.read<RadarrMoviesEditState>().canExecuteAction) {
context.read<RadarrMoviesEditState>().state = LunaLoadingState.ACTIVE;
if (context.read<RadarrMoviesEditState>().movie != null) {
RadarrMovie movie = context
.read<RadarrMoviesEditState>()
.movie!
.updateEdits(context.read<RadarrMoviesEditState>());
bool result = await RadarrAPIHelper().updateMovie(
context: context,
movie: movie,
);
if (result) LunaRouter().popSafely();
final state = context.read<RadarrMoviesEditState>();
state.state = LunaLoadingState.ACTIVE;

if (state.canExecuteAction && state.movie != null) {
bool moveFiles = false;
if (state.path != state.movie?.path) {
moveFiles = await RadarrDialogs().moveFiles();
}

final movie = state.movie!.updateEdits(state);
bool result = await RadarrAPIHelper().updateMovie(
context: context,
movie: movie,
moveFiles: moveFiles,
);
if (result) LunaRouter().popSafely();
}
}
}
2 changes: 1 addition & 1 deletion lib/modules/settings/routes/system/route.dart
Expand Up @@ -66,7 +66,7 @@ class _State extends State<SystemRoute> with LunaScrollControllerMixin {
Widget _clearImageCache() {
return LunaBlock(
title: 'Clear Image Cache',
body: const [TextSpan(text: 'Clear cached images from the disk')],
body: const [TextSpan(text: 'Clear Cached Images From the Disk')],
trailing: const LunaIconButton(icon: Icons.image_not_supported_rounded),
onTap: () async {
bool result = await SettingsDialogs().clearImageCache(context);
Expand Down
4 changes: 3 additions & 1 deletion localization/lunasea/en.json
Expand Up @@ -57,6 +57,7 @@
"lunasea.Months": "{} Months",
"lunasea.MonthsAgo": "{} Months Ago",
"lunasea.New": "New",
"lunasea.No": "No",
"lunasea.NotSet": "Not Set",
"lunasea.NoModulesEnabled": "No Modules Enabled",
"lunasea.OneDay": "1 Day",
Expand Down Expand Up @@ -105,5 +106,6 @@
"lunasea.Warning": "Warning",
"lunasea.Website": "Website",
"lunasea.Years": "{} Years",
"lunasea.YearsAgo": "{} Years Ago"
"lunasea.YearsAgo": "{} Years Ago",
"lunasea.Yes": "Yes"
}
3 changes: 3 additions & 0 deletions localization/radarr/en.json
Expand Up @@ -18,6 +18,7 @@
"radarr.Codec": "Codec",
"radarr.Configure": "Configure",
"radarr.Copy": "Copy",
"radarr.CopyFiles": "Hardlink/Copy Files",
"radarr.CopyFull": "Hardlink/Copy Files",
"radarr.CutoffUnmet": "Cutoff Unmet",
"radarr.DateAdded": "Date Added",
Expand Down Expand Up @@ -54,6 +55,8 @@
"radarr.MonitorMovie": "Monitor Movie",
"radarr.More": "More",
"radarr.Move": "Move",
"radarr.MoveFiles": "Move Files",
"radarr.MoveFilesDescription": "Would you like to move the files?",
"radarr.MoveFull": "Move Files",
"radarr.Movie": "Movie",
"radarr.Movies": "Movies",
Expand Down

0 comments on commit c9bd02b

Please sign in to comment.