Skip to content

Commit

Permalink
Merge pull request #5 from Hollow-Ego/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
TheNordicOne authored May 20, 2024
2 parents 4396233 + 2ed2974 commit d6c290b
Show file tree
Hide file tree
Showing 48 changed files with 383 additions and 332 deletions.
2 changes: 1 addition & 1 deletion android/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
flutter.versionCode=5
flutter.versionName=0.4.0
flutter.versionName=0.4.1
6 changes: 6 additions & 0 deletions lib/database/daos/basket_items_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class BasketItemsDao extends DatabaseAccessor<AppDatabase> with _$BasketItemsDao
int? categoryId,
required int basketId,
String? imagePath,
String? note,
int? unitId,
}) async {
final existingItems = await findBasketItemsByNameCategoryUnit(name, basketId, categoryId, unitId);
Expand All @@ -38,6 +39,7 @@ class BasketItemsDao extends DatabaseAccessor<AppDatabase> with _$BasketItemsDao
category: Value(categoryId),
basket: Value(basketId),
imagePath: Value(imagePath),
note: Value(note),
unit: Value(unitId),
amount: Value(amount),
);
Expand All @@ -51,6 +53,7 @@ class BasketItemsDao extends DatabaseAccessor<AppDatabase> with _$BasketItemsDao
int? categoryId,
int? basketId,
String? imagePath,
String? note,
int? unitId,
bool? isChecked,
}) {
Expand All @@ -59,6 +62,7 @@ class BasketItemsDao extends DatabaseAccessor<AppDatabase> with _$BasketItemsDao
category: Value.absentIfNull(categoryId),
basket: Value.absentIfNull(basketId),
imagePath: Value.absentIfNull(imagePath),
note: Value.absentIfNull(note),
unit: Value.absentIfNull(unitId),
amount: Value.absentIfNull(amount),
isChecked: Value.absentIfNull(isChecked),
Expand All @@ -73,6 +77,7 @@ class BasketItemsDao extends DatabaseAccessor<AppDatabase> with _$BasketItemsDao
int? categoryId,
required int basketId,
String? imagePath,
String? note,
int? unitId,
bool? isChecked,
}) {
Expand All @@ -82,6 +87,7 @@ class BasketItemsDao extends DatabaseAccessor<AppDatabase> with _$BasketItemsDao
category: Value(categoryId),
basket: Value(basketId),
imagePath: Value(imagePath),
note: Value(note),
unit: Value(unitId),
amount: Value(amount ?? 0),
isChecked: Value(isChecked ?? false),
Expand Down
11 changes: 0 additions & 11 deletions lib/database/daos/item_templates_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ class ItemTemplatesDao extends DatabaseAccessor<AppDatabase> with _$ItemTemplate
String name, {
int? categoryId,
required int libraryId,
int? variantKeyId,
String? imagePath,
}) {
final companion = ItemTemplatesCompanion(
name: Value(name),
category: Value(categoryId),
library: Value(libraryId),
variantKey: Value(variantKeyId),
imagePath: Value(imagePath),
);
return into(itemTemplates).insert(companion);
Expand All @@ -37,14 +35,12 @@ class ItemTemplatesDao extends DatabaseAccessor<AppDatabase> with _$ItemTemplate
String? name,
int? categoryId,
int? libraryId,
int? variantKeyId,
String? imagePath,
}) {
final companion = ItemTemplatesCompanion(
name: Value.absentIfNull(name),
category: Value.absentIfNull(categoryId),
library: Value.absentIfNull(libraryId),
variantKey: Value.absentIfNull(variantKeyId),
imagePath: Value.absentIfNull(imagePath));
return (update(itemTemplates)..where((li) => li.id.equals(id))).write(companion);
}
Expand All @@ -54,15 +50,13 @@ class ItemTemplatesDao extends DatabaseAccessor<AppDatabase> with _$ItemTemplate
required String name,
int? categoryId,
required int libraryId,
int? variantKeyId,
String? imagePath,
}) {
final newItemTemplate = ItemTemplatesCompanion(
id: Value(id),
name: Value(name),
category: Value(categoryId),
library: Value(libraryId),
variantKey: Value(variantKeyId),
imagePath: Value(imagePath),
);
return update(itemTemplates).replace(newItemTemplate);
Expand All @@ -77,11 +71,6 @@ class ItemTemplatesDao extends DatabaseAccessor<AppDatabase> with _$ItemTemplate
return _rowToViewModel(row);
}

Future<List<ItemTemplateViewModel>> getItemTemplatesByVariantKey(int variantKeyId) async {
final rows = await _joinValues(select(itemTemplates)..where((li) => li.variantKey.equals(variantKeyId))).get();
return _rowsToViewModels(rows);
}

Future<int> deleteItemTemplateWithId(int id) {
return (delete(itemTemplates)..where((li) => li.id.equals(id))).go();
}
Expand Down
22 changes: 0 additions & 22 deletions lib/database/daos/variant_keys_dao.dart

This file was deleted.

23 changes: 16 additions & 7 deletions lib/database/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import 'package:rabenkorb/database/daos/shopping_baskets_dao.dart';
import 'package:rabenkorb/database/daos/sort_orders_dao.dart';
import 'package:rabenkorb/database/daos/sort_rules_dao.dart';
import 'package:rabenkorb/database/daos/template_libraries_dao.dart';
import 'package:rabenkorb/database/daos/variant_keys_dao.dart';
import 'package:rabenkorb/database/tables/basket_items.dart';
import 'package:rabenkorb/database/tables/item_categories.dart';
import 'package:rabenkorb/database/tables/item_templates.dart';
Expand All @@ -21,7 +20,6 @@ import 'package:rabenkorb/database/tables/shopping_basket.dart';
import 'package:rabenkorb/database/tables/sort_orders.dart';
import 'package:rabenkorb/database/tables/sort_rules.dart';
import 'package:rabenkorb/database/tables/template_libraries.dart';
import 'package:rabenkorb/database/tables/variant_keys.dart';

part 'database.g.dart';

Expand All @@ -35,7 +33,6 @@ part 'database.g.dart';
SortOrders,
SortRules,
TemplateLibraries,
VariantKeys,
],
daos: [
ItemCategoriesDao,
Expand All @@ -46,24 +43,36 @@ part 'database.g.dart';
SortOrdersDao,
SortRulesDao,
TemplateLibrariesDao,
VariantKeysDao,
],
)
class AppDatabase extends _$AppDatabase {
static const databaseFileName = 'db.sqlite';

AppDatabase() : super(_openConnection());

AppDatabase.forTesting(super.e);

AppDatabase.forImport(String path, String fileName) : super(_openImportDatabase(path, fileName));

@override
int get schemaVersion => 1;
int get schemaVersion => 2;

@override
MigrationStrategy get migration => MigrationStrategy(beforeOpen: (details) async {
MigrationStrategy get migration {
return MigrationStrategy(
beforeOpen: (details) async {
await customStatement('PRAGMA foreign_keys = ON');
});
},
onUpgrade: (Migrator m, int from, int to) async {
if (from < 2) {
m.deleteTable("variant_keys");
await m.addColumn(basketItems, basketItems.note);
await m.alterTable(TableMigration(basketItems));
await m.alterTable(TableMigration(itemTemplates));
}
},
);
}

Future<void> exportInto(File file) async {
await file.parent.create(recursive: true);
Expand Down
2 changes: 2 additions & 0 deletions lib/database/tables/basket_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class BasketItems extends Table {

TextColumn get imagePath => text().nullable()();

TextColumn get note => text().nullable()();

RealColumn get amount => real()();

IntColumn get category => integer().nullable().references(ItemCategories, #id, onDelete: KeyAction.setNull)();
Expand Down
3 changes: 0 additions & 3 deletions lib/database/tables/item_templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:drift/drift.dart';
import 'package:rabenkorb/database/constants.dart';
import 'package:rabenkorb/database/tables/item_categories.dart';
import 'package:rabenkorb/database/tables/template_libraries.dart';
import 'package:rabenkorb/database/tables/variant_keys.dart';

@DataClassName('ItemTemplate')
class ItemTemplates extends Table {
Expand All @@ -12,8 +11,6 @@ class ItemTemplates extends Table {

TextColumn get imagePath => text().nullable()();

IntColumn get variantKey => integer().nullable().references(VariantKeys, #id, onDelete: KeyAction.setNull)();

IntColumn get category => integer().nullable().references(ItemCategories, #id, onDelete: KeyAction.setNull)();

IntColumn get library => integer().references(TemplateLibraries, #id, onDelete: KeyAction.cascade)();
Expand Down
6 changes: 0 additions & 6 deletions lib/database/tables/variant_keys.dart

This file was deleted.

4 changes: 1 addition & 3 deletions lib/di/di_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import 'package:rabenkorb/services/data_access/shopping_basket_service.dart';
import 'package:rabenkorb/services/data_access/sort_order_service.dart';
import 'package:rabenkorb/services/data_access/sort_rule_service.dart';
import 'package:rabenkorb/services/data_access/template_library_service.dart';
import 'package:rabenkorb/services/data_access/variant_key_service.dart';
import 'package:rabenkorb/services/state/basket_state_service.dart';
import 'package:rabenkorb/services/state/data_management_navigation_state_service.dart';
import 'package:rabenkorb/services/state/data_management_state_service.dart';
Expand Down Expand Up @@ -109,7 +108,6 @@ void _registerDataAccessServices() {
di.registerSingleton<SortOrderService>(SortOrderService());
di.registerSingleton<SortRuleService>(SortRuleService());
di.registerSingleton<TemplateLibraryService>(TemplateLibraryService());
di.registerSingleton<VariantKeyService>(VariantKeyService());
}

void _registerBusinessServices() {
Expand Down Expand Up @@ -172,7 +170,7 @@ Future<void> _unregisterDataAccessServices() async {
await di.unregister<SortOrderService>();
await di.unregister<SortRuleService>();
await di.unregister<TemplateLibraryService>();
await di.unregister<VariantKeyService>();
await di.unregister<DataManagementService>();
}

Future<void> _unregisterDatabase() async {
Expand Down
15 changes: 13 additions & 2 deletions lib/features/backup/backup_create.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:rabenkorb/generated/l10n.dart';
import 'package:rabenkorb/services/core/snackbar_service.dart';
import 'package:rabenkorb/services/utility/backup_service.dart';
import 'package:rabenkorb/shared/helper_functions.dart';
import 'package:rabenkorb/shared/widgets/inputs/core_primary_button.dart';
Expand All @@ -26,8 +27,18 @@ class BackupCreate extends StatelessWidget {
if (exportPath == null || exportPath.trim().isEmpty) {
return;
}
doWithLoadingIndicator(() async {
await di<BackupService>().backup(exportPath);
bool exportSuccess = false;
await doWithLoadingIndicator(() async {
exportSuccess = await di<BackupService>().backup(exportPath);
});

if (!context.mounted) {
return;
}
if (exportSuccess) {
di<SnackBarService>().show(context: context, text: S.of(context).BackupCreated);
return;
}
di<SnackBarService>().show(context: context, text: S.of(context).BackupCreationFailed);
}
}
15 changes: 13 additions & 2 deletions lib/features/backup/backup_restore_screen.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:path/path.dart' as p;
import 'package:rabenkorb/features/core/structural/core_scaffold.dart';
import 'package:rabenkorb/generated/l10n.dart';
import 'package:rabenkorb/services/core/snackbar_service.dart';
import 'package:rabenkorb/services/utility/backup_service.dart';
import 'package:rabenkorb/shared/helper_functions.dart';
import 'package:rabenkorb/shared/widgets/constant_widgets.dart';
Expand Down Expand Up @@ -114,9 +116,18 @@ class _BackupRestoreScreenState extends State<BackupRestoreScreen> {
if (_backupFile == null) {
return;
}

bool importSuccess = false;
await doWithLoadingIndicator(() async {
await di<BackupService>().restore(_backupFile!);
importSuccess = await di<BackupService>().restore(_backupFile!);
});
if (!context.mounted) {
return;
}
if (importSuccess) {
di<SnackBarService>().show(context: context, text: S.of(context).BackupImported);
context.pop();
return;
}
di<SnackBarService>().show(context: context, text: S.of(context).BackupImportFailed);
}
}
24 changes: 23 additions & 1 deletion lib/features/basket/basket_item_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class BasketItemTile extends StatelessWidget {

@override
Widget build(BuildContext context) {
final extraWidget = _extra();
return Card(
key: Key(item.key),
color: item.isChecked ? Theme.of(context).colorScheme.surface.withAlpha(220) : null,
Expand All @@ -38,6 +39,7 @@ class BasketItemTile extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
if (extraWidget != null) extraWidget,
if (item.imagePath.isValid())
ItemImage(
imagePath: item.imagePath!,
Expand Down Expand Up @@ -69,7 +71,7 @@ class BasketItemTile extends StatelessWidget {
);
}

Widget? _subtitle() {
Widget? _amountUnit() {
final unit = item.unit;
final amount = item.amount;
final hasAmount = amount > 0;
Expand All @@ -79,4 +81,24 @@ class BasketItemTile extends StatelessWidget {
final subtitle = "${hasAmount ? amount.toFormattedString() : ''} ${unit?.name ?? ''}";
return Text(subtitle.trim());
}

Widget? _note() {
final note = item.note;
if (!note.isValid()) {
return null;
}
final subtitle = note!;
return Text(
subtitle.trim(),
style: const TextStyle(fontSize: 14),
);
}

Widget? _subtitle() {
return _amountUnit();
}

Widget? _extra() {
return _note();
}
}
4 changes: 3 additions & 1 deletion lib/features/basket/basket_popup_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ enum BasketPopupMenuActions {
class BasketPopupMenu extends StatelessWidget with WatchItMixin {
final bool isShoppingMode;
final bool isMultiSelectMode;
final bool disabled;

const BasketPopupMenu({super.key, required this.isShoppingMode, required this.isMultiSelectMode});
const BasketPopupMenu({super.key, required this.isShoppingMode, required this.isMultiSelectMode, this.disabled = false});

@override
Widget build(BuildContext context) {
return PopupMenuButton<BasketPopupMenuActions>(
key: const Key("basket-popup-menu"),
enabled: !disabled,
itemBuilder: isShoppingMode
? _shoppingModeItems
: isMultiSelectMode
Expand Down
Loading

0 comments on commit d6c290b

Please sign in to comment.