fix: Fixed saved views bug, formatted files, minor changes

This commit is contained in:
Anton Stubenbord
2023-06-10 16:29:12 +02:00
parent 3161343c35
commit 4c3f97136e
93 changed files with 1049 additions and 585 deletions

View File

@@ -26,11 +26,14 @@ class ManageAccountsPage extends StatelessWidget {
return const SizedBox.shrink();
}
return ValueListenableBuilder(
valueListenable: Hive.box<LocalUserAccount>(HiveBoxes.localUserAccount).listenable(),
valueListenable:
Hive.box<LocalUserAccount>(HiveBoxes.localUserAccount)
.listenable(),
builder: (context, box, _) {
final userIds = box.keys.toList().cast<String>();
final otherAccounts = userIds
.whereNot((element) => element == globalSettings.currentLoggedInUser)
.whereNot(
(element) => element == globalSettings.currentLoggedInUser)
.toList();
return SimpleDialog(
insetPadding: const EdgeInsets.all(24),
@@ -68,10 +71,13 @@ class ManageAccountsPage extends StatelessWidget {
],
onSelected: (value) async {
if (value == 0) {
final currentUser = globalSettings.currentLoggedInUser!;
final currentUser =
globalSettings.currentLoggedInUser!;
await context.read<AuthenticationCubit>().logout();
Navigator.of(context).pop();
await context.read<AuthenticationCubit>().removeAccount(currentUser);
await context
.read<AuthenticationCubit>()
.removeAccount(currentUser);
}
},
),
@@ -89,7 +95,8 @@ class ManageAccountsPage extends StatelessWidget {
PopupMenuItem(
child: ListTile(
title: Text(S.of(context)!.switchAccount),
leading: const Icon(Icons.switch_account_rounded),
leading:
const Icon(Icons.switch_account_rounded),
),
value: 0,
),
@@ -150,7 +157,8 @@ class ManageAccountsPage extends StatelessWidget {
MaterialPageRoute(
builder: (context) => LoginPage(
titleString: S.of(context)!.addAccount,
onSubmit: (context, username, password, serverUrl, clientCertificate) async {
onSubmit: (context, username, password, serverUrl,
clientCertificate) async {
final userId = await context.read<AuthenticationCubit>().addAccount(
credentials: LoginFormCredentials(
username: username,
@@ -179,7 +187,8 @@ class ManageAccountsPage extends StatelessWidget {
}
}
void _onSwitchAccount(BuildContext context, String currentUser, String newUser) async {
void _onSwitchAccount(
BuildContext context, String currentUser, String newUser) async {
if (currentUser == newUser) return;
Navigator.of(context).pop();

View File

@@ -26,7 +26,9 @@ class SettingsPage extends StatelessWidget {
textAlign: TextAlign.center,
),
subtitle: FutureBuilder<PaperlessServerInformationModel>(
future: context.read<PaperlessServerStatsApi>().getServerInformation(),
future: context
.read<PaperlessServerStatsApi>()
.getServerInformation(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return Text(

View File

@@ -14,8 +14,8 @@ class ClearCacheSetting extends StatelessWidget {
Widget build(BuildContext context) {
return ListTile(
title: const Text("Clear downloaded files"), //TODO: INTL
subtitle:
const Text("Deletes all files downloaded from this app."), //TODO: INTL
subtitle: const Text(
"Deletes all files downloaded from this app."), //TODO: INTL
onTap: () async {
final dir = await FileService.downloadsDirectory;
final deletedSize = _dirSize(dir);

View File

@@ -32,7 +32,8 @@ class ColorSchemeOptionSetting extends StatelessWidget {
options: [
RadioOption(
value: ColorSchemeOption.classic,
label: translateColorSchemeOption(context, ColorSchemeOption.classic),
label: translateColorSchemeOption(
context, ColorSchemeOption.classic),
),
RadioOption(
value: ColorSchemeOption.dynamic,

View File

@@ -25,15 +25,18 @@ class DefaultDownloadFileTypeSetting extends StatelessWidget {
options: [
RadioOption(
value: FileDownloadType.alwaysAsk,
label: _downloadFileTypeToString(context, FileDownloadType.alwaysAsk),
label: _downloadFileTypeToString(
context, FileDownloadType.alwaysAsk),
),
RadioOption(
value: FileDownloadType.original,
label: _downloadFileTypeToString(context, FileDownloadType.original),
label: _downloadFileTypeToString(
context, FileDownloadType.original),
),
RadioOption(
value: FileDownloadType.archived,
label: _downloadFileTypeToString(context, FileDownloadType.archived),
label: _downloadFileTypeToString(
context, FileDownloadType.archived),
),
],
initialValue: settings.defaultDownloadType,
@@ -51,7 +54,8 @@ class DefaultDownloadFileTypeSetting extends StatelessWidget {
);
}
String _downloadFileTypeToString(BuildContext context, FileDownloadType type) {
String _downloadFileTypeToString(
BuildContext context, FileDownloadType type) {
switch (type) {
case FileDownloadType.original:
return S.of(context)!.original;

View File

@@ -25,15 +25,18 @@ class DefaultShareFileTypeSetting extends StatelessWidget {
options: [
RadioOption(
value: FileDownloadType.alwaysAsk,
label: _downloadFileTypeToString(context, FileDownloadType.alwaysAsk),
label: _downloadFileTypeToString(
context, FileDownloadType.alwaysAsk),
),
RadioOption(
value: FileDownloadType.original,
label: _downloadFileTypeToString(context, FileDownloadType.original),
label: _downloadFileTypeToString(
context, FileDownloadType.original),
),
RadioOption(
value: FileDownloadType.archived,
label: _downloadFileTypeToString(context, FileDownloadType.archived),
label: _downloadFileTypeToString(
context, FileDownloadType.archived),
),
],
initialValue: settings.defaultShareType,
@@ -51,7 +54,8 @@ class DefaultShareFileTypeSetting extends StatelessWidget {
);
}
String _downloadFileTypeToString(BuildContext context, FileDownloadType type) {
String _downloadFileTypeToString(
BuildContext context, FileDownloadType type) {
switch (type) {
case FileDownloadType.original:
return S.of(context)!.original;

View File

@@ -10,7 +10,8 @@ class GlobalSettingsBuilder extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ValueListenableBuilder(
valueListenable: Hive.box<GlobalSettings>(HiveBoxes.globalSettings).listenable(),
valueListenable:
Hive.box<GlobalSettings>(HiveBoxes.globalSettings).listenable(),
builder: (context, value, _) {
final settings = value.getValue()!;
return builder(context, settings);

View File

@@ -7,7 +7,8 @@ class LanguageSelectionSetting extends StatefulWidget {
const LanguageSelectionSetting({super.key});
@override
State<LanguageSelectionSetting> createState() => _LanguageSelectionSettingState();
State<LanguageSelectionSetting> createState() =>
_LanguageSelectionSettingState();
}
class _LanguageSelectionSettingState extends State<LanguageSelectionSetting> {
@@ -27,7 +28,8 @@ class _LanguageSelectionSettingState extends State<LanguageSelectionSetting> {
builder: (context, settings) {
return ListTile(
title: Text(S.of(context)!.language),
subtitle: Text(_languageOptions[settings.preferredLocaleSubtag]!.name),
subtitle:
Text(_languageOptions[settings.preferredLocaleSubtag]!.name),
onTap: () => showDialog<String>(
context: context,
builder: (_) => RadioSettingsDialog<String>(
@@ -39,7 +41,8 @@ class _LanguageSelectionSettingState extends State<LanguageSelectionSetting> {
for (var language in _languageOptions.entries)
RadioOption(
value: language.key,
label: language.value.name + (language.value.isComplete ? '' : '*'),
label: language.value.name +
(language.value.isComplete ? '' : '*'),
),
],
initialValue: settings.preferredLocaleSubtag,

View File

@@ -50,7 +50,8 @@ class _RadioSettingsDialogState<T> extends State<RadioSettingsDialog<T>> {
mainAxisSize: MainAxisSize.min,
children: [
if (widget.descriptionText != null)
Text(widget.descriptionText!, style: Theme.of(context).textTheme.bodySmall),
Text(widget.descriptionText!,
style: Theme.of(context).textTheme.bodySmall),
...widget.options.map(_buildOptionListTile),
if (widget.footer != null) widget.footer!,
],

View File

@@ -12,7 +12,8 @@ class ThemeModeSetting extends StatelessWidget {
builder: (context, settings) {
return ListTile(
title: Text(S.of(context)!.appearance),
subtitle: Text(_mapThemeModeToLocalizedString(settings.preferredThemeMode, context)),
subtitle: Text(_mapThemeModeToLocalizedString(
settings.preferredThemeMode, context)),
onTap: () => showDialog<ThemeMode>(
context: context,
builder: (_) => RadioSettingsDialog<ThemeMode>(

View File

@@ -11,15 +11,18 @@ class UserAvatar extends StatelessWidget {
@override
Widget build(BuildContext context) {
final backgroundColor = Colors.primaries[account.id.hashCode % Colors.primaries.length];
final foregroundColor = backgroundColor.computeLuminance() > 0.5 ? Colors.black : Colors.white;
final backgroundColor =
Colors.primaries[account.id.hashCode % Colors.primaries.length];
final foregroundColor =
backgroundColor.computeLuminance() > 0.5 ? Colors.black : Colors.white;
return CircleAvatar(
child: Text((account.paperlessUser.fullName ?? account.paperlessUser.username)
.split(" ")
.take(2)
.map((e) => e.substring(0, 1))
.map((e) => e.toUpperCase())
.join("")),
child: Text(
(account.paperlessUser.fullName ?? account.paperlessUser.username)
.split(" ")
.take(2)
.map((e) => e.substring(0, 1))
.map((e) => e.toUpperCase())
.join("")),
backgroundColor: backgroundColor,
foregroundColor: foregroundColor,
);

View File

@@ -18,10 +18,12 @@ class UserAccountBuilder extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ValueListenableBuilder<Box<LocalUserAccount>>(
valueListenable: Hive.box<LocalUserAccount>(HiveBoxes.localUserAccount).listenable(),
valueListenable:
Hive.box<LocalUserAccount>(HiveBoxes.localUserAccount).listenable(),
builder: (context, accountBox, _) {
final currentUser =
Hive.box<GlobalSettings>(HiveBoxes.globalSettings).getValue()!.currentLoggedInUser;
final currentUser = Hive.box<GlobalSettings>(HiveBoxes.globalSettings)
.getValue()!
.currentLoggedInUser;
if (currentUser != null) {
final account = accountBox.get(currentUser);
return builder(context, account);