From 73fc6135a9ce71b4f9d1707f6ad649c35248c228 Mon Sep 17 00:00:00 2001 From: stonegate Date: Wed, 12 Feb 2020 23:16:46 +0800 Subject: [PATCH] modified: README.md modified: lib/episodes/episodedetail.dart modified: lib/home/appbar/importompl.dart modified: lib/home/homescroll.dart modified: lib/podcasts/podcastdetail.dart modified: lib/podcasts/podcastlist.dart modified: lib/util/episodegrid.dart Change networkcachedimage to localimage --- README.md | 2 +- lib/episodes/episodedetail.dart | 65 ++----- lib/home/appbar/importompl.dart | 2 +- lib/home/homescroll.dart | 20 +- lib/podcasts/podcastdetail.dart | 10 - lib/podcasts/podcastlist.dart | 26 +-- lib/util/episodegrid.dart | 311 +++++++++++++++++--------------- 7 files changed, 207 insertions(+), 229 deletions(-) diff --git a/README.md b/README.md index b625168..81fa1b7 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ The podcasts search engine is powered by [ListenNotes](https://listennotes.com). ## License -Tsacdop is under licensed under the [MIT](https://github.com/stonega/tsacdop/blob/master/LICENSE) license. +Tsacdop is licensed under the [MIT](https://github.com/stonega/tsacdop/blob/master/LICENSE) license. ## Getting Started diff --git a/lib/episodes/episodedetail.dart b/lib/episodes/episodedetail.dart index eaa48a3..86d60fb 100644 --- a/lib/episodes/episodedetail.dart +++ b/lib/episodes/episodedetail.dart @@ -1,4 +1,3 @@ -import 'dart:convert'; import 'dart:math' as math; import 'package:flutter/material.dart'; @@ -53,7 +52,6 @@ class _EpisodeDetailState extends State { @override Widget build(BuildContext context) { - return Scaffold( backgroundColor: Colors.grey[100], appBar: AppBar( @@ -97,7 +95,16 @@ class _EpisodeDetailState extends State { child: Row( children: [ (widget.episodeItem.explicit == 1) - ? ExplicitScale() + ? Container( + decoration: BoxDecoration( + color: Colors.red[800], + shape: BoxShape.circle), + height: 25.0, + width: 25.0, + margin: EdgeInsets.only(right: 10.0), + alignment: Alignment.center, + child: Text('E', + style: TextStyle(color: Colors.white))) : Center(), Container( decoration: BoxDecoration( @@ -512,54 +519,4 @@ class _ImageRotateState extends State ), ); } -} - -class ExplicitScale extends StatefulWidget { - @override - _ExplicitScaleState createState() => _ExplicitScaleState(); -} - - class _ExplicitScaleState extends State - with SingleTickerProviderStateMixin { - Animation _animation; - AnimationController _controller; - double _value; - - @override - void initState() { - super.initState(); - _controller = AnimationController( - vsync: this, - duration: Duration(milliseconds: 500), - ); - _animation = Tween(begin: 0.0, end: 1.0).animate(_controller) - ..addListener(() { - if (mounted) - setState(() { - _value = _animation.value; - }); - }); - _controller.forward(); - } - - @override - void dispose() { - _controller.dispose(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return Transform.scale( - scale: _value, - child: Container( - decoration: - BoxDecoration(color: Colors.red[800], shape: BoxShape.circle), - height: 25.0, - width: 25.0, - margin: EdgeInsets.only(right: 10.0), - padding: EdgeInsets.symmetric(horizontal: 10.0), - alignment: Alignment.center, - child: Text('E', style: TextStyle(color: Colors.white)))); - } -} +} \ No newline at end of file diff --git a/lib/home/appbar/importompl.dart b/lib/home/appbar/importompl.dart index b52cd6c..29bb355 100644 --- a/lib/home/appbar/importompl.dart +++ b/lib/home/appbar/importompl.dart @@ -32,7 +32,7 @@ class Import extends StatelessWidget { padding: EdgeInsets.symmetric(horizontal: 20.0), alignment: Alignment.centerLeft, child: - Text('Importing: ' + (importOmpl.rsstitle))), + Text('Connetting: ' + (importOmpl.rsstitle))), ], ) : importOmpl.importState == ImportState.parse diff --git a/lib/home/homescroll.dart b/lib/home/homescroll.dart index c540761..5c92bad 100644 --- a/lib/home/homescroll.dart +++ b/lib/home/homescroll.dart @@ -5,7 +5,6 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'package:cached_network_image/cached_network_image.dart'; import 'package:path_provider/path_provider.dart'; import 'package:tsacdop/class/episodebrief.dart'; @@ -116,8 +115,11 @@ class PodcastPreview extends StatefulWidget { } class _PodcastPreviewState extends State { + String path; Future> _getRssItemTop(PodcastLocal podcastLocal) async { var dbHelper = DBHelper(); + var dir = await getApplicationDocumentsDirectory(); + path = dir.path; Future> episodes = dbHelper.getRssItemTop(podcastLocal.title); return episodes; @@ -150,7 +152,9 @@ class _PodcastPreviewState extends State { return (snapshot.hasData) ? ShowEpisode( podcast: snapshot.data, - podcastLocal: widget.podcastLocal) + podcastLocal: widget.podcastLocal, + path: path, + ) : Center(child: CircularProgressIndicator()); }, ), @@ -191,7 +195,9 @@ class _PodcastPreviewState extends State { class ShowEpisode extends StatelessWidget { final List podcast; final PodcastLocal podcastLocal; - ShowEpisode({Key key, this.podcast, this.podcastLocal}) : super(key: key); + final String path; + ShowEpisode({Key key, this.podcast, this.podcastLocal, this.path}) + : super(key: key); @override Widget build(BuildContext context) { return CustomScrollView( @@ -222,7 +228,8 @@ class ShowEpisode extends StatelessWidget { ScaleRoute( page: EpisodeDetail( episodeItem: podcast[index], - heroTag: 'scroll', + heroTag: 'scroll', + //unique hero tag )), ); }, @@ -260,9 +267,8 @@ class ShowEpisode extends StatelessWidget { child: Container( height: 30.0, width: 30.0, - child: CachedNetworkImage( - imageUrl: podcastLocal.imageUrl, - ), + child: Image.file(File( + "$path/${podcastLocal.title}.png")), ), ), ), diff --git a/lib/podcasts/podcastdetail.dart b/lib/podcasts/podcastdetail.dart index c5c06af..1aa39e5 100644 --- a/lib/podcasts/podcastdetail.dart +++ b/lib/podcasts/podcastdetail.dart @@ -19,16 +19,6 @@ class _PodcastDetailState extends State { final GlobalKey _refreshIndicatorKey = GlobalKey(); - @override - void initState() { - super.initState(); - } - - @override - void dispose(){ - super.dispose(); - } - Future _updateRssItem(PodcastLocal podcastLocal) async { var dbHelper = DBHelper(); final response = await Dio().get(podcastLocal.rssUrl); diff --git a/lib/podcasts/podcastlist.dart b/lib/podcasts/podcastlist.dart index 095f051..da75c22 100644 --- a/lib/podcasts/podcastlist.dart +++ b/lib/podcasts/podcastlist.dart @@ -1,20 +1,16 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter_html/flutter_html.dart'; -import 'package:cached_network_image/cached_network_image.dart'; +import 'package:path_provider/path_provider.dart'; import 'package:tsacdop/class/podcastlocal.dart'; import 'package:tsacdop/class/sqflite_localpodcast.dart'; import 'package:tsacdop/podcasts/podcastdetail.dart'; -Future> getPodcastLocal() async { - var dbHelper = DBHelper(); - Future> podcastList = dbHelper.getPodcastLocal(); - return podcastList; -} - class AboutPodcast extends StatefulWidget { final PodcastLocal podcastLocal; AboutPodcast({this.podcastLocal, Key key}) : super(key: key); @@ -90,6 +86,14 @@ class PodcastList extends StatefulWidget { } class _PodcastListState extends State { + var dir; + Future> getPodcastLocal() async { + dir = await getApplicationDocumentsDirectory(); + var dbHelper = DBHelper(); + Future> podcastList = dbHelper.getPodcastLocal(); + return podcastList; + } + @override Widget build(BuildContext context) { return Container( @@ -141,11 +145,8 @@ class _PodcastListState extends State { child: Container( height: 120.0, width: 120.0, - child: CachedNetworkImage( - imageUrl: snapshot.data[index].imageUrl, - placeholder: (context, url) => - CircularProgressIndicator(), - ), + child: Image.file( + File("${dir.path}/${snapshot.data[index].title}.png")), ), ), Container( @@ -186,6 +187,7 @@ class Podcast extends StatelessWidget { appBar: AppBar( backgroundColor: Colors.grey[100], elevation: 0, + centerTitle: true, title: Text('Podcasts'), ), body: Container(child: PodcastList()), diff --git a/lib/util/episodegrid.dart b/lib/util/episodegrid.dart index 6224d62..5bf8f21 100644 --- a/lib/util/episodegrid.dart +++ b/lib/util/episodegrid.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:io'; import 'dart:isolate'; import 'dart:ui'; @@ -6,6 +7,7 @@ import 'package:flutter/material.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter_downloader/flutter_downloader.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:path_provider/path_provider.dart'; import 'package:tsacdop/class/episodebrief.dart'; import 'package:tsacdop/episodes/episodedetail.dart'; import 'package:tsacdop/util/pageroute.dart'; @@ -24,160 +26,181 @@ class EpisodeGrid extends StatelessWidget { this.showNumber, this.heroTag}) : super(key: key); + + Future _getPath() async { + var dir = await getApplicationDocumentsDirectory(); + return dir.path; + } + @override Widget build(BuildContext context) { - return CustomScrollView( - physics: const AlwaysScrollableScrollPhysics(), - primary: false, - slivers: [ - SliverPadding( - padding: const EdgeInsets.all(5.0), - sliver: SliverGrid( - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - childAspectRatio: 1.0, - crossAxisCount: 3, - mainAxisSpacing: 6.0, - crossAxisSpacing: 6.0, - ), - delegate: SliverChildBuilderDelegate( - (BuildContext context, int index) { - Color _c; - var color = json.decode(podcast[index].primaryColor); - (color[0] > 200 && color[1] > 200 && color[2] > 200) - ? _c = Color.fromRGBO( - (255 - color[0]), 255 - color[1], 255 - color[2], 1.0) - : _c = Color.fromRGBO(color[0], color[1], color[2], 1.0); - return InkWell( - onTap: () { - Navigator.push( - context, - ScaleRoute( - page: EpisodeDetail( - episodeItem: podcast[index], - heroTag: heroTag - )), - ); - }, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(5.0)), - color: Theme.of(context).scaffoldBackgroundColor, - border: Border.all( - color: Colors.grey[100], - width: 3.0, - ), - boxShadow: [ - BoxShadow( - color: Colors.grey[100], - blurRadius: 1.0, - spreadRadius: 0.5, - ), - ]), - alignment: Alignment.center, - padding: EdgeInsets.all(8.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( - flex: 2, - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Hero( - tag: podcast[index].enclosureUrl + heroTag, - child: Container( - child: ClipRRect( - borderRadius: - BorderRadius.all(Radius.circular(15.0)), - child: Container( - height: 30.0, - width: 30.0, - child: CachedNetworkImage( - imageUrl: podcast[index].imageUrl, - ), - ), - ), + return FutureBuilder( + future: _getPath(), + builder: (context, snapshot) { + if (snapshot.hasData) { + return CustomScrollView( + physics: const AlwaysScrollableScrollPhysics(), + primary: false, + slivers: [ + SliverPadding( + padding: const EdgeInsets.all(5.0), + sliver: SliverGrid( + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + childAspectRatio: 1.0, + crossAxisCount: 3, + mainAxisSpacing: 6.0, + crossAxisSpacing: 6.0, + ), + delegate: SliverChildBuilderDelegate( + (BuildContext context, int index) { + Color _c; + var color = json.decode(podcast[index].primaryColor); + (color[0] > 200 && color[1] > 200 && color[2] > 200) + ? _c = Color.fromRGBO((255 - color[0]), + 255 - color[1], 255 - color[2], 1.0) + : _c = Color.fromRGBO( + color[0], color[1], color[2], 1.0); + return InkWell( + onTap: () { + Navigator.push( + context, + ScaleRoute( + page: EpisodeDetail( + episodeItem: podcast[index], + heroTag: heroTag)), + ); + }, + child: Container( + decoration: BoxDecoration( + borderRadius: + BorderRadius.all(Radius.circular(5.0)), + color: + Theme.of(context).scaffoldBackgroundColor, + border: Border.all( + color: Colors.grey[100], + width: 3.0, ), - ), - Spacer(), - showNumber - ? Container( - alignment: Alignment.topRight, - child: Text( - (podcast.length - index).toString(), - style: GoogleFonts.teko( - textStyle: TextStyle( - fontSize: 20.0, - color: _c, + boxShadow: [ + BoxShadow( + color: Colors.grey[100], + blurRadius: 1.0, + spreadRadius: 0.5, + ), + ]), + alignment: Alignment.center, + padding: EdgeInsets.all(8.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + flex: 2, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Hero( + tag: podcast[index].enclosureUrl + + heroTag, + child: Container( + child: ClipRRect( + borderRadius: BorderRadius.all( + Radius.circular(15.0)), + child: Container( + height: 30.0, + width: 30.0, + child: Image.file(File( + "${snapshot.data}/${podcast[index].feedTitle}.png")), + ), ), ), ), - ) - : Center(), - ], - ), - ), - Expanded( - flex: 5, - child: Container( - alignment: Alignment.topLeft, - padding: EdgeInsets.only(top: 2.0), - child: Text( - podcast[index].title, - style: TextStyle( - fontSize: 15.0, - ), - maxLines: 4, + Spacer(), + showNumber + ? Container( + alignment: Alignment.topRight, + child: Text( + (podcast.length - index) + .toString(), + style: GoogleFonts.teko( + textStyle: TextStyle( + fontSize: 20.0, + color: _c, + ), + ), + ), + ) + : Center(), + ], + ), + ), + Expanded( + flex: 5, + child: Container( + alignment: Alignment.topLeft, + padding: EdgeInsets.only(top: 2.0), + child: Text( + podcast[index].title, + style: TextStyle( + fontSize: 15.0, + ), + maxLines: 4, + ), + ), + ), + Expanded( + flex: 1, + child: Row( + children: [ + Align( + alignment: Alignment.bottomLeft, + child: Text( + podcast[index] + .pubDate + .substring(4, 16), + style: TextStyle( + color: _c, + fontStyle: FontStyle.italic), + ), + ), + Spacer(), + showDownload + ? DownloadIcon( + episodeBrief: podcast[index]) + : Center(), + Padding( + padding: EdgeInsets.all(1), + ), + showFavorite + ? Container( + alignment: Alignment.bottomRight, + child: (podcast[index].liked == 0) + ? Center() + : IconTheme( + data: IconThemeData( + size: 15), + child: Icon( + Icons.favorite, + color: Colors.red, + ), + ), + ) + : Center(), + ], + ), + ), + ], ), ), - ), - Expanded( - flex: 1, - child: Row( - children: [ - Align( - alignment: Alignment.bottomLeft, - child: Text( - podcast[index].pubDate.substring(4, 16), - style: TextStyle( - color: _c, fontStyle: FontStyle.italic), - ), - ), - Spacer(), - showDownload - ? DownloadIcon(episodeBrief: podcast[index]) - : Center(), - Padding( - padding: EdgeInsets.all(1), - ), - showFavorite - ? Container( - alignment: Alignment.bottomRight, - child: (podcast[index].liked == 0) - ? Center() - : IconTheme( - data: IconThemeData(size: 15), - child: Icon( - Icons.favorite, - color: Colors.red, - ), - ), - ) - : Center(), - ], - ), - ), - ], + ); + }, + childCount: podcast.length, ), ), - ); - }, - childCount: podcast.length, - ), - ), - ), - ], - ); + ), + ], + ); + } + return Center(); + }); } }