-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
corrected charts cubits and impt. db for caching
- Loading branch information
1 parent
7beb52d
commit bc338fb
Showing
33 changed files
with
2,888 additions
and
519 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// ignore_for_file: public_member_api_docs, sort_constructors_first | ||
import 'dart:developer'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
|
||
import 'package:Bloomee/model/MediaPlaylistModel.dart'; | ||
import 'package:Bloomee/model/chart_model.dart'; | ||
import 'package:Bloomee/plugins/chart_defines.dart'; | ||
import 'package:Bloomee/repository/Youtube/yt_charts_home.dart'; | ||
import 'package:Bloomee/screens/screen/chart/show_charts.dart'; | ||
import 'package:Bloomee/services/db/bloomee_db_service.dart'; | ||
|
||
part 'explore_states.dart'; | ||
|
||
class TrendingCubit extends Cubit<TrendingCubitState> { | ||
bool isLatest = false; | ||
TrendingCubit() : super(TrendingCubitInitial()) { | ||
getTrendingVideosFromDB(); | ||
getTrendingVideos(); | ||
} | ||
|
||
void getTrendingVideos() async { | ||
final ytCharts = await fetchTrendingVideos(); | ||
emit(state.copyWith(ytCharts: ytCharts)); | ||
isLatest = true; | ||
} | ||
|
||
void getTrendingVideosFromDB() async { | ||
final ytChart = await BloomeeDBService.getChart("Trending Videos"); | ||
if ((!isLatest) && | ||
ytChart != null && | ||
(ytChart.chartItems?.isNotEmpty ?? false)) { | ||
emit(state.copyWith(ytCharts: [ytChart])); | ||
} | ||
} | ||
} | ||
|
||
class RecentlyCubit extends Cubit<RecentlyCubitState> { | ||
late Stream<void> watcher; | ||
RecentlyCubit() : super(RecentlyCubitInitial()) { | ||
BloomeeDBService.refreshRecentlyPlayed(); | ||
getRecentlyPlayed(); | ||
watchRecentlyPlayed(); | ||
} | ||
|
||
Future<void> watchRecentlyPlayed() async { | ||
watcher = await BloomeeDBService.watchRecentlyPlayed(); | ||
watcher.listen((event) { | ||
getRecentlyPlayed(); | ||
log("Recently Played Updated"); | ||
}); | ||
} | ||
|
||
void getRecentlyPlayed() async { | ||
final mediaPlaylist = await BloomeeDBService.getRecentlyPlayed(); | ||
emit(state.copyWith(mediaPlaylist: mediaPlaylist)); | ||
} | ||
} | ||
|
||
class ChartCubit extends Cubit<ChartState> { | ||
ChartInfo chartInfo; | ||
ChartCubit( | ||
this.chartInfo, | ||
) : super(ChartInitial()) { | ||
getChartFromDB(); | ||
getChart(); | ||
} | ||
|
||
void getChart() async { | ||
final chart = await chartInfo.chartFunction(chartInfo.url); | ||
emit(state.copyWith( | ||
chart: chart, coverImg: chart.chartItems?.first.imageUrl)); | ||
} | ||
|
||
void getChartFromDB() async { | ||
final chart = await BloomeeDBService.getChart(chartInfo.title); | ||
if (chart != null) { | ||
emit(state.copyWith( | ||
chart: chart, coverImg: chart.chartItems?.first.imageUrl)); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// ignore_for_file: public_member_api_docs, sort_constructors_first | ||
part of 'explore_cubits.dart'; | ||
|
||
class TrendingCubitState { | ||
List<ChartModel>? ytCharts; | ||
TrendingCubitState({ | ||
required this.ytCharts, | ||
}); | ||
|
||
TrendingCubitState copyWith({ | ||
List<ChartModel>? ytCharts, | ||
}) { | ||
return TrendingCubitState( | ||
ytCharts: ytCharts ?? this.ytCharts, | ||
); | ||
} | ||
} | ||
|
||
final class TrendingCubitInitial extends TrendingCubitState { | ||
TrendingCubitInitial() : super(ytCharts: []); | ||
} | ||
|
||
class RecentlyCubitState { | ||
MediaPlaylist mediaPlaylist; | ||
RecentlyCubitState({ | ||
required this.mediaPlaylist, | ||
}); | ||
|
||
RecentlyCubitState copyWith({ | ||
MediaPlaylist? mediaPlaylist, | ||
}) { | ||
return RecentlyCubitState( | ||
mediaPlaylist: mediaPlaylist ?? this.mediaPlaylist, | ||
); | ||
} | ||
} | ||
|
||
class RecentlyCubitInitial extends RecentlyCubitState { | ||
RecentlyCubitInitial() | ||
: super(mediaPlaylist: MediaPlaylist(albumName: "", mediaItems: [])); | ||
} | ||
|
||
class ChartState { | ||
ChartModel chart; | ||
String coverImg; | ||
ChartState({ | ||
required this.chart, | ||
required this.coverImg, | ||
}); | ||
|
||
ChartState copyWith({ | ||
ChartModel? chart, | ||
String? coverImg, | ||
}) { | ||
return ChartState( | ||
chart: chart ?? this.chart, | ||
coverImg: coverImg ?? this.coverImg, | ||
); | ||
} | ||
} | ||
|
||
class ChartInitial extends ChartState { | ||
ChartInitial() | ||
: super( | ||
chart: ChartModel( | ||
chartName: "", | ||
chartItems: [], | ||
), | ||
coverImg: ""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import 'package:Bloomee/services/db/GlobalDB.dart'; | ||
|
||
class ChartModel { | ||
final String chartName; | ||
final String? url; | ||
List<ChartItemModel>? chartItems = List.empty(growable: true); | ||
DateTime? lastUpdated = DateTime.now(); | ||
|
||
ChartModel( | ||
{required this.chartName, this.chartItems, this.lastUpdated, this.url}); | ||
} | ||
|
||
class ChartItemModel { | ||
final String? name; | ||
final String? imageUrl; | ||
final String? subtitle; | ||
|
||
ChartItemModel({ | ||
required this.name, | ||
required this.imageUrl, | ||
required this.subtitle, | ||
}); | ||
} | ||
|
||
ChartsCacheDB chartModelToChartCacheDB(ChartModel chartModel) { | ||
return ChartsCacheDB( | ||
chartItems: chartModel.chartItems | ||
?.map((e) => chartItemModelToChartItemDB(e)) | ||
.toList() ?? | ||
List.empty(growable: true), | ||
chartName: chartModel.chartName, | ||
lastUpdated: chartModel.lastUpdated ?? DateTime.now(), | ||
permaURL: chartModel.url); | ||
} | ||
|
||
ChartModel chartCacheDBToChartModel(ChartsCacheDB chartsCacheDB) { | ||
return ChartModel( | ||
chartItems: chartsCacheDB.chartItems | ||
.map((e) => chartItemDBToChartItemModel(e)) | ||
.toList(), | ||
chartName: chartsCacheDB.chartName, | ||
lastUpdated: chartsCacheDB.lastUpdated, | ||
url: chartsCacheDB.permaURL); | ||
} | ||
|
||
ChartItemDB chartItemModelToChartItemDB(ChartItemModel chartItemModel) { | ||
return ChartItemDB() | ||
..artURL = chartItemModel.imageUrl | ||
..artist = chartItemModel.subtitle | ||
..title = chartItemModel.name; | ||
} | ||
|
||
ChartItemModel chartItemDBToChartItemModel(ChartItemDB chartItemDB) { | ||
return ChartItemModel( | ||
imageUrl: chartItemDB.artURL, | ||
name: chartItemDB.title, | ||
subtitle: chartItemDB.artist); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.