Skip to content

Commit

Permalink
Revert Playlist + Update UI (#1437)
Browse files Browse the repository at this point in the history
* Add Menu

* Update Scan QR Code

* Update Navigation

* Refactor + FF Exhibition

* Update Navigation Bar

* Fix lint

* Update Asset

* Revert "Remove Playlist Section"

This reverts commit 65c31b6.

* Organize Update

* Update Icon

* Update Asset
  • Loading branch information
ppupha authored Dec 26, 2023
1 parent e03d4b6 commit 604ecd3
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 136 deletions.
144 changes: 144 additions & 0 deletions lib/screen/collection_pro/collection_pro_screen.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import 'dart:async';
import 'dart:convert';

import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/main.dart';
import 'package:autonomy_flutter/model/play_list_model.dart';
import 'package:autonomy_flutter/model/shared_postcard.dart';
import 'package:autonomy_flutter/screen/app_router.dart';
import 'package:autonomy_flutter/screen/bloc/identity/identity_bloc.dart';
import 'package:autonomy_flutter/screen/collection_pro/collection_pro_bloc.dart';
import 'package:autonomy_flutter/screen/collection_pro/collection_pro_state.dart';
import 'package:autonomy_flutter/screen/detail/artwork_detail_page.dart';
import 'package:autonomy_flutter/screen/playlists/list_playlists/list_playlists.dart';
import 'package:autonomy_flutter/screen/playlists/view_playlist/view_playlist.dart';
import 'package:autonomy_flutter/screen/predefined_collection/predefined_collection_screen.dart';
import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/service/playlist_service.dart';
import 'package:autonomy_flutter/service/versions_service.dart';
import 'package:autonomy_flutter/util/collection_ext.dart';
import 'package:autonomy_flutter/util/medium_category_ext.dart';
import 'package:autonomy_flutter/util/predefined_collection_ext.dart';
import 'package:autonomy_flutter/util/string_ext.dart';
Expand All @@ -17,6 +27,7 @@ import 'package:autonomy_flutter/view/header.dart';
import 'package:autonomy_flutter/view/search_bar.dart';
import 'package:autonomy_theme/autonomy_theme.dart';
import 'package:collection/collection.dart';
import 'package:crypto/crypto.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -43,6 +54,7 @@ class CollectionProState extends State<CollectionPro>
late ValueNotifier<String> searchStr;
late bool isShowSearchBar;
late bool isShowFullHeader;
final GlobalKey<CollectionSectionState> _collectionSectionKey = GlobalKey();

@override
void initState() {
Expand Down Expand Up @@ -94,6 +106,7 @@ class CollectionProState extends State<CollectionPro>
}

void loadCollection() {
unawaited(refreshCollectionSection());
_bloc.add(LoadCollectionEvent(filterStr: searchStr.value));
}

Expand All @@ -110,6 +123,13 @@ class CollectionProState extends State<CollectionPro>
}
}

Future<void> refreshCollectionSection() async {
final collectionSectionState = _collectionSectionKey.currentState;
if (collectionSectionState != null) {
await collectionSectionState.refreshPlaylist();
}
}

@override
Widget build(BuildContext context) => SafeArea(
child: BlocConsumer(
Expand Down Expand Up @@ -149,6 +169,17 @@ class CollectionProState extends State<CollectionPro>
SliverToBoxAdapter(
child: _header(context),
),
SliverToBoxAdapter(
child: ValueListenableBuilder(
valueListenable: searchStr,
builder: (BuildContext context, String value,
Widget? child) =>
CollectionSection(
key: _collectionSectionKey,
filterString: value,
),
),
),
const SliverToBoxAdapter(
child: SizedBox(height: 60),
),
Expand Down Expand Up @@ -544,6 +575,119 @@ class _WorksSectionState extends State<WorksSection> {
}
}

class CollectionSection extends StatefulWidget {
final String filterString;

const CollectionSection({super.key, this.filterString = ''});

@override
State<CollectionSection> createState() => CollectionSectionState();
}

class CollectionSectionState extends State<CollectionSection>
with RouteAware, WidgetsBindingObserver {
final _configurationService = injector.get<ConfigurationService>();
final _playlistService = injector.get<PlaylistService>();
final _versionService = injector.get<VersionService>();
late ValueNotifier<List<PlayListModel>?> _playlists;
late bool isDemo;

Future<List<PlayListModel>?> getPlaylist({bool withDefault = false}) async {
final isSubscribed = _configurationService.isPremium();
if (!isSubscribed && !isDemo) {
return null;
}
if (isDemo) {
return _versionService.getDemoAccountFromGithub();
}
List<PlayListModel> playlists = await _playlistService.getPlayList();
if (withDefault) {
final defaultPlaylists = await _playlistService.defaultPlaylists();
playlists = defaultPlaylists..addAll(playlists);
}
return playlists;
}

Future<void> _initPlayList() async {
_playlists.value = await getPlaylist() ?? [];
}

@override
void initState() {
_playlists = ValueNotifier(null);
isDemo = _configurationService.isDemoArtworksMode();
super.initState();
unawaited(_initPlayList());
WidgetsBinding.instance.addObserver(this);
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
routeObserver.subscribe(this, ModalRoute.of(context)!);
}

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}

@override
void didPopNext() {
unawaited(_initPlayList());
super.didPopNext();
}

Future<void> _gotoCreatePlaylist(BuildContext context) async {
await Navigator.of(context)
.pushNamed(AppRouter.createPlayListPage)
.then((value) {
if (value != null && value is PlayListModel) {
Navigator.pushNamed(
context,
AppRouter.viewPlayListPage,
arguments: ViewPlaylistScreenPayload(playListModel: value),
);
}
});
}

Future<void> refreshPlaylist() async {
await _initPlayList();
}

@override
Widget build(BuildContext context) =>
ValueListenableBuilder<List<PlayListModel>?>(
valueListenable: _playlists,
builder: (context, value, child) {
if (value == null) {
return const SizedBox.shrink();
}

final playlists = value.filter(widget.filterString);
final playlistIDsString = playlists.map((e) => e.id).toList().join();
final playlistKeyBytes = utf8.encode(playlistIDsString);
final playlistKey = sha256.convert(playlistKeyBytes).toString();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ListPlaylistsScreen(
key: Key(playlistKey),
playlists: _playlists,
filter: widget.filterString,
onReorder: (oldIndex, newIndex) {},
onAdd: () async {
await _gotoCreatePlaylist(context);
},
)
],
);
},
);
}

class SectionInfo {
Map<CollectionProSection, bool> state;

Expand Down
7 changes: 7 additions & 0 deletions lib/screen/home/collection_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:autonomy_flutter/database/cloud_database.dart';
import 'package:autonomy_flutter/main.dart';
import 'package:autonomy_flutter/model/blockchain.dart';
import 'package:autonomy_flutter/screen/app_router.dart';
import 'package:autonomy_flutter/screen/collection_pro/collection_pro_screen.dart';
import 'package:autonomy_flutter/screen/detail/artwork_detail_page.dart';
import 'package:autonomy_flutter/screen/home/home_bloc.dart';
import 'package:autonomy_flutter/screen/home/home_state.dart';
Expand Down Expand Up @@ -78,10 +79,12 @@ class CollectionHomePageState extends State<CollectionHomePage>
final _configurationService = injector<ConfigurationService>();

final nftBloc = injector<ClientTokenService>().nftBloc;
late GlobalKey<CollectionProState> collectionProKey;

@override
void initState() {
super.initState();
collectionProKey = GlobalKey<CollectionProState>();
_metricClient = injector.get<MetricClientService>();
WidgetsBinding.instance.addObserver(this);
_fgbgSubscription = FGBGEvents.stream.listen(_handleForeBackground);
Expand Down Expand Up @@ -222,6 +225,10 @@ class CollectionHomePageState extends State<CollectionHomePage>
return tokens;
}

Future<void> refreshPlaylists() async {
await collectionProKey.currentState?.refreshCollectionSection();
}

@override
Widget build(BuildContext context) {
super.build(context);
Expand Down
4 changes: 2 additions & 2 deletions lib/screen/home/home_navigation_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,14 @@ class _HomeNavigationPageState extends State<HomeNavigationPage>
),
const FFNavigationBarItem(
icon: Icon(
AuIcon.discover,
AuIcon.set,
size: 25,
),
label: '',
),
const FFNavigationBarItem(
icon: Icon(
AuIcon.wallet,
AuIcon.controller,
size: 25,
),
label: '',
Expand Down
Loading

0 comments on commit 604ecd3

Please sign in to comment.