Skip to content

Commit

Permalink
feat: performance mode
Browse files Browse the repository at this point in the history
(highPerformance, balanced, goodLooking, custom)
  • Loading branch information
MSOB7YY committed Oct 14, 2023
1 parent aca3df4 commit a3dcedc
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 12 deletions.
18 changes: 16 additions & 2 deletions lib/controller/settings_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SettingsController {
final RxInt searchResultsPlayMode = 1.obs;
final RxDouble borderRadiusMultiplier = 1.0.obs;
final RxDouble fontScaleFactor = 0.9.obs;
final RxDouble artworkCacheHeightMultiplier = 0.8.obs;
final RxDouble trackThumbnailSizeinList = 70.0.obs;
final RxDouble trackListTileHeight = 70.0.obs;
final RxDouble albumThumbnailSizeinList = 90.0.obs;
Expand All @@ -47,8 +48,8 @@ class SettingsController {
final RxInt artistGridCount = 3.obs;
final RxInt genreGridCount = 2.obs;
final RxInt playlistGridCount = 1.obs;
final RxBool enableBlurEffect = true.obs;
final RxBool enableGlowEffect = true.obs;
final RxBool enableBlurEffect = false.obs;
final RxBool enableGlowEffect = false.obs;
final RxBool hourFormat12 = true.obs;
final RxString dateTimeFormat = 'MMM yyyy'.obs;
final RxList<String> trackArtistsSeparators = <String>['&', ',', ';', '//', ' ft. ', ' x '].obs;
Expand Down Expand Up @@ -177,6 +178,7 @@ class SettingsController {
final RxBool pickColorsFromDeviceWallpaper = false.obs;
final onNotificationTapAction = NotificationTapAction.openApp.obs;
final onYoutubeLinkOpen = OnYoutubeLinkOpenAction.alwaysAsk.obs;
final performanceMode = PerformanceMode.balanced.obs;

final RxMap<TrackTilePosition, TrackTileItem> trackItem = {
TrackTilePosition.row1Item1: TrackTileItem.title,
Expand Down Expand Up @@ -269,6 +271,7 @@ class SettingsController {
searchResultsPlayMode.value = json['searchResultsPlayMode'] ?? searchResultsPlayMode.value;
borderRadiusMultiplier.value = json['borderRadiusMultiplier'] ?? borderRadiusMultiplier.value;
fontScaleFactor.value = json['fontScaleFactor'] ?? fontScaleFactor.value;
artworkCacheHeightMultiplier.value = json['artworkCacheHeightMultiplier'] ?? artworkCacheHeightMultiplier.value;
trackThumbnailSizeinList.value = json['trackThumbnailSizeinList'] ?? trackThumbnailSizeinList.value;
trackListTileHeight.value = json['trackListTileHeight'] ?? trackListTileHeight.value;
albumThumbnailSizeinList.value = json['albumThumbnailSizeinList'] ?? albumThumbnailSizeinList.value;
Expand Down Expand Up @@ -392,6 +395,7 @@ class SettingsController {
pickColorsFromDeviceWallpaper.value = json['pickColorsFromDeviceWallpaper'] ?? pickColorsFromDeviceWallpaper.value;
onNotificationTapAction.value = NotificationTapAction.values.getEnum(json['onNotificationTapAction']) ?? onNotificationTapAction.value;
onYoutubeLinkOpen.value = OnYoutubeLinkOpenAction.values.getEnum(json['onYoutubeLinkOpen']) ?? onYoutubeLinkOpen.value;
performanceMode.value = PerformanceMode.values.getEnum(json['performanceMode']) ?? performanceMode.value;

trackItem.value = _getEnumMap(
json['trackItem'],
Expand Down Expand Up @@ -456,6 +460,7 @@ class SettingsController {
'searchResultsPlayMode': searchResultsPlayMode.value,
'borderRadiusMultiplier': borderRadiusMultiplier.value,
'fontScaleFactor': fontScaleFactor.value,
'artworkCacheHeightMultiplier': artworkCacheHeightMultiplier.value,
'trackThumbnailSizeinList': trackThumbnailSizeinList.value,
'trackListTileHeight': trackListTileHeight.value,
'albumThumbnailSizeinList': albumThumbnailSizeinList.value,
Expand Down Expand Up @@ -555,6 +560,7 @@ class SettingsController {
'mostPlayedTimeRange': mostPlayedTimeRange.value.convertToString,
'onNotificationTapAction': onNotificationTapAction.value.convertToString,
'onYoutubeLinkOpen': onYoutubeLinkOpen.value.convertToString,
'performanceMode': performanceMode.value.convertToString,
'mostPlayedCustomDateRange': mostPlayedCustomDateRange.value.toJson(),
'mostPlayedCustomisStartOfDay': mostPlayedCustomisStartOfDay.value,

Expand Down Expand Up @@ -604,6 +610,7 @@ class SettingsController {
List<AlbumIdentifier>? albumIdentifiers,
double? borderRadiusMultiplier,
double? fontScaleFactor,
double? artworkCacheHeightMultiplier,
double? trackThumbnailSizeinList,
double? trackListTileHeight,
double? albumThumbnailSizeinList,
Expand Down Expand Up @@ -713,6 +720,7 @@ class SettingsController {
MostPlayedTimeRange? mostPlayedTimeRange,
NotificationTapAction? onNotificationTapAction,
OnYoutubeLinkOpenAction? onYoutubeLinkOpen,
PerformanceMode? performanceMode,
DateRange? mostPlayedCustomDateRange,
bool? mostPlayedCustomisStartOfDay,
bool? didSupportNamida,
Expand Down Expand Up @@ -779,6 +787,9 @@ class SettingsController {
if (fontScaleFactor != null) {
this.fontScaleFactor.value = fontScaleFactor;
}
if (artworkCacheHeightMultiplier != null) {
this.artworkCacheHeightMultiplier.value = artworkCacheHeightMultiplier;
}
if (trackThumbnailSizeinList != null) {
this.trackThumbnailSizeinList.value = trackThumbnailSizeinList;
}
Expand Down Expand Up @@ -1138,6 +1149,9 @@ class SettingsController {
if (onYoutubeLinkOpen != null) {
this.onYoutubeLinkOpen.value = onYoutubeLinkOpen;
}
if (performanceMode != null) {
this.performanceMode.value = performanceMode;
}
if (mostPlayedCustomDateRange != null) {
this.mostPlayedCustomDateRange.value = mostPlayedCustomDateRange;
}
Expand Down
7 changes: 7 additions & 0 deletions lib/core/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,10 @@ enum OnYoutubeLinkOpenAction {
addToPlaylist,
alwaysAsk,
}

enum PerformanceMode {
highPerformance,
balanced,
goodLooking,
custom,
}
48 changes: 47 additions & 1 deletion lib/core/namida_converter_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ extension OnYoutubeLinkOpenActionUtils on OnYoutubeLinkOpenAction {
final idnames = {for (final id in ids) id: YoutubeController.inst.fetchVideoDetailsFromCacheSync(id)?.name};
showAddToPlaylistSheet(ids: ids, idsNamesLookup: idnames);
case OnYoutubeLinkOpenAction.play:
Player.inst.playOrPause(0, ids.map((e) => YoutubeID(id: e, playlistID: null)), QueueSource.others);
await Player.inst.playOrPause(0, ids.map((e) => YoutubeID(id: e, playlistID: null)), QueueSource.others);
case OnYoutubeLinkOpenAction.alwaysAsk:
{
final newVals = List<OnYoutubeLinkOpenAction>.from(OnYoutubeLinkOpenAction.values);
Expand Down Expand Up @@ -498,6 +498,40 @@ extension OnYoutubeLinkOpenActionUtils on OnYoutubeLinkOpenAction {
}
}

extension PerformanceModeUtils on PerformanceMode {
String toText() => _NamidaConverters.inst.getTitle(this);
IconData toIcon() => _NamidaConverters.inst.getIcon(this);

Future<void> execute() async {
switch (this) {
case PerformanceMode.highPerformance:
settings.save(
enableBlurEffect: false,
enableGlowEffect: false,
enableMiniplayerParallaxEffect: false,
artworkCacheHeightMultiplier: 0.5,
);
case PerformanceMode.balanced:
settings.save(
enableBlurEffect: false,
enableGlowEffect: false,
enableMiniplayerParallaxEffect: true,
artworkCacheHeightMultiplier: 0.8,
);
case PerformanceMode.goodLooking:
settings.save(
enableBlurEffect: true,
enableGlowEffect: true,
enableMiniplayerParallaxEffect: true,
artworkCacheHeightMultiplier: 1.0,
);
// case PerformanceMode.custom:
default:
null;
}
}
}

extension ThemeUtils on ThemeMode {
IconData toIcon() => _NamidaConverters.inst.getIcon(this);
}
Expand Down Expand Up @@ -1186,6 +1220,12 @@ class _NamidaConverters {
OnYoutubeLinkOpenAction.play: lang.PLAY,
OnYoutubeLinkOpenAction.addToPlaylist: lang.ADD_TO_PLAYLIST,
OnYoutubeLinkOpenAction.alwaysAsk: lang.ALWAYS_ASK,
},
PerformanceMode: {
PerformanceMode.highPerformance: lang.HIGH_PERFORMANCE,
PerformanceMode.balanced: lang.BALANCED,
PerformanceMode.goodLooking: lang.GOOD_LOOKING,
PerformanceMode.custom: lang.CUSTOM,
}
};

Expand Down Expand Up @@ -1293,6 +1333,12 @@ class _NamidaConverters {
OnYoutubeLinkOpenAction.play: Broken.play,
OnYoutubeLinkOpenAction.addToPlaylist: Broken.music_library_2,
OnYoutubeLinkOpenAction.alwaysAsk: Broken.message_question,
},
PerformanceMode: {
PerformanceMode.highPerformance: Broken.activity,
PerformanceMode.balanced: Broken.cd,
PerformanceMode.goodLooking: Broken.buy_crypto,
PerformanceMode.custom: Broken.candle,
}
};
_toTitle
Expand Down
4 changes: 4 additions & 0 deletions lib/core/translations/keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class LanguageKeys {
late String AUTOMATIC_BACKUP;
late String BACKUP_AND_RESTORE_SUBTITLE;
late String BACKUP_AND_RESTORE;
late String BALANCED;
late String BETA;
late String BETWEEN_DATES;
late String BITRATE;
Expand Down Expand Up @@ -211,6 +212,7 @@ class LanguageKeys {
late String GENERATE;
late String GENRE;
late String GENRES;
late String GOOD_LOOKING;
late String GO_TO_ALBUM;
late String GO_TO_ARTIST;
late String GO_TO_CHANNEL;
Expand All @@ -221,6 +223,7 @@ class LanguageKeys {
late String HEIGHT_OF_ALBUM_TILE;
late String HEIGHT_OF_TRACK_TILE;
late String HIGH_MATCHES;
late String HIGH_PERFORMANCE;
late String HISTORY;
late String HISTORY_IMPORT_MISSING_ENTRIES_NOTE;
late String HISTORY_LISTENS_REPLACE_WARNING;
Expand Down Expand Up @@ -352,6 +355,7 @@ class LanguageKeys {
late String PAUSE_FADE_DURATION;
late String PAUSE_PLAYBACK;
late String PERCENTAGE;
late String PERFORMANCE_MODE;
late String PERFORMANCE_NOTE;
late String PERMISSION_UPDATE;
late String PICK_COLORS_FROM_DEVICE_WALLPAPER;
Expand Down
8 changes: 8 additions & 0 deletions lib/core/translations/language.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class Language extends LanguageKeys {
AUTOMATIC_BACKUP = getKey("AUTOMATIC_BACKUP");
BACKUP_AND_RESTORE_SUBTITLE = getKey("BACKUP_AND_RESTORE_SUBTITLE");
BACKUP_AND_RESTORE = getKey("BACKUP_AND_RESTORE");
BALANCED = getKey("BALANCED");
BETA = getKey("BETA");
BETWEEN_DATES = getKey("BETWEEN_DATES");
BITRATE = getKey("BITRATE");
Expand Down Expand Up @@ -278,6 +279,7 @@ class Language extends LanguageKeys {
GENERATE = getKey("GENERATE");
GENRE = getKey("GENRE");
GENRES = getKey("GENRES");
GOOD_LOOKING = getKey("GOOD_LOOKING");
GO_TO_ALBUM = getKey("GO_TO_ALBUM");
GO_TO_ARTIST = getKey("GO_TO_ARTIST");
GO_TO_CHANNEL = getKey("GO_TO_CHANNEL");
Expand All @@ -288,6 +290,7 @@ class Language extends LanguageKeys {
HEIGHT_OF_ALBUM_TILE = getKey("HEIGHT_OF_ALBUM_TILE");
HEIGHT_OF_TRACK_TILE = getKey("HEIGHT_OF_TRACK_TILE");
HIGH_MATCHES = getKey("HIGH_MATCHES");
HIGH_PERFORMANCE = getKey("HIGH_PERFORMANCE");
HISTORY = getKey("HISTORY");
HISTORY_IMPORT_MISSING_ENTRIES_NOTE = getKey("HISTORY_IMPORT_MISSING_ENTRIES_NOTE");
HISTORY_LISTENS_REPLACE_WARNING = getKey("HISTORY_LISTENS_REPLACE_WARNING");
Expand Down Expand Up @@ -419,6 +422,7 @@ class Language extends LanguageKeys {
PAUSE_FADE_DURATION = getKey("PAUSE_FADE_DURATION");
PAUSE_PLAYBACK = getKey("PAUSE_PLAYBACK");
PERCENTAGE = getKey("PERCENTAGE");
PERFORMANCE_MODE = getKey("PERFORMANCE_MODE");
PERFORMANCE_NOTE = getKey("PERFORMANCE_NOTE");
PERMISSION_UPDATE = getKey("PERMISSION_UPDATE");
PICK_COLORS_FROM_DEVICE_WALLPAPER = getKey("PICK_COLORS_FROM_DEVICE_WALLPAPER");
Expand Down Expand Up @@ -690,6 +694,10 @@ class Language extends LanguageKeys {










Expand Down
9 changes: 3 additions & 6 deletions lib/ui/widgets/artwork.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,13 @@ class _ArtworkWidgetState extends State<ArtworkWidget> {
double? _lastBorderRadius;

Widget getImagePathWidget() {
final pixelRatio = context.mediaQuery.devicePixelRatio.round();
final pixelRatio = context.mediaQuery.devicePixelRatio;
final cacheMultiplier = (pixelRatio * settings.artworkCacheHeightMultiplier.value).round();
return Image.file(
File(widget.path!),
gaplessPlayback: true,
fit: BoxFit.cover,
cacheHeight: widget.useTrackTileCacheHeight
? settings.trackThumbnailSizeinList.value > 120
? null
: 60 * pixelRatio
: widget.cacheHeight * pixelRatio,
cacheHeight: widget.useTrackTileCacheHeight ? 60 * cacheMultiplier : widget.cacheHeight * cacheMultiplier,
filterQuality: FilterQuality.medium,
width: _realWidthAndHeight,
height: _realWidthAndHeight,
Expand Down
44 changes: 44 additions & 0 deletions lib/ui/widgets/settings/advanced_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:namida/core/constants.dart';
import 'package:namida/core/enums.dart';
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/main.dart';
import 'package:namida/ui/dialogs/edit_tags_dialog.dart';
Expand All @@ -40,6 +41,49 @@ class AdvancedSettings extends StatelessWidget {
// icon: Broken.danger,
child: Column(
children: [
CustomListTile(
icon: Broken.cpu_setting,
title: lang.PERFORMANCE_MODE,
trailingRaw: NamidaPopupWrapper(
children: [
...PerformanceMode.values.map(
(e) => Obx(
() => NamidaInkWell(
margin: const EdgeInsets.symmetric(horizontal: 6.0, vertical: 2.0),
padding: const EdgeInsets.symmetric(horizontal: 4.0, vertical: 6.0),
borderRadius: 6.0,
bgColor: settings.performanceMode.value == e ? context.theme.cardColor : null,
child: Row(
children: [
Icon(
e.toIcon(),
size: 18.0,
),
const SizedBox(width: 6.0),
Text(
e.toText(),
style: context.textTheme.displayMedium?.copyWith(fontSize: 14.0.multipliedFontScale),
),
],
),
onTap: () {
e.execute();
settings.save(performanceMode: e);
NamidaNavigator.inst.popMenu(handleClosing: false);
Navigator.of(context).pop();
},
),
),
),
],
child: Obx(
() => Text(
settings.performanceMode.value.toText(),
style: context.textTheme.displaySmall,
),
),
),
),
CustomListTile(
leading: const StackedIcon(
baseIcon: Broken.video,
Expand Down
16 changes: 13 additions & 3 deletions lib/ui/widgets/settings/customization_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:get/get.dart';
import 'package:namida/controller/navigator_controller.dart';
import 'package:namida/controller/settings_controller.dart';
import 'package:namida/core/constants.dart';
import 'package:namida/core/enums.dart';
import 'package:namida/core/icon_fonts/broken_icons.dart';
import 'package:namida/core/translations/language.dart';
import 'package:namida/ui/widgets/custom_widgets.dart';
Expand All @@ -31,7 +32,10 @@ class CustomizationSettings extends StatelessWidget {
title: lang.ENABLE_BLUR_EFFECT,
subtitle: lang.PERFORMANCE_NOTE,
onChanged: (p0) {
settings.save(enableBlurEffect: !p0);
settings.save(
enableBlurEffect: !p0,
performanceMode: PerformanceMode.custom,
);
},
value: settings.enableBlurEffect.value,
),
Expand All @@ -40,15 +44,21 @@ class CustomizationSettings extends StatelessWidget {
title: lang.ENABLE_GLOW_EFFECT,
subtitle: lang.PERFORMANCE_NOTE,
onChanged: (p0) {
settings.save(enableGlowEffect: !p0);
settings.save(
enableGlowEffect: !p0,
performanceMode: PerformanceMode.custom,
);
},
value: settings.enableGlowEffect.value,
),
CustomSwitchListTile(
icon: Broken.maximize,
title: lang.ENABLE_PARALLAX_EFFECT,
subtitle: lang.PERFORMANCE_NOTE,
onChanged: (isTrue) => settings.save(enableMiniplayerParallaxEffect: !isTrue),
onChanged: (isTrue) => settings.save(
enableMiniplayerParallaxEffect: !isTrue,
performanceMode: PerformanceMode.custom,
),
value: settings.enableMiniplayerParallaxEffect.value,
),
CustomSwitchListTile(
Expand Down

0 comments on commit a3dcedc

Please sign in to comment.