Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve setup #103

Merged
merged 5 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions assets/l10n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@
"setup.slides.offline": "You own your data",
"setup.slides.offline.description": "All of your data is stored only on-device, with full export options available",
"setup.profile.setup": "What's your name?",
"setup.profile.addPhoto": "Add a profile photo",
"setup.profile.addPhoto": "Add a photo",
"setup.profile.addPhoto.skip": "Skip",
"setup.primaryCurrency.setup": "What currency do you primarily use?",
"setup.primaryCurrency.choose": "Choose primary currency",
"setup.profile.addPhoto.description": "This is optional. Your photo will be stored only on your device, and will not be included in backups.",
"setup.primaryCurrency.setup": "Select currency",
"setup.primaryCurrency.description": "This will be your primary currency. You can change this later in \"Preferences\" menu.",
"setup.primaryCurrency.choose": "Choose a currency",
"setup.accounts.setup": "Setup accounts",
"setup.accounts.description": "Create new accounts, and/or add from the presets. You can change this later in the accounts tab.",
"setup.accounts.description": "Create new accounts, and/or add from the presets. You can change this later in the \"Accounts\" tab.",
"setup.accounts.addAccount": "Add new account",
"setup.accounts.preset.description": "Click on a preset to add",
"setup.accounts.preset.main": "Main",
"setup.accounts.preset.cash": "Cash",
"setup.accounts.preset.savings": "Savings",
"setup.categories.setup": "Setup categories",
"setup.categories.preset.description": "Click on a preset to add",
"setup.categories.description": "Create categories, and/or add from the presets. You can change this later in \"Profile > Categories\" menu.",
"setup.categories.preset.eatingOut": "Eating out",
"setup.categories.preset.groceries": "Groceries",
"setup.categories.preset.drinks": "Drinks & Beverages",
Expand Down
11 changes: 6 additions & 5 deletions assets/l10n/mn_MN.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@
"setup.slides.offline": "Таны мэдээлэл таны мэдэлд",
"setup.slides.offline.description": "Хэрэглэгчийн бүх мэдээлэл зөвхөн төхөөрөмж дээр хадгалагддаг ба хүссэн үедээ нөөцөлж авах боломжтой",
"setup.profile.setup": "Таныг хэн гэдэг вэ?",
"setup.profile.addPhoto": "Нүүр зураг нэмэх",
"setup.profile.addPhoto": "Зураг нэмэх",
"setup.profile.addPhoto.skip": "Алгасах",
"setup.primaryCurrency.setup": "Та ямар валют голчлон ашигладаг вэ?",
"setup.profile.addPhoto.description": "Зураг оруулах шаардлагагүй. Таны зураг зөвхөн таны төхөөрөмж дээр хадгалагдах бөгөөд нөөцлөх үед хамт нөөцлөгдөхгүй.",
"setup.primaryCurrency.setup": "Валют сонгох",
"setup.primaryCurrency.description": "Энэ таны үндсэн валют болох бөгөөд та үүнийг \"Тохиргоо\" цэсээс өөрчлөх боломжтой.",
"setup.primaryCurrency.choose": "Үндсэн валют сонгох",
"setup.accounts.setup": "Данс тохируулах",
"setup.accounts.description": "Шинэ данс үүсгэх, эсвэл доорх урьдчилан бэлдсэн данснуудаас нэмээрэй. Та дараа данснууд цэсээс үүнийг дахин тохируулах боломжтой.",
"setup.accounts.description": "Шинэ данс үүсгэх, эсвэл доорх сонголтуудаас нэмээрэй. Та үүнийг дараа \"Данснууд\" цэсээс тохируулах боломжтой.",
"setup.accounts.addAccount": "Шинэ данс нэмэх",
"setup.accounts.preset.description": "Урьдчилан бэлдсэн данс дээр дарж нэмээрэй",
"setup.accounts.preset.main": "Үндсэн",
"setup.accounts.preset.cash": "Бэлэн мөнгө",
"setup.accounts.preset.savings": "Хадгаламж",
"setup.categories.setup": "Ангиллууд тохируулах",
"setup.categories.preset.description": "Урьдчилан бэлдсэн ангилал дээр дарж нэмээрэй",
"setup.categories.description": "Шинээр ангилал үүсгэх, эсвэл доорх сонголтуудаас нэмээрэй. Та үүнийг дараа \"Бүртгэл\" цэсээс тохируулах боломжтой.",
"setup.categories.preset.eatingOut": "Гадуур хооллолт",
"setup.categories.preset.groceries": "Хүнс",
"setup.categories.preset.drinks": "Уух зүйлс",
Expand Down
12 changes: 6 additions & 6 deletions lib/data/setup/default_accounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import 'package:material_symbols_icons/symbols.dart';

List<Account> getAccountPresets(String currency) {
return [
Account(
id: -1,
Account.preset(
name: "setup.accounts.preset.main".tr(),
currency: currency,
iconCode: FlowIconData.icon(Symbols.credit_card_rounded).toString(),
uuid: "864df1dc-fe59-47e0-8423-98d8f86453b6",
),
Account(
id: -1,
Account.preset(
name: "setup.accounts.preset.cash".tr(),
currency: currency,
iconCode: FlowIconData.icon(Symbols.payments_rounded).toString(),
uuid: "d7ef9672-256b-4097-a55a-27a58c6f5ba5",
),
Account(
id: -1,
Account.preset(
name: "setup.accounts.preset.savings".tr(),
currency: currency,
iconCode: FlowIconData.icon(Symbols.savings_rounded).toString(),
uuid: "c04e1cdd-842f-48c1-9c6c-d07fb2b09193",
),
];
}
60 changes: 30 additions & 30 deletions lib/data/setup/default_categories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,82 @@ import 'package:material_symbols_icons/symbols.dart';

List<Category> getCategoryPresets() {
return [
Category(
id: -1,
Category.preset(
uuid: "f38b4e03-2ce6-4605-aeb9-a5e5fa6d01f5",
name: "setup.categories.preset.eatingOut".tr(),
iconCode: const IconFlowIcon(Symbols.restaurant_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "9ee43092-34bb-4647-ba43-59b23ba69afe",
name: "setup.categories.preset.groceries".tr(),
iconCode: const IconFlowIcon(Symbols.grocery_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "fea4be2c-96cd-4844-a953-022a966985ee",
name: "setup.categories.preset.drinks".tr(),
iconCode: const IconFlowIcon(Symbols.local_cafe_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "dd3aacb3-35a9-4b04-b1f3-9fb3f58f1332",
name: "setup.categories.preset.education".tr(),
iconCode: const IconFlowIcon(Symbols.school_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "39bfdc73-4cba-4980-ba0d-c200f903cc97",
name: "setup.categories.preset.health".tr(),
iconCode:
const IconFlowIcon(Symbols.health_and_safety_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "1a67735a-561a-48c0-bf86-f19dab4b95b5",
name: "setup.categories.preset.transport".tr(),
iconCode: const IconFlowIcon(Symbols.train_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "92e5e684-0bbf-4456-b731-2ad945d5773b",
name: "setup.categories.preset.petrol".tr(),
iconCode:
const IconFlowIcon(Symbols.local_gas_station_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "c04b893b-bea8-4df3-804c-8b14e3e65c6d",
name: "setup.categories.preset.shopping".tr(),
iconCode: const IconFlowIcon(Symbols.shopping_cart_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "4c75d6c4-aed2-4f60-9d28-4b3ae55b4498",
name: "setup.categories.preset.entertainment".tr(),
iconCode:
const IconFlowIcon(Symbols.sports_basketball_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "9555eecf-7570-4118-89b0-e7343ece6572",
name: "setup.categories.preset.onlineServices".tr(),
iconCode: const IconFlowIcon(Symbols.cloud_circle_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "e8cf1c76-cdf7-41e1-9343-923b86cd9ea2",
name: "setup.categories.preset.gifts".tr(),
iconCode: const IconFlowIcon(Symbols.featured_seasonal_and_gifts_rounded)
.toString(),
),
Category(
id: -1,
Category.preset(
uuid: "f442d114-b8c0-4f7e-befd-70844ad16fb4",
name: "setup.categories.preset.rent".tr(),
iconCode: const IconFlowIcon(Symbols.request_quote_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "a535e3ac-2103-40d6-acb7-0c664eb3bf6e",
name: "setup.categories.preset.utils".tr(),
iconCode: const IconFlowIcon(Symbols.valve_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "4213e196-8974-41d4-8eb9-b4debf3118aa",
name: "setup.categories.preset.taxes".tr(),
iconCode: const IconFlowIcon(Symbols.account_balance_rounded).toString(),
),
Category(
id: -1,
Category.preset(
uuid: "8bec1ea1-726f-4228-9d14-d210e86a9586",
name: "setup.categories.preset.paychecks".tr(),
iconCode: const IconFlowIcon(Symbols.wallet_rounded).toString(),
),
Expand Down
10 changes: 10 additions & 0 deletions lib/entity/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ class Account implements EntityBase {
}) : createdDate = createdDate ?? DateTime.now(),
uuid = const Uuid().v4();

Account.preset({
required this.name,
required this.currency,
required this.iconCode,
required this.uuid,
}) : excludeFromTotalBalance = false,
sortOrder = -1,
id = -1,
createdDate = DateTime.now();

factory Account.fromJson(Map<String, dynamic> json) =>
_$AccountFromJson(json);
Map<String, dynamic> toJson() => _$AccountToJson(this);
Expand Down
7 changes: 7 additions & 0 deletions lib/entity/category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ class Category implements EntityBase {
}) : createdDate = createdDate ?? DateTime.now(),
uuid = const Uuid().v4();

Category.preset({
required this.name,
required this.iconCode,
required this.uuid,
}) : createdDate = DateTime.now(),
id = -1;

factory Category.fromJson(Map<String, dynamic> json) =>
_$CategoryFromJson(json);
Map<String, dynamic> toJson() => _$CategoryToJson(this);
Expand Down
87 changes: 60 additions & 27 deletions lib/routes/setup/setup_accounts_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import 'package:flow/l10n/extensions.dart';
import 'package:flow/objectbox.dart';
import 'package:flow/objectbox/objectbox.g.dart';
import 'package:flow/prefs.dart';
import 'package:flow/utils/utils.dart';
import 'package:flow/widgets/general/button.dart';
import 'package:flow/widgets/general/info_text.dart';
import 'package:flow/widgets/setup/accounts/account_preset_card.dart';
import 'package:flow/widgets/setup/accounts/add_account_card.dart';
import 'package:flow/widgets/setup/setup_header.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:local_hero/local_hero.dart';
import 'package:material_symbols_icons/symbols.dart';

class SetupAccountsPage extends StatefulWidget {
Expand Down Expand Up @@ -42,14 +43,16 @@ class _SetupAccountsPageState extends State<SetupAccountsPage> {

presetAccounts = getAccountPresets(primaryCurrency)
.where((account) => !existingAccounts
.any((existingAccount) => existingAccount.name == account.name))
.any((existingAccount) => existingAccount.uuid == account.uuid))
.toList();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
appBar: AppBar(
title: Text("setup.accounts.setup".t(context)),
),
body: SafeArea(
child: StreamBuilder(
stream: qb().watch(triggerImmediately: true),
Expand All @@ -59,41 +62,52 @@ class _SetupAccountsPageState extends State<SetupAccountsPage> {
return SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
SetupHeader("setup.accounts.setup".t(context)),
InfoText(
child: Text(
"setup.accounts.description".t(context),
),
),
const SizedBox(height: 16.0),
const AddAccountCard(),
const SizedBox(height: 16.0),
...currentAccounts.map(
(e) => Padding(
(account) => Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: AccountPresetCard(
account: e,
key: ValueKey(account.uuid),
account: account,
onSelect: null,
selected: true,
preexisting: true,
),
),
),
const SizedBox(height: 16.0),
if (presetAccounts.isNotEmpty) ...[
InfoText(
child: Text(
"setup.accounts.preset.description".t(context),
),
),
const SizedBox(height: 8.0),
],
...presetAccounts.indexed.map(
(e) => Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: AccountPresetCard(
account: e.$2,
onSelect: (selected) => select(e.$1, selected),
selected: e.$2.id == 0,
),
LocalHeroScope(
duration: const Duration(milliseconds: 200),
curve: Curves.easeOut,
child: Column(
mainAxisSize: MainAxisSize.min,
children: presetAccounts
.map((preset) => Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child: LocalHero(
key: ValueKey(preset.uuid),
tag: preset.uuid,
child: AccountPresetCard(
key: ValueKey(preset.uuid),
account: preset,
onSelect: (selected) =>
select(preset.uuid, selected),
selected: preset.id == 0,
preexisting: false,
),
),
))
.toList(),
),
),
)
],
),
);
Expand All @@ -117,14 +131,27 @@ class _SetupAccountsPageState extends State<SetupAccountsPage> {
);
}

void select(int index, bool selected) {
presetAccounts[index].id = selected ? 0 : -1;
void loadPresets() {}

void select(String uuid, bool selected) {
final Account? preset =
presetAccounts.firstWhereOrNull((element) => element.uuid == uuid);

if (preset != null) {
preset.id = selected ? 0 : -1;
}

presetAccounts.sort((a, b) => b.id.compareTo(a.id));
setState(() {});
}

void save() async {
if (busy) return;

setState(() {
busy = true;
});

try {
final List<Account> selectedAccounts =
presetAccounts.where((element) => element.id == 0).toList();
Expand All @@ -135,6 +162,12 @@ class _SetupAccountsPageState extends State<SetupAccountsPage> {

await ObjectBox().box<Account>().putManyAsync(selectedAccounts);

presetAccounts.removeWhere((element) =>
selectedAccounts.indexWhere(
(selected) => element.uuid == selected.uuid,
) !=
-1);

if (mounted) {
context.push("/setup/categories");
}
Expand Down
Loading