Skip to content

Commit

Permalink
feat: play downloaded result from download page
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardoFasan committed Aug 9, 2024
1 parent 50d5bef commit 0b65f6a
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 76 deletions.
15 changes: 14 additions & 1 deletion lib/pages/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import 'package:youtube_downloader/widgets/widgets.dart';
class SearchPage extends StatelessWidget {
final VideoSearchController _searchController =
Get.find<VideoSearchController>();

final PlayerController _playerController = Get.find<PlayerController>();

final DownloadController _downloadController = Get.find<DownloadController>();

final Debouncer _searchDebouncer = Debouncer(milliseconds: 200);
Expand Down Expand Up @@ -63,7 +66,8 @@ class SearchPage extends StatelessWidget {
key: ValueKey(result.id),
result: result,
saved: saved,
downloadCallback: () => _downloadController.download(result),
tapCallback: () =>
saved ? _playResult(result) : _downloadController.download(result),
);
}

Expand Down Expand Up @@ -109,4 +113,13 @@ class SearchPage extends StatelessWidget {
}
});
}

void _playResult(AudioInfo result) {
try {
final Audio audio = _downloadController.audios.firstWhere(
(Audio a) => a.id == result.id,
);
_playerController.setCurrentAudioAndPlay(audio);
} catch (e) {}
}
}
13 changes: 11 additions & 2 deletions lib/widgets/navigation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:youtube_downloader/controllers/controllers.dart';
class Navigation extends StatelessWidget {
final PlayerController _playerController = Get.find<PlayerController>();

static const double _navigationHeight = 80;
static const double _navigationHeight = 83;
static const double _playerHeight = 72;
static const double _margin = 5;

Expand Down Expand Up @@ -116,10 +116,19 @@ class Navigation extends StatelessWidget {
label,
style: TextStyle(
color: color,
fontSize: 11,
fontSize: 12,
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 2),
Container(
height: 2,
width: 35,
decoration: BoxDecoration(
color: active ? AppColors.red : Colors.transparent,
borderRadius: BorderRadius.circular(5),
),
)
],
),
),
Expand Down
149 changes: 76 additions & 73 deletions lib/widgets/result_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,89 +6,92 @@ import 'package:youtube_downloader/models/models.dart';
class ResultTile extends StatelessWidget {
final AudioInfo _result;
final bool _saved;
final Function _downloadCallback;
final Function _tapCallback;

const ResultTile({super.key, result, saved, downloadCallback})
const ResultTile({super.key, result, saved, tapCallback})
: _result = result,
_saved = saved,
_downloadCallback = downloadCallback;
_tapCallback = tapCallback;

@override
Widget build(BuildContext context) {
final String duration = printDuration(_result.duration);
final String channel = _result.channel;
return Padding(
padding: const EdgeInsets.fromLTRB(18, 10, 18, 10),
child: Row(
children: <Widget>[
SizedBox(
height: 65,
width: 65,
child: VideoThumbnail(
radius: 5,
url: _result.thumbnailMinResUrl,
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
_result.title,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: AppColors.white,
fontWeight: FontWeight.w800,
fontSize: 16,
),
),
Text(
channel,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: AppColors.lightGray,
fontSize: 14,
fontWeight: FontWeight.w400,
),
return InkWell(
onTap: () => _tapCallback(),
child: Padding(
padding: const EdgeInsets.fromLTRB(18, 10, 18, 10),
child: Row(
children: <Widget>[
SizedBox(
height: 65,
width: 65,
child: VideoThumbnail(
radius: 5,
url: _result.thumbnailMinResUrl,
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
_result.title,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: AppColors.white,
fontWeight: FontWeight.w800,
fontSize: 16,
),
),
Text(
channel,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: AppColors.lightGray,
fontSize: 14,
fontWeight: FontWeight.w400,
),
),
Text(
duration,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: AppColors.lightGray,
fontSize: 14,
fontWeight: FontWeight.w400,
),
)
],
),
Text(
duration,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
color: AppColors.lightGray,
fontSize: 14,
fontWeight: FontWeight.w400,
),
)
],
),
),
),
if (!_saved)
Container(
height: 44,
width: 44,
margin: const EdgeInsets.only(left: 2),
child: const Icon(
AppIcons.download,
size: 22,
color: AppColors.lightGray,
),
),
if (_saved)
Container(
height: 44,
width: 44,
margin: const EdgeInsets.only(left: 8, right: 2),
child: const Icon(
AppIcons.cloudCheck,
size: 22,
color: AppColors.gray,
),
),
],
),
if (!_saved)
IconButton(
padding: const EdgeInsets.only(left: 2),
color: AppColors.white,
onPressed: () => _downloadCallback(),
icon: const Icon(
AppIcons.download,
size: 22,
),
),
if (_saved)
Container(
height: 44,
width: 44,
margin: const EdgeInsets.only(left: 8, right: 2),
child: const Icon(
AppIcons.cloudCheck,
size: 22,
color: AppColors.gray,
),
),
],
),
);
));
}
}

0 comments on commit 0b65f6a

Please sign in to comment.