Skip to content

Commit

Permalink
fixed playlist loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikh Haziq committed Oct 23, 2024
1 parent ebc4478 commit 4f00b36
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/app_config.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AppConfig appConfig = AppConfig(version: 29, codeName: '2.0.4');
AppConfig appConfig = AppConfig(version: 30, codeName: '2.0.5');

class AppConfig {
int version;
Expand Down
21 changes: 21 additions & 0 deletions lib/screens/home_screen/section_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import 'package:expandable_text/expandable_text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:gyawun/main.dart';
import 'package:gyawun/utils/pprint.dart';
import 'package:gyawun/ytmusic/ytmusic.dart';

import '../../generated/l10n.dart';
import '../../services/bottom_message.dart';
Expand All @@ -30,6 +33,7 @@ class SectionItem extends StatefulWidget {
class _SectionItemState extends State<SectionItem> {
final ScrollController horizontalScrollController = ScrollController();
PageController horizontalPageController = PageController();
bool loadingMore = false;

@override
void initState() {
Expand All @@ -43,6 +47,21 @@ class _SectionItemState extends State<SectionItem> {
super.dispose();
}

loadMoreItems(){
if(widget.section['continuation']!=null){
setState(() {
loadingMore = true;
});
GetIt.I<YTMusic>().getMoreItems(continuation: widget.section['continuation']).then((value) {
setState(() {
widget.section['contents'].addAll(value['items']);
widget.section['continuation'] = value['continuation'];
loadingMore = false;
});
});
}
}

@override
Widget build(BuildContext context) {
horizontalPageController = PageController(
Expand Down Expand Up @@ -162,6 +181,8 @@ class _SectionItemState extends State<SectionItem> {
items: widget.section['contents'],
controller: horizontalScrollController,
),
if(loadingMore)const AdaptiveProgressRing(),
if(widget.section['continuation']!=null && !loadingMore) AdaptiveButton(onPressed: loadMoreItems, child:const Text("Load More"))
],
);
}
Expand Down
14 changes: 14 additions & 0 deletions lib/screens/settings_screen/about/about_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ class AboutScreen extends StatelessWidget {
onTap: () => launchUrl(
Uri.parse('https://jhelumcorp.github.io'),
mode: LaunchMode.externalApplication),
),
AdaptiveListTile(
margin: const EdgeInsets.symmetric(vertical: 4),
leading: const ColorIcon(
color: null, icon: Icons.link),
title: Text(
"Website",
style: textStyle(context, bold: false)
.copyWith(fontSize: 16),
),
trailing: Icon(AdaptiveIcons.chevron_right),
onTap: () => launchUrl(
Uri.parse('https://gyawunmusic.vercel.app'),
mode: LaunchMode.externalApplication),
),
AdaptiveListTile(
margin: const EdgeInsets.symmetric(vertical: 4),
Expand Down
15 changes: 14 additions & 1 deletion lib/ytmusic/mixins/browsing.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:core';
import 'dart:math';

import 'package:gyawun/utils/pprint.dart';

import '../helpers.dart';
import '../yt_service_provider.dart';
import 'utils.dart';
Expand Down Expand Up @@ -175,7 +177,19 @@ mixin BrowsingMixin on YTMusicServices {

return result;
}
Future<Map<String, dynamic>> getMoreItems(
{continuation=''}) async {
String endpoint = 'browse';
Map<String,dynamic>? body = {"browseId": "FEmusic_home"};

var response =
await sendRequest(endpoint, body, additionalParams: continuation);
List contents =
nav(response,['continuationContents','musicPlaylistShelfContinuation','contents'])??[];
return {
'items':handleContents(contents),
};
}
int getDatestamp() {
final DateTime now = DateTime.now();
final DateTime epoch = DateTime.fromMillisecondsSinceEpoch(0);
Expand Down Expand Up @@ -359,7 +373,6 @@ List<Map<String, dynamic>> handleOuterContents(List contents,
} else if (gridRenderer != null) {
results.add(handleGridRenderer(gridRenderer));
} else {
// pprint(content);
}
results.add(result);
}
Expand Down
3 changes: 3 additions & 0 deletions lib/ytmusic/mixins/playlists.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:gyawun/ytmusic/yt_service_provider.dart';

mixin PlaylistsMixin on YTMusicServices{}
7 changes: 7 additions & 0 deletions lib/ytmusic/mixins/utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:core';

import 'package:gyawun/utils/pprint.dart';

import '../helpers.dart';

Map<String, dynamic> handlePageHeader(Map<String, dynamic> header,
Expand Down Expand Up @@ -328,6 +330,11 @@ handleMusicPlaylistShelfRenderer(Map item) {
section['playlistId'] = nav(item, ['playlistId']);
section['viewType'] = 'COLUMN';
}
String? cont = nav(item,
['continuations', 0, 'nextContinuationData', 'continuation']);
String? continuationparams =cont !=null ? getContinuationString(cont):null;
section['continuation'] = continuationparams;

List? contents = nav(item, ['contents']);
if (contents != null) {
section['contents'].addAll(handleContents(contents));
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ packages:
dependency: "direct main"
description:
name: fluent_ui
sha256: ae97c15cbf41594e31d9582a359b5a725cb66753bef73ed845ba534d3c7ec053
sha256: e7804bf3bbb3ecf9e77d5498181dc36375f5ca736ccfb3862fea17c50050eb89
url: "https://pub.dev"
source: hosted
version: "4.9.1"
version: "4.9.2"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -1319,10 +1319,10 @@ packages:
dependency: "direct main"
description:
name: window_manager
sha256: "8699323b30da4cdbe2aa2e7c9de567a6abd8a97d9a5c850a3c86dcd0b34bbfbf"
sha256: ab8b2a7f97543d3db2b506c9d875e637149d48ee0c6a5cb5f5fd6e0dac463792
url: "https://pub.dev"
source: hosted
version: "0.3.9"
version: "0.4.2"
xdg_directories:
dependency: transitive
description:
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: gyawun
description: "A new Flutter project."
publish_to: 'none'
version: 2.0.4+29
version: 2.0.5+30

environment:
sdk: '>=3.4.1 <4.0.0'
Expand Down Expand Up @@ -53,8 +53,8 @@ dependencies:
just_audio_media_kit: ^2.0.5
media_kit_native_event_loop: ^1.0.8
flutter_acrylic: ^1.1.4
fluent_ui: ^4.9.1
window_manager: ^0.3.9
fluent_ui: ^4.9.2
window_manager: ^0.4.2
receive_sharing_intent:
git:
url: https://github.com/sheikhhaziq/receive_sharing_intent.git
Expand Down

0 comments on commit 4f00b36

Please sign in to comment.