Skip to content

Commit

Permalink
perf: performance improvements & ui tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Nov 5, 2023
1 parent 39d7fc8 commit 4c41353
Show file tree
Hide file tree
Showing 9 changed files with 376 additions and 303 deletions.
2 changes: 1 addition & 1 deletion lib/controller/lifecycle_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LifeCycleController {

late final MethodChannel namidaChannel;

_initLiseners() {
void _initLiseners() {
namidaChannel.setMethodCallHandler((call) async {
switch (call.method) {
case 'onResume':
Expand Down
9 changes: 9 additions & 0 deletions lib/ui/dialogs/setting_dialog_with_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void showSettingDialogWithTextField({
bool dateTimeFormat = false,
bool trackTileSeparator = false,
bool addNewPlaylist = false,
void Function()? onTrackTileSettingsChanged,
}) async {
final controller = TextEditingController();
final formKey = GlobalKey<FormState>();
Expand All @@ -48,6 +49,8 @@ void showSettingDialogWithTextField({
);
}

void onTTSetChange() => onTrackTileSettingsChanged?.call();

NamidaNavigator.inst.navigateDialog(
dialog: Form(
key: formKey,
Expand All @@ -61,11 +64,13 @@ void showSettingDialogWithTextField({
if (trackThumbnailSizeinList) {
settings.save(trackThumbnailSizeinList: 70.0);
showResetToDefaultSnackBar("${settings.trackThumbnailSizeinList.value}", title: title);
onTTSetChange();
}
if (trackListTileHeight) {
settings.save(trackListTileHeight: 70.0);
showResetToDefaultSnackBar("${settings.trackListTileHeight.value}", title: title);
Dimensions.inst.updateTrackTileDimensions();
onTTSetChange();
}
if (albumThumbnailSizeinList) {
settings.save(albumThumbnailSizeinList: 90.0);
Expand All @@ -92,6 +97,7 @@ void showSettingDialogWithTextField({
if (trackTileSeparator) {
settings.save(trackTileSeparator: '•');
showResetToDefaultSnackBar("${settings.trackTileSeparator}", title: title);
onTTSetChange();
}

NamidaNavigator.inst.closeDialog();
Expand All @@ -106,10 +112,12 @@ void showSettingDialogWithTextField({
if (formKey.currentState!.validate()) {
if (trackThumbnailSizeinList) {
settings.save(trackThumbnailSizeinList: double.parse(controller.text));
onTTSetChange();
}
if (trackListTileHeight) {
settings.save(trackListTileHeight: double.parse(controller.text));
Dimensions.inst.updateTrackTileDimensions();
onTTSetChange();
}
if (albumThumbnailSizeinList) {
settings.save(albumThumbnailSizeinList: double.parse(controller.text));
Expand All @@ -130,6 +138,7 @@ void showSettingDialogWithTextField({
}
if (trackTileSeparator) {
settings.save(trackTileSeparator: controller.text);
onTTSetChange();
}
if (addNewPlaylist) {
PlaylistController.inst.addNewPlaylist(controller.text);
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/widgets/artwork.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class _ArtworkWidgetState extends State<ArtworkWidget> {
imagePath: widget.path!,
compressed: widget.compressed,
checkFileFirst: false,
size: widget.useTrackTileCacheHeight ? 200 : null,
size: widget.useTrackTileCacheHeight ? 240 : null,
);
if ((res.$1 != null || res.$2 != null) && widget.compressed) setState(() {});
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/widgets/custom_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2845,8 +2845,8 @@ class _NamidaTabViewState extends State<NamidaTabView> with SingleTickerProvider
)
.toList(),
splashBorderRadius: BorderRadius.circular(12.0.multipliedRadius),
indicatorPadding: const EdgeInsets.symmetric(horizontal: 32.0),
indicatorSize: TabBarIndicatorSize.tab,
// indicatorPadding: const EdgeInsets.symmetric(horizontal: 32.0),
indicatorSize: TabBarIndicatorSize.label,
),
Expanded(
child: TabBarView(
Expand Down
597 changes: 318 additions & 279 deletions lib/ui/widgets/library/track_tile.dart

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/ui/widgets/settings/advanced_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ class AdvancedSettings extends StatelessWidget {
child: Row(
children: [
ArtworkWidget(
key: Key(id ?? ''),
thumbnailSize: 92.0,
iconSize: 24.0,
width: 92,
Expand Down
28 changes: 18 additions & 10 deletions lib/ui/widgets/settings/track_tile_customization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import 'package:namida/core/translations/language.dart';
import 'package:namida/ui/widgets/artwork.dart';
import 'package:namida/ui/widgets/custom_widgets.dart';
import 'package:namida/ui/dialogs/setting_dialog_with_text_field.dart';
import 'package:namida/ui/widgets/library/track_tile.dart';

class TrackTileCustomization extends StatelessWidget {
const TrackTileCustomization({super.key});

void _onSettingsChanged() => TrackTileManager.onTrackItemPropChange();

@override
Widget build(BuildContext context) {
return NamidaExpansionTile(
Expand All @@ -37,6 +40,7 @@ class TrackTileCustomization extends StatelessWidget {
onChanged: (value) {
settings.save(forceSquaredTrackThumbnail: !value);
Player.inst.refreshRxVariables();
_onSettingsChanged();
if (!value && settings.trackThumbnailSizeinList.toInt() != settings.trackListTileHeight.toInt()) {
NamidaNavigator.inst.navigateDialog(
dialog: CustomBlurryDialog(
Expand Down Expand Up @@ -92,9 +96,10 @@ class TrackTileCustomization extends StatelessWidget {
icon: Broken.chart_1,
rotateIcon: 1,
title: lang.DISPLAY_THIRD_ROW_IN_TRACK_TILE,
onChanged: (_) => settings.save(
displayThirdRow: !settings.displayThirdRow.value,
),
onChanged: (isTrue) {
settings.save(displayThirdRow: !isTrue);
_onSettingsChanged();
},
value: settings.displayThirdRow.value,
),
),
Expand All @@ -103,19 +108,21 @@ class TrackTileCustomization extends StatelessWidget {
icon: Broken.coin,
rotateIcon: 3,
title: lang.DISPLAY_THIRD_ITEM_IN_ROW_IN_TRACK_TILE,
onChanged: (_) => settings.save(
displayThirdItemInEachRow: !settings.displayThirdItemInEachRow.value,
),
onChanged: (isTrue) {
settings.save(displayThirdItemInEachRow: !isTrue);
_onSettingsChanged();
},
value: settings.displayThirdItemInEachRow.value,
),
),
Obx(
() => CustomSwitchListTile(
icon: Broken.heart,
title: lang.DISPLAY_FAVOURITE_ICON_IN_TRACK_TILE,
onChanged: (_) => settings.save(
displayFavouriteIconInListTile: !settings.displayFavouriteIconInListTile.value,
),
onChanged: (isTrue) {
settings.save(displayFavouriteIconInListTile: !isTrue);
_onSettingsChanged();
},
value: settings.displayFavouriteIconInListTile.value,
),
),
Expand Down Expand Up @@ -269,7 +276,7 @@ class TrackTileCustomization extends StatelessWidget {
);
}

_showTrackItemsDialog(TrackTilePosition p) {
void _showTrackItemsDialog(TrackTilePosition p) {
NamidaNavigator.inst.navigateDialog(
dialog: CustomBlurryDialog(
title: lang.CHOOSE,
Expand All @@ -287,6 +294,7 @@ class TrackTileCustomization extends StatelessWidget {
title: trItem.toText(),
onTap: () {
settings.updateTrackItemList(p, trItem);
_onSettingsChanged();
NamidaNavigator.inst.closeDialog();
},
active: settings.trackItem[p] == trItem,
Expand Down
34 changes: 25 additions & 9 deletions lib/youtube/pages/youtube_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,28 @@ class _YoutubePageState extends State<YoutubePage> with AutomaticKeepAliveClient
return BackgroundWrapper(
child: Obx(
() {
final feed = YoutubeController.inst.homepageFeed;
final List<YoutubeFeed?> l = [];
if (feed.isEmpty) {
l.addAll(List.filled(20, null));
} else {
l.addAll(feed);
final homepageFeed = YoutubeController.inst.homepageFeed;
final feed = homepageFeed.isEmpty ? List<YoutubeFeed?>.filled(10, null) : homepageFeed;

if (feed.isNotEmpty && feed.first == null) {
return ShimmerWrapper(
transparent: false,
shimmerEnabled: true,
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
itemCount: feed.length,
shrinkWrap: true,
itemBuilder: (context, index) {
return YoutubeVideoCard(
isImageImportantInCache: false,
video: null,
playlistID: null,
thumbnailWidth: thumbnailWidth,
thumbnailHeight: thumbnailHeight,
);
},
),
);
}
return NamidaListView(
// padding: const EdgeInsets.only(top: 32.0, bottom: kBottomPadding),
Expand All @@ -51,7 +67,7 @@ class _YoutubePageState extends State<YoutubePage> with AutomaticKeepAliveClient
),
),
itemBuilder: (context, i) {
final feedItem = l[i];
final feedItem = feed[i];
return YoutubeVideoCard(
key: ValueKey(i),
isImageImportantInCache: false,
Expand All @@ -61,8 +77,8 @@ class _YoutubePageState extends State<YoutubePage> with AutomaticKeepAliveClient
thumbnailHeight: thumbnailHeight,
);
},
itemCount: l.length,
itemExtents: List.filled(l.length, thumbnailItemExtent),
itemCount: feed.length,
itemExtents: List.filled(feed.length, thumbnailItemExtent),
);
},
),
Expand Down
2 changes: 1 addition & 1 deletion lib/youtube/widgets/yt_thumbnail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class _YoutubeThumbnailState extends State<YoutubeThumbnail> {
icon: widget.channelUrl != null ? Broken.user : Broken.video,
iconSize: widget.channelUrl != null ? null : widget.width * 0.3,
forceSquared: true,
cacheHeight: (widget.height?.round() ?? widget.width.round()) ~/ 1.4,
cacheHeight: (widget.height?.round() ?? widget.width.round()) ~/ 1.2,
onTopWidgets: [
...widget.onTopWidgets,
if (widget.smallBoxText != null)
Expand Down

0 comments on commit 4c41353

Please sign in to comment.