tsacdop-podcast-app-android/lib/podcasts/podcastlist.dart

214 lines
7.5 KiB
Dart
Raw Normal View History

2020-07-26 12:20:42 +02:00
import 'dart:async';
import 'dart:io';
2020-07-26 12:20:42 +02:00
import 'package:flutter/foundation.dart';
2020-02-09 13:29:09 +01:00
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
2020-02-11 14:01:57 +01:00
import 'package:flutter_html/flutter_html.dart';
import 'package:provider/provider.dart';
2020-02-09 13:29:09 +01:00
2020-07-26 12:20:42 +02:00
import '../local_storage/sqflite_localpodcast.dart';
2020-05-06 18:50:32 +02:00
import '../state/podcast_group.dart';
import '../type/podcastlocal.dart';
2020-10-09 17:59:29 +02:00
import '../util/custom_widget.dart';
import '../util/extension_helper.dart';
import '../util/general_dialog.dart';
2020-07-26 12:20:42 +02:00
import '../util/pageroute.dart';
import 'podcast_detail.dart';
import 'podcast_settings.dart';
2020-02-09 13:29:09 +01:00
class AboutPodcast extends StatefulWidget {
final PodcastLocal podcastLocal;
AboutPodcast({this.podcastLocal, Key key}) : super(key: key);
@override
_AboutPodcastState createState() => _AboutPodcastState();
}
class _AboutPodcastState extends State<AboutPodcast> {
String _description;
bool _load;
void getDescription(String id) async {
2020-02-09 13:29:09 +01:00
var dbHelper = DBHelper();
2020-07-26 12:20:42 +02:00
var description = await dbHelper.getFeedDescription(id);
2020-02-09 13:29:09 +01:00
_description = description;
setState(() {
_load = true;
});
}
@override
void initState() {
super.initState();
_load = false;
getDescription(widget.podcastLocal.id);
2020-02-09 13:29:09 +01:00
}
@override
Widget build(BuildContext context) {
var _groupList = Provider.of<GroupList>(context, listen: false);
2020-07-07 17:29:21 +02:00
final s = context.s;
2020-02-09 13:29:09 +01:00
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0))),
2020-06-02 16:05:49 +02:00
titlePadding: EdgeInsets.only(
top: 20, left: 20, right: context.width / 3, bottom: 20),
2020-02-09 13:29:09 +01:00
actions: <Widget>[
FlatButton(
2020-09-12 12:22:26 +02:00
splashColor: context.accentColor.withAlpha(70),
2020-02-09 13:29:09 +01:00
padding: EdgeInsets.all(10.0),
onPressed: () {
2020-09-23 16:19:07 +02:00
_groupList.removePodcast(widget.podcastLocal);
2020-02-09 13:29:09 +01:00
Navigator.of(context).pop();
},
textColor: Colors.red,
child: Text(
2020-07-07 17:29:21 +02:00
s.remove,
2020-02-09 13:29:09 +01:00
),
),
],
title: Text(widget.podcastLocal.title),
2020-06-02 16:05:49 +02:00
content: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
!_load
? Center()
2020-10-09 17:59:29 +02:00
: _description != null
? Html(data: _description)
: Center(),
if (widget.podcastLocal.author != null)
Text(widget.podcastLocal.author,
style: TextStyle(color: Colors.blue))
2020-06-02 16:05:49 +02:00
],
),
2020-02-09 13:29:09 +01:00
),
);
}
}
class PodcastList extends StatefulWidget {
@override
_PodcastListState createState() => _PodcastListState();
}
class _PodcastListState extends State<PodcastList> {
Future<List<PodcastLocal>> _getPodcastLocal() async {
var dbHelper = DBHelper();
var podcastList = await dbHelper.getPodcastLocalAll();
return podcastList;
}
2020-02-09 13:29:09 +01:00
@override
Widget build(BuildContext context) {
final width = context.width;
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
statusBarIconBrightness: Theme.of(context).accentColorBrightness,
systemNavigationBarColor: context.primaryColor,
systemNavigationBarIconBrightness:
Theme.of(context).accentColorBrightness,
),
child: Scaffold(
appBar: AppBar(
2020-07-07 17:29:21 +02:00
title: Text(context.s.podcast(2)),
2020-10-09 17:59:29 +02:00
leading: CustomBackButton(),
centerTitle: true,
),
body: SafeArea(
child: Container(
color: context.primaryColor,
child: FutureBuilder<List<PodcastLocal>>(
future: _getPodcastLocal(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return CustomScrollView(
slivers: <Widget>[
SliverPadding(
padding: const EdgeInsets.all(10.0),
sliver: SliverGrid(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: 0.8,
crossAxisCount: 3,
),
delegate: SliverChildBuilderDelegate(
2020-07-26 12:20:42 +02:00
(context, index) {
return InkWell(
onTap: () {
Navigator.push(
context,
ScaleRoute(
page: PodcastDetail(
podcastLocal: snapshot.data[index],
)),
);
},
onLongPress: () async {
generalSheet(
context,
title: snapshot.data[index].title,
child: PodcastSetting(
podcastLocal: snapshot.data[index]),
).then((value) {
if (mounted) setState(() {});
});
},
child: Align(
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 10.0,
),
ClipRRect(
borderRadius:
BorderRadius.circular(width / 8),
child: Container(
height: width / 4,
width: width / 4,
child: Image.file(File(
"${snapshot.data[index].imagePath}")),
),
),
Padding(
padding: const EdgeInsets.all(4.0),
child: Text(
snapshot.data[index].title,
textAlign: TextAlign.center,
style: context.textTheme.bodyText1,
maxLines: 2,
),
),
],
2020-02-09 13:29:09 +01:00
),
),
);
},
childCount: snapshot.data.length,
),
),
),
],
);
}
return Center(
child: SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator()),
);
},
),
),
),
2020-02-09 13:29:09 +01:00
),
);
}
}