Skip to content

Commit

Permalink
chore: soomee some some
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Jul 27, 2024
1 parent f017377 commit 68457aa
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 117 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ jobs:
done <<< "$COMMITS"
# Encode special characters
CHANGELOG="${CHANGELOG//'%'/'%25'}"
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
CHANGELOG="${CHANGELOG//$'%'/%25}"
CHANGELOG="${CHANGELOG//$'\n'/%0A}"
CHANGELOG="${CHANGELOG//$'\r'/%0D}"
echo "CHANGELOG=$CHANGELOG" >> $GITHUB_ENV
- name: Creating Snapshot Release at namida-snapshots
Expand All @@ -119,7 +119,8 @@ jobs:
make_latest: true
draft: false
tag_name: ${{ steps.extract_version.outputs.version}}
body: ${{ env.CHANGELOG}}
body: |
${{ env.CHANGELOG }}
files: |
build_final/*
token: ${{ secrets.SNAPSHOTS_REPO_SECRET }}
Expand Down
75 changes: 64 additions & 11 deletions lib/base/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,67 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
Future<void> setVideoLockCache(VideoStream stream) async {
final url = stream.buildUrl();
if (url == null) throw Exception('null url');
await setVideoSource(

final cachedAudioPath = currentCachedAudio.value?.file.path;
final curritem = currentItem.value;

AudioVideoSource? activeAudioSource;
if (cachedAudioPath != null) {
activeAudioSource = AudioVideoSource.file(
cachedAudioPath,
tag: curritem is YoutubeID
? curritem.toMediaItem(
videoId,
_ytNotificationVideoInfo,
_ytNotificationVideoThumbnail,
currentIndex.value,
currentQueue.value.length,
currentItemDuration.value,
)
: null,
);
} else {
AudioStream? audioStream = currentAudioStream.value;
if (audioStream == null) {
final streamRes = YoutubeInfoController.video.fetchVideoStreamsSync(videoId)?.audioStreams;
if (streamRes != null) audioStream = YoutubeController.inst.getPreferredAudioStream(streamRes);
}
if (audioStream != null) {
final url = audioStream.buildUrl();
if (url != null) {
activeAudioSource = LockCachingAudioSource(
url,
cacheFile: File(audioStream.cachePath(videoId)),
tag: mediaItem,
onCacheDone: (cacheFile) async => await _onAudioCacheDone(videoId, cacheFile),
);
}
}
}
final videoOptions = VideoSourceOptions(
source: LockCachingVideoSource(
url,
cacheFile: File(stream.cachePath(videoId)),
onCacheDone: (cacheFile) async => await _onVideoCacheDone(videoId, cacheFile),
),
cacheKey: stream.cacheKey(videoId),
loop: false,
videoOnly: false,
);
// -- setting completely new source is needed as a workaround to internal source error
// where settings LockCachingVideoSource only throws source_not_found exception.
// -- its not likely for activeAudioSource to be null but just in case
activeAudioSource != null
? await setSource(
activeAudioSource,
item: curritem,
startPlaying: () => wasPlaying,
videoOptions: videoOptions,
keepOldVideoSource: true,
cachedAudioPath: cachedAudioPath,
)
: await setVideoSource(
source: videoOptions.source,
);
refreshNotification();
}

Expand Down Expand Up @@ -1065,8 +1118,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {

if (checkInterrupted()) return;
final prefferedVideoStream = _isAudioOnlyPlayback || videoStreams.isEmpty ? null : YoutubeController.inst.getPreferredStreamQuality(videoStreams, preferIncludeWebm: false);
final prefferedAudioStream =
audiostreams.firstWhereEff((e) => !e.isWebm && e.audioTrack?.langCode == 'en') ?? audiostreams.firstWhereEff((e) => !e.isWebm) ?? audiostreams.firstOrNull;
final prefferedAudioStream = YoutubeController.inst.getPreferredAudioStream(audiostreams);
final prefferedAudioStreamUrl = prefferedAudioStream?.buildUrl();
final prefferedVideoStreamUrl = prefferedVideoStream?.buildUrl();
if (prefferedAudioStreamUrl != null || prefferedVideoStreamUrl != null) {
Expand Down Expand Up @@ -1122,13 +1174,14 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
if (checkInterrupted()) return;

if (shouldResetAudioSource && prefferedAudioStream != null && prefferedAudioStreamUrl != null) {
final audioSource = LockCachingAudioSource(
prefferedAudioStreamUrl,
cacheFile: File(prefferedAudioStream.cachePath(item.id)),
tag: mediaItem,
onCacheDone: (cacheFile) async => await _onAudioCacheDone(item.id, cacheFile),
);
duration = await setSource(
LockCachingAudioSource(
prefferedAudioStreamUrl,
cacheFile: File(prefferedAudioStream.cachePath(item.id)),
tag: mediaItem,
onCacheDone: (cacheFile) async => await _onAudioCacheDone(item.id, cacheFile),
),
audioSource,
item: pi,
startPlaying: startPlaying,
videoOptions: videoOptions,
Expand Down Expand Up @@ -1660,7 +1713,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {

// ------- video -------

Future<void> setVideoSource({required AudioVideoSource source, String cacheKey = '', bool loopingAnimation = false, bool isFile = false}) async {
Future<void> setVideoSource({required AudioVideoSource source, bool loopingAnimation = false, bool isFile = false}) async {
if (isFile && source is UriSource) File.fromUri(source.uri).setLastAccessedTry(DateTime.now());
final videoOptions = VideoSourceOptions(
source: source,
Expand Down
4 changes: 2 additions & 2 deletions lib/controller/json_to_history_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class JsonToHistoryParser {
final startTime = DateTime.now();
_notificationTimer?.cancel();
_notificationTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
NotificationService.inst.importHistoryNotification(parsedHistoryJson.value, totalJsonToParse.value, startTime);
NotificationService.importHistoryNotification(parsedHistoryJson.value, totalJsonToParse.value, startTime);
});

final datesAdded = <int>[];
Expand Down Expand Up @@ -446,7 +446,7 @@ class JsonToHistoryParser {
isParsing.value = false;

_notificationTimer?.cancel();
NotificationService.inst.doneImportingHistoryNotification(parsedHistoryJson.value, addedHistoryJsonToPlaylist.value);
NotificationService.doneImportingHistoryNotification(parsedHistoryJson.value, addedHistoryJsonToPlaylist.value);

_latestMissingMap.value = allMissingEntries;
_latestMissingMapAddedStatus.clear();
Expand Down
50 changes: 20 additions & 30 deletions lib/controller/notification_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,35 @@ import 'package:namida/core/extensions.dart';
import 'package:namida/youtube/class/download_task_base.dart';

class NotificationService {
//Hanle displaying of notifications.
static final NotificationService _notificationService = NotificationService._internal();
static final FlutterLocalNotificationsPlugin _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

factory NotificationService() => NotificationService._internal();

static NotificationService get inst => _notificationService;

NotificationService._internal() {
init();
}

static Future<void> cancelAll() async {
try {
await _flutterLocalNotificationsPlugin.cancelAll();
return _flutterLocalNotificationsPlugin.cancelAll();
} catch (_) {}
}

final _historyImportID = 1;
static const _historyImportID = 1;
static const _historyImportPayload = 'history_import';
final _historyImportChannelName = 'History Import';
final _historyImportChannelDescription = 'Imports Tracks to History from a source';
static const _historyImportChannelName = 'History Import';
static const _historyImportChannelDescription = 'Imports Tracks to History from a source';

final _youtubeDownloadID = 2;
final _youtubeDownloadPayload = 'youtube_download';
final _youtubeDownloadChannelName = 'Downloads';
final _youtubeDownloadChannelDescription = 'Downlaod content from youtube';
static const _youtubeDownloadID = 2;
static const _youtubeDownloadPayload = 'youtube_download';
static const _youtubeDownloadChannelName = 'Downloads';
static const _youtubeDownloadChannelDescription = 'Downlaod content from youtube';

static Future<void> init() async {
await _flutterLocalNotificationsPlugin.initialize(
static Future<bool?> init() {
return _flutterLocalNotificationsPlugin.initialize(
const InitializationSettings(
android: AndroidInitializationSettings('ic_stat_musicnote'),
),
onDidReceiveBackgroundNotificationResponse: (details) => _onDidReceiveLocalNotification(details),
onDidReceiveNotificationResponse: (details) => _onDidReceiveLocalNotification(details),
onDidReceiveBackgroundNotificationResponse: _onDidReceiveLocalNotification,
onDidReceiveNotificationResponse: _onDidReceiveLocalNotification,
);
}

void mediaNotification({
static void mediaNotification({
required String title,
required String subText,
required String subtitle,
Expand Down Expand Up @@ -94,7 +84,7 @@ class NotificationService {
);
}

void downloadYoutubeNotification({
static void downloadYoutubeNotification({
required DownloadTaskFilename notificationID,
required String title,
required String Function(String progressText) subtitle,
Expand All @@ -121,11 +111,11 @@ class NotificationService {
);
}

Future<void> removeDownloadingYoutubeNotification({required DownloadTaskFilename notificationID}) async {
static Future<void> removeDownloadingYoutubeNotification({required DownloadTaskFilename notificationID}) async {
await _flutterLocalNotificationsPlugin.cancel(_youtubeDownloadID, tag: notificationID.filename);
}

void doneDownloadingYoutubeNotification({
static void doneDownloadingYoutubeNotification({
required DownloadTaskFilename notificationID,
required String videoTitle,
required String subtitle,
Expand All @@ -148,7 +138,7 @@ class NotificationService {
);
}

void importHistoryNotification(int parsed, int total, DateTime displayTime) {
static void importHistoryNotification(int parsed, int total, DateTime displayTime) {
_createProgressNotification(
id: _historyImportID,
progress: parsed,
Expand All @@ -163,7 +153,7 @@ class NotificationService {
);
}

void doneImportingHistoryNotification(int totalParsed, int totalAdded) {
static void doneImportingHistoryNotification(int totalParsed, int totalAdded) {
_createNotification(
id: _historyImportID,
title: 'Done importing history',
Expand All @@ -183,7 +173,7 @@ class NotificationService {
}
}

void _createNotification({
static void _createNotification({
required int id,
required String title,
required String body,
Expand Down Expand Up @@ -225,7 +215,7 @@ class NotificationService {
);
}

void _createProgressNotification({
static void _createProgressNotification({
required int id,
required int progress,
required int maxProgress,
Expand Down
4 changes: 2 additions & 2 deletions lib/controller/player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ class Player {
return _audioHandler.tryGenerateWaveform(video);
}

Future<void> setVideo({required AudioVideoSource source, String cacheKey = '', bool loopingAnimation = false, required bool isFile}) async {
await _audioHandler.setVideoSource(source: source, cacheKey: cacheKey, loopingAnimation: loopingAnimation, isFile: isFile);
Future<void> setVideo({required AudioVideoSource source, bool loopingAnimation = false, required bool isFile}) async {
await _audioHandler.setVideoSource(source: source, loopingAnimation: loopingAnimation, isFile: isFile);
}

Future<void> disposeVideo() async {
Expand Down
2 changes: 1 addition & 1 deletion lib/controller/search_sort_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ class SearchSortController {
sortThis((e) => e.value[0].artistsList.join().toLowerCase());
break;
case GroupSortType.genresList:
sortThis((e) => e.value[0].genresList.join().toLowerCase());
sortThis((e) => e.key.toLowerCase());
break;
case GroupSortType.composer:
sortThis((e) => e.value.composer.toLowerCase());
Expand Down
3 changes: 2 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void mainInitialization() async {
NamidaNavigator.inst.setDefaultSystemUIOverlayStyle();

ScrollSearchController.inst.initialize();
NotificationService.init();
NotificationService.cancelAll();
FlutterVolumeController.updateShowSystemUI(false);
CurrentColor.inst.initialize();
Expand Down Expand Up @@ -297,7 +298,7 @@ Future<void> _initializeIntenties() async {
final linkRaw = files.first.value;
if (linkRaw != null) {
final link = linkRaw.replaceAll(r'\', '');
if (link.startsWith('app://com.msob7y.namida.patreonauth')) {
if (link.startsWith('app://patreonauth.msob7y.namida')) {
final link = linkRaw.replaceAll(r'\', '');
YoutubeAccountController.membership.redirectUrlCompleter?.completeIfWasnt(link);
return;
Expand Down
51 changes: 0 additions & 51 deletions lib/ui/dialogs/general_popup_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,57 +165,6 @@ Future<void> showGeneralPopupDialog(

void cancelSkipTimer() => Player.inst.cancelPlayErrorSkipTimer();

void setMoodsOrTags(List<String> initialMoods, void Function(List<String> moodsFinal) saveFunction, {bool isTags = false}) async {
final controller = TextEditingController();
final currentMoods = initialMoods.join(', ');
controller.text = currentMoods;

final title = isTags ? lang.SET_TAGS : lang.SET_MOODS;
final subtitle = lang.SET_MOODS_SUBTITLE;
await openDialog(
onDisposing: () {
controller.dispose();
},
(theme) => CustomBlurryDialog(
title: title,
actions: [
const CancelButton(),
NamidaButton(
text: lang.SAVE,
onPressed: () async {
List<String> moodsPre = controller.text.split(',');
List<String> moodsFinal = [];
moodsPre.loop((m) {
if (!m.contains(',') && m != ' ' && m.isNotEmpty) {
moodsFinal.add(m.trimAll());
}
});

saveFunction(moodsFinal.uniqued());

NamidaNavigator.inst.closeDialog();
},
),
],
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
subtitle,
style: theme.textTheme.displaySmall,
),
const SizedBox(height: 20.0),
CustomTagTextField(
controller: controller,
hintText: currentMoods.overflow,
labelText: title,
),
],
),
),
);
}

final stats = tracks.firstOrNull?.stats.obs;

List<String> splitByCommaList(String listText) {
Expand Down
6 changes: 4 additions & 2 deletions lib/ui/widgets/custom_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ class CustomListTile extends StatelessWidget {
final TextStyle? titleStyle;
final double borderR;
final Color? bgColor;
final double verticalPadding;

const CustomListTile({
super.key,
Expand All @@ -237,6 +238,7 @@ class CustomListTile extends StatelessWidget {
this.titleStyle,
this.borderR = 20.0,
this.bgColor,
this.verticalPadding = 0.0,
});

@override
Expand All @@ -253,7 +255,7 @@ class CustomListTile extends StatelessWidget {
),
visualDensity: visualDensity,
onTap: onTap,
contentPadding: const EdgeInsets.symmetric(horizontal: 16.0),
contentPadding: EdgeInsets.symmetric(horizontal: 16.0, vertical: verticalPadding),
minVerticalPadding: 8.0,
leading: icon != null
? SizedBox(
Expand Down Expand Up @@ -711,7 +713,7 @@ class SmallListTile extends StatelessWidget {
size: 18.0,
),
),
visualDensity: visualDensity ?? (compact ? const VisualDensity(horizontal: -2.0, vertical: -2.0) : const VisualDensity(horizontal: -1.0, vertical: -1.0)),
visualDensity: visualDensity ?? (compact ? const VisualDensity(horizontal: -2.2, vertical: -2.2) : const VisualDensity(horizontal: -1.2, vertical: -1.2)),
title: Text(
title,
style: context.textTheme.displayMedium?.copyWith(
Expand Down
Loading

0 comments on commit 68457aa

Please sign in to comment.