mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-09 08:08:14 -06:00
Removed unused files, code cleanup
This commit is contained in:
3
lib/helpers/file_helpers.dart
Normal file
3
lib/helpers/file_helpers.dart
Normal file
@@ -0,0 +1,3 @@
|
||||
String extractFilenameFromPath(String path) {
|
||||
return path.split(RegExp('[./]')).reversed.skip(1).first;
|
||||
}
|
||||
6
lib/helpers/format_helpers.dart
Normal file
6
lib/helpers/format_helpers.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
String formatMaxCount(int? count, [int maxCount = 99]) {
|
||||
if ((count ?? 0) > maxCount) {
|
||||
return "$maxCount+";
|
||||
}
|
||||
return (count ?? 0).toString().padLeft(maxCount.toString().length);
|
||||
}
|
||||
38
lib/helpers/image_helpers.dart
Normal file
38
lib/helpers/image_helpers.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
// Taken from https://github.com/flutter/flutter/issues/26127#issuecomment-782083060
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
Future<void> loadImage(ImageProvider provider) {
|
||||
final config = ImageConfiguration(
|
||||
bundle: rootBundle,
|
||||
devicePixelRatio: window.devicePixelRatio,
|
||||
platform: defaultTargetPlatform,
|
||||
);
|
||||
final Completer<void> completer = Completer();
|
||||
final ImageStream stream = provider.resolve(config);
|
||||
|
||||
late final ImageStreamListener listener;
|
||||
|
||||
listener = ImageStreamListener((ImageInfo image, bool sync) {
|
||||
debugPrint("Image ${image.debugLabel} finished loading");
|
||||
completer.complete();
|
||||
stream.removeListener(listener);
|
||||
}, onError: (dynamic exception, StackTrace? stackTrace) {
|
||||
completer.complete();
|
||||
stream.removeListener(listener);
|
||||
FlutterError.reportError(FlutterErrorDetails(
|
||||
context: ErrorDescription('image failed to load'),
|
||||
library: 'image resource service',
|
||||
exception: exception,
|
||||
stack: stackTrace,
|
||||
silent: true,
|
||||
));
|
||||
});
|
||||
|
||||
stream.addListener(listener);
|
||||
return completer.future;
|
||||
}
|
||||
111
lib/helpers/message_helpers.dart
Normal file
111
lib/helpers/message_helpers.dart
Normal file
@@ -0,0 +1,111 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/service/github_issue_service.dart';
|
||||
import 'package:paperless_mobile/core/translation/error_code_localization_mapper.dart';
|
||||
import 'package:paperless_mobile/generated/l10n.dart';
|
||||
|
||||
class SnackBarActionConfig {
|
||||
final String label;
|
||||
final VoidCallback onPressed;
|
||||
|
||||
SnackBarActionConfig({
|
||||
required this.label,
|
||||
required this.onPressed,
|
||||
});
|
||||
}
|
||||
|
||||
void showSnackBar(
|
||||
BuildContext context,
|
||||
String message, {
|
||||
String? details,
|
||||
SnackBarActionConfig? action,
|
||||
Duration duration = const Duration(seconds: 5),
|
||||
}) {
|
||||
ScaffoldMessenger.of(context)
|
||||
..hideCurrentSnackBar()
|
||||
..showSnackBar(
|
||||
SnackBar(
|
||||
content: (details != null)
|
||||
? RichText(
|
||||
maxLines: 5,
|
||||
text: TextSpan(
|
||||
text: message,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onInverseSurface,
|
||||
),
|
||||
children: <TextSpan>[
|
||||
TextSpan(
|
||||
text: "\n$details",
|
||||
style: const TextStyle(
|
||||
fontStyle: FontStyle.italic,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Text(message),
|
||||
action: action != null
|
||||
? SnackBarAction(
|
||||
label: action.label,
|
||||
onPressed: action.onPressed,
|
||||
textColor: Theme.of(context).colorScheme.onInverseSurface,
|
||||
)
|
||||
: null,
|
||||
duration: duration,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void showGenericError(
|
||||
BuildContext context,
|
||||
dynamic error, [
|
||||
StackTrace? stackTrace,
|
||||
]) {
|
||||
showSnackBar(
|
||||
context,
|
||||
error.toString(),
|
||||
action: SnackBarActionConfig(
|
||||
label: S.of(context).errorReportLabel,
|
||||
onPressed: () => GithubIssueService.createIssueFromError(
|
||||
context,
|
||||
stackTrace: stackTrace,
|
||||
),
|
||||
),
|
||||
);
|
||||
log(
|
||||
"An error has occurred.",
|
||||
error: error,
|
||||
stackTrace: stackTrace,
|
||||
time: DateTime.now(),
|
||||
);
|
||||
}
|
||||
|
||||
void showLocalizedError(
|
||||
BuildContext context,
|
||||
String localizedMessage, [
|
||||
StackTrace? stackTrace,
|
||||
]) {
|
||||
showSnackBar(context, localizedMessage);
|
||||
log(localizedMessage, stackTrace: stackTrace);
|
||||
}
|
||||
|
||||
void showErrorMessage(
|
||||
BuildContext context,
|
||||
PaperlessServerException error, [
|
||||
StackTrace? stackTrace,
|
||||
]) {
|
||||
showSnackBar(
|
||||
context,
|
||||
translateError(context, error.code),
|
||||
details: error.details,
|
||||
);
|
||||
log(
|
||||
"An error has occurred.",
|
||||
error: error,
|
||||
stackTrace: stackTrace,
|
||||
time: DateTime.now(),
|
||||
);
|
||||
}
|
||||
14
lib/helpers/permission_helpers.dart
Normal file
14
lib/helpers/permission_helpers.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
Future<bool> askForPermission(Permission permission) async {
|
||||
final status = await permission.request();
|
||||
log("Permission requested, new status is $status");
|
||||
// If user has permanently declined permission, open settings.
|
||||
if (status == PermissionStatus.permanentlyDenied) {
|
||||
await openAppSettings();
|
||||
}
|
||||
|
||||
return status == PermissionStatus.granted;
|
||||
}
|
||||
Reference in New Issue
Block a user