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

Sadespresso/241019-theme-overhaul #205

Merged
merged 8 commits into from
Oct 26, 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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Beta 0.7.2

* Added themes

## Beta 0.7.1

* Fixed transfer transactions

## Beta 0.7.0

* Added an option to choose location on a map
Expand Down
9 changes: 4 additions & 5 deletions assets/l10n/en_IN.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@
"preferences.primaryCurrency": "Primary currency",
"preferences.language": "Language",
"preferences.language.choose": "Select a language",
"preferences.themeMode": "Theme",
"preferences.themeMode.choose": "Select a theme",
"preferences.themeMode.light": "Light",
"preferences.themeMode.dark": "Dark",
"preferences.themeMode.system": "Auto (system)",
"preferences.theme": "Theme",
"preferences.theme.choose": "Select a theme",
"preferences.theme.light": "Light",
"preferences.theme.dark": "Dark",
"preferences.numpad": "Numpad",
"preferences.numpad.layout": "Numpad layout",
"preferences.numpad.layout.classic": "Classic",
Expand Down
9 changes: 4 additions & 5 deletions assets/l10n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@
"preferences.primaryCurrency": "Primary currency",
"preferences.language": "Language",
"preferences.language.choose": "Select a language",
"preferences.themeMode": "Theme",
"preferences.themeMode.choose": "Select a theme",
"preferences.themeMode.light": "Light",
"preferences.themeMode.dark": "Dark",
"preferences.themeMode.system": "Auto (system)",
"preferences.theme": "Theme",
"preferences.theme.choose": "Select a theme",
"preferences.theme.light": "Light",
"preferences.theme.dark": "Dark",
"preferences.numpad": "Numpad",
"preferences.numpad.layout": "Numpad layout",
"preferences.numpad.layout.classic": "Classic",
Expand Down
9 changes: 4 additions & 5 deletions assets/l10n/it_IT.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@
"preferences.primaryCurrency": "Valuta principale",
"preferences.language": "Lingua",
"preferences.language.choose": "Selezionare una lingua",
"preferences.themeMode": "Tema",
"preferences.themeMode.choose": "Seleziona un tema",
"preferences.themeMode.light": "Chiaro",
"preferences.themeMode.dark": "Scuro",
"preferences.themeMode.system": "Auto (sistema)",
"preferences.theme": "Tema",
"preferences.theme.choose": "Seleziona un tema",
"preferences.theme.light": "Chiaro",
"preferences.theme.dark": "Scuro",
"preferences.numpad": "Tastierino numerico",
"preferences.numpad.layout": "Layout del tastierino numerico",
"preferences.numpad.layout.classic": "Classico",
Expand Down
9 changes: 4 additions & 5 deletions assets/l10n/mn_MN.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@
"preferences.primaryCurrency": "Үндсэн валют",
"preferences.language": "Хэл",
"preferences.language.choose": "Хэл сонгох",
"preferences.themeMode": "Үзэмж",
"preferences.themeMode.choose": "Үзэмж сонгох",
"preferences.themeMode.light": "Гэгээлэг",
"preferences.themeMode.dark": "Харанхуй",
"preferences.themeMode.system": "Авто (систем)",
"preferences.theme": "Үзэмж",
"preferences.theme.choose": "Үзэмж сонгох",
"preferences.theme.light": "Гэгээлэг",
"preferences.theme.dark": "Харанхуй",
"preferences.numpad": "Тоон товчлуур",
"preferences.numpad.layout": "Тооны байрлал",
"preferences.numpad.layout.classic": "Хуучны",
Expand Down
Binary file removed lib/libobjectbox.so
Binary file not shown.
67 changes: 43 additions & 24 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import "dart:async";
import "dart:developer";
import "dart:io";

import "package:dynamic_color/dynamic_color.dart";
import "package:flow/constants.dart";
import "package:flow/entity/profile.dart";
import "package:flow/entity/transaction.dart";
Expand All @@ -28,13 +29,14 @@ import "package:flow/objectbox/actions.dart";
import "package:flow/prefs.dart";
import "package:flow/routes.dart";
import "package:flow/services/exchange_rates.dart";
import "package:flow/theme/color_themes/registry.dart";
import "package:flow/theme/flow_color_scheme.dart";
import "package:flow/theme/theme.dart";
import "package:flutter/material.dart";
import "package:flutter_localizations/flutter_localizations.dart";
import "package:intl/intl.dart";
import "package:moment_dart/moment_dart.dart";
import "package:package_info_plus/package_info_plus.dart";
import "package:pie_menu/pie_menu.dart";

void main() async {
WidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -80,16 +82,14 @@ class FlowState extends State<Flow> {
Locale _locale = FlowLocalizations.supportedLanguages.first;
ThemeMode _themeMode = ThemeMode.system;

ThemeFactory _themeFactory = ThemeFactory.fromThemeName(null);

ThemeMode get themeMode => _themeMode;

bool get useDarkTheme => (_themeMode == ThemeMode.system
? (MediaQuery.platformBrightnessOf(context) == Brightness.dark)
: (_themeMode == ThemeMode.dark));

PieTheme get pieTheme {
return useDarkTheme ? pieThemeDark : pieThemeLight;
}

@override
void initState() {
super.initState();
Expand All @@ -98,7 +98,7 @@ class FlowState extends State<Flow> {
_reloadTheme();

LocalPreferences().localeOverride.addListener(_reloadLocale);
LocalPreferences().themeMode.addListener(_reloadTheme);
LocalPreferences().themeName.addListener(_reloadTheme);

ObjectBox().box<Transaction>().query().watch().listen((event) {
ObjectBox().invalidateAccountsTab();
Expand All @@ -112,34 +112,53 @@ class FlowState extends State<Flow> {
@override
void dispose() {
LocalPreferences().localeOverride.removeListener(_reloadLocale);
LocalPreferences().themeMode.removeListener(_reloadTheme);
LocalPreferences().themeName.removeListener(_reloadTheme);
super.dispose();
}

@override
Widget build(BuildContext context) {
return MaterialApp.router(
onGenerateTitle: (context) => "appName".t(context),
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
if (flowDebugMode || Platform.isIOS)
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
FlowLocalizations.delegate,
],
supportedLocales: FlowLocalizations.supportedLanguages,
locale: _locale,
routerConfig: router,
theme: lightTheme,
darkTheme: darkTheme,
themeMode: _themeMode,
debugShowCheckedModeBanner: false,
return DynamicColorBuilder(
builder: (dynamicLight, dynamicDark) {
return MaterialApp.router(
onGenerateTitle: (context) => "appName".t(context),
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
if (flowDebugMode || Platform.isIOS)
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
FlowLocalizations.delegate,
],
supportedLocales: FlowLocalizations.supportedLanguages,
locale: _locale,
routerConfig: router,
theme: _themeFactory.materialTheme,
darkTheme: _themeFactory.materialTheme,
themeMode: _themeMode,
debugShowCheckedModeBanner: false,
);
},
);
}

void _reloadTheme() {
final String? themeName = LocalPreferences().themeName.value;

log("[Theme] Reloading theme $themeName");

({FlowColorScheme scheme, ThemeMode mode})? experimentalTheme =
getTheme(themeName);

if (experimentalTheme == null) {
log("[Theme] Didn't find theme for $themeName");
unawaited(LocalPreferences().themeName.set(lightThemes.keys.first));
experimentalTheme = null;
}

setState(() {
_themeMode = LocalPreferences().themeMode.value ?? _themeMode;
_themeMode = experimentalTheme?.mode ?? _themeMode;
_themeFactory = ThemeFactory(experimentalTheme?.scheme ??
(_themeMode == ThemeMode.dark ? electricLavender : shadeOfViolet));
});
}

Expand Down
19 changes: 12 additions & 7 deletions lib/objectbox/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extension MainActions on ObjectBox {
if (ignoreTransfers && transaction.isTransfer) continue;

final String categoryUuid =
transaction.category.target?.uuid ?? Uuid.NAMESPACE_NIL;
transaction.category.target?.uuid ?? Namespace.nil.value;

flow[categoryUuid] ??= MoneyFlow(
associatedData: transaction.category.target,
Expand Down Expand Up @@ -149,7 +149,7 @@ extension MainActions on ObjectBox {
if (ignoreTransfers && transaction.isTransfer) continue;

final String accountUuid =
transaction.account.target?.uuid ?? Uuid.NAMESPACE_NIL;
transaction.account.target?.uuid ?? Namespace.nil.value;

flow[accountUuid] ??= MoneyFlow(
associatedData: transaction.account.target,
Expand All @@ -158,7 +158,7 @@ extension MainActions on ObjectBox {
}

assert(
!flow.containsKey(Uuid.NAMESPACE_NIL),
!flow.containsKey(Namespace.nil.value),
"There is no way you've managed to make a transaction without an account",
);

Expand Down Expand Up @@ -314,7 +314,7 @@ extension TransactionActions on Transaction {
final Query<Transaction> query = ObjectBox()
.box<Transaction>()
.query(Transaction_.uuid
.equals(transfer.relatedTransactionUuid ?? Uuid.NAMESPACE_NIL))
.equals(transfer.relatedTransactionUuid ?? Namespace.nil.value))
.build();

try {
Expand All @@ -336,7 +336,7 @@ extension TransactionActions on Transaction {
final Query<Transaction> relatedTransactionQuery = ObjectBox()
.box<Transaction>()
.query(Transaction_.uuid
.equals(transfer.relatedTransactionUuid ?? Uuid.NAMESPACE_NIL))
.equals(transfer.relatedTransactionUuid ?? Namespace.nil.value))
.build();

final Transaction? relatedTransaction =
Expand Down Expand Up @@ -513,7 +513,7 @@ extension AccountActions on Account {
uuid: const Uuid().v4(),
fromAccountUuid: uuid,
toAccountUuid: targetAccount.uuid,
relatedTransactionUuid: fromTransactionUuid,
relatedTransactionUuid: toTransactionUuid,
);

final String resolvedTitle = title ??
Expand All @@ -540,7 +540,7 @@ extension AccountActions on Account {
title: resolvedTitle,
description: description,
extensions: [
transferData.copyWith(relatedTransactionUuid: toTransactionUuid),
transferData.copyWith(relatedTransactionUuid: fromTransactionUuid),
...filteredExtensions,
],
uuidOverride: toTransactionUuid,
Expand Down Expand Up @@ -585,6 +585,11 @@ extension AccountActions on Account {
return ext..setRelatedTransactionUuid(uuid);
}

if (ext.key == Transfer.keyName) {
// Transfer extension is handled separately
return ext;
}

if (ext.relatedTransactionUuid == uuid) {
return ext;
}
Expand Down
16 changes: 9 additions & 7 deletions lib/prefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "package:flow/entity/category.dart";
import "package:flow/entity/transaction.dart";
import "package:flow/objectbox.dart";
import "package:flow/objectbox/objectbox.g.dart";
import "package:flutter/material.dart";
import "package:flow/theme/color_themes/registry.dart";
import "package:intl/intl.dart";
import "package:latlong2/latlong.dart";
import "package:local_settings/local_settings.dart";
Expand Down Expand Up @@ -60,7 +60,6 @@ class LocalPreferences {

late final BoolSettingsEntry completedInitialSetup;

late final ThemeModeSettingsEntry themeMode;
late final LocaleSettingsEntry localeOverride;

/// Whether the user uses only one currency across accounts
Expand All @@ -76,6 +75,8 @@ class LocalPreferences {

late final JsonSettingsEntry<LatLng> lastKnownGeo;

late final PrimitiveSettingsEntry<String> themeName;

LocalPreferences._internal(this._prefs) {
primaryCurrency = PrimitiveSettingsEntry<String>(
key: "flow.primaryCurrency",
Expand Down Expand Up @@ -127,11 +128,6 @@ class LocalPreferences {
initialValue: false,
);

themeMode = ThemeModeSettingsEntry(
key: "flow.themeMode",
preferences: _prefs,
initialValue: ThemeMode.system,
);
localeOverride = LocaleSettingsEntry(
key: "flow.localeOverride",
preferences: _prefs,
Expand Down Expand Up @@ -175,6 +171,12 @@ class LocalPreferences {
toJson: (data) => data.toJson(),
);

themeName = PrimitiveSettingsEntry<String>(
key: "flow.themeName",
preferences: _prefs,
initialValue: lightThemes.keys.first,
);

updateTransitiveProperties();
}

Expand Down
5 changes: 5 additions & 0 deletions lib/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import "package:flow/routes/import_wizard/v1.dart";
import "package:flow/routes/preferences/button_order_preferences_page.dart";
import "package:flow/routes/preferences/home_tab_preferences.dart";
import "package:flow/routes/preferences/numpad_preferences_page.dart";
import "package:flow/routes/preferences/theme_preferences_page.dart";
import "package:flow/routes/preferences/transaction_geo_preferences_page.dart";
import "package:flow/routes/preferences/transfer_preferences_page.dart";
import "package:flow/routes/preferences_page.dart";
Expand Down Expand Up @@ -169,6 +170,10 @@ final router = GoRouter(
path: "transactionGeo",
builder: (context, state) => const TransactionGeoPreferencesPage(),
),
GoRoute(
path: "theme",
builder: (context, state) => const ThemePreferencesPage(),
),
],
),
GoRoute(
Expand Down
Loading