1
0
mirror of https://github.com/stonega/tsacdop synced 2024-12-16 10:22:23 +01:00
tsacdop-podcast-app-android/lib/podcasts/podcastlist.dart

227 lines
8.9 KiB
Dart
Raw Normal View History

import 'dart:io';
2020-02-09 13:29:09 +01:00
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'dart:async';
import 'package:flutter/foundation.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-05-06 18:50:32 +02:00
import '../state/podcast_group.dart';
import '../type/podcastlocal.dart';
import '../local_storage/sqflite_localpodcast.dart';
2020-07-07 17:29:21 +02:00
import 'podcast_detail.dart';
2020-05-06 18:50:32 +02:00
import '../util/pageroute.dart';
2020-06-02 16:05:49 +02:00
import '../util/context_extension.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();
String 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(
padding: EdgeInsets.all(10.0),
onPressed: () {
_groupList.removePodcast(widget.podcastLocal.id);
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()
: _description != null ? Html(data: _description) : Center(),
(widget.podcastLocal.author != null)
? Text(widget.podcastLocal.author,
style: TextStyle(color: Colors.blue))
: Center(),
],
),
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) {
double _width = MediaQuery.of(context).size.width;
return AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
statusBarIconBrightness: Theme.of(context).accentColorBrightness,
systemNavigationBarColor: Theme.of(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)),
centerTitle: true,
),
body: SafeArea(
child: Container(
color: Theme.of(context).primaryColor,
child: FutureBuilder<List<PodcastLocal>>(
future: getPodcastLocal(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return CustomScrollView(
primary: false,
slivers: <Widget>[
SliverPadding(
padding: const EdgeInsets.all(10.0),
sliver: SliverGrid(
gridDelegate:
SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: 0.8,
crossAxisCount: 3,
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return InkWell(
onTap: () {
Navigator.push(
context,
ScaleRoute(
page: PodcastDetail(
podcastLocal: snapshot.data[index],
)),
);
},
onLongPress: () {
showGeneralDialog(
context: context,
barrierDismissible: true,
barrierLabel:
MaterialLocalizations.of(context)
.modalBarrierDismissLabel,
barrierColor: Colors.black54,
transitionDuration:
const Duration(milliseconds: 200),
pageBuilder: (BuildContext context,
Animation animaiton,
Animation secondaryAnimation) =>
AnnotatedRegion<SystemUiOverlayStyle>(
value: SystemUiOverlayStyle(
statusBarIconBrightness:
Brightness.light,
systemNavigationBarColor:
Theme.of(context)
.brightness ==
Brightness.light
? Color.fromRGBO(
113, 113, 113, 1)
: Color.fromRGBO(
15, 15, 15, 1),
),
child: AboutPodcast(
podcastLocal:
snapshot.data[index]),
));
},
child: Container(
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
height: 10.0,
),
ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(_width / 8)),
child: Container(
height: _width / 4,
width: _width / 4,
child: Image.file(File(
"${snapshot.data[index].imagePath}")),
),
),
Container(
padding: EdgeInsets.all(4.0),
child: Text(
snapshot.data[index].title,
textAlign: TextAlign.center,
2020-03-01 13:17:06 +01:00
style: Theme.of(context)
.textTheme
.bodyText1,
maxLines: 2,
),
),
],
2020-02-09 13:29:09 +01:00
),
),
);
},
childCount: snapshot.data.length,
),
),
),
],
);
}
return Text('NoData');
},
),
),
),
2020-02-09 13:29:09 +01:00
),
);
}
}