bug fixes
This commit is contained in:
parent
873c1f6692
commit
4df58d093a
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:didvan/config/theme_data.dart';
|
||||
import 'package:didvan/providers/media.dart';
|
||||
import 'package:didvan/providers/theme_provider.dart';
|
||||
import 'package:didvan/providers/user_provider.dart';
|
||||
import 'package:didvan/routes/route_generator.dart';
|
||||
|
|
@ -21,6 +22,9 @@ class Didvan extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<MediaProvider>(
|
||||
create: (context) => MediaProvider(),
|
||||
),
|
||||
ChangeNotifierProvider<UserProvider>(
|
||||
create: (context) => UserProvider(),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/providers/core_provider.dart';
|
||||
import 'package:didvan/services/network/request.dart';
|
||||
import 'package:didvan/services/storage/storage.dart';
|
||||
|
||||
class MediaProvider extends CoreProvier {
|
||||
static final List<int> downloadedItemIds = [];
|
||||
final List<String> downloadQueue = [];
|
||||
|
||||
Future<void> getDownloadsList() async {
|
||||
downloadedItemIds.clear();
|
||||
final videosDir = Directory(
|
||||
StorageService.appDocsDir + ('/videos'),
|
||||
);
|
||||
final podcastsDir = Directory(
|
||||
StorageService.appDocsDir + ('/podcasts'),
|
||||
);
|
||||
if (!await videosDir.exists()) {
|
||||
await videosDir.create();
|
||||
}
|
||||
if (!await podcastsDir.exists()) {
|
||||
await podcastsDir.create();
|
||||
}
|
||||
videosDir.list(recursive: false).listen(
|
||||
(event) {
|
||||
downloadedItemIds.add(
|
||||
int.parse(
|
||||
event.path.split('/').last.split('-').last.split('.').first,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
podcastsDir.list(recursive: false).listen(
|
||||
(event) {
|
||||
downloadedItemIds.add(
|
||||
int.parse(
|
||||
event.path.split('/').last.split('-').last.split('.').first,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
await Future.delayed(const Duration(milliseconds: 300), notifyListeners);
|
||||
}
|
||||
|
||||
Future<void> download({
|
||||
required String url,
|
||||
required String fileName,
|
||||
required bool isVideo,
|
||||
}) async {
|
||||
appState = AppState.busy;
|
||||
downloadQueue.add(url);
|
||||
notifyListeners();
|
||||
final service = RequestService(url);
|
||||
await service.download(fileName, isVideo ? 'videos' : 'podcasts');
|
||||
downloadQueue.remove(url);
|
||||
getDownloadsList();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
import 'package:didvan/models/requests/studio.dart';
|
||||
import 'package:didvan/models/studio_details_data.dart';
|
||||
import 'package:didvan/providers/media.dart';
|
||||
import 'package:didvan/services/network/request.dart';
|
||||
import 'package:didvan/services/network/request_helper.dart';
|
||||
import 'package:didvan/services/storage/storage.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
|
|
@ -30,6 +32,10 @@ class MediaService {
|
|||
String tag;
|
||||
tag = '${isVoiceMessage ? 'message' : 'podcast'}-$id';
|
||||
isNetworkAudio ??= audioSource.runtimeType == String;
|
||||
if (!isVoiceMessage && MediaProvider.downloadedItemIds.contains(id)) {
|
||||
audioSource = StorageService.appDocsDir + '/podcasts/podcast-$id.mp3';
|
||||
isNetworkAudio = false;
|
||||
}
|
||||
if (audioPlayerTag == tag) {
|
||||
if (audioPlayer.playing) {
|
||||
await audioPlayer.pause();
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ class RequestService {
|
|||
}
|
||||
|
||||
Future<void> download(String fileName, String subDirectory) async {
|
||||
Permission.storage.request();
|
||||
await Permission.storage.request();
|
||||
final response = await http.get(Uri.parse(url));
|
||||
StorageService.createFile(
|
||||
bytes: response.bodyBytes,
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class StorageService {
|
|||
await dir.create(recursive: true);
|
||||
}
|
||||
final file = await io.File(
|
||||
appDocsDir + '/$subDirectory/podcast-$name.mp3',
|
||||
appDocsDir + '/$subDirectory/$name',
|
||||
).create(recursive: true);
|
||||
await file.writeAsBytes(bytes);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import 'dart:io';
|
|||
import 'package:didvan/config/design_config.dart';
|
||||
import 'package:didvan/config/theme_data.dart';
|
||||
import 'package:didvan/models/view/app_bar_data.dart';
|
||||
import 'package:didvan/services/media/media.dart';
|
||||
import 'package:didvan/views/home/studio/studio_details/studio_details_state.dart';
|
||||
import 'package:didvan/views/home/studio/studio_details/widgets/details_tab_bar.dart';
|
||||
import 'package:didvan/views/home/studio/studio_details/widgets/studio_details_widget.dart';
|
||||
|
|
@ -93,6 +94,9 @@ class _StudioDetailsState extends State<StudioDetails> {
|
|||
await _changeFullSceen(false);
|
||||
return false;
|
||||
}
|
||||
if (MediaService.currentPodcast != null) {
|
||||
state.studio = MediaService.currentPodcast!;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
child: DidvanScaffold(
|
||||
|
|
@ -205,7 +209,6 @@ class _StudioDetailsState extends State<StudioDetails> {
|
|||
children: [
|
||||
StudioDetailsWidget(
|
||||
scrollController: _scrollController,
|
||||
studio: state.studio,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'dart:ui' as ui;
|
|||
|
||||
import 'package:didvan/config/design_config.dart';
|
||||
import 'package:didvan/models/view/app_bar_data.dart';
|
||||
import 'package:didvan/services/media/media.dart';
|
||||
import 'package:didvan/views/home/studio/studio_details/studio_details_state.dart';
|
||||
import 'package:didvan/views/home/studio/studio_details/widgets/details_tab_bar.dart';
|
||||
import 'package:didvan/views/home/studio/studio_details/widgets/studio_details_widget.dart';
|
||||
|
|
@ -93,6 +94,9 @@ class _StudioDetailsState extends State<StudioDetails> {
|
|||
await _changeFullSceen(false);
|
||||
return false;
|
||||
}
|
||||
if (MediaService.currentPodcast != null) {
|
||||
state.studio = MediaService.currentPodcast!;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
child: DidvanScaffold(
|
||||
|
|
@ -144,7 +148,6 @@ class _StudioDetailsState extends State<StudioDetails> {
|
|||
children: [
|
||||
StudioDetailsWidget(
|
||||
scrollController: _scrollController,
|
||||
studio: state.studio,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import 'package:didvan/models/overview_data.dart';
|
|||
import 'package:didvan/models/requests/studio.dart';
|
||||
import 'package:didvan/models/studio_details_data.dart';
|
||||
import 'package:didvan/providers/core_provider.dart';
|
||||
import 'package:didvan/providers/media.dart';
|
||||
import 'package:didvan/services/media/media.dart';
|
||||
import 'package:didvan/services/network/request.dart';
|
||||
import 'package:didvan/services/network/request_helper.dart';
|
||||
|
|
@ -17,9 +18,9 @@ class StudioDetailsState extends CoreProvier {
|
|||
StudioDetailsData? prevStudio;
|
||||
late int initialIndex;
|
||||
late StudioRequestArgs args;
|
||||
StudioRequestArgs? podcastArgs;
|
||||
final List<int> relatedQueue = [];
|
||||
bool _positionListenerActivated = false;
|
||||
final List<int> downloadedFileIds = [];
|
||||
|
||||
int _selectedDetailsIndex = 0;
|
||||
Timer? timer;
|
||||
|
|
@ -39,15 +40,19 @@ class StudioDetailsState extends CoreProvier {
|
|||
int id, {
|
||||
StudioRequestArgs? args,
|
||||
bool? isForward,
|
||||
bool forceFetch = false,
|
||||
}) async {
|
||||
if (args != null) {
|
||||
this.args = args;
|
||||
}
|
||||
if (MediaService.currentPodcast?.id == id && this.args.type == 'podcast') {
|
||||
if (this.args.type == 'podcast') {
|
||||
podcastArgs = this.args;
|
||||
}
|
||||
if (MediaService.currentPodcast?.id == id &&
|
||||
this.args.type == 'podcast' &&
|
||||
!forceFetch) {
|
||||
return;
|
||||
}
|
||||
|
||||
_getDownloadsList();
|
||||
_selectedDetailsIndex = 0;
|
||||
if (isForward != null) {
|
||||
if (isForward) {
|
||||
|
|
@ -85,7 +90,7 @@ class StudioDetailsState extends CoreProvier {
|
|||
if (result['prevStudio'].isNotEmpty && this.args.page != 0) {
|
||||
prevStudio = StudioDetailsData.fromJson(result['prevStudio']);
|
||||
}
|
||||
if (isForward == null) {
|
||||
if (isForward == null && !forceFetch) {
|
||||
await _handlePodcastPlayback(studio);
|
||||
}
|
||||
appState = AppState.idle;
|
||||
|
|
@ -100,14 +105,10 @@ class StudioDetailsState extends CoreProvier {
|
|||
if (args.type == 'podcast') {
|
||||
MediaService.currentPodcast = studio;
|
||||
MediaService.podcastPlaylistArgs = args;
|
||||
final downloaded = downloadedFileIds.contains(studio.id);
|
||||
await MediaService.handleAudioPlayback(
|
||||
audioSource: downloaded
|
||||
? StorageService.appDocsDir + '/podcasts/podcast-${studio.id}.mp3'
|
||||
: studio.media,
|
||||
audioSource: studio.media,
|
||||
id: studio.id,
|
||||
isVoiceMessage: false,
|
||||
isNetworkAudio: !downloaded,
|
||||
);
|
||||
if (nextStudio != null && !_positionListenerActivated) {
|
||||
_positionListenerActivated = true;
|
||||
|
|
@ -129,25 +130,6 @@ class StudioDetailsState extends CoreProvier {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> _getDownloadsList() async {
|
||||
downloadedFileIds.clear();
|
||||
final dir = Directory(
|
||||
StorageService.appDocsDir + ('/${args.type}s'),
|
||||
);
|
||||
if (!await dir.exists()) {
|
||||
await dir.create();
|
||||
}
|
||||
dir.list(recursive: false).listen(
|
||||
(event) {
|
||||
downloadedFileIds.add(
|
||||
int.parse(
|
||||
event.path.split('/').last.split('-').last.split('.').first,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> getRelatedContents() async {
|
||||
if (studio.relatedContents.isNotEmpty) return;
|
||||
relatedQueue.add(studio.id);
|
||||
|
|
|
|||
|
|
@ -15,30 +15,28 @@ import 'package:flutter/material.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
|
||||
class StudioDetailsWidget extends StatelessWidget {
|
||||
final StudioDetailsData studio;
|
||||
final ScrollController? scrollController;
|
||||
final VoidCallback? onCommentsTabSelected;
|
||||
const StudioDetailsWidget({
|
||||
Key? key,
|
||||
required this.studio,
|
||||
this.onCommentsTabSelected,
|
||||
this.scrollController,
|
||||
}) : super(key: key);
|
||||
|
||||
bool get _isVideo => studio.media.contains('iframe');
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ds = MediaQuery.of(context).size;
|
||||
return Consumer<StudioDetailsState>(
|
||||
builder: (context, state, child) => Container(
|
||||
builder: (context, state, child) {
|
||||
bool isVideo = state.studio.media.contains('iframe');
|
||||
return Container(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (!_isVideo)
|
||||
if (!isVideo)
|
||||
DetailsTabBar(
|
||||
isVideo: _isVideo,
|
||||
isVideo: isVideo,
|
||||
onCommentsTabSelected: onCommentsTabSelected ?? () {},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
|
@ -54,13 +52,14 @@ class StudioDetailsWidget extends StatelessWidget {
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
DidvanText(state.studio.description),
|
||||
if (studio.tags.isNotEmpty) const SizedBox(height: 20),
|
||||
if (state.studio.tags.isNotEmpty)
|
||||
const SizedBox(height: 20),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
for (var i = 0; i < studio.tags.length; i++)
|
||||
TagItem(tag: studio.tags[i]),
|
||||
for (var i = 0; i < state.studio.tags.length; i++)
|
||||
TagItem(tag: state.studio.tags[i]),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
|
@ -97,9 +96,9 @@ class StudioDetailsWidget extends StatelessWidget {
|
|||
MediaQuery.of(context).padding.top,
|
||||
child: Comments(
|
||||
pageData: {
|
||||
'id': studio.id,
|
||||
'id': state.studio.id,
|
||||
'type': 'studio',
|
||||
'title': studio.title,
|
||||
'title': state.studio.title,
|
||||
'onCommentsChanged': state.onCommentsChanged,
|
||||
'isPage': false,
|
||||
},
|
||||
|
|
@ -109,7 +108,7 @@ class StudioDetailsWidget extends StatelessWidget {
|
|||
}
|
||||
return Column(
|
||||
children: [
|
||||
if (studio.relatedContents.isEmpty)
|
||||
if (state.studio.relatedContents.isEmpty)
|
||||
for (var i = 0; i < 3; i++)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
|
|
@ -119,7 +118,9 @@ class StudioDetailsWidget extends StatelessWidget {
|
|||
),
|
||||
child: MultitypeOverview.placeholder,
|
||||
),
|
||||
for (var i = 0; i < studio.relatedContents.length; i++)
|
||||
for (var i = 0;
|
||||
i < state.studio.relatedContents.length;
|
||||
i++)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
bottom: 8,
|
||||
|
|
@ -127,7 +128,7 @@ class StudioDetailsWidget extends StatelessWidget {
|
|||
right: 16,
|
||||
),
|
||||
child: MultitypeOverview(
|
||||
item: studio.relatedContents[i],
|
||||
item: state.studio.relatedContents[i],
|
||||
onMarkChanged: (id, value) {},
|
||||
),
|
||||
),
|
||||
|
|
@ -137,7 +138,8 @@ class StudioDetailsWidget extends StatelessWidget {
|
|||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/models/overview_data.dart';
|
||||
|
|
@ -9,15 +8,10 @@ import 'package:didvan/providers/core_provider.dart';
|
|||
import 'package:didvan/providers/user_provider.dart';
|
||||
import 'package:didvan/services/network/request.dart';
|
||||
import 'package:didvan/services/network/request_helper.dart';
|
||||
import 'package:didvan/services/storage/storage.dart';
|
||||
|
||||
class StudioState extends CoreProvier {
|
||||
final List<OverviewData> studios = [];
|
||||
final List<SliderData> sliders = [];
|
||||
final List<int> downloadedFileIds = [];
|
||||
final List<String> downloadQueue = [];
|
||||
|
||||
AppState downloadState = AppState.idle;
|
||||
|
||||
String search = '';
|
||||
String lastSearch = '';
|
||||
|
|
@ -37,29 +31,9 @@ class StudioState extends CoreProvier {
|
|||
_videosSelected = value;
|
||||
selectedSortTypeIndex = 0;
|
||||
_getSliders();
|
||||
getDownloadsList();
|
||||
getStudios(page: page);
|
||||
}
|
||||
|
||||
Future<void> getDownloadsList() async {
|
||||
downloadedFileIds.clear();
|
||||
final dir = Directory(
|
||||
StorageService.appDocsDir + (videosSelected ? '/videos' : '/podcasts'),
|
||||
);
|
||||
if (!await dir.exists()) {
|
||||
await dir.create();
|
||||
}
|
||||
dir.list(recursive: false).listen(
|
||||
(event) {
|
||||
downloadedFileIds.add(
|
||||
int.parse(
|
||||
event.path.split('/').last.split('-').last.split('.').first,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
String get order {
|
||||
if (selectedSortTypeIndex == 0 || selectedSortTypeIndex == 1) return 'date';
|
||||
if (selectedSortTypeIndex == 2) return 'view';
|
||||
|
|
@ -83,7 +57,6 @@ class StudioState extends CoreProvier {
|
|||
lastSearch = '';
|
||||
_videosSelected = true;
|
||||
selectedSortTypeIndex = 0;
|
||||
getDownloadsList();
|
||||
Future.delayed(Duration.zero, () {
|
||||
_getSliders();
|
||||
getStudios(page: 1);
|
||||
|
|
@ -148,15 +121,4 @@ class StudioState extends CoreProvier {
|
|||
studios.firstWhere((radar) => radar.id == id).comments = count;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> download(String url, String fileName) async {
|
||||
downloadState = AppState.busy;
|
||||
downloadQueue.add(url);
|
||||
notifyListeners();
|
||||
final service = RequestService(url);
|
||||
await service.download(fileName, videosSelected ? 'videos' : 'podcasts');
|
||||
downloadState = AppState.idle;
|
||||
downloadQueue.remove(url);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,10 @@ class _StudioTypeButton extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
onTap: () {
|
||||
onTap();
|
||||
FocusScope.of(context).unfocus();
|
||||
},
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
child: Column(
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import 'package:didvan/constants/app_icons.dart';
|
|||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/models/studio_details_data.dart';
|
||||
import 'package:didvan/models/view/action_sheet_data.dart';
|
||||
import 'package:didvan/providers/media.dart';
|
||||
import 'package:didvan/services/media/media.dart';
|
||||
import 'package:didvan/utils/action_sheet.dart';
|
||||
import 'package:didvan/views/home/studio/studio_details/studio_details_state.dart';
|
||||
|
|
@ -346,10 +347,6 @@ class __PlayPouseAnimatedIconState extends State<_PlayPouseAnimatedIcon>
|
|||
audioSource: widget.audioSource,
|
||||
isVoiceMessage: false,
|
||||
id: widget.id,
|
||||
isNetworkAudio: !context
|
||||
.read<StudioDetailsState>()
|
||||
.downloadedFileIds
|
||||
.contains(widget.id),
|
||||
);
|
||||
_handleAnimation();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@ import 'package:didvan/constants/app_icons.dart';
|
|||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/models/overview_data.dart';
|
||||
import 'package:didvan/models/requests/studio.dart';
|
||||
import 'package:didvan/providers/media.dart';
|
||||
import 'package:didvan/services/media/media.dart';
|
||||
import 'package:didvan/utils/date_time.dart';
|
||||
import 'package:didvan/views/home/studio/studio_details/studio_details_state.dart';
|
||||
import 'package:didvan/views/home/studio/studio_state.dart';
|
||||
import 'package:didvan/views/home/widgets/bookmark_button.dart';
|
||||
import 'package:didvan/views/home/widgets/duration_widget.dart';
|
||||
import 'package:didvan/views/widgets/didvan/card.dart';
|
||||
|
|
@ -21,19 +22,18 @@ import 'package:provider/provider.dart';
|
|||
class PodcastOverview extends StatelessWidget {
|
||||
final OverviewData podcast;
|
||||
final void Function(int id, bool value) onMarkChanged;
|
||||
final StudioRequestArgs? studioRequestArgs;
|
||||
final StudioRequestArgs studioRequestArgs;
|
||||
final bool hasUnmarkConfirmation;
|
||||
const PodcastOverview({
|
||||
Key? key,
|
||||
required this.podcast,
|
||||
required this.onMarkChanged,
|
||||
this.studioRequestArgs,
|
||||
required this.studioRequestArgs,
|
||||
this.hasUnmarkConfirmation = false,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final state = context.read<StudioState>();
|
||||
return DidvanCard(
|
||||
onTap: () {
|
||||
context
|
||||
|
|
@ -77,27 +77,31 @@ class PodcastOverview extends StatelessWidget {
|
|||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const DidvanDivider(verticalPadding: 8),
|
||||
Row(
|
||||
Consumer<MediaProvider>(
|
||||
builder: (context, state, child) => Row(
|
||||
children: [
|
||||
DurationWidget(duration: podcast.duration!),
|
||||
const Spacer(),
|
||||
if (!kIsWeb) ...[
|
||||
if (state.downloadState == AppState.idle ||
|
||||
if (state.appState == AppState.idle ||
|
||||
!state.downloadQueue.contains(podcast.media))
|
||||
DidvanIconButton(
|
||||
gestureSize: 28,
|
||||
color: _isDownloaded(state)
|
||||
color: _isDownloaded
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: null,
|
||||
icon: _isDownloaded(state)
|
||||
icon: _isDownloaded
|
||||
? DidvanIcons.download_solid
|
||||
: DidvanIcons.download_regular,
|
||||
onPressed: _isDownloaded(state)
|
||||
onPressed: _isDownloaded
|
||||
? () {}
|
||||
: () => state.download(
|
||||
podcast.media!, podcast.id.toString()),
|
||||
fileName: 'podcast-${podcast.id}.mp3',
|
||||
isVideo: false,
|
||||
url: podcast.media!,
|
||||
),
|
||||
if (state.downloadState == AppState.busy &&
|
||||
),
|
||||
if (state.appState == AppState.busy &&
|
||||
state.downloadQueue.contains(podcast.media))
|
||||
const SizedBox(
|
||||
width: 18,
|
||||
|
|
@ -116,13 +120,14 @@ class PodcastOverview extends StatelessWidget {
|
|||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
bool _isDownloaded(state) {
|
||||
return state.downloadedFileIds.contains(podcast.id);
|
||||
bool get _isDownloaded {
|
||||
return MediaProvider.downloadedItemIds.contains(podcast.id);
|
||||
}
|
||||
|
||||
static Widget get placeholder => DidvanCard(
|
||||
|
|
|
|||
|
|
@ -102,13 +102,6 @@ class RadarOverview extends StatelessWidget {
|
|||
const DidvanDivider(),
|
||||
Row(
|
||||
children: [
|
||||
BookmarkButton(
|
||||
gestureSize: 32,
|
||||
value: radar.marked,
|
||||
onMarkChanged: (value) => onMarkChanged(radar.id, value),
|
||||
askForConfirmation: hasUnmarkConfirmation,
|
||||
),
|
||||
const Spacer(),
|
||||
if (radar.comments != 0) DidvanText(radar.comments.toString()),
|
||||
const SizedBox(width: 4),
|
||||
DidvanIconButton(
|
||||
|
|
@ -125,10 +118,17 @@ class RadarOverview extends StatelessWidget {
|
|||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
// const SizedBox(width: 16),
|
||||
// const DidvanText('10'),
|
||||
// const SizedBox(width: 4),
|
||||
// const Icon(DidvanIcons.evaluation_regular),
|
||||
const Spacer(),
|
||||
BookmarkButton(
|
||||
gestureSize: 32,
|
||||
value: radar.marked,
|
||||
onMarkChanged: (value) => onMarkChanged(radar.id, value),
|
||||
askForConfirmation: hasUnmarkConfirmation,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'dart:developer';
|
|||
|
||||
import 'package:didvan/config/design_config.dart';
|
||||
import 'package:didvan/main.dart';
|
||||
import 'package:didvan/providers/media.dart';
|
||||
import 'package:didvan/providers/server_data_provider.dart';
|
||||
import 'package:didvan/providers/theme_provider.dart';
|
||||
import 'package:didvan/providers/user_provider.dart';
|
||||
|
|
@ -109,6 +110,7 @@ class _SplashState extends State<Splash> {
|
|||
final String? token = await userProvider.setAndGetToken();
|
||||
if (token != null) {
|
||||
log(token);
|
||||
context.read<MediaProvider>().getDownloadsList();
|
||||
RequestService.token = token;
|
||||
final result = await userProvider.getUserInfo();
|
||||
if (!result) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'package:didvan/config/design_config.dart';
|
|||
import 'package:didvan/config/theme_data.dart';
|
||||
import 'package:didvan/constants/app_icons.dart';
|
||||
import 'package:didvan/models/enums.dart';
|
||||
import 'package:didvan/providers/media.dart';
|
||||
import 'package:didvan/services/media/media.dart';
|
||||
import 'package:didvan/services/storage/storage.dart';
|
||||
import 'package:didvan/views/home/studio/studio_details/studio_details_state.dart';
|
||||
|
|
@ -26,171 +27,11 @@ class DidvanBNB extends StatelessWidget {
|
|||
{Key? key, required this.currentTabIndex, required this.onTabChanged})
|
||||
: super(key: key);
|
||||
|
||||
bool _enablePlayerController(StudioDetailsState state) =>
|
||||
MediaService.currentPodcast != null ||
|
||||
(MediaService.audioPlayerTag?.contains('podcast') ?? false);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StreamBuilder<bool>(
|
||||
stream: MediaService.audioPlayer.playingStream,
|
||||
builder: (context, snapshot) {
|
||||
return Stack(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => MediaService.currentPodcast == null
|
||||
? null
|
||||
: _showPlayerBottomSheet(context),
|
||||
child: Consumer<StudioDetailsState>(
|
||||
builder: (context, state, child) => AnimatedContainer(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
duration: DesignConfig.lowAnimationDuration,
|
||||
height: _enablePlayerController(state) ? 128 : 72,
|
||||
decoration: BoxDecoration(
|
||||
color: DesignConfig.isDark
|
||||
? Theme.of(context).colorScheme.focused
|
||||
: Theme.of(context).colorScheme.navigation,
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.topCenter,
|
||||
child: !_enablePlayerController(state)
|
||||
? const SizedBox()
|
||||
: MediaService.currentPodcast == null
|
||||
? SizedBox(
|
||||
height: 32,
|
||||
child: Center(
|
||||
child: SpinKitThreeBounce(
|
||||
size: 18,
|
||||
color: DesignConfig.isDark
|
||||
? null
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondCTA,
|
||||
),
|
||||
),
|
||||
)
|
||||
: SizedBox(
|
||||
height: 56,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
right: 12,
|
||||
left: 16,
|
||||
),
|
||||
child: DidvanIconButton(
|
||||
icon: DidvanIcons.close_regular,
|
||||
color: DesignConfig.isDark
|
||||
? null
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondCTA,
|
||||
gestureSize: 28,
|
||||
onPressed:
|
||||
MediaService.resetAudioPlayer,
|
||||
),
|
||||
),
|
||||
SkeletonImage(
|
||||
imageUrl:
|
||||
MediaService.currentPodcast!.image,
|
||||
width: 32,
|
||||
height: 32,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
DidvanText(
|
||||
MediaService.currentPodcast!.title,
|
||||
color: DesignConfig.isDark
|
||||
? null
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondCTA,
|
||||
),
|
||||
AudioSlider(
|
||||
disableThumb: true,
|
||||
tag: MediaService.audioPlayerTag!,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
StreamBuilder<PlayerState>(
|
||||
stream: MediaService
|
||||
.audioPlayer.playerStateStream,
|
||||
builder: (context, snapshot) {
|
||||
if (state.appState == AppState.busy ||
|
||||
MediaService.audioPlayer.playerState
|
||||
.processingState ==
|
||||
ProcessingState.loading) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 4,
|
||||
left: 16,
|
||||
right: 16,
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 18,
|
||||
width: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondCTA,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
if (state.appState != AppState.busy &&
|
||||
MediaService.audioPlayer.playerState
|
||||
.processingState !=
|
||||
ProcessingState.loading)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 12,
|
||||
right: 16,
|
||||
),
|
||||
child: DidvanIconButton(
|
||||
gestureSize: 28,
|
||||
color: DesignConfig.isDark
|
||||
? null
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondCTA,
|
||||
icon: snapshot.data!
|
||||
? DidvanIcons.pause_solid
|
||||
: DidvanIcons.play_solid,
|
||||
onPressed: () {
|
||||
MediaService.handleAudioPlayback(
|
||||
audioSource: state
|
||||
.downloadedFileIds
|
||||
.contains(state.studio.id)
|
||||
? StorageService.appDocsDir +
|
||||
'/podcasts/podcast-${state.studio.id}.mp3'
|
||||
: state.studio.media,
|
||||
isNetworkAudio: !state
|
||||
.downloadedFileIds
|
||||
.contains(state.studio.id),
|
||||
id: state.studio.id,
|
||||
isVoiceMessage: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const _PlayerNavBar(),
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
|
|
@ -247,13 +88,183 @@ class DidvanBNB extends StatelessWidget {
|
|||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class _PlayerNavBar extends StatelessWidget {
|
||||
const _PlayerNavBar({Key? key}) : super(key: key);
|
||||
|
||||
bool _enablePlayerController(StudioDetailsState state) =>
|
||||
MediaService.currentPodcast != null ||
|
||||
(MediaService.audioPlayerTag?.contains('podcast') ?? false);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StreamBuilder<bool>(
|
||||
stream: MediaService.audioPlayer.playingStream,
|
||||
builder: (context, snapshot) => GestureDetector(
|
||||
onTap: () => MediaService.currentPodcast == null
|
||||
? null
|
||||
: _showPlayerBottomSheet(context),
|
||||
child: Consumer<StudioDetailsState>(
|
||||
builder: (context, state, child) => AnimatedContainer(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
duration: DesignConfig.lowAnimationDuration,
|
||||
height: _enablePlayerController(state) ? 128 : 72,
|
||||
decoration: BoxDecoration(
|
||||
color: DesignConfig.isDark
|
||||
? Theme.of(context).colorScheme.focused
|
||||
: Theme.of(context).colorScheme.navigation,
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(16),
|
||||
),
|
||||
),
|
||||
alignment: Alignment.topCenter,
|
||||
child: !_enablePlayerController(state)
|
||||
? const SizedBox()
|
||||
: MediaService.currentPodcast == null
|
||||
? SizedBox(
|
||||
height: 32,
|
||||
child: Center(
|
||||
child: SpinKitThreeBounce(
|
||||
size: 18,
|
||||
color: DesignConfig.isDark
|
||||
? Theme.of(context).colorScheme.title
|
||||
: Theme.of(context).colorScheme.secondCTA,
|
||||
),
|
||||
),
|
||||
)
|
||||
: SizedBox(
|
||||
height: 56,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
right: 12,
|
||||
left: 16,
|
||||
),
|
||||
child: DidvanIconButton(
|
||||
icon: DidvanIcons.close_regular,
|
||||
color: DesignConfig.isDark
|
||||
? null
|
||||
: Theme.of(context).colorScheme.secondCTA,
|
||||
gestureSize: 28,
|
||||
onPressed: MediaService.resetAudioPlayer,
|
||||
),
|
||||
),
|
||||
SkeletonImage(
|
||||
imageUrl: MediaService.currentPodcast!.image,
|
||||
width: 32,
|
||||
height: 32,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
DidvanText(
|
||||
MediaService.currentPodcast!.title,
|
||||
color: DesignConfig.isDark
|
||||
? null
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondCTA,
|
||||
),
|
||||
AudioSlider(
|
||||
disableThumb: true,
|
||||
tag: MediaService.audioPlayerTag!,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
StreamBuilder<PlayerState>(
|
||||
stream:
|
||||
MediaService.audioPlayer.playerStateStream,
|
||||
builder: (context, snapshot) {
|
||||
final playerState = MediaService
|
||||
.audioPlayer.playerState.processingState;
|
||||
if (playerState == ProcessingState.loading ||
|
||||
state.appState == AppState.busy) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 4,
|
||||
left: 16,
|
||||
right: 16,
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 18,
|
||||
width: 18,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: DesignConfig.isDark
|
||||
? Theme.of(context)
|
||||
.colorScheme
|
||||
.title
|
||||
: Theme.of(context)
|
||||
.colorScheme
|
||||
.secondCTA,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
if (state.appState != AppState.busy &&
|
||||
MediaService.audioPlayer.playerState
|
||||
.processingState !=
|
||||
ProcessingState.loading)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 12,
|
||||
right: 16,
|
||||
),
|
||||
child: DidvanIconButton(
|
||||
gestureSize: 28,
|
||||
color: DesignConfig.isDark
|
||||
? null
|
||||
: Theme.of(context).colorScheme.secondCTA,
|
||||
icon: snapshot.data!
|
||||
? DidvanIcons.pause_solid
|
||||
: DidvanIcons.play_solid,
|
||||
onPressed: () {
|
||||
if (state.args.type == 'video') {
|
||||
state.getStudioDetails(
|
||||
MediaService.currentPodcast!.id,
|
||||
args: state.podcastArgs,
|
||||
forceFetch: true,
|
||||
);
|
||||
}
|
||||
MediaService.handleAudioPlayback(
|
||||
audioSource:
|
||||
MediaService.currentPodcast!.media,
|
||||
id: MediaService.currentPodcast!.id,
|
||||
isVoiceMessage: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showPlayerBottomSheet(BuildContext context) {
|
||||
final sheetKey = GlobalKey<ExpandableBottomSheetState>();
|
||||
bool isExpanded = false;
|
||||
final detailsState = context.read<StudioDetailsState>();
|
||||
if (detailsState.args.type == 'video') {
|
||||
detailsState.getStudioDetails(
|
||||
MediaService.currentPodcast!.id,
|
||||
args: detailsState.podcastArgs,
|
||||
forceFetch: true,
|
||||
);
|
||||
}
|
||||
final state = context.read<StudioState>();
|
||||
showModalBottomSheet(
|
||||
backgroundColor: Colors.transparent,
|
||||
|
|
@ -288,12 +299,9 @@ class DidvanBNB extends StatelessWidget {
|
|||
color: Theme.of(context).colorScheme.surface,
|
||||
child: Column(
|
||||
children: [
|
||||
StatefulBuilder(
|
||||
builder: (context, setState) => DidvanIconButton(
|
||||
DidvanIconButton(
|
||||
size: 32,
|
||||
icon: isExpanded
|
||||
? DidvanIcons.angle_down_regular
|
||||
: DidvanIcons.angle_up_regular,
|
||||
icon: DidvanIcons.angle_up_regular,
|
||||
onPressed: () {
|
||||
if (!isExpanded) {
|
||||
sheetKey.currentState?.expand();
|
||||
|
|
@ -302,10 +310,8 @@ class DidvanBNB extends StatelessWidget {
|
|||
isExpanded = false;
|
||||
sheetKey.currentState?.contract();
|
||||
}
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
|
|
@ -322,7 +328,6 @@ class DidvanBNB extends StatelessWidget {
|
|||
),
|
||||
)
|
||||
: StudioDetailsWidget(
|
||||
studio: detailsState.studio,
|
||||
onCommentsTabSelected: () {
|
||||
Future.delayed(
|
||||
const Duration(milliseconds: 100),
|
||||
|
|
|
|||
Loading…
Reference in New Issue