Skip to content

Commit

Permalink
working on the ui of chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
SherlockHolmes2045 committed Apr 20, 2020
1 parent 9c256cf commit 6057018
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 59 deletions.
6 changes: 3 additions & 3 deletions lib/Home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class _HomeState extends State<Home>{
color: Colors.white
),
),
leading: Icon(Icons.phone,color: Colors.grey),
leading: Icon(Icons.book,color: Colors.grey),
),
),

Expand All @@ -146,7 +146,7 @@ class _HomeState extends State<Home>{
style: TextStyle(
fontSize: 17.0,
color: Colors.white),),
leading: Icon(Icons.photo,color: Colors.grey,),
leading: Icon(Icons.explore,color: Colors.grey,),
onTap: (){
Navigator.of(context).pop();
Navigator.of(context).push(new MaterialPageRoute(
Expand All @@ -160,7 +160,7 @@ class _HomeState extends State<Home>{
style: TextStyle(
fontSize: 17.0,
color: Colors.white),),
leading: Icon(Icons.more,color: Colors.grey),
leading: Icon(Icons.file_download,color: Colors.grey),
onTap: () {
Navigator.of(context).pop();
Navigator.of(context).push(
Expand Down
210 changes: 157 additions & 53 deletions lib/chapitre.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:manga_reader/read_manga.dart';
import 'package:manga_reader/Chapter.dart';
import 'package:manga_reader/task_info.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:manga_reader/Manga.dart';
import 'package:manga_reader/services.dart';
Expand Down Expand Up @@ -106,7 +105,106 @@ class _ChapitreState extends State<Chapitre> {
builder: (c) => ReadManga(widget.catalog,widget.chapter,widget.manga)
));
},
child: Container(
child: Padding(
padding: EdgeInsets.only(left:MediaQuery.of(context).size.width/51.43,right: MediaQuery.of(context).size.width/51.3),
child:
Card(
elevation: 0.75,
color: Color.fromRGBO(32, 32, 32, 1),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)
),
child: ListTile(
title: Text(
widget.chapter.title,
style: TextStyle(
color: Colors.white,
fontSize: MediaQuery.of(context).size.width/30
),
),
trailing: Row(
children: <Widget>[
InkWell(

onTap: ()async {

PermissionStatus permission = await PermissionHandler().checkPermissionStatus(PermissionGroup.storage);

if (permission != PermissionStatus.granted) {
Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler().requestPermissions([PermissionGroup.storage]);
}

if(permission == PermissionStatus.granted){
final myDir = new Directory(
"/storage/emulated/0"+'/Sunbae/' + widget.catalog +"/" + widget.manga.title + "/" +
widget.chapter.title
);

myDir.exists().then((isThere) {
if (isThere) {
List<TaskInfo> tasks = [];
getPages(widget.catalog, widget.chapter).then((onValue) async {
for (var i = 0; i < onValue.length; i++) {
getImageUrl(
widget.catalog, onValue[i]).then((url) async {
final taskId = await FlutterDownloader.enqueue(
url: url,
savedDir: myDir.path,
showNotification: true,
// show download progress in status bar (for Android)
openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);
tasks.add(new TaskInfo(taskId: taskId));
});
}
Provider.of<Downloads>(context,listen: false).addTask(tasks, widget.manga.title, widget.chapter.title,tasks.length);
print(Provider.of<Downloads>(context,listen: false).getDownloads().toString());
});
} else {
new Directory(
"/storage/emulated/0"+'/Sunbae/' + widget.catalog +"/" + widget.manga.title + "/" +
widget.chapter.title).create(recursive: true).then((Directory directory) {
getPages(widget.catalog, widget.chapter).then((onValue) async {

Dio dio = new Dio();
List<TaskInfo> tasks = [];
for (var i = 0; i < onValue.length; i++) {
getImageUrl(
widget.catalog, onValue[i]).then((url) async {
/*tasks.add(
dio.download(url,directory.path+"/"+(i+1).toString()+".png",onReceiveProgress: (int sent, int total) {
if(sent==total){
setState(() {
percentage += ((sent/total)*100)/onValue.length;
print(percentage);
});
}
},)
);*/
final taskId = await FlutterDownloader.enqueue(
url: url,
savedDir: directory.path,
showNotification: true,
// show download progress in status bar (for Android)
openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);
tasks.add(new TaskInfo(taskId: taskId));
});
}
Provider.of<Downloads>(context,listen: false).addTask(tasks, widget.manga.title, widget.chapter.title,tasks.length);
print(Provider.of<Downloads>(context,listen: false).getDownloads().toString());
});
});
}
});
}

},
child: !isDownloading ? Icon(Icons.get_app,color: Colors.grey) : Icon(Icons.pause, color: Colors.grey)
),
],
),
)Container(
height: 50.0,
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.only(left: 17.0,right: 8.0),
Expand All @@ -128,74 +226,80 @@ class _ChapitreState extends State<Chapitre> {
),
),
InkWell(

onTap: ()async {

Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler().requestPermissions([PermissionGroup.storage]);

Directory tempDir = await getExternalStorageDirectory();

final myDir = new Directory(
"/storage/emulated/0"+'/Sunbae/' + widget.catalog +"/" + widget.manga.title + "/" +
widget.chapter.title
);

myDir.exists().then((isThere) {
if (isThere) {
List<TaskInfo> tasks = [];
getPages(widget.catalog, widget.chapter).then((onValue) async {
for (var i = 0; i < onValue.length; i++) {
getImageUrl(
widget.catalog, onValue[i]).then((url) async {
final taskId = await FlutterDownloader.enqueue(
url: url,
savedDir: myDir.path,
showNotification: true,
// show download progress in status bar (for Android)
openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);
tasks.add(new TaskInfo(taskId: taskId));
});
}
Provider.of<Downloads>(context,listen: false).addTask(tasks, widget.manga.title, widget.chapter.title);
print(Provider.of<Downloads>(context,listen: false).getDownloads().toString());
});
} else {
new Directory(
"/storage/emulated/0"+'/Sunbae/' + widget.catalog +"/" + widget.manga.title + "/" +
widget.chapter.title).create(recursive: true).then((Directory directory) {
getPages(widget.catalog, widget.chapter).then((onValue) async {
PermissionStatus permission = await PermissionHandler().checkPermissionStatus(PermissionGroup.storage);

Dio dio = new Dio();
List<TaskInfo> tasks = [];
if (permission != PermissionStatus.granted) {
Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler().requestPermissions([PermissionGroup.storage]);
}

if(permission == PermissionStatus.granted){
final myDir = new Directory(
"/storage/emulated/0"+'/Sunbae/' + widget.catalog +"/" + widget.manga.title + "/" +
widget.chapter.title
);

myDir.exists().then((isThere) {
if (isThere) {
List<TaskInfo> tasks = [];
getPages(widget.catalog, widget.chapter).then((onValue) async {
for (var i = 0; i < onValue.length; i++) {
getImageUrl(
widget.catalog, onValue[i]).then((url) async {
/*tasks.add(
dio.download(url,directory.path+"/"+(i+1).toString()+".png",onReceiveProgress: (int sent, int total) {
if(sent==total){
setState(() {
percentage += ((sent/total)*100)/onValue.length;
print(percentage);
});
}
},)
);*/
final taskId = await FlutterDownloader.enqueue(
url: url,
savedDir: directory.path,
savedDir: myDir.path,
showNotification: true,
// show download progress in status bar (for Android)
openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);
tasks.add(new TaskInfo(taskId: taskId));
});
}
Provider.of<Downloads>(context,listen: false).addTask(tasks, widget.manga.title, widget.chapter.title);
Provider.of<Downloads>(context,listen: false).addTask(tasks, widget.manga.title, widget.chapter.title,tasks.length);
print(Provider.of<Downloads>(context,listen: false).getDownloads().toString());
});
});
}
});
} else {
new Directory(
"/storage/emulated/0"+'/Sunbae/' + widget.catalog +"/" + widget.manga.title + "/" +
widget.chapter.title).create(recursive: true).then((Directory directory) {
getPages(widget.catalog, widget.chapter).then((onValue) async {

Dio dio = new Dio();
List<TaskInfo> tasks = [];
for (var i = 0; i < onValue.length; i++) {
getImageUrl(
widget.catalog, onValue[i]).then((url) async {
/*tasks.add(
dio.download(url,directory.path+"/"+(i+1).toString()+".png",onReceiveProgress: (int sent, int total) {
if(sent==total){
setState(() {
percentage += ((sent/total)*100)/onValue.length;
print(percentage);
});
}
},)
);*/
final taskId = await FlutterDownloader.enqueue(
url: url,
savedDir: directory.path,
showNotification: true,
// show download progress in status bar (for Android)
openFileFromNotification: true, // click on notification to open downloaded file (for Android)
);
tasks.add(new TaskInfo(taskId: taskId));
});
}
Provider.of<Downloads>(context,listen: false).addTask(tasks, widget.manga.title, widget.chapter.title,tasks.length);
print(Provider.of<Downloads>(context,listen: false).getDownloads().toString());
});
});
}
});
}

},
child: !isDownloading ? Icon(Icons.get_app,color: Colors.grey) : Icon(Icons.pause, color: Colors.grey)
),
Expand Down
6 changes: 4 additions & 2 deletions lib/downloads.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import 'package:manga_reader/task_info.dart';
class Downloads extends ChangeNotifier{
var downloads = [];

void addTask(List<TaskInfo> tasks,String manga,String chapter){
double count = tasks.length/100;
void addTask(List<TaskInfo> tasks,String manga,String chapter,int items){
print(tasks);
double count = items.toDouble()/100.0;
print(count);
downloads.add({
'manga': manga,
'chapitre':chapter,
Expand Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void main() async {

WidgetsFlutterBinding.ensureInitialized();
await FlutterDownloader.initialize();

createDb();

runApp(
Expand Down
5 changes: 4 additions & 1 deletion lib/read_manga.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class _ReadMangaState extends State<ReadManga> {
paths.add(int.parse(temp2[0]));
});
paths.sort();
downloaded = true;
setState(() {
downloaded = true;
});

print(paths.toString());
}
});
Expand Down

0 comments on commit 6057018

Please sign in to comment.