Skip to content

Commit

Permalink
Finished inbox, fixed reverse sort order, bloc refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
astubenbord committed Nov 30, 2022
1 parent 50190f0 commit b1db2a1
Show file tree
Hide file tree
Showing 27 changed files with 1,118 additions and 606 deletions.
1 change: 0 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ linter:
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
11 changes: 11 additions & 0 deletions lib/core/bloc/bloc_changes_observer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'dart:developer';

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:paperless_mobile/features/inbox/bloc/inbox_cubit.dart';

class BlocChangesObserver extends BlocObserver {
@override
void onChange(BlocBase bloc, Change change) {
super.onChange(bloc, change);
}
}
1 change: 0 additions & 1 deletion lib/core/logic/timeout_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class TimeoutClient implements BaseClient {
// try to parse contained error message, otherwise return response
final JSON json = jsonDecode(utf8.decode(response.bodyBytes));
final PaperlessValidationErrors errorMessages = {};
//TODO: This could be simplified, look at error message format of paperless-ngx
for (final entry in json.entries) {
if (entry.value is List) {
errorMessages.putIfAbsent(
Expand Down
2 changes: 1 addition & 1 deletion lib/core/service/file_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FileService {
) async {
final dir = await documentsDirectory;
if (dir == null) {
throw ErrorMessage.unknown(); //TODO: better handling
throw const ErrorMessage.unknown(); //TODO: better handling
}
File file = File("${dir.path}/$filename");
return file..writeAsBytes(bytes);
Expand Down
2 changes: 0 additions & 2 deletions lib/core/service/github_issue_service.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:paperless_mobile/core/model/github_error_report.model.dart';
import 'package:paperless_mobile/core/widgets/error_report_page.dart';
import 'package:url_launcher/url_launcher.dart';
Expand Down
107 changes: 61 additions & 46 deletions lib/core/widgets/documents_list_loading_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import 'package:flutter/material.dart';
import 'package:shimmer/shimmer.dart';

class DocumentsListLoadingWidget extends StatelessWidget {
final List<Widget> above;
final List<Widget> below;
static const tags = [" ", " ", " "];
static const titleLengths = <double>[double.infinity, 150.0, 200.0];
static const correspondentLengths = <double>[200.0, 300.0, 150.0];
static const fontSize = 16.0;

const DocumentsListLoadingWidget({super.key});
const DocumentsListLoadingWidget({
super.key,
this.above = const [],
this.below = const [],
});

@override
Widget build(BuildContext context) {
Expand All @@ -27,58 +33,67 @@ class DocumentsListLoadingWidget extends StatelessWidget {
highlightColor: Theme.of(context).brightness == Brightness.light
? Colors.grey[100]!
: Colors.grey[600]!,
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
final r = Random(index);
final tagCount = r.nextInt(tags.length + 1);
final correspondentLength = correspondentLengths[
r.nextInt(correspondentLengths.length - 1)];
final titleLength =
titleLengths[r.nextInt(titleLengths.length - 1)];
return ListTile(
isThreeLine: true,
leading: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Container(
color: Colors.white,
height: 50,
width: 35,
),
),
title: Container(
padding: const EdgeInsets.symmetric(vertical: 2.0),
width: correspondentLength,
height: fontSize,
color: Colors.white,
),
subtitle: Padding(
padding: const EdgeInsets.symmetric(vertical: 2.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
child: Column(
children: [
...above,
Expanded(
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
itemBuilder: (context, index) {
final r = Random(index);
final tagCount = r.nextInt(tags.length + 1);
final correspondentLength = correspondentLengths[
r.nextInt(correspondentLengths.length - 1)];
final titleLength =
titleLengths[r.nextInt(titleLengths.length - 1)];
return ListTile(
isThreeLine: true,
leading: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Container(
color: Colors.white,
height: 50,
width: 35,
),
),
title: Container(
padding: const EdgeInsets.symmetric(vertical: 2.0),
width: correspondentLength,
height: fontSize,
width: titleLength,
color: Colors.white,
),
Wrap(
spacing: 2.0,
children: List.generate(
tagCount,
(index) => InputChip(
label: Text(tags[r.nextInt(tags.length)]),
),
subtitle: Padding(
padding: const EdgeInsets.symmetric(vertical: 2.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
padding:
const EdgeInsets.symmetric(vertical: 2.0),
height: fontSize,
width: titleLength,
color: Colors.white,
),
Wrap(
spacing: 2.0,
children: List.generate(
tagCount,
(index) => InputChip(
label: Text(tags[r.nextInt(tags.length)]),
),
),
),
],
),
),
],
),
);
},
itemCount: 25,
),
);
},
itemCount: 25,
),
...below,
],
),
),
),
Expand Down
43 changes: 20 additions & 23 deletions lib/core/widgets/error_report_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:paperless_mobile/core/model/github_error_report.model.dart';
import 'package:paperless_mobile/extensions/flutter_extensions.dart';

Expand All @@ -18,20 +15,20 @@ class ErrorReportPage extends StatefulWidget {
class _ErrorReportPageState extends State<ErrorReportPage> {
final GlobalKey<FormBuilderState> _formKey = GlobalKey();

static const String shortDescriptionKey = "shortDescription";
static const String longDescriptionKey = "longDescription";
static const String shortDescriptionKey = 'shortDescription';
static const String longDescriptionKey = 'longDescription';

bool _stackTraceCopied = false;
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(
title: Text("Report error"),
title: const Text('Report error'),
actions: [
TextButton(
onPressed: _onSubmit,
child: Text("Submit"),
child: const Text('Submit'),
),
],
),
Expand All @@ -40,51 +37,51 @@ class _ErrorReportPageState extends State<ErrorReportPage> {
child: ListView(
children: [
Text(
"""Oops, an error has occurred!
'''Oops, an error has occurred!
In order to improve the app and prevent messages like these, it is greatly appreciated if you report this error with a description of what happened and the actions leading up to this window.
Please fill the fields below and create a new issue in GitHub. Thanks!
Note: If you have the GitHub Android app installed, the descriptions will not be taken into account! Skip these here and fill them in the GitHub issues form after submitting this report.""",
Note: If you have the GitHub Android app installed, the descriptions will not be taken into account! Skip these here and fill them in the GitHub issues form after submitting this report.''',
style: Theme.of(context).textTheme.bodyMedium,
).padded(),
Text(
"Description",
'Description',
style: Theme.of(context).textTheme.subtitle1,
).padded(),
FormBuilderTextField(
name: shortDescriptionKey,
decoration: const InputDecoration(
label: Text("Short Description"),
label: Text('Short Description'),
hintText:
"Please provide a brief description of what went wrong."),
'Please provide a brief description of what went wrong.'),
).padded(),
FormBuilderTextField(
name: shortDescriptionKey,
maxLines: null,
keyboardType: TextInputType.multiline,
decoration: const InputDecoration(
label: Text("Detailled Description"),
label: Text('Detailled Description'),
hintText:
"Please describe the exact actions taken that caused this error. Provide as much details as possible.",
'Please describe the exact actions taken that caused this error. Provide as much details as possible.',
),
).padded(),
if (widget.stackTrace != null) ...[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Stack Trace",
'Stack Trace',
style: Theme.of(context).textTheme.subtitle1,
).padded(
const EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0)),
TextButton.icon(
label: const Text("Copy"),
label: const Text('Copy'),
icon: const Icon(Icons.copy),
onPressed: _copyStackTrace,
),
],
),
Text(
"Since stack traces cannot be attached to the GitHub issue url, please copy the content of the stackTrace and paste it in the issue description. This will greatly increase the chance of quickly resolving the issue!",
'Since stack traces cannot be attached to the GitHub issue url, please copy the content of the stackTrace and paste it in the issue description. This will greatly increase the chance of quickly resolving the issue!',
style: Theme.of(context).textTheme.caption,
).padded(),
Text(
Expand All @@ -107,7 +104,7 @@ Note: If you have the GitHub Android app installed, the descriptions will not be
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
"Stack trace copied to clipboard.",
'Stack trace copied to clipboard.',
),
duration: Duration(seconds: 2),
),
Expand All @@ -123,25 +120,25 @@ Note: If you have the GitHub Android app installed, the descriptions will not be
final continueSubmission = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: const Text("Continue without stack trace?"),
title: const Text('Continue without stack trace?'),
content: const Text(
"It seems you have not yet copied the stack trace. The stack trace provides valuable insights into where an error came from and how it could be fixed. Are you sure you want to continue without providing the stack trace?",
'It seems you have not yet copied the stack trace. The stack trace provides valuable insights into where an error came from and how it could be fixed. Are you sure you want to continue without providing the stack trace?',
),
actionsAlignment: MainAxisAlignment.end,
actions: [
TextButton(
child: const Text("Yes, continue"),
child: const Text('Yes, continue'),
onPressed: () => Navigator.pop(context, true),
),
TextButton(
child: const Text("No, copy stack trace"),
child: const Text('No, copy stack trace'),
onPressed: () {
_copyStackTrace();
Navigator.pop(context, true);
},
),
TextButton(
child: const Text("Cancel"),
child: const Text('Cancel'),
onPressed: () => Navigator.pop(context, false),
),
],
Expand Down
14 changes: 14 additions & 0 deletions lib/extensions/dart_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ extension DuplicateCheckable<T> on Iterable<T> {
return toSet().length != length;
}
}

extension DateHelpers on DateTime {
bool get isToday {
final now = DateTime.now();
return now.day == day && now.month == month && now.year == year;
}

bool get isYesterday {
final yesterday = DateTime.now().subtract(const Duration(days: 1));
return yesterday.day == day &&
yesterday.month == month &&
yesterday.year == year;
}
}
1 change: 1 addition & 0 deletions lib/features/app_intro/application_intro_slideshow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ApplicationIntroSlideshow extends StatefulWidget {
_ApplicationIntroSlideshowState();
}

//TODO: INTL ALL
class _ApplicationIntroSlideshowState extends State<ApplicationIntroSlideshow> {
AssetImage secureImage = AssetImages.secureDocuments.image;
AssetImage successImage = AssetImages.success.image;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:injectable/injectable.dart';
import 'package:paperless_mobile/features/documents/model/document.model.dart';
import 'package:paperless_mobile/features/documents/repository/document_repository.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
print("Returning document...");
Navigator.of(context)
.pop(BlocProvider.of<DocumentDetailsCubit>(context).state.document);
return Future.value(false);
Expand Down
6 changes: 4 additions & 2 deletions lib/features/documents/bloc/documents_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ class DocumentsCubit extends Cubit<DocumentsState> {
}
final newFilter = state.filter.copyWith(page: state.filter.page + 1);
final result = await documentRepository.find(newFilter);
emit(DocumentsState(
isLoaded: true, value: [...state.value, result], filter: newFilter));
emit(
DocumentsState(
isLoaded: true, value: [...state.value, result], filter: newFilter),
);
}

///
Expand Down
Loading

0 comments on commit b1db2a1

Please sign in to comment.