mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 10:08:02 -06:00
WIP - started implementing quick search
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:paperless_mobile/features/settings/view/widgets/color_scheme_option_setting.dart';
|
||||
import 'package:paperless_mobile/features/settings/view/widgets/language_selection_setting.dart';
|
||||
import 'package:paperless_mobile/features/settings/view/widgets/theme_mode_setting.dart';
|
||||
import 'package:paperless_mobile/generated/l10n.dart';
|
||||
import 'package:paperless_mobile/constants.dart';
|
||||
|
||||
class ApplicationSettingsPage extends StatelessWidget {
|
||||
const ApplicationSettingsPage({super.key});
|
||||
@@ -16,6 +21,7 @@ class ApplicationSettingsPage extends StatelessWidget {
|
||||
children: const [
|
||||
LanguageSelectionSetting(),
|
||||
ThemeModeSetting(),
|
||||
ColorSchemeOptionSetting(),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:paperless_mobile/features/settings/view/widgets/clear_storage_setting.dart';
|
||||
import 'package:paperless_mobile/features/settings/view/widgets/clear_storage_settings.dart';
|
||||
import 'package:paperless_mobile/generated/l10n.dart';
|
||||
|
||||
class StorageSettingsPage extends StatelessWidget {
|
||||
@@ -13,7 +13,7 @@ class StorageSettingsPage extends StatelessWidget {
|
||||
),
|
||||
body: ListView(
|
||||
children: const [
|
||||
ClearStorageSetting(),
|
||||
ClearCacheSetting(),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:paperless_mobile/features/login/services/authentication_service.dart';
|
||||
import 'package:paperless_mobile/features/settings/bloc/application_settings_cubit.dart';
|
||||
import 'package:paperless_mobile/features/settings/model/application_settings_state.dart';
|
||||
import 'package:paperless_mobile/features/settings/bloc/application_settings_state.dart';
|
||||
import 'package:paperless_mobile/generated/l10n.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart' as cm;
|
||||
import 'package:paperless_mobile/core/service/file_service.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ClearStorageSetting extends StatelessWidget {
|
||||
const ClearStorageSetting({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
title: Text("Clear data"),
|
||||
subtitle:
|
||||
Text("Remove downloaded files, scans and clear the cache's content"),
|
||||
onTap: () {
|
||||
context.read<cm.CacheManager>().emptyCache();
|
||||
FileService.clearUserData();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart' as cm;
|
||||
import 'package:paperless_mobile/core/service/file_service.dart';
|
||||
import 'package:paperless_mobile/helpers/format_helpers.dart';
|
||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ClearCacheSetting extends StatelessWidget {
|
||||
const ClearCacheSetting({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
title: Text("Clear downloaded files"), //TODO: INTL
|
||||
subtitle:
|
||||
Text("Deletes all files downloaded from this app."), //TODO: INTL
|
||||
onTap: () async {
|
||||
final dir = await FileService.downloadsDirectory;
|
||||
final deletedSize = _dirSize(dir);
|
||||
await dir.delete(recursive: true);
|
||||
// await context.read<cm.CacheManager>().emptyCache();
|
||||
showSnackBar(
|
||||
context,
|
||||
"Downloads successfully cleared, removed $deletedSize.",
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ClearDownloadsSetting extends StatelessWidget {
|
||||
const ClearDownloadsSetting({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
title: Text("Clear downloads"), //TODO: INTL
|
||||
subtitle: Text(
|
||||
"Remove downloaded files, scans and clear the cache's content"), //TODO: INTL
|
||||
onTap: () {
|
||||
FileService.documentsDirectory;
|
||||
FileService.downloadsDirectory;
|
||||
context.read<cm.CacheManager>().emptyCache();
|
||||
FileService.clearUserData();
|
||||
//TODO: Show notification about clearing (include size?)
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _dirSize(Directory dir) {
|
||||
int totalSize = 0;
|
||||
try {
|
||||
if (dir.existsSync()) {
|
||||
dir
|
||||
.listSync(recursive: true, followLinks: false)
|
||||
.forEach((FileSystemEntity entity) {
|
||||
if (entity is File) {
|
||||
totalSize += entity.lengthSync();
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
|
||||
return formatBytes(totalSize, 2);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:paperless_mobile/core/translation/color_scheme_option_localization_mapper.dart';
|
||||
import 'package:paperless_mobile/core/widgets/hint_card.dart';
|
||||
import 'package:paperless_mobile/features/login/services/authentication_service.dart';
|
||||
import 'package:paperless_mobile/features/settings/bloc/application_settings_cubit.dart';
|
||||
import 'package:paperless_mobile/features/settings/bloc/application_settings_state.dart';
|
||||
import 'package:paperless_mobile/features/settings/model/color_scheme_option.dart';
|
||||
import 'package:paperless_mobile/features/settings/view/widgets/radio_settings_dialog.dart';
|
||||
import 'package:paperless_mobile/generated/l10n.dart';
|
||||
import 'package:paperless_mobile/constants.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ColorSchemeOptionSetting extends StatelessWidget {
|
||||
const ColorSchemeOptionSetting({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<ApplicationSettingsCubit, ApplicationSettingsState>(
|
||||
builder: (context, settings) {
|
||||
return ListTile(
|
||||
title: Text(S.of(context).settingsPageColorSchemeSettingLabel),
|
||||
subtitle: Text(
|
||||
translateColorSchemeOption(
|
||||
context,
|
||||
settings.preferredColorSchemeOption,
|
||||
),
|
||||
),
|
||||
onTap: () => showDialog(
|
||||
context: context,
|
||||
builder: (_) => RadioSettingsDialog<ColorSchemeOption>(
|
||||
titleText: S.of(context).settingsPageColorSchemeSettingLabel,
|
||||
descriptionText:
|
||||
S.of(context).settingsPageColorSchemeSettingDialogDescription,
|
||||
options: [
|
||||
RadioOption(
|
||||
value: ColorSchemeOption.classic,
|
||||
label: translateColorSchemeOption(
|
||||
context, ColorSchemeOption.classic),
|
||||
),
|
||||
RadioOption(
|
||||
value: ColorSchemeOption.dynamic,
|
||||
label: translateColorSchemeOption(
|
||||
context,
|
||||
ColorSchemeOption.dynamic,
|
||||
),
|
||||
),
|
||||
],
|
||||
footer: _isBelowAndroid12()
|
||||
? HintCard(
|
||||
hintText: S
|
||||
.of(context)
|
||||
.settingsPageColorSchemeSettingDynamicThemeingVersionMismatchWarning,
|
||||
hintIcon: Icons.warning_amber,
|
||||
)
|
||||
: null,
|
||||
initialValue: context
|
||||
.read<ApplicationSettingsCubit>()
|
||||
.state
|
||||
.preferredColorSchemeOption,
|
||||
),
|
||||
).then(
|
||||
(value) {
|
||||
if (value != null) {
|
||||
context
|
||||
.read<ApplicationSettingsCubit>()
|
||||
.setColorSchemeOption(value);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
bool _isBelowAndroid12() {
|
||||
if (Platform.isAndroid) {
|
||||
final int version =
|
||||
int.tryParse(androidInfo!.version.release ?? '0') ?? 0;
|
||||
return version < 12;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:paperless_mobile/features/settings/bloc/application_settings_cubit.dart';
|
||||
import 'package:paperless_mobile/features/settings/model/application_settings_state.dart';
|
||||
import 'package:paperless_mobile/features/settings/bloc/application_settings_state.dart';
|
||||
import 'package:paperless_mobile/features/settings/view/widgets/radio_settings_dialog.dart';
|
||||
import 'package:paperless_mobile/generated/l10n.dart';
|
||||
|
||||
@@ -30,7 +30,7 @@ class _LanguageSelectionSettingState extends State<LanguageSelectionSetting> {
|
||||
onTap: () => showDialog(
|
||||
context: context,
|
||||
builder: (_) => RadioSettingsDialog<String>(
|
||||
title: Text(S.of(context).settingsPageLanguageSettingLabel),
|
||||
titleText: S.of(context).settingsPageLanguageSettingLabel,
|
||||
options: [
|
||||
RadioOption(
|
||||
value: 'en',
|
||||
@@ -54,8 +54,11 @@ class _LanguageSelectionSettingState extends State<LanguageSelectionSetting> {
|
||||
.state
|
||||
.preferredLocaleSubtag,
|
||||
),
|
||||
).then((value) =>
|
||||
context.read<ApplicationSettingsCubit>().setLocale(value)),
|
||||
).then((value) {
|
||||
if (value != null) {
|
||||
context.read<ApplicationSettingsCubit>().setLocale(value);
|
||||
}
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -4,7 +4,9 @@ import 'package:paperless_mobile/generated/l10n.dart';
|
||||
class RadioSettingsDialog<T> extends StatefulWidget {
|
||||
final List<RadioOption<T>> options;
|
||||
final T initialValue;
|
||||
final Widget? title;
|
||||
final String? titleText;
|
||||
final String? descriptionText;
|
||||
final Widget? footer;
|
||||
final Widget? confirmButton;
|
||||
final Widget? cancelButton;
|
||||
|
||||
@@ -12,9 +14,11 @@ class RadioSettingsDialog<T> extends StatefulWidget {
|
||||
super.key,
|
||||
required this.options,
|
||||
required this.initialValue,
|
||||
this.title,
|
||||
this.titleText,
|
||||
this.confirmButton,
|
||||
this.cancelButton,
|
||||
this.descriptionText,
|
||||
this.footer,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -43,10 +47,16 @@ class _RadioSettingsDialogState<T> extends State<RadioSettingsDialog<T>> {
|
||||
onPressed: () => Navigator.pop(context, _groupValue),
|
||||
child: Text(S.of(context).genericActionOkLabel)),
|
||||
],
|
||||
title: widget.title,
|
||||
title: widget.titleText != null ? Text(widget.titleText!) : null,
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: widget.options.map(_buildOptionListTile).toList(),
|
||||
children: [
|
||||
if (widget.descriptionText != null)
|
||||
Text(widget.descriptionText!,
|
||||
style: Theme.of(context).textTheme.bodySmall),
|
||||
...widget.options.map(_buildOptionListTile),
|
||||
if (widget.footer != null) widget.footer!,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:paperless_mobile/features/settings/bloc/application_settings_cubit.dart';
|
||||
import 'package:paperless_mobile/features/settings/model/application_settings_state.dart';
|
||||
import 'package:paperless_mobile/features/settings/bloc/application_settings_state.dart';
|
||||
import 'package:paperless_mobile/features/settings/view/widgets/radio_settings_dialog.dart';
|
||||
import 'package:paperless_mobile/generated/l10n.dart';
|
||||
|
||||
@@ -19,6 +19,11 @@ class ThemeModeSetting extends StatelessWidget {
|
||||
onTap: () => showDialog<ThemeMode>(
|
||||
context: context,
|
||||
builder: (_) => RadioSettingsDialog<ThemeMode>(
|
||||
titleText: S.of(context).settingsPageAppearanceSettingTitle,
|
||||
initialValue: context
|
||||
.read<ApplicationSettingsCubit>()
|
||||
.state
|
||||
.preferredThemeMode,
|
||||
options: [
|
||||
RadioOption(
|
||||
value: ThemeMode.system,
|
||||
@@ -38,14 +43,11 @@ class ThemeModeSetting extends StatelessWidget {
|
||||
S.of(context).settingsPageAppearanceSettingDarkThemeLabel,
|
||||
)
|
||||
],
|
||||
initialValue: context
|
||||
.read<ApplicationSettingsCubit>()
|
||||
.state
|
||||
.preferredThemeMode,
|
||||
title: Text(S.of(context).settingsPageAppearanceSettingTitle),
|
||||
),
|
||||
).then((value) {
|
||||
return context.read<ApplicationSettingsCubit>().setThemeMode(value);
|
||||
if (value != null) {
|
||||
context.read<ApplicationSettingsCubit>().setThemeMode(value);
|
||||
}
|
||||
}),
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user