Skip to content

Commit

Permalink
Start using some code metrics on my project
Browse files Browse the repository at this point in the history
  • Loading branch information
Kara-Zor-El committed Nov 6, 2023
1 parent 5ce453d commit cc49825
Show file tree
Hide file tree
Showing 25 changed files with 132 additions and 293 deletions.
29 changes: 29 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,32 @@ linter:

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options

analyzer:
plugins:
- dart_code_linter

dart_code_linter:
metrics:
cyclomatic-complexity: 20
number-of-parameters: 4
maximum-nesting-level: 5
metrics-exclude:
- test/**
rules:
- avoid-dynamic
- avoid-passing-async-when-sync-expected
- avoid-redundant-async
- avoid-unnecessary-type-assertions
- avoid-unnecessary-type-casts
- avoid-unrelated-type-assertions
- avoid-unused-parameters
- avoid-nested-conditional-expressions
- newline-before-return
- no-boolean-literal-compare
- no-empty-block
- prefer-trailing-comma
- prefer-conditional-expressions
- no-equal-then-else
- prefer-moving-to-variable
- prefer-match-file-name
21 changes: 9 additions & 12 deletions lib/providers/ComicInfoXML.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import 'dart:io';
import 'package:xml/xml.dart' as xml;
import 'dart:convert';
import 'package:archive/archive.dart';
import 'package:jellybook/variables.dart';
import 'package:isar/isar.dart';
import 'package:isar_flutter_libs/isar_flutter_libs.dart';
import 'package:jellybook/models/entry.dart';

Future<void> parseXML(Entry entry) async {
Expand Down Expand Up @@ -34,55 +31,55 @@ Future<void> parseXML(Entry entry) async {
if (xmlFileContent.findAllElements('Writer').isNotEmpty) {
final author = xmlFileContent.findAllElements('Writer');
// add the author
entry.writer = author.first.text;
entry.writer = author.first.innerText;
logger.d('writer: ${entry.writer}');
}
if (xmlFileContent.findAllElements('Penciller').isNotEmpty) {
final author = xmlFileContent.findAllElements('Penciller');
// add the author
entry.penciller = author.first.text;
entry.penciller = author.first.innerText;
logger.d('penciller: ${entry.penciller}');
}
if (xmlFileContent.findAllElements('Inker').isNotEmpty) {
final author = xmlFileContent.findAllElements('Inker');
// add the author
entry.inker = author.first.text;
entry.inker = author.first.innerText;
logger.d('inker: ${entry.inker}');
}
if (xmlFileContent.findAllElements('Colorist').isNotEmpty) {
final author = xmlFileContent.findAllElements('Colorist');
// add the author
entry.colorist = author.first.text;
entry.colorist = author.first.innerText;
logger.d('colorist: ${entry.colorist}');
}
if (xmlFileContent.findAllElements('Letterer').isNotEmpty) {
final author = xmlFileContent.findAllElements('Letterer');
// add the author
entry.letterer = author.first.text;
entry.letterer = author.first.innerText;
logger.d('letterer: ${entry.letterer}');
}
if (xmlFileContent.findAllElements('CoverArtist').isNotEmpty) {
final author = xmlFileContent.findAllElements('CoverArtist');
// add the author
entry.coverArtist = author.first.text;
entry.coverArtist = author.first.innerText;
logger.d('coverArtist: ${entry.coverArtist}');
}
if (xmlFileContent.findAllElements('Editor').isNotEmpty) {
final author = xmlFileContent.findAllElements('Editor');
// add the author
entry.editor = author.first.text;
entry.editor = author.first.innerText;
logger.d('editor: ${entry.editor}');
}
if (xmlFileContent.findAllElements('Publisher').isNotEmpty) {
final author = xmlFileContent.findAllElements('Publisher');
// add the author
entry.publisher = author.first.text;
entry.publisher = author.first.innerText;
logger.d('publisher: ${entry.publisher}');
}
if (xmlFileContent.findAllElements('Imprint').isNotEmpty) {
final author = xmlFileContent.findAllElements('Imprint');
// add the author
entry.imprint = author.first.text;
entry.imprint = author.first.innerText;
logger.d('imprint: ${entry.imprint}');
}

Expand Down
18 changes: 9 additions & 9 deletions lib/providers/deleteComic.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
// The purpose of this file is to delete a comic from the client
import 'package:flutter/material.dart';
import 'package:isar/isar.dart';
import 'package:isar_flutter_libs/isar_flutter_libs.dart';
import 'package:jellybook/models/entry.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'dart:io';
import 'package:jellybook/variables.dart';

Future<void> deleteComic(String id, context) async {
bool delete = false;
await showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Delete Comic"),
content: Text("Are you sure you want to delete this comic?"),
title: Text(AppLocalizations.of(context)?.delete ?? "Delete Comic"),
content: Text(AppLocalizations.of(context)?.deleteConfirm ??
"Are you sure you want to delete this comic?"),
actions: [
TextButton(
child: Text("Cancel"),
child: Text(AppLocalizations.of(context)?.cancel ?? "Cancel"),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text("Delete"),
child: Text(AppLocalizations.of(context)?.delete ?? "Delete"),
onPressed: () {
confirmedDelete(id, context);
Navigator.of(context).pop();
Expand Down Expand Up @@ -64,12 +64,12 @@ Future<void> confirmedDelete(String id, context) async {
await isar.writeTxn(() async {
await isar.entrys.put(entry);
});

} else {
logger.d("Comic not downloaded");
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Comic not downloaded"),
SnackBar(
content: Text(
AppLocalizations.of(context)?.noContent ?? "Comic not downloaded"),
),
);
}
Expand Down
26 changes: 0 additions & 26 deletions lib/providers/downloader.dart

This file was deleted.

13 changes: 0 additions & 13 deletions lib/providers/fetchBooks.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
// the purpose of this file is to fetch books from the database to be displayed in the app

import 'package:shared_preferences/shared_preferences.dart';
import 'package:logger/logger.dart';
import 'package:openapi/openapi.dart';
import 'dart:convert';
import 'package:built_collection/built_collection.dart';

// database imports
import 'package:jellybook/models/entry.dart';
import 'package:jellybook/models/folder.dart';
import 'package:isar/isar.dart';

import 'package:isar_flutter_libs/isar_flutter_libs.dart';
import 'package:jellybook/variables.dart';

// get comics
Expand Down Expand Up @@ -70,7 +66,6 @@ Future<List<Entry>> getComics(String comicsId, String etag) async {
logger.d("Now saving comics to database");

final isar = Isar.getInstance();
Entry entry;
// get entries from the database
try {
final entries = await isar!.entrys.where().idEqualTo(comicsId).findAll();
Expand All @@ -85,7 +80,6 @@ Future<List<Entry>> getComics(String comicsId, String etag) async {
logger.d("got entries");

// List<Map<String, dynamic>> comics = [];
List<Entry> comics = [];
responseData.forEach((element) {
Entry entry = Entry(
id: element.id ?? '',
Expand Down Expand Up @@ -205,13 +199,6 @@ Future<void> updateFolders() async {

Map<String, String> getHeaders(String url, String client, String device,
String deviceId, String version, String token) {
logger.d("getting headers");
logger.d(url);
logger.d(client);
logger.d(device);
logger.d(deviceId);
logger.d(version);
logger.d(token);
var uri = Uri.parse(url);
var headers = {
'Accept': 'application/json',
Expand Down
85 changes: 3 additions & 82 deletions lib/providers/fetchCategories.dart
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
// The purpose of this file is to fetch the categories from the database

import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:openapi/openapi.dart';
import 'dart:convert';
import 'package:jellybook/providers/fetchBooks.dart';
import 'package:flutter/material.dart';
import 'package:jellybook/providers/folderProvider.dart';
import 'package:jellybook/models/entry.dart';
import 'package:jellybook/models/folder.dart';
import 'package:isar/isar.dart';
import 'package:isar_flutter_libs/isar_flutter_libs.dart';
import 'package:package_info_plus/package_info_plus.dart' as p_info;
import 'package:jellybook/providers/pair.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:jellybook/variables.dart';

// have optional perameter to have the function return the list of folders
Expand Down Expand Up @@ -222,82 +214,14 @@ Future<void> removeEntriesFromDatabase(
});
}

Future<List<String>> chooseCategories(List<String> categories, context) async {
List<String> selected = [];
List<String> wantedCategories = [];

// pop up a dialog to choose categories
// use stateful builder to rebuild the dialog when the list changes

showDialog(
context: context,
builder: (BuildContext context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return AlertDialog(
title: Text("Choose Categories"),
content: Container(
width: MediaQuery.of(context).size.width * 0.8,
height: MediaQuery.of(context).size.height * 0.8,
child: ListView.builder(
itemCount: categories.length,
itemBuilder: (BuildContext context, int index) {
return CheckboxListTile(
title: Text(categories[index]),
value: selected.contains(categories[index]),
onChanged: (bool? value) {
if (value == true) {
wantedCategories.add(categories[index]);
} else {
wantedCategories.remove(categories[index]);
}
setState(() {});
},
);
},
),
),
actions: [
TextButton(
child: Text("Cancel"),
onPressed: () {
Navigator.of(context).pop();
},
),
TextButton(
child: Text("Ok"),
onPressed: () {
Navigator.of(context).pop(wantedCategories);
},
),
],
);
},
);
},
);
return wantedCategories;
}

Future<(List<Entry>, List<Folder>)> getServerCategoriesOffline(context) async {
logger.d("getting server categories");
// final p_info.PackageInfo packageInfo =
// await p_info.PackageInfo.fromPlatform();
// final prefs = await SharedPreferences.getInstance();
// final token = prefs.getString('accessToken') ?? "";
// final url = prefs.getString('server') ?? "";
// final userId = prefs.getString('UserId') ?? "";
// final client = prefs.getString('client') ?? "JellyBook";
// final device = prefs.getString('device') ?? "";
// final deviceId = prefs.getString('deviceId') ?? "";
// final version = prefs.getString('version') ?? packageInfo.version;
logger.d("got prefs");

bool hasComics = true;
if (hasComics) {
// get the comics and folders from the database
final isar = Isar.getInstance();
List<Entry> unlikedEntries = await isar!.entrys
List<Entry> entries = await isar!.entrys
.where()
.filter()
.group((q) {
Expand All @@ -314,8 +238,7 @@ Future<(List<Entry>, List<Folder>)> getServerCategoriesOffline(context) async {
.isFavoritedEqualTo(false)
.sortByTitle()
.findAll();

List<Entry> likedEntries = await isar.entrys
entries.addAll(await isar.entrys
.where()
.filter()
.group((q) {
Expand All @@ -331,9 +254,7 @@ Future<(List<Entry>, List<Folder>)> getServerCategoriesOffline(context) async {
.and()
.isFavoritedEqualTo(true)
.sortByTitle()
.findAll();

List<Entry> entries = likedEntries + unlikedEntries;
.findAll());

List<Folder> folders = await isar.folders.where().findAll();
logger.d("got entries and folders");
Expand Down
2 changes: 0 additions & 2 deletions lib/providers/folderProvider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import 'package:shared_preferences/shared_preferences.dart';

import 'package:isar/isar.dart';
import 'package:isar_flutter_libs/isar_flutter_libs.dart';
import 'package:jellybook/models/folder.dart';
import 'package:jellybook/models/entry.dart';
import 'package:jellybook/variables.dart';

// This function takes the list of entries and creates folders if their parentId is not one of the categories
// It adds the folder to the list of folders in a isar box
Expand Down
2 changes: 0 additions & 2 deletions lib/providers/languageProvider.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// the purpose of this file is to write a extension to the Localizations class to set a new locale

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:shared_preferences/shared_preferences.dart';

class LocaleChangeNotifier extends ChangeNotifier {
Expand Down
Loading

0 comments on commit cc49825

Please sign in to comment.