Skip to content

Commit

Permalink
Merge pull request #8 from Kara-Zor-El/addReadingAndOtherScreens
Browse files Browse the repository at this point in the history
Add screens and menu bar
  • Loading branch information
Kara-Zor-El authored Dec 13, 2022
2 parents 5bb46f2 + 417e485 commit e757159
Show file tree
Hide file tree
Showing 13 changed files with 1,306 additions and 482 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release
libisar.so
Binary file added assets/images/NoCoverArt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions lib/providers/fetchBooks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Future<List<Map<String, dynamic>>> getComics(
'imagePath':
"$url/Items/${responseData['Items'][i]['Id']}/Images/Primary?&quality=90&Tag=${responseData['Items'][i]['ImageTags']['Primary']}",
if (responseData['Items'][i]['ImageTags']['Primary'] == null)
'imagePath': "https://via.placeholder.com/200x316?text=No+Cover+Art",
'imagePath': 'Asset',
'releaseDate': responseData['Items'][i]['ProductionYear'].toString(),
'path': responseData['Items'][i]['Path'] ?? '',
'description': responseData['Items'][i]['Overview'] ?? '',
Expand Down Expand Up @@ -99,7 +99,7 @@ Future<List<Map<String, dynamic>>> getComics(
String imagePath =
"$url/Items/${responseData['Items'][i]['Id']}/Images/Primary?&quality=90&Tag=${responseData['Items'][i]['ImageTags']['Primary']}";
if (responseData['Items'][i]['ImageTags']['Primary'] == null) {
imagePath = "https://via.placeholder.com/200x316?text=No+Cover+Art";
imagePath = 'Asset';
}
String releaseDate =
responseData['Items'][i]['ProductionYear'].toString();
Expand Down Expand Up @@ -161,6 +161,7 @@ Future<List<Map<String, dynamic>>> getComics(
entry.folderPath = entryExists.folderPath;
entry.filePath = entryExists.filePath;
entry.epubCfi = entryExists.epubCfi;
entry.pageNum = entryExists.pageNum;
}

await isar.writeTxn(() async {
Expand Down
41 changes: 22 additions & 19 deletions lib/providers/fetchCategories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ Future<void> removeEntriesFromDatabase(
// now see if the database has any entries that are not in the server
// if it does, remove those from the database

// get all the entries from the database

final isar = Isar.getInstance();
final entries = await isar!.entrys.where().findAll();
final folders = await isar.folders.where().findAll();
Expand All @@ -156,38 +158,39 @@ Future<void> removeEntriesFromDatabase(
List<int> entriesToRemove = [];
List<int> foldersToRemove = [];

for (var i = 0; i < entries.length; i++) {
entryIds.add(entries[i].id);
// get all the ids from the server
for (int i = 0; i < comicsArray.length; i++) {
List<Map<String, dynamic>> comics = await comicsArray[i];
for (int j = 0; j < comics.length; j++) {
serverIds.add(comics[j]['id']);
}
}

for (var i = 0; i < folders.length; i++) {
folderIds.add(folders[i].id);
// get all the ids from the database
for (int i = 0; i < entries.length; i++) {
entryIds.add(entries[i].id);
}

for (var i = 0; i < comicsArray.length; i++) {
List<Map<String, dynamic>> comics = await comicsArray[i];
for (var j = 0; j < comics.length; j++) {
serverIds.add(comics[j]['id']);
}
// get all the ids from the database
for (int i = 0; i < folders.length; i++) {
folderIds.add(folders[i].id);
}

for (var i = 0; i < entryIds.length; i++) {
// find the ids that are in the database but not in the server
for (int i = 0; i < entryIds.length; i++) {
if (!serverIds.contains(entryIds[i])) {
int isarId = await isar.entrys.where().idEqualTo(entryIds[i]).findAll().then((value) => value[0].isarId);
entriesToRemove.add(isarId);
entriesToRemove.add(i);
}
}

for (var i = 0; i < folderIds.length; i++) {
// find the ids that are in the database but not in the server
for (int i = 0; i < folderIds.length; i++) {
if (!serverIds.contains(folderIds[i])) {
int isarId = await isar.folders.where().findAll().then((value) => value[i].isarId);
foldersToRemove.add(isarId);
foldersToRemove.add(i);
}
}

debugPrint("entriesToRemove: $entriesToRemove");
debugPrint("foldersToRemove: $foldersToRemove");

// remove the entries from the database
await isar.writeTxn(() async {
await isar.entrys.deleteAll(entriesToRemove);
await isar.folders.deleteAll(foldersToRemove);
Expand Down Expand Up @@ -237,7 +240,7 @@ Future<List<String>> chooseCategories(List<String> categories, context) async {
TextButton(
child: const Text('Done'),
onPressed: () {
if (selected != null && selected.isNotEmpty) {
if (selected.isNotEmpty) {
Navigator.of(context).pop();
} else {
debugPrint("No categories selected");
Expand Down
259 changes: 259 additions & 0 deletions lib/screens/MainScreens/continueReadingScreen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
// the purpose of this file is to show a list of books that the user has started reading and has not finished yet

import 'package:flutter/material.dart';
import 'package:jellybook/screens/collectionScreen.dart';
import 'package:jellybook/screens/infoScreen.dart';
import 'package:isar/isar.dart';
import 'package:jellybook/models/entry.dart';
import 'package:auto_size_text/auto_size_text.dart';
import 'package:jellybook/providers/fixRichText.dart';
import 'package:flutter_star/flutter_star.dart';

class ContinueReadingScreen extends StatefulWidget {
@override
_ContinueReadingScreenState createState() => _ContinueReadingScreenState();
}

class _ContinueReadingScreenState extends State<ContinueReadingScreen> {
var isar = Isar.getInstance();

// get all the entries that have been started but not finished
Future<List<Entry>> getEntries() async {
var entries = await isar!.entrys
.where()
.filter()
.downloadedEqualTo(true)
.and()
.pageNumGreaterThan(0)
.findAll();
// convert the entries to a list
List<Entry> entriesList = [];
for (int i = 0; i < entries.length; i++) {
entriesList.add(entries[i]);
}
return entriesList;
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Continue Reading"),
),
body: FutureBuilder(
future: getEntries(),
builder: (context, snapshot) {
if (snapshot.hasData &&
snapshot.data != null &&
snapshot.data!.length > 0) {
debugPrint(snapshot.data.toString());
return ListView.builder(
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => InfoScreen(
year: snapshot.data![index].releaseDate,
title: snapshot.data![index].title,
path: snapshot.data![index].filePath,
stars: snapshot.data![index].rating,
comicId: snapshot.data![index].id,
url: snapshot.data![index].url,
tags: snapshot.data![index].tags,
description: snapshot.data![index].description,
imageUrl: snapshot.data![index].imagePath,
),
),
);
},
title: AutoSizeText(
snapshot.data![index].title,
maxLines: 1,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
leading: Stack(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.5),
spreadRadius: 1,
blurRadius: 3,
offset: const Offset(2, 3),
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(5),
child: snapshot.data![index].imagePath != "Asset"
? Image.network(
snapshot.data![index].imagePath,
width:
MediaQuery.of(context).size.width * 0.1,
fit: BoxFit.fitWidth,
)
: Image.asset(
'assets/images/NoCoverArt.png',
width:
MediaQuery.of(context).size.width * 0.1,
fit: BoxFit.fitWidth,
),
),
),
snapshot.data![index].progress != null &&
snapshot.data![index].progress != 0
? Positioned(
top: 0,
left: 0,
child: Container(
width:
MediaQuery.of(context).size.width * 0.1,
height:
MediaQuery.of(context).size.height * 0.14,
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(5),
),
),
child: Center(
child: Text(
snapshot.data![index].progress
.toString() +
"%",
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
),
),
)
: Positioned(
top: 0,
left: 0,
child: Container(
width:
MediaQuery.of(context).size.width * 0.1,
height:
MediaQuery.of(context).size.width * 0.14,
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(5),
),
),
child: Center(
child: Text(
snapshot.data![index].pageNum.toString(),
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
),
),
),
],
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (snapshot.data![index].description.isNotEmpty)
AutoSizeText(
snapshot.data![index].description,
maxLines: 2,
style: TextStyle(
fontSize: 15,
),
overflow: TextOverflow.ellipsis,
),
if (snapshot.data![index].rating > 0)
Row(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
child: CustomRating(
max: 5,
score: snapshot.data![index].rating / 2,
star: Star(
fillColor: Color.lerp(
Colors.red,
Colors.yellow,
snapshot.data![index].rating / 10)!,
emptyColor: Colors.grey.withOpacity(0.5),
),
onRating: (double score) {},
),
),
Text(
" " + snapshot.data![index].rating.toString(),
style: TextStyle(
fontSize: 15,
),
),
],
),
],
),
),
);
},
);
} else if (snapshot.hasError) {
// return the error in the center of the screen
return Center(
child: Text(
snapshot.error.toString(),
style: TextStyle(
fontSize: 20,
),
),
);
} else if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
// if its empty, tell the user that there are no entries
} else if (snapshot.data!.length == 0) {
return Center(
// add text saying that there are no books/comics that have been started and have a frown under it
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"No books/comics have been started",
style: TextStyle(
fontSize: 25,
),
textAlign: TextAlign.center,
),
SizedBox(
height: 10,
),
Icon(
Icons.sentiment_dissatisfied,
size: 100,
),
],
),
);
} else {
return Center(
child: CircularProgressIndicator(),
);
}
},
),
);
}
}
Loading

0 comments on commit e757159

Please sign in to comment.