Skip to content

Commit

Permalink
feat: display fcc podcasts first (#1109)
Browse files Browse the repository at this point in the history
* chore: remove unused file

* feat: show fcc podcasts first

* fix: episode duration
  • Loading branch information
Nirajn2311 authored Sep 6, 2023
1 parent 61313e0 commit b239eb0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import 'package:freecodecamp/service/podcast/podcasts_service.dart';
import 'package:path_provider/path_provider.dart';
import 'package:stacked/stacked.dart';

const fccPodcastUrls = [
'https://freecodecamp.libsyn.com/rss',
'https://feeds.transistor.fm/freecodecamp-podcast-en-espanol',
'https://feeds.transistor.fm/freecodecamp-podcast-in-chinese'
];

class PodcastListViewModel extends BaseViewModel {
final _databaseService = locator<PodcastsDatabaseService>();
final _developerService = locator<DeveloperService>();
Expand All @@ -32,15 +38,23 @@ class PodcastListViewModel extends BaseViewModel {

Future<List<Podcasts>> fetchPodcasts(bool isDownloadView) async {
String baseUrl = (await _developerService.developmentMode())
? 'https://api.mobile.freecodecamp.dev/'
: 'https://api.mobile.freecodecamp.org/';
? 'https://api.mobile.freecodecamp.dev'
: 'https://api.mobile.freecodecamp.org';
await _databaseService.initialise();
if (isDownloadView) {
return await _databaseService.getPodcasts();
} else {
final res = await _dio.get('${baseUrl}podcasts');
final res = await _dio.get('$baseUrl/podcasts');
final List<dynamic> podcasts = res.data;
return podcasts.map((podcast) => Podcasts.fromAPIJson(podcast)).toList();
final podcastList =
podcasts.map((podcast) => Podcasts.fromAPIJson(podcast)).toList();
final fccPodcasts = podcastList
.where((podcast) => fccPodcastUrls.contains(podcast.url))
.toList();
final otherPodcasts = podcastList
.where((podcast) => !fccPodcastUrls.contains(podcast.url))
.toList();
return [...fccPodcasts, ...otherPodcasts];
}
}
}
6 changes: 0 additions & 6 deletions mobile-app/lib/ui/views/podcast/podcast_urls.dart

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class PodcastTileState extends State<PodcastTile> {

String _parseDuration(Duration dur, BuildContext context) {
String hours = (widget.episode.duration!.inMinutes ~/ 60).toString();
String minutes = (widget.episode.duration!.inMinutes).toString();
String minutes = (widget.episode.duration!.inMinutes % 60).toString();

if (dur.inMinutes > 59) {
return context.t.podcast_duration_hours(
Expand Down

0 comments on commit b239eb0

Please sign in to comment.