Skip to content

Commit

Permalink
chore: various tweaks & fixes
Browse files Browse the repository at this point in the history
ref #142
  • Loading branch information
MSOB7YY committed Mar 24, 2024
1 parent b2c71ee commit 267e1a3
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 70 deletions.
19 changes: 12 additions & 7 deletions android/app/src/main/kotlin/com/example/namida/StorageUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,24 @@ public class StorageUtils(private val context: Context) {

fun getStorageDirsData(): MutableList<String> {
val folders = mutableListOf<String>()
for (dir in context.getExternalFilesDirs(null)) {
if (dir != null) {
folders.add(dir.getAbsolutePath())
try {
for (dir in context.getExternalFilesDirs(null)) {
if (dir != null) {
folders.add(dir.getAbsolutePath())
}
}
}
} catch (ignore: Exception) {}
return folders
}

fun getStorageDirsCache(): MutableList<String> {
val folders = mutableListOf<String>()
for (f in context.getExternalCacheDirs()) {
folders.add(f.path)
}
try {
for (f in context.getExternalCacheDirs()) {
folders.add(f.path)
}
} catch (ignore: Exception) {}

return folders
}
}
1 change: 1 addition & 0 deletions lib/controller/backup_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class BackupController {
AppPaths.FAVOURITES_PLAYLIST,
AppPaths.SETTINGS,
AppPaths.SETTINGS_EQUALIZER,
AppPaths.SETTINGS_PLAYER,
AppPaths.LATEST_QUEUE,
AppPaths.YT_LIKES_PLAYLIST,
AppDirs.PLAYLISTS,
Expand Down
2 changes: 1 addition & 1 deletion lib/core/dimensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Dimensions {
// -- YT --
static const youtubeCardItemHeight = 24.0 * 3;
static const youtubeCardItemVerticalPadding = 4.0;
static double get youtubeCardItemExtent => youtubeCardItemHeight + tileBottomMargin + 2 * youtubeCardItemVerticalPadding;
static const youtubeCardItemExtent = youtubeCardItemHeight + tileBottomMargin + 2 * youtubeCardItemVerticalPadding;

// -- Track Tile --
double trackTileItemExtent = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion lib/packages/miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class NamidaMiniPlayerYoutubeID extends StatelessWidget {
playlistName: '',
openMenuOnLongPress: false,
displayTimeAgo: false,
thumbnailHeight: context.width * 0.3 * 9 / 16,
thumbnailHeight: Dimensions.youtubeCardItemHeight - Dimensions.youtubeCardItemVerticalPadding,
fromPlayerQueue: true,
draggingEnabled: true,
draggableThumbnail: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/packages/mp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class NamidaYTMiniplayerState extends State<NamidaYTMiniplayer> with SingleTicke
/// used to invoke other animation (eg. entering video fullscreen),
bool _alternativePercentage = false;
bool _isDraggingDownwards = false;
double get _percentageMultiplier => _alternativePercentage && _isDraggingDownwards ? 0.5 : 1.0;
double get _percentageMultiplier => _alternativePercentage && _isDraggingDownwards ? 0.25 : 1.0;

bool _isDragManagedInternally = true;
void updatePercentageMultiplier(bool alt) {
Expand Down
48 changes: 23 additions & 25 deletions lib/ui/widgets/inner_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ class NamidaInnerDrawerState extends State<NamidaInnerDrawer> with SingleTickerP

@override
Widget build(BuildContext context) {
const scaffoldShadows = [
BoxShadow(
color: Color(0x20202020),
blurRadius: 4.0,
spreadRadius: 2.0,
offset: Offset(-2.0, 0),
),
];

return AnimatedBuilderMulti(
animation: controller,
children: [
Expand Down Expand Up @@ -129,6 +120,23 @@ class NamidaInnerDrawerState extends State<NamidaInnerDrawer> with SingleTickerP
color: context.theme.scaffoldBackgroundColor,
),
),
Positioned.fill(
child: Transform.translate(
offset: Offset(context.width * controller.value * 0.6, 0),
child: DecoratedBox(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: context.theme.colorScheme.primary.withAlpha(context.isDarkMode ? 5 : 25),
blurRadius: 58.0,
spreadRadius: 12.0,
offset: const Offset(-2.0, 0),
),
],
),
),
),
),
// -- drawer
Padding(
padding: EdgeInsets.only(right: context.width * (1 - controller.upperBound)),
Expand All @@ -151,25 +159,15 @@ class NamidaInnerDrawerState extends State<NamidaInnerDrawer> with SingleTickerP
Transform.translate(
offset: Offset(context.width * controller.value, 0),
child: widget.borderRadius > 0
? DecoratedBox(
decoration: const BoxDecoration(
boxShadow: scaffoldShadows,
),
child: ClipPath(
clipper: DecorationClipper(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(widget.borderRadius * controller.value),
),
? ClipPath(
clipper: DecorationClipper(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(widget.borderRadius * controller.value),
),
child: child,
),
)
: DecoratedBox(
decoration: const BoxDecoration(
boxShadow: scaffoldShadows,
),
child: child,
),
)
: child,
),
],
);
Expand Down
1 change: 1 addition & 0 deletions lib/ui/widgets/video_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
Navigator.of(context).pop();
if (!isSelected) {
Player.inst.setPlayerSpeed(speed);
settings.player.save(speed: speed);
}
},
decoration: const BoxDecoration(),
Expand Down
10 changes: 8 additions & 2 deletions lib/youtube/controller/youtube_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,12 @@ class YoutubeController {
Future<List<StreamInfoItem>> getChannelStreams(String channelID) async {
if (channelID == '') return [];
final url = 'https://www.youtube.com/channel/$channelID';
final streams = await NewPipeExtractorDart.channels.getChannelUploads(url);
var streams = await NewPipeExtractorDart.channels.getChannelUploads(url);
int retries = 3;
while (streams.isEmpty && retries > 0) {
retries--;
streams = await NewPipeExtractorDart.channels.getChannelUploads(url);
}
_fillTempVideoInfoMap(streams);
return streams;
}
Expand Down Expand Up @@ -1086,7 +1091,8 @@ class YoutubeController {
config.videoStream = availableVideos.firstWhereEff((e) => e.id == config.prefferedVideoQualityID);
}
if (config.videoStream == null || config.videoStream?.url == null || config.videoStream?.url == '') {
config.videoStream = getPreferredStreamQuality(availableVideos, qualities: preferredQualities);
final webm = config.filename.endsWith('.webm') || config.filename.endsWith('.WEBM');
config.videoStream = getPreferredStreamQuality(availableVideos, qualities: preferredQualities, preferIncludeWebm: webm);
}
completerV.completeIfWasnt();
});
Expand Down
3 changes: 2 additions & 1 deletion lib/youtube/controller/youtube_import_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ class YoutubeImportController {
final file = File(filePath);
try {
final lines = file.readAsLinesSync();
lines.removeAt(0);
final header = lines.removeAt(0);
final list = <({String id, String title})>[];
if (header.split(',').length < 3) return list;
lines.loop((e, _) {
try {
final parts = e.split(','); // id, url, name
Expand Down
2 changes: 1 addition & 1 deletion lib/youtube/pages/youtube_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class _YoutubePageState extends State<YoutubePage> with AutomaticKeepAliveClient
@override
Widget build(BuildContext context) {
super.build(context);
final thumbnailWidth = context.width * 0.36;
final thumbnailWidth = context.width * 0.36; // card height is dynamic
final thumbnailHeight = thumbnailWidth * 9 / 16;
final thumbnailItemExtent = thumbnailHeight + 8.0 * 2;
return BackgroundWrapper(
Expand Down
8 changes: 4 additions & 4 deletions lib/youtube/pages/yt_channel_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ class _YTChannelSubpageState extends YoutubeChannelController<YTChannelSubpage>

@override
Widget build(BuildContext context) {
final thumbnailWidth = context.width * 0.28;
final thumbnailHeight = thumbnailWidth * 9 / 16;
final thumbnailItemExtent = thumbnailHeight + 8.0 * 2;
const thumbnailHeight = 0.8 * (Dimensions.youtubeCardItemHeight - Dimensions.youtubeCardItemVerticalPadding);
const thumbnailWidth = thumbnailHeight * 16 / 9;
const thumbnailItemExtent = thumbnailHeight + 8.0 * 2;
final channelID = _channelInfo?.id ?? ch.channelID;
final avatarUrl = _channelInfo?.avatarUrl ?? _channelInfo?.thumbnailUrl ?? ch.channelID;
final bannerUrl = _channelInfo?.bannerUrl ?? _channelInfo?.bannerUrl;
Expand Down Expand Up @@ -309,7 +309,7 @@ class _YTChannelSubpageState extends YoutubeChannelController<YTChannelSubpage>
child: ListView.builder(
itemCount: 15,
itemBuilder: (context, index) {
return YoutubeVideoCard(
return const YoutubeVideoCard(
thumbnailHeight: thumbnailHeight,
thumbnailWidth: thumbnailWidth,
isImageImportantInCache: false,
Expand Down
8 changes: 4 additions & 4 deletions lib/youtube/pages/yt_channels_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ class _YoutubeChannelsPageState extends YoutubeChannelController<YoutubeChannels
Widget build(BuildContext context) {
const horizontalPadding = 6.0;

final thumbnailWidth = context.width * 0.28;
final thumbnailHeight = thumbnailWidth * 9 / 16;
final thumbnailItemExtent = thumbnailHeight + 8.0 * 2;
const thumbnailHeight = 0.8 * (Dimensions.youtubeCardItemHeight - Dimensions.youtubeCardItemVerticalPadding);
const thumbnailWidth = thumbnailHeight * 16 / 9;
const thumbnailItemExtent = thumbnailHeight + 8.0 * 2;

final ch = channel;

Expand Down Expand Up @@ -329,7 +329,7 @@ class _YoutubeChannelsPageState extends YoutubeChannelController<YoutubeChannels
child: ListView.builder(
itemCount: 15,
itemBuilder: (context, index) {
return YoutubeVideoCard(
return const YoutubeVideoCard(
thumbnailHeight: thumbnailHeight,
thumbnailWidth: thumbnailWidth,
isImageImportantInCache: false,
Expand Down
6 changes: 3 additions & 3 deletions lib/youtube/pages/yt_local_search_results.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class YTLocalSearchResultsState extends State<YTLocalSearchResults> {

@override
Widget build(BuildContext context) {
final thumbnailWidth = context.width * 0.32;
final thumbnailHeight = thumbnailWidth * 9 / 16;
final thumbnailItemExtent = thumbnailHeight + 8.0 * 2;
const thumbnailHeight = Dimensions.youtubeCardItemHeight - Dimensions.youtubeCardItemVerticalPadding;
const thumbnailWidth = thumbnailHeight * 16 / 9;
const thumbnailItemExtent = thumbnailHeight + 8.0 * 2;
return BackgroundWrapper(
child: NamidaScrollbar(
controller: YTLocalSearchController.inst.scrollController,
Expand Down
4 changes: 2 additions & 2 deletions lib/youtube/pages/yt_playlist_download_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ class _YTPlaylistDownloadPageState extends State<YTPlaylistDownloadPage> {

@override
Widget build(BuildContext context) {
final thumWidth = context.width * 0.3 * _hmultiplier;
final thumHeight = thumWidth * 9 / 16;
final thumHeight = _hmultiplier * (Dimensions.youtubeCardItemHeight - Dimensions.youtubeCardItemVerticalPadding);
final thumWidth = thumHeight * 16 / 9;
return BackgroundWrapper(
child: Stack(
children: [
Expand Down
7 changes: 3 additions & 4 deletions lib/youtube/pages/yt_playlist_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,9 @@ class _YTHostedPlaylistSubpageState extends State<YTHostedPlaylistSubpage> with
final bigThumbWidth = context.width - horizontalBigThumbPadding * 2;
final playlist = widget.playlist;

const hmultiplier = 0.3;
final itemsThumbnailWidth = context.width * hmultiplier;
final itemsThumbnailHeight = itemsThumbnailWidth * 9 / 16;
final itemsThumbnailItemExtent = itemsThumbnailHeight + 8.0 * 2;
const itemsThumbnailHeight = (Dimensions.youtubeCardItemHeight - Dimensions.youtubeCardItemVerticalPadding);
const itemsThumbnailWidth = itemsThumbnailHeight * 16 / 9;
const itemsThumbnailItemExtent = itemsThumbnailHeight + 8.0 * 2;

final firstID = playlist.streams.firstOrNull?.id;
final hasMoreStreamsLeft = playlist.streams.length < playlist.streamCount;
Expand Down
12 changes: 6 additions & 6 deletions lib/youtube/pages/yt_search_results_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ class YoutubeSearchResultsPageState extends State<YoutubeSearchResultsPage> with
@override
Widget build(BuildContext context) {
super.build(context);
final thumbnailWidth = context.width * 0.36;
final thumbnailHeight = thumbnailWidth * 9 / 16;
final thumbnailItemExtent = thumbnailHeight + 8.0 * 2;
const thumbnailHeight = Dimensions.youtubeCardItemHeight - Dimensions.youtubeCardItemVerticalPadding;
const thumbnailWidth = thumbnailHeight * 16 / 9;
const thumbnailItemExtent = thumbnailHeight + 8.0 * 2;
const localMultiplier = 0.7;
final thumbnailWidthLocal = thumbnailWidth * localMultiplier;
final thumbnailHeightLocal = thumbnailHeight * localMultiplier;
final thumbnailItemExtentLocal = thumbnailItemExtent * localMultiplier;
const thumbnailWidthLocal = thumbnailWidth * localMultiplier;
const thumbnailHeightLocal = thumbnailHeight * localMultiplier;
const thumbnailItemExtentLocal = thumbnailItemExtent * localMultiplier;
return BackgroundWrapper(
child: Navigator(
key: NamidaNavigator.inst.ytLocalSearchNavigatorKey,
Expand Down
6 changes: 4 additions & 2 deletions lib/youtube/widgets/yt_card.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'package:namida/core/dimensions.dart';
import 'package:namida/core/extensions.dart';
import 'package:namida/ui/widgets/custom_widgets.dart';
import 'package:namida/youtube/widgets/yt_shimmer.dart';
Expand Down Expand Up @@ -69,8 +70,9 @@ class YoutubeCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
const verticalPadding = 8.0;
final thumbnailWidth = this.thumbnailWidth ?? (thumbnailWidthPercentage * context.width * 0.36);
final thumbnailHeight = this.thumbnailHeight ?? (isCircle ? thumbnailWidth : thumbnailWidth * 9 / 16);

final thumbnailHeight = this.thumbnailHeight ?? (thumbnailWidthPercentage * (Dimensions.youtubeCardItemHeight - Dimensions.youtubeCardItemVerticalPadding));
final thumbnailWidth = this.thumbnailWidth ?? (isCircle ? thumbnailHeight : thumbnailHeight * 16 / 9);

final channelThumbSize = 20.0 * thumbnailWidthPercentage;

Expand Down
3 changes: 2 additions & 1 deletion lib/youtube/widgets/yt_queue_chip.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ class YTMiniplayerQueueChipState extends State<YTMiniplayerQueueChip> with Ticke
Widget build(BuildContext context) {
final maxHeight = context.height;
const minHeight = kYTQueueSheetMinHeight;
final itemThumbnailHeight = context.width * 0.3 * 9 / 16;

const itemThumbnailHeight = Dimensions.youtubeCardItemHeight - Dimensions.youtubeCardItemVerticalPadding;

return Stack(
alignment: Alignment.bottomCenter,
Expand Down
8 changes: 4 additions & 4 deletions lib/youtube/youtube_miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ class _YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {
const space5sb = 8.0;
const miniplayerHeight = kYoutubeMiniplayerHeight;

final relatedThumbnailWidth = context.width * 0.36;
final relatedThumbnailHeight = relatedThumbnailWidth * 9 / 16;
final relatedThumbnailItemExtent = relatedThumbnailHeight + 8.0 * 2;
const relatedThumbnailHeight = Dimensions.youtubeCardItemHeight - Dimensions.youtubeCardItemVerticalPadding;
const relatedThumbnailWidth = relatedThumbnailHeight * 16 / 9;
const relatedThumbnailItemExtent = relatedThumbnailHeight + 8.0 * 2;

final miniplayerBGColor = Color.alphaBlend(context.theme.secondaryHeaderColor.withOpacity(0.25), context.theme.scaffoldBackgroundColor);

Expand Down Expand Up @@ -1146,7 +1146,7 @@ class _YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {
alignment: Alignment.centerRight,
child: SizedBox(
height: context.height,
width: (context.width / 2).withMaximum(324.0),
width: (context.width * 0.25).withMaximum(324.0),
child: Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (event) {
Expand Down
8 changes: 7 additions & 1 deletion lib/youtube/youtube_playlists_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class YoutubePlaylistsView extends StatelessWidget {
Widget build(BuildContext context) {
final isMinimalView = minimalView ?? idsToAdd.isNotEmpty;

const playlistsItemExtent = Dimensions.youtubeCardItemExtent * 0.9;
const playlistThumbnailHeight = playlistsItemExtent - Dimensions.tileBottomMargin - (Dimensions.youtubeCardItemVerticalPadding * 2);
const playlistThumbnailWidth = playlistThumbnailHeight * 16 / 9;

return NamidaScrollbarWithController(
child: (sc) => CustomScrollView(
controller: sc,
Expand Down Expand Up @@ -254,7 +258,7 @@ class YoutubePlaylistsView extends StatelessWidget {
final playlistsMap = YoutubePlaylistController.inst.playlistsMap;
final playlistsNames = playlistsMap.keys.toList();
return SliverFixedExtentList.builder(
itemExtent: Dimensions.youtubeCardItemExtent * 0.9,
itemExtent: playlistsItemExtent,
itemCount: playlistsNames.length,
itemBuilder: (context, index) {
final name = playlistsNames[index];
Expand All @@ -278,6 +282,8 @@ class YoutubePlaylistsView extends StatelessWidget {
thirdLineText: Jiffy.parseFromMillisecondsSinceEpoch(playlist.modifiedDate).fromNow(),
displayChannelThumbnail: false,
channelThumbnailUrl: '',
thumbnailHeight: playlistThumbnailHeight,
thumbnailWidth: playlistThumbnailWidth,
onTap: () {
if (idsToAdd.isNotEmpty) {
if (idsExist == true) {
Expand Down

0 comments on commit 267e1a3

Please sign in to comment.