Skip to content

Commit

Permalink
chore: remove failed icon in youtube thumbnail
Browse files Browse the repository at this point in the history
the top right 'danger' icon indicating that no thumbnail was found
  • Loading branch information
MSOB7YY committed Jul 19, 2024
1 parent dfeb7d4 commit 89ed743
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 47 deletions.
16 changes: 1 addition & 15 deletions lib/controller/thumbnail_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class ThumbnailManager {
String? customUrl,
bool isImportantInCache = true,
String? symlinkId,
VoidCallback? onNotFound,
}) async {
if (id == null && customUrl == null) return null;

Expand Down Expand Up @@ -118,7 +117,6 @@ class ThumbnailManager {
isTemp: isTemp,
forceRequest: false,
lowerResYTID: false,
onNotFound: onNotFound,
);

return downloaded;
Expand Down Expand Up @@ -146,7 +144,6 @@ class ThumbnailManager {
isTemp: isTemp,
forceRequest: false,
lowerResYTID: lowerResYTID,
onNotFound: onNotFound,
);

return downloaded;
Expand All @@ -166,7 +163,6 @@ class ThumbnailManager {
required bool isImportantInCache,
required File destinationFile,
required String? symlinkId,
required VoidCallback? onNotFound,
}) async {
final activeRequest = _thumbnailDownloader.resultForId(itemId);
if (activeRequest != null) return activeRequest;
Expand All @@ -187,7 +183,6 @@ class ThumbnailManager {
destinationFile: destinationFile,
symlinkId: symlinkId,
isTemp: isTemp,
onNotFound: onNotFound,
);
}
}
Expand All @@ -208,12 +203,8 @@ class _YTThumbnailDownloadManager with PortsProvider<SendPort> {
required bool isImportantInCache,
required File destinationFile,
required String? symlinkId,
required VoidCallback? onNotFound,
}) async {
if (_notFoundThumbnails[id] == true) {
if (onNotFound != null) onNotFound();
return null;
}
if (_notFoundThumbnails[id] == true) return null;

_requestsCountForId.update(id, (value) => value++, ifAbsent: () => 1);

Expand Down Expand Up @@ -241,11 +232,6 @@ class _YTThumbnailDownloadManager with PortsProvider<SendPort> {
final res = await _downloadCompleters[id]?.future;

_requestsCountForId.update(id, (value) => value--);

if (res == null && _notFoundThumbnails[id] == true) {
if (onNotFound != null) onNotFound();
return null;
}
return res;
}

Expand Down
33 changes: 2 additions & 31 deletions lib/youtube/widgets/yt_thumbnail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:namida/core/utils.dart';

import 'package:namida/base/loading_items_delay.dart';
import 'package:namida/class/color_m.dart';
Expand All @@ -12,6 +11,7 @@ import 'package:namida/controller/thumbnail_manager.dart';
import 'package:namida/core/constants.dart';
import 'package:namida/core/extensions.dart';
import 'package:namida/core/icon_fonts/broken_icons.dart';
import 'package:namida/core/utils.dart';
import 'package:namida/ui/widgets/artwork.dart';
import 'package:namida/ui/widgets/custom_widgets.dart';

Expand Down Expand Up @@ -89,7 +89,6 @@ class _YoutubeThumbnailState extends State<YoutubeThumbnail> with LoadingItemsDe
String? imagePath;
NamidaColor? imageColors;
Color? smallBoxDynamicColor;
final _thumbnailNotFound = false.obs;

Timer? _dontTouchMeImFetchingThumbnail;

Expand All @@ -105,7 +104,6 @@ class _YoutubeThumbnailState extends State<YoutubeThumbnail> with LoadingItemsDe
if (widget.customUrl != null) ThumbnailManager.inst.closeThumbnailClients(widget.customUrl!);
_dontTouchMeImFetchingThumbnail?.cancel();
_dontTouchMeImFetchingThumbnail = null;
_thumbnailNotFound.close();
super.dispose();
}

Expand All @@ -115,8 +113,6 @@ class _YoutubeThumbnailState extends State<YoutubeThumbnail> with LoadingItemsDe
_dontTouchMeImFetchingThumbnail = null;
_dontTouchMeImFetchingThumbnail = Timer(const Duration(seconds: 8), () {});

void onThumbnailNotFound() => _thumbnailNotFound.value = true;

if (imagePath == null) {
final videoId = widget.videoId;

Expand Down Expand Up @@ -144,18 +140,16 @@ class _YoutubeThumbnailState extends State<YoutubeThumbnail> with LoadingItemsDe
res = await ThumbnailManager.inst.getYoutubeThumbnailAndCache(
id: videoId,
isImportantInCache: true,
onNotFound: onThumbnailNotFound,
);
} else {
res = await ThumbnailManager.inst.getLowResYoutubeVideoThumbnail(videoId, onNotFound: onThumbnailNotFound);
res = await ThumbnailManager.inst.getLowResYoutubeVideoThumbnail(videoId);
}
} else {
// for channels/playlists -> default
res = await ThumbnailManager.inst.getYoutubeThumbnailAndCache(
customUrl: widget.customUrl,
symlinkId: widget.urlSymLinkId,
isImportantInCache: widget.isImportantInCache,
onNotFound: onThumbnailNotFound,
);
}
}
Expand Down Expand Up @@ -258,29 +252,6 @@ class _YoutubeThumbnailState extends State<YoutubeThumbnail> with LoadingItemsDe
),
),
),
ObxO(
rx: _thumbnailNotFound,
builder: (notFound) => notFound
? Positioned(
top: 0.0,
right: 0.0,
child: Container(
clipBehavior: Clip.hardEdge,
margin: const EdgeInsets.all(2.0),
padding: const EdgeInsets.symmetric(horizontal: 3.0, vertical: 1.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0.multipliedRadius),
color: Colors.black.withOpacity(0.3),
),
child: Icon(
Broken.danger,
size: 12.0,
color: Colors.white.withOpacity(0.6),
),
),
)
: const SizedBox(),
)
],
displayIcon: widget.displayFallbackIcon,
),
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: 3.3.9-beta+240716234
version: 3.4.0-beta+240719125

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

0 comments on commit 89ed743

Please sign in to comment.