2020-02-09 13:29:09 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2020-05-06 18:50:32 +02:00
|
|
|
import '../state/podcast_group.dart';
|
|
|
|
import '../state/subscribe_podcast.dart';
|
|
|
|
import '../state/refresh_podcast.dart';
|
|
|
|
import '../util/context_extension.dart';
|
2020-02-09 13:29:09 +01:00
|
|
|
|
|
|
|
class Import extends StatelessWidget {
|
2020-04-18 06:48:02 +02:00
|
|
|
Widget importColumn(String text, BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
color: context.primaryColorDark,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
SizedBox(height: 2.0, child: LinearProgressIndicator()),
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 20.0),
|
|
|
|
height: 20.0,
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: Text(text),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-09 13:29:09 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-04-18 06:48:02 +02:00
|
|
|
GroupList groupList = Provider.of<GroupList>(context, listen: false);
|
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Consumer<SubscribeWorker>(
|
|
|
|
builder: (_, subscribeWorker, __) {
|
|
|
|
SubscribeItem item = subscribeWorker.currentSubscribeItem;
|
|
|
|
switch (item.subscribeState) {
|
|
|
|
case SubscribeState.start:
|
2020-04-23 19:46:36 +02:00
|
|
|
return importColumn("Subscribe ${item.title}", context);
|
2020-04-18 06:48:02 +02:00
|
|
|
case SubscribeState.subscribe:
|
|
|
|
groupList.subscribeNewPodcast(item.id);
|
|
|
|
return importColumn("Fetch data ${item.title}", context);
|
|
|
|
case SubscribeState.fetch:
|
2020-06-02 16:05:49 +02:00
|
|
|
// groupList.updatePodcast(item.id);
|
2020-04-18 06:48:02 +02:00
|
|
|
return importColumn("Subscribe success ${item.title}", context);
|
|
|
|
case SubscribeState.exist:
|
|
|
|
return importColumn(
|
|
|
|
"Subscribe failed, podcast existed ${item.title}", context);
|
|
|
|
case SubscribeState.error:
|
|
|
|
return importColumn(
|
|
|
|
"Subscribe failed, network error ${item.title}", context);
|
|
|
|
default:
|
|
|
|
return Center();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Consumer<RefreshWorker>(
|
|
|
|
builder: (context, refreshWorker, child) {
|
|
|
|
RefreshItem item = refreshWorker.currentRefreshItem;
|
2020-04-22 20:10:57 +02:00
|
|
|
if (refreshWorker.complete) {
|
|
|
|
groupList.updateGroups();
|
|
|
|
// audio.addNewEpisode('all');
|
|
|
|
}
|
2020-04-18 06:48:02 +02:00
|
|
|
switch (item.refreshState) {
|
|
|
|
case RefreshState.fetch:
|
2020-04-22 20:10:57 +02:00
|
|
|
return importColumn("Update ${item.title}", context);
|
2020-04-18 06:48:02 +02:00
|
|
|
case RefreshState.error:
|
|
|
|
return importColumn("Update error ${item.title}", context);
|
|
|
|
default:
|
|
|
|
return Center();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
2020-02-11 14:01:57 +01:00
|
|
|
);
|
2020-02-09 13:29:09 +01:00
|
|
|
}
|
|
|
|
}
|