Skip to content

Commit

Permalink
Youtube home added to explore page
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantKArya committed Apr 11, 2024
1 parent cc278a0 commit e890aeb
Show file tree
Hide file tree
Showing 27 changed files with 946 additions and 195 deletions.
30 changes: 30 additions & 0 deletions lib/blocs/explore/cubit/explore_cubits.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'dart:isolate';
import 'package:Bloomee/repository/Youtube/yt_music_api.dart';
import 'package:Bloomee/services/db/GlobalDB.dart';
import 'package:bloc/bloc.dart';
import 'package:Bloomee/model/MediaPlaylistModel.dart';
Expand All @@ -10,6 +12,8 @@ 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';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:isar/isar.dart';
Expand Down Expand Up @@ -165,3 +169,29 @@ class FetchChartCubit extends Cubit<FetchChartState> {
}
}
}

class YTMusicCubit extends Cubit<YTMusicCubitState> {
YTMusicCubit() : super(YTMusicCubitInitial()) {
fetchYTMusicDB();
fetchYTMusic();
}

void fetchYTMusicDB() async {
final data = await BloomeeDBService.getAPICache("YTMusic");
if (data != null) {
final ytmData = await compute(parseYTMusicData, data);
emit(state.copyWith(ytmData: ytmData));
}
}

Map<String, List<dynamic>> parseYTMusicData(String source) {
return jsonDecode(source);
}

void fetchYTMusic() async {
final ytCharts = await YtMusicService().getMusicHome();
emit(state.copyWith(ytmData: ytCharts));
final ytChartsJson = jsonEncode(ytCharts);
BloomeeDBService.putAPICache("YTMusic", ytChartsJson);
}
}
22 changes: 22 additions & 0 deletions lib/blocs/explore/cubit/explore_states.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,25 @@ class FetchChartState {
class FetchChartInitial extends FetchChartState {
FetchChartInitial() : super(isFetched: false);
}

class YTMusicCubitState extends Equatable {
final Map<String, List<dynamic>> ytmData;
const YTMusicCubitState({
required this.ytmData,
});

@override
List<Object?> get props => [ytmData];

YTMusicCubitState copyWith({
Map<String, List<dynamic>>? ytmData,
}) {
return YTMusicCubitState(
ytmData: ytmData ?? this.ytmData,
);
}
}

class YTMusicCubitInitial extends YTMusicCubitState {
YTMusicCubitInitial() : super(ytmData: {});
}
1 change: 0 additions & 1 deletion lib/routes_and_consts/routes.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:Bloomee/screens/screen/test_screen.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:Bloomee/routes_and_consts/global_str_consts.dart';
Expand Down
5 changes: 3 additions & 2 deletions lib/screens/screen/add_to_playlist_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:go_router/go_router.dart';
import 'package:Bloomee/blocs/add_to_playlist/cubit/add_to_playlist_cubit.dart';
import 'package:Bloomee/model/songModel.dart';
import 'package:Bloomee/screens/widgets/createPlaylist_bottomsheet.dart';
import 'package:Bloomee/screens/widgets/smallPlaylistCard_widget.dart';
import 'package:Bloomee/screens/widgets/playlist_tile.dart';
import 'package:Bloomee/services/db/GlobalDB.dart';
import 'package:Bloomee/theme_data/default.dart';
import 'package:Bloomee/routes_and_consts/global_conts.dart';
Expand Down Expand Up @@ -53,11 +53,12 @@ class _AddToPlaylistScreenState extends State<AddToPlaylistScreen> {
appBar: AppBar(
backgroundColor: Default_Theme.themeColor,
foregroundColor: Default_Theme.primaryColor1,
centerTitle: true,
title: Text(
'Add to Playlist',
style: const TextStyle(
color: Default_Theme.primaryColor1,
fontSize: 25,
fontSize: 20,
fontWeight: FontWeight.bold)
.merge(Default_Theme.secondoryTextStyle),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/screen/chart/chart_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class _ChartScreenState extends State<ChartScreen> {
titlePadding:
const EdgeInsets.only(left: 8, bottom: 0, right: 0, top: 0),
title: Text(state.chartName,
textScaleFactor: 1,
textScaler: const TextScaler.linear(1.0),
textAlign: TextAlign.start,
style: Default_Theme.secondoryTextStyleMedium.merge(const TextStyle(
fontSize: 24, color: Color.fromARGB(255, 255, 235, 251)))),
Expand Down
77 changes: 39 additions & 38 deletions lib/screens/screen/explore_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import 'package:Bloomee/blocs/explore/cubit/explore_cubits.dart';
import 'package:Bloomee/blocs/mediaPlayer/bloomee_player_cubit.dart';
import 'package:Bloomee/routes_and_consts/global_str_consts.dart';
import 'package:Bloomee/screens/screen/home_views/recents_view.dart';
import 'package:Bloomee/screens/widgets/chart_list_tile.dart';
import 'package:Bloomee/screens/widgets/more_bottom_sheet.dart';
import 'package:Bloomee/screens/widgets/song_card_widget.dart';
import 'package:Bloomee/screens/widgets/song_tile.dart';
import 'package:Bloomee/services/db/cubit/bloomee_db_cubit.dart';
import 'package:Bloomee/utils/app_updater.dart';
import 'package:flutter/material.dart';
Expand All @@ -15,6 +14,7 @@ import 'package:Bloomee/theme_data/default.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:icons_plus/icons_plus.dart';
import '../widgets/carousal_widget.dart';
import '../widgets/horizontal_card_view.dart';
import '../widgets/tabList_widget.dart';

class ExploreScreen extends StatefulWidget {
Expand All @@ -41,14 +41,22 @@ class _ExploreScreenState extends State<ExploreScreen> {
Widget build(BuildContext context) {
return MultiBlocProvider(
providers: [
BlocProvider<TrendingCubit>(
create: (context) => TrendingCubit(),
lazy: false,
),
// BlocProvider<TrendingCubit>(
// create: (context) => TrendingCubit(),
// lazy: false,
// ),
BlocProvider<RecentlyCubit>(
create: (context) => RecentlyCubit(),
lazy: false,
),
BlocProvider(
create: (context) => YTMusicCubit(),
lazy: false,
),
BlocProvider(
create: (context) => FetchChartCubit(),
lazy: false,
),
],
child: Scaffold(
body: CustomScrollView(
Expand Down Expand Up @@ -119,38 +127,15 @@ class _ExploreScreenState extends State<ExploreScreen> {
),
),
),
Padding(
padding: const EdgeInsets.only(top: 0.0),
child: SizedBox(
child: BlocBuilder<TrendingCubit, TrendingCubitState>(
builder: (context, state) {
return AnimatedSwitcher(
duration: const Duration(milliseconds: 1000),
child: state is TrendingCubitInitial
? const Center(
child: SizedBox(
height: 60,
width: 60,
child: CircularProgressIndicator(
color: Default_Theme.accentColor2,
)),
)
: TabSongListWidget(
list: state.ytCharts![0].chartItems!
.map((e) => ChartListTile(
title: e.name ?? "",
subtitle: e.subtitle ?? "",
imgUrl: e.imageUrl ?? "",
rectangularImage: true,
))
.toList(),
category: "Trending",
columnSize: 4,
),
);
},
),
),
BlocBuilder<YTMusicCubit, YTMusicCubitState>(
builder: (context, state) {
return AnimatedSwitcher(
duration: const Duration(milliseconds: 400),
child: state is YTMusicCubitInitial
? const SizedBox()
: ytSection(state.ytmData),
);
},
),
],
),
Expand All @@ -162,6 +147,22 @@ class _ExploreScreenState extends State<ExploreScreen> {
);
}

Widget ytSection(Map<String, List<dynamic>> ytmData) {
List<Widget> ytList = List.empty(growable: true);
// log(ytmData.toString());

for (var value in (ytmData["body"]!)) {
// log(value.toString());
ytList.add(HorizontalCardView(data: value));
}
return ListView(
shrinkWrap: true,
padding: const EdgeInsets.only(top: 0),
physics: const NeverScrollableScrollPhysics(),
children: ytList,
);
}

SliverAppBar customDiscoverBar(BuildContext context) {
return SliverAppBar(
floating: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/screen/home_views/recents_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import 'package:Bloomee/blocs/history/cubit/history_cubit.dart';
import 'package:Bloomee/blocs/mediaPlayer/bloomee_player_cubit.dart';
import 'package:Bloomee/screens/widgets/more_bottom_sheet.dart';
import 'package:Bloomee/screens/widgets/song_card_widget.dart';
import 'package:Bloomee/screens/widgets/song_tile.dart';
import 'package:flutter/material.dart';
import 'package:Bloomee/theme_data/default.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down
Loading

0 comments on commit e890aeb

Please sign in to comment.