Skip to content

Commit

Permalink
perf: perfomance optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Nov 3, 2023
1 parent 5535233 commit 77a7481
Show file tree
Hide file tree
Showing 10 changed files with 491 additions and 415 deletions.
1 change: 1 addition & 0 deletions lib/controller/current_color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ class CurrentColor {
.getArtwork(
imagePath: imagePath,
compressed: true,
size: 200,
)
.then((value) => value.$2);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/controller/navigator_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class NamidaNavigator {

void popAllMenus() {
if (_currentMenusNumber > 0) {
Get.close(_currentMenusNumber);
Get.until((route) => route.isFirst);
_currentMenusNumber = 0;
}
_printMenus();
Expand Down
2 changes: 1 addition & 1 deletion lib/core/namida_converter_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ extension PerformanceModeUtils on PerformanceMode {
enableBlurEffect: false,
enableGlowEffect: false,
enableMiniplayerParallaxEffect: false,
artworkCacheHeightMultiplier: 0.5,
artworkCacheHeightMultiplier: 0.6,
);
case PerformanceMode.balanced:
settings.save(
Expand Down
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ class Namida extends StatelessWidget {
// prevent accidental miniplayer swipe when performing back gesture
Positioned(
right: 0,
child: GestureDetector(
onHorizontalDragUpdate: (details) {},
child: SizedBox(
width: 8.0,
height: context.height,
child: GestureDetector(
onHorizontalDragUpdate: (details) {},
),
),
),
Expand Down
81 changes: 42 additions & 39 deletions lib/packages/miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1246,43 +1246,47 @@ class NamidaMiniPlayer extends StatelessWidget {
child: Stack(
alignment: Alignment.bottomRight,
children: [
NamidaListView(
key: const Key('minikuru'),
itemExtents: List.filled(Player.inst.currentQueue.length, Dimensions.inst.trackTileItemExtent),
scrollController: MiniPlayerController.inst.queueScrollController,
padding: EdgeInsets.only(bottom: 56.0 + SelectedTracksController.inst.bottomPadding.value),
onReorderStart: (index) => MiniPlayerController.inst.invokeStartReordering(),
onReorderEnd: (index) => MiniPlayerController.inst.invokeDoneReordering(),
onReorder: (oldIndex, newIndex) => Player.inst.reorderTrack(oldIndex, newIndex),
itemCount: Player.inst.currentQueue.length,
itemBuilder: (context, i) {
final track = Player.inst.currentQueue[i];
final key = "$i${track.track.path}";
return FadeDismissible(
key: Key("Diss_$key"),
onDismissed: (direction) {
Player.inst.removeFromQueue(i);
MiniPlayerController.inst.invokeDoneReordering();
},
onUpdate: (detailts) {
final isReordering = detailts.progress != 0.0;
if (isReordering) {
MiniPlayerController.inst.invokeStartReordering();
} else {
DefaultTextStyle(
style: context.textTheme.displayMedium!,
child: NamidaListView(
key: const Key('minikuru'),
itemExtents: List.filled(Player.inst.currentQueue.length, Dimensions.inst.trackTileItemExtent),
scrollController: MiniPlayerController.inst.queueScrollController,
padding: EdgeInsets.only(bottom: 56.0 + SelectedTracksController.inst.bottomPadding.value),
onReorderStart: (index) => MiniPlayerController.inst.invokeStartReordering(),
onReorderEnd: (index) => MiniPlayerController.inst.invokeDoneReordering(),
onReorder: (oldIndex, newIndex) => Player.inst.reorderTrack(oldIndex, newIndex),
itemCount: Player.inst.currentQueue.length,
itemBuilder: (context, i) {
final track = Player.inst.currentQueue[i];
final key = "$i${track.track.path}";
return FadeDismissible(
key: Key("Diss_$key"),
onDismissed: (direction) {
Player.inst.removeFromQueue(i);
MiniPlayerController.inst.invokeDoneReordering();
}
},
child: TrackTile(
index: i,
trackOrTwd: track,
displayRightDragHandler: true,
draggableThumbnail: true,
queueSource: QueueSource.playerQueue,
cardColorOpacity: 0.5,
fadeOpacity: i < currentIndex ? 0.3 : 0.0,
),
);
},
},
onUpdate: (detailts) {
final isReordering = detailts.progress != 0.0;
if (isReordering) {
MiniPlayerController.inst.invokeStartReordering();
} else {
MiniPlayerController.inst.invokeDoneReordering();
}
},
child: TrackTile(
key: Key("tt_$key"),
index: i,
trackOrTwd: track,
displayRightDragHandler: true,
draggableThumbnail: true,
queueSource: QueueSource.playerQueue,
cardColorOpacity: 0.5,
fadeOpacity: i < currentIndex ? 0.3 : 0.0,
),
);
},
),
),
Container(
width: context.width,
Expand Down Expand Up @@ -2231,9 +2235,8 @@ class LyricsWrapper extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (cp == 0.0) {
return child;
}
// if (cp == 0.0) return child;

return Obx(
() => AnimatedSwitcher(
key: Key(track.path),
Expand Down
1 change: 0 additions & 1 deletion lib/ui/widgets/artwork.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ class _ArtworkWidgetState extends State<ArtworkWidget> {

final bytes = widget.bytes ?? Indexer.inst.artworksMap[widget.path];
final isValidBytes = bytes != null && bytes.isNotEmpty;
print('HHHHHHHHHHHHH ${bytes?.length} || $_imagePath');
return (_imagePath == null && !isValidBytes) || widget.forceDummyArtwork
? getStockWidget(
stackWithOnTopWidgets: true,
Expand Down
40 changes: 23 additions & 17 deletions lib/ui/widgets/custom_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1921,37 +1921,43 @@ class NamidaContainerDivider extends StatelessWidget {
}
}

class FadeDismissible extends StatelessWidget {
class FadeDismissible extends StatefulWidget {
final Widget child;
final void Function(DismissDirection onDismissed)? onDismissed;
final void Function(DismissUpdateDetails detailts)? onUpdate;
final DismissDirection direction;

FadeDismissible({
super.key,
const FadeDismissible({
required super.key,
required this.child,
this.onDismissed,
this.onUpdate,
this.direction = DismissDirection.horizontal,
});

final fadeOpacity = 0.0.obs;
@override
State<FadeDismissible> createState() => _FadeDismissibleState();
}

class _FadeDismissibleState extends State<FadeDismissible> {
final fadeOpacity = ValueNotifier(0.0);

@override
Widget build(BuildContext context) {
return Dismissible(
key: key!,
onDismissed: onDismissed,
key: widget.key!,
onDismissed: widget.onDismissed,
onUpdate: (details) {
fadeOpacity.value = details.progress;
if (onUpdate != null) onUpdate!(details);
if (widget.onUpdate != null) widget.onUpdate!(details);
},
direction: direction,
child: Obx(
() => AnimatedOpacity(
direction: widget.direction,
child: ValueListenableBuilder(
valueListenable: fadeOpacity,
builder: (context, value, child) => AnimatedOpacity(
duration: const Duration(milliseconds: 100),
opacity: 1 - fadeOpacity.value,
child: child,
child: widget.child,
),
),
);
Expand Down Expand Up @@ -2742,16 +2748,16 @@ class _NamidaLifeCycleWrapperState extends State<NamidaLifeCycleWrapper> {
namidaChannel.setMethodCallHandler((call) async {
switch (call.method) {
case 'onResume':
await Future.wait([
SystemChrome.setPreferredOrientations(kDefaultOrientations),
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values),
if (widget.onResume != null) widget.onResume!(),
]);
await Future.wait([
SystemChrome.setPreferredOrientations(kDefaultOrientations),
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values),
if (widget.onResume != null) widget.onResume!(),
]);
case 'onUserLeaveHint':
await widget.onSuspending?.call();
case 'onStop':
await widget.onDetach?.call();
}
}
});
}

Expand Down
Loading

0 comments on commit 77a7481

Please sign in to comment.