Skip to content

Commit

Permalink
chore: refactor some parts
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Oct 3, 2024
1 parent 044622c commit 8efe0a6
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 34 deletions.
12 changes: 6 additions & 6 deletions lib/class/track.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,6 @@ extension SelectableListUtils on Iterable<Selectable> {
}

class Track extends Selectable<String> {
Folder get folder => Folder.explicit(folderPath);

bool hasInfoInLibrary() => toTrackExtOrNull() != null;
TrackExtended toTrackExt() => toTrackExtOrNull() ?? kDummyExtendedTrack.copyWith(title: path.getFilenameWOExt, path: path);
TrackExtended? toTrackExtOrNull() => Indexer.inst.allTracksMappedByPath[path];

@override
Track get track => this;

Expand Down Expand Up @@ -628,6 +622,12 @@ extension TrackExtUtils on TrackExtended {
}

extension TrackUtils on Track {
Folder get folder => Folder.explicit(folderPath);

bool hasInfoInLibrary() => toTrackExtOrNull() != null;
TrackExtended toTrackExt() => toTrackExtOrNull() ?? kDummyExtendedTrack.copyWith(title: path.getFilenameWOExt, path: path);
TrackExtended? toTrackExtOrNull() => Indexer.inst.allTracksMappedByPath[path];

String get yearPreferyyyyMMdd => toTrackExt().yearPreferyyyyMMdd;

String get title => toTrackExt().title;
Expand Down
14 changes: 6 additions & 8 deletions lib/controller/ffmpeg_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,20 +339,18 @@ class NamidaFFMPEG {
}) async {
assert(quality >= 1 && quality <= 31, 'quality ranges only between 1 & 31');

final didExecute = await _ffmpegExecute('-i "$videoPath" -map 0:v -map -0:V -c copy -y "$thumbnailSavePath"');
if (didExecute) return true;

int? atMillisecond = atDuration?.inMilliseconds;
if (atMillisecond == null) {
final duration = await getMediaDuration(videoPath);
if (duration != null) atMillisecond = duration.inMilliseconds;
}

final didExecute = await _ffmpegExecute('-i "$videoPath" -map 0:v -map -0:V -c copy -y "$thumbnailSavePath"');
if (didExecute) {
return true;
} else {
final totalSeconds = (atMillisecond ?? 0) / 1000; // converting to decimal seconds.
final extractFromSecond = totalSeconds * 0.1; // thumbnail at 10% of duration.
return await _ffmpegExecute('-ss $extractFromSecond -i "$videoPath" -frames:v 1 -q:v $quality -y "$thumbnailSavePath"');
}
final totalSeconds = (atMillisecond ?? 0) / 1000; // converting to decimal seconds.
final extractFromSecond = totalSeconds * 0.1; // thumbnail at 10% of duration.
return await _ffmpegExecute('-ss $extractFromSecond -i "$videoPath" -frames:v 1 -q:v $quality -y "$thumbnailSavePath"');
}

Future<Duration?> getMediaDuration(String path) async {
Expand Down
2 changes: 2 additions & 0 deletions lib/controller/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class _SettingsController with SettingsFileWriter {
final heatmapListensView = false.obs;
final RxList<String> backupItemslist = [
AppPaths.TRACKS,
AppPaths.TRACKS_STATS_OLD,
AppPaths.TRACKS_STATS_DB_INFO.file.path,
AppPaths.TOTAL_LISTEN_TIME,
AppPaths.VIDEOS_CACHE,
Expand All @@ -131,6 +132,7 @@ class _SettingsController with SettingsFileWriter {
AppDirs.YT_PLAYLISTS,
AppDirs.YT_HISTORY_PLAYLIST,
AppPaths.YT_LIKES_PLAYLIST,
AppDirs.YT_DOWNLOAD_TASKS,
].obs;
final enableVideoPlayback = true.obs;
final enableLyrics = false.obs;
Expand Down
7 changes: 2 additions & 5 deletions lib/core/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,10 @@ extension CloseDialogIfTrueFuture on FutureOr<bool> {
}
}

extension ThreadOpener<M, R> on ComputeCallback<M, R> {
/// Executes function on a separate thread using compute().
extension IsolateOpener<M, R> on ComputeCallback<M, R> {
/// Executes function on a separate isolate using compute().
/// Must be `static` or `global` function.
Future<R> thready(M parameter) async {
try {
WidgetsFlutterBinding.ensureInitialized();
} catch (_) {}
return await compute(this, parameter);
}
}
Expand Down
29 changes: 28 additions & 1 deletion lib/packages/miniplayer_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ class _NamidaMiniPlayerBaseState<E extends Playable> extends State<NamidaMiniPla
child: SizedBox(
height: velpy(a: 82.0, b: panelFinal, c: cp),
width: double.infinity,
child: AnimatedDecoration(
child: _AnimatedDecorationOrDecoration(
duration: const Duration(milliseconds: kThemeAnimationDurationMS),
decoration: BoxDecoration(
color: context.theme.scaffoldBackgroundColor,
Expand Down Expand Up @@ -1586,3 +1586,30 @@ class _QueueListChildWrapper extends StatelessWidget {
);
}
}

class _AnimatedDecorationOrDecoration extends StatelessWidget {
final Duration duration;
final Decoration decoration;
final Widget child;

const _AnimatedDecorationOrDecoration({
super.key,
required this.duration,
required this.decoration,
required this.child,
});

@override
Widget build(BuildContext context) {
return settings.animatedTheme.value
? AnimatedDecoration(
decoration: decoration,
duration: duration,
child: child,
)
: DecoratedBox(
decoration: decoration,
child: child,
);
}
}
25 changes: 13 additions & 12 deletions lib/ui/widgets/custom_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2859,6 +2859,18 @@ class NamidaInkWell extends StatelessWidget {
Widget build(BuildContext context) {
final realBorderRadius = transparentHighlight ? 0.0 : borderRadius;
final borderR = BorderRadius.circular(realBorderRadius.multipliedRadius);
final childFinal = Material(
type: MaterialType.transparency,
child: InkWell(
highlightColor: transparentHighlight ? Colors.transparent : Color.alphaBlend(context.theme.scaffoldBackgroundColor.withAlpha(20), context.theme.highlightColor),
onTap: onTap,
onLongPress: onLongPress,
child: Padding(
padding: padding,
child: child,
),
),
);
return AnimatedContainer(
alignment: alignment,
height: height,
Expand All @@ -2874,18 +2886,7 @@ class NamidaInkWell extends StatelessWidget {
borderRadius: borderR,
),
clipBehavior: Clip.antiAlias,
child: Material(
type: MaterialType.transparency,
child: InkWell(
highlightColor: transparentHighlight ? Colors.transparent : Color.alphaBlend(context.theme.scaffoldBackgroundColor.withAlpha(20), context.theme.highlightColor),
onTap: onTap,
onLongPress: onLongPress,
child: Padding(
padding: padding,
child: child,
),
),
),
child: childFinal,
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/widgets/library/track_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,13 @@ class TrackTile extends StatelessWidget {
),
),
if (track is Video)
const Positioned(
Positioned(
top: 6.0,
right: 6.0,
child: Icon(
Broken.video,
size: 12.0,
color: textColor?.withAlpha(100) ?? context.textTheme.displaySmall?.color?.withAlpha(100),
),
),
],
Expand Down
1 change: 1 addition & 0 deletions lib/ui/widgets/settings/playback_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:audio_service/audio_service.dart';

import 'package:namida/base/setting_subpage_provider.dart';
import 'package:namida/class/track.dart';
import 'package:namida/controller/navigator_controller.dart';
import 'package:namida/controller/player_controller.dart';
import 'package:namida/controller/settings_controller.dart';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 4.5.16-beta+241003149
version: 4.5.19-beta+241003149

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit 8efe0a6

Please sign in to comment.