Skip to content

Commit

Permalink
Remove self explanatory comments
Browse files Browse the repository at this point in the history
- also make sure that it doesn't clear db on start (used for debugging)
  • Loading branch information
Kara-Zor-El committed Nov 12, 2022
1 parent a324d18 commit e482e1e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 39 deletions.
16 changes: 8 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Future<void> main() async {
await Hive.openBox<Entry>('bookShelf');

// if running in debug mode then clear the hive box
if (kDebugMode) {
try {
await Hive.box<Entry>('bookShelf').clear();
} catch (e) {
debugPrint(e.toString());
}
debugPrint("cleared hive box");
}
// if (kDebugMode) {
// try {
// await Hive.box<Entry>('bookShelf').clear();
// } catch (e) {
// debugPrint(e.toString());
// }
// debugPrint("cleared hive box");
// }

runApp(MyApp());
}
Expand Down
6 changes: 0 additions & 6 deletions lib/screens/databaseViewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ class DatabaseViewer extends StatelessWidget {
return Scaffold(
appBar: AppBar(
title: Text('Database Viewer'),
// button to delete all entries
actions: [
IconButton(
icon: Icon(Icons.delete),
onPressed: () {
// confirm deletion
showDialog(
context: context,
builder: (BuildContext context) {
Expand Down Expand Up @@ -53,8 +51,6 @@ class DatabaseViewer extends StatelessWidget {
child: Text('No entries'),
);
} else {
// return a scrollable list of the entries where each entry is a row can be tapped to view the entry
// make scrollable
return Scrollbar(
child: ListView.builder(
itemCount: box.values.length,
Expand Down Expand Up @@ -170,8 +166,6 @@ class EntryViewer extends StatelessWidget {
}

Future<void> deleteAllEntries(BuildContext context) async {
// delete all entries
final box = Hive.box<Entry>('bookShelf');
await box.clear();
// refresh the database viewer
}
24 changes: 0 additions & 24 deletions lib/screens/downloaderScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class _DownloadScreenState extends State<DownloadScreen> {
}

Future<void> downloadFile(bool forceDown) async {
// open the database
var box = Hive.box<Entry>('bookShelf');

// get the entry that matches the comicId
Expand All @@ -79,7 +78,6 @@ class _DownloadScreenState extends State<DownloadScreen> {
if (entry.folderPath != '' && forceDown == false) {
return;
}
// get the data from the database

url = entry.url;
imageUrl = entry.imagePath;
Expand Down Expand Up @@ -141,13 +139,9 @@ class _DownloadScreenState extends State<DownloadScreen> {
debugPrint('Comic folder created');
debugPrint(dirLocation + '/' + fileName2);

// make directory to extract to
FileUtils.mkdir([dirLocation + '/' + fileName2]);
comicFolder = dirLocation + '/' + fileName2;
// check if the file is a zip or rar
// final fileType = lookupMimeType(dirLocation + '/' + fileName2 + '.zip');
if (dir.contains('.zip')) {
// if (filePath.contains('.zip')) {
var bytes =
File(dirLocation + '/' + fileName2 + '.zip').readAsBytesSync();

Expand All @@ -167,10 +161,8 @@ class _DownloadScreenState extends State<DownloadScreen> {
debugPrint('Unzipped');
File(dirLocation + '/' + fileName + '.zip').deleteSync();

// change entry to downloaded
entry.downloaded = true;

// save the location of the comic
entry.folderPath = dirLocation + '/' + fileName2;

debugPrint('Zip file extracted');
Expand All @@ -181,36 +173,24 @@ class _DownloadScreenState extends State<DownloadScreen> {
debugPrint('Rar file extracted');
debugPrint('Unzipped');
File(dirLocation + '/' + fileName + '.rar').deleteSync();
// change entry to downloaded
entry.downloaded = true;
} catch (e) {
debugPrint("Extraction failed " + e.toString());
}
} else if (entry.path.contains('.pdf')) {
debugPrint('PDF file');
// change entry to downloaded

try {
var file = File(dirLocation + '/' + fileName + '.pdf');
// make folder
FileUtils.mkdir([dirLocation + '/' + fileName2]);
// move the file to the folder
file.renameSync(
dirLocation + '/' + fileName2 + '/' + fileName + '.pdf');
// get the index of the entry
// save the location of the comic
entry.folderPath = dirLocation + '/' + fileName2;
entry.filePath =
dirLocation + '/' + fileName2 + '/' + fileName + '.pdf';
debugPrint('PDF file moved');
entry.downloaded = true;
// int index = box.values.toList().indexOf(entry);
// update the entry
// box.putAt(index, entry);

// save the location of the comic
entry.folderPath = dirLocation + '/' + fileName2;
// entry.downloaded = true;
} catch (e) {
debugPrint(e.toString());
}
Expand All @@ -228,9 +208,7 @@ class _DownloadScreenState extends State<DownloadScreen> {
Navigator.pop(context);
});
}
// var prefs = await SharedPreferences.getInstance();
debugPrint("title: " + entry.title);
// debugPrint("path: " + filePath);
debugPrint("comicFolder: " + comicFolder);
// prefs.setString(title, comicFolder);
}
Expand All @@ -250,10 +228,8 @@ class _DownloadScreenState extends State<DownloadScreen> {
actions: [
if (!downloading)
IconButton(
// redownload the file
icon: Icon(Icons.download),
onPressed: () {
// ask user to confirm
showDialog(
context: context,
builder: (context) => AlertDialog(
Expand Down
1 change: 0 additions & 1 deletion lib/screens/homeScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class _HomeScreenState extends State<HomeScreen> {
title: Text('Home'),
actions: [
IconButton(
// debug button
icon: Icon(Icons.bug_report),
onPressed: () {
Navigator.push(
Expand Down

0 comments on commit e482e1e

Please sign in to comment.