Skip to content

Commit

Permalink
feat: edit & rename download tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Dec 2, 2023
1 parent ea5d4c2 commit e500d93
Show file tree
Hide file tree
Showing 11 changed files with 470 additions and 206 deletions.
2 changes: 1 addition & 1 deletion lib/controller/video_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ class VideoController {
if (client != null) {
final res = await client.get<Uint8List?>(
link,
options: Options(responseType: ResponseType.bytes),
options: Options(responseType: ResponseType.bytes, validateStatus: (status) => true),
);
requestRes = (res.data ?? Uint8List.fromList([]), res.statusCode ?? 404);
}
Expand Down
17 changes: 17 additions & 0 deletions lib/core/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -456,3 +456,20 @@ extension NavigatorUtils on BuildContext? {
if (context != null && context.mounted) Navigator.of(context, rootNavigator: rootNavigator).maybePop();
}
}

extension DisposingUtils on TextEditingController {
Future<void> disposeAfterAnimation({int durationMS = 200, void Function()? also}) async {
void fn() {
dispose();
if (also != null) also();
}

await fn.executeDelayed(Duration(milliseconds: durationMS));
}
}

extension ExecuteDelayedUtils<T> on T Function() {
Future<T> executeDelayed(Duration dur) async {
return await Future.delayed(dur, this);
}
}
92 changes: 92 additions & 0 deletions lib/core/functions.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:io';

import 'package:calendar_date_picker2/calendar_date_picker2.dart';
Expand All @@ -8,6 +9,7 @@ import 'package:history_manager/history_manager.dart';
import 'package:namida/class/folder.dart';
import 'package:namida/class/queue.dart';
import 'package:namida/class/track.dart';
import 'package:namida/controller/current_color.dart';
import 'package:namida/controller/folders_controller.dart';
import 'package:namida/controller/history_controller.dart';
import 'package:namida/controller/indexer_controller.dart';
Expand All @@ -23,6 +25,7 @@ import 'package:namida/core/extensions.dart';
import 'package:namida/core/icon_fonts/broken_icons.dart';
import 'package:namida/core/namida_converter_ext.dart';
import 'package:namida/core/translations/language.dart';
import 'package:namida/ui/dialogs/edit_tags_dialog.dart';
import 'package:namida/ui/pages/subpages/album_tracks_subpage.dart';
import 'package:namida/ui/pages/subpages/artist_tracks_subpage.dart';
import 'package:namida/ui/pages/subpages/genre_tracks_subpage.dart';
Expand Down Expand Up @@ -372,6 +375,95 @@ Future<void> showCalendarDialog<T extends ItemWithDate, E>({
);
}

Future<String> showNamidaBottomSheetWithTextField({
required BuildContext context,
bool isScrollControlled = true,
bool useRootNavigator = true,
bool showDragHandle = true,
required String title,
String? initalControllerText,
required String hintText,
required String labelText,
required String? Function(String? value)? validator,
required String buttonText,
TextStyle? buttonTextStyle,
Color? buttonColor,
required FutureOr<bool> Function(String text) onButtonTap,
}) async {
final controller = TextEditingController(text: initalControllerText);
final GlobalKey<FormState> formKey = GlobalKey<FormState>();

final focusNode = FocusNode();
focusNode.requestFocus();

await Future.delayed(Duration.zero); // delay bcz sometimes doesnt show
// ignore: use_build_context_synchronously
await showModalBottomSheet(
context: context,
useRootNavigator: useRootNavigator,
showDragHandle: showDragHandle,
isScrollControlled: isScrollControlled,
builder: (context) {
final bottomPadding = MediaQuery.viewInsetsOf(context).bottom;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 28.0).add(EdgeInsets.only(bottom: 18.0 + bottomPadding)),
child: Form(
key: formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
title,
style: context.textTheme.displayLarge,
),
const SizedBox(height: 18.0),
CustomTagTextField(
focusNode: focusNode,
controller: controller,
hintText: hintText,
labelText: labelText,
validator: validator,
),
const SizedBox(height: 18.0),
Row(
children: [
SizedBox(width: context.width * 0.1),
CancelButton(onPressed: context.safePop),
SizedBox(width: context.width * 0.1),
Expanded(
child: NamidaInkWell(
borderRadius: 12.0,
padding: const EdgeInsets.all(12.0),
height: 48.0,
bgColor: buttonColor ?? CurrentColor.inst.color,
decoration: const BoxDecoration(),
child: Center(
child: Text(
buttonText,
style: buttonTextStyle ?? context.textTheme.displayMedium?.copyWith(color: Colors.white.withOpacity(0.9)),
),
),
onTap: () async {
if (formKey.currentState!.validate()) {
final canPop = await onButtonTap(controller.text);
if (canPop && context.mounted) context.safePop();
}
},
),
),
],
),
],
),
),
);
},
);
final t = controller.text;
controller.disposeAfterAnimation(also: focusNode.dispose);
return t;
}

// Returns a [0-1] scale representing how much similar both are.
double checkIfListsSimilar<E>(List<E> q1, List<E> q2, {bool fullyFunctional = false}) {
if (fullyFunctional) {
Expand Down
2 changes: 2 additions & 0 deletions lib/core/translations/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ abstract class LanguageKeys {
String get FAILED => _getKey('FAILED');
String get FAVOURITES => _getKey('FAVOURITES');
String get FETCHING => _getKey('FETCHING');
String get FILENAME_SHOULDNT_START_WITH => _getKey('FILENAME_SHOULDNT_START_WITH');
String get FILE_NAME_WO_EXT => _getKey('FILE_NAME_WO_EXT');
String get FILE_NAME => _getKey('FILE_NAME');
String get FILE => _getKey('FILE');
Expand Down Expand Up @@ -455,6 +456,7 @@ abstract class LanguageKeys {
String get REMOVE_WHITESPACES => _getKey('REMOVE_WHITESPACES');
String get REMOVE => _getKey('REMOVE');
String get REMOVED => _getKey('REMOVED');
String get RENAME => _getKey('RENAME');
String get RENAME_PLAYLIST => _getKey('RENAME_PLAYLIST');
String get REORDERABLE => _getKey('REORDERABLE');
String get REPEAT_FOR_N_TIMES => _getKey('REPEAT_FOR_N_TIMES');
Expand Down
2 changes: 1 addition & 1 deletion lib/youtube/class/youtube_item_download_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:newpipeextractor_dart/newpipeextractor_dart.dart';

class YoutubeItemDownloadConfig {
final String id;
final String filename;
String filename; // filename can be changed after deciding quality/codec, or manually.
final Map<String, String?> ffmpegTags;
DateTime? fileDate;
VideoStream? videoStream;
Expand Down
Loading

0 comments on commit e500d93

Please sign in to comment.