macOS widgets
This commit is contained in:
parent
607ed2878b
commit
b0b4345a49
|
|
@ -0,0 +1,144 @@
|
|||
import 'package:invoiceninja_flutter/constants.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/dashboard_model.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/static/currency_model.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||
import 'package:invoiceninja_flutter/redux/company/company_selectors.dart';
|
||||
import 'package:invoiceninja_flutter/redux/company/company_state.dart';
|
||||
import 'package:invoiceninja_flutter/redux/static/static_state.dart';
|
||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||
import 'package:invoiceninja_flutter/utils/strings.dart';
|
||||
|
||||
class WidgetData {
|
||||
WidgetData({
|
||||
this.url,
|
||||
this.companies,
|
||||
this.companyId,
|
||||
this.dateRanges,
|
||||
});
|
||||
|
||||
WidgetData.fromState(AppState state, AppLocalization localization)
|
||||
: url = formatApiUrl(state.authState.url),
|
||||
companyId = state.account.defaultCompanyId,
|
||||
companies = {
|
||||
for (var userCompany in state.userCompanyStates
|
||||
.where((state) => state.company.hasName))
|
||||
userCompany.company.id: WidgetCompany.fromUserCompany(
|
||||
userCompanyState: userCompany,
|
||||
staticState: state.staticState,
|
||||
)
|
||||
},
|
||||
dateRanges = Map.fromIterable(
|
||||
DateRange.values.where((value) => value != DateRange.custom),
|
||||
key: (dynamic item) => toSnakeCase('$item'),
|
||||
value: (dynamic item) => localization.lookup('$item'));
|
||||
|
||||
WidgetData.fromJson(Map<String, dynamic> json)
|
||||
: url = json['url'],
|
||||
companyId = json['company_id'],
|
||||
companies = json['companies'],
|
||||
dateRanges = json['date_ranges'];
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'companies': companies,
|
||||
'company_id': companyId,
|
||||
'url': url,
|
||||
'date_ranges': dateRanges,
|
||||
};
|
||||
|
||||
final String url;
|
||||
final String companyId;
|
||||
final Map<String, WidgetCompany> companies;
|
||||
final Map<String, String> dateRanges;
|
||||
}
|
||||
|
||||
class WidgetCompany {
|
||||
WidgetCompany(
|
||||
{this.id,
|
||||
this.name,
|
||||
this.token,
|
||||
this.accentColor,
|
||||
this.firstMonthOfYear,
|
||||
this.currencyId,
|
||||
this.currencies});
|
||||
|
||||
WidgetCompany.fromUserCompany(
|
||||
{UserCompanyState userCompanyState, StaticState staticState})
|
||||
: id = userCompanyState.userCompany.company.id,
|
||||
name = userCompanyState.userCompany.company.displayName,
|
||||
token = userCompanyState.userCompany.token.token,
|
||||
accentColor = userCompanyState.userCompany.settings.validatedAccentColor,
|
||||
firstMonthOfYear =
|
||||
parseInt(userCompanyState.userCompany.company.firstMonthOfYear),
|
||||
currencyId = userCompanyState.userCompany.company.currencyId,
|
||||
currencies = {
|
||||
for (var currencyId in getCurrencyIds(
|
||||
userCompanyState.userCompany.company,
|
||||
userCompanyState.clientState.map,
|
||||
userCompanyState.groupState.map,
|
||||
).where((currencyId) => currencyId != kCurrencyAll))
|
||||
currencyId: WidgetCurrency.fromCurrency(
|
||||
staticState.currencyMap[currencyId],
|
||||
)
|
||||
};
|
||||
|
||||
WidgetCompany.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'],
|
||||
name = json['name'],
|
||||
token = json['token'],
|
||||
accentColor = json['accent_color'],
|
||||
currencies = json['currencies'],
|
||||
currencyId = json['currency_id'],
|
||||
firstMonthOfYear = json['first_month_of_year'];
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'id': id,
|
||||
'name': name,
|
||||
'token': token,
|
||||
'accent_color': accentColor,
|
||||
'currencies': currencies,
|
||||
'currency_id': currencyId,
|
||||
'first_month_of_year': firstMonthOfYear,
|
||||
};
|
||||
|
||||
final String id;
|
||||
final String name;
|
||||
final String token;
|
||||
final String accentColor;
|
||||
final String currencyId;
|
||||
final int firstMonthOfYear;
|
||||
final Map<String, WidgetCurrency> currencies;
|
||||
}
|
||||
|
||||
class WidgetCurrency {
|
||||
WidgetCurrency({
|
||||
this.id,
|
||||
this.name,
|
||||
this.code,
|
||||
this.exchangeRate,
|
||||
});
|
||||
|
||||
WidgetCurrency.fromCurrency(CurrencyEntity currency)
|
||||
: id = currency.id,
|
||||
name = currency.name,
|
||||
code = currency.code,
|
||||
exchangeRate = currency.exchangeRate;
|
||||
|
||||
WidgetCurrency.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'],
|
||||
name = json['name'],
|
||||
code = json['code'],
|
||||
exchangeRate = json['exchange_rate'];
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'id': id,
|
||||
'name': name,
|
||||
'code': code,
|
||||
'exchange_rate': exchangeRate,
|
||||
};
|
||||
|
||||
final String id;
|
||||
final String name;
|
||||
final String code;
|
||||
final double exchangeRate;
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import 'package:flutter/services.dart';
|
|||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:flutter_styled_toast/flutter_styled_toast.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/dashboard_model.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/widget_model.dart';
|
||||
import 'package:invoiceninja_flutter/redux/auth/auth_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/reports/reports_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/settings/settings_actions.dart';
|
||||
|
|
@ -1407,7 +1408,6 @@ void _showAbout(BuildContext context) async {
|
|||
]);
|
||||
} else {
|
||||
final json = jsonEncode(WidgetData.fromState(state, localization));
|
||||
print('## Set Widget Data: $json');
|
||||
await UserDefaults.setString(
|
||||
'widget_data', json, 'group.com.invoiceninja.app');
|
||||
await WidgetKit.reloadAllTimelines();
|
||||
|
|
|
|||
|
|
@ -1,24 +1,11 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:invoiceninja_flutter/constants.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/company_model.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/dashboard_model.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/static/currency_model.dart';
|
||||
import 'package:invoiceninja_flutter/main_app.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||
import 'package:invoiceninja_flutter/redux/company/company_selectors.dart';
|
||||
import 'package:invoiceninja_flutter/redux/company/company_state.dart';
|
||||
import 'package:invoiceninja_flutter/redux/static/static_state.dart';
|
||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
||||
import 'package:invoiceninja_flutter/utils/strings.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:widget_kit_plugin/user_defaults/user_defaults.dart';
|
||||
import 'package:widget_kit_plugin/widget_kit/widget_kit.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
class WindowManager extends StatefulWidget {
|
||||
|
|
@ -95,140 +82,11 @@ class _WindowManagerState extends State<WindowManager> with WindowListener {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
void updateWidgetData() {
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => widget.child;
|
||||
}
|
||||
|
||||
class WidgetData {
|
||||
WidgetData({
|
||||
this.url,
|
||||
this.companies,
|
||||
this.companyId,
|
||||
this.dateRanges,
|
||||
});
|
||||
|
||||
WidgetData.fromState(AppState state, AppLocalization localization)
|
||||
: url = formatApiUrl(state.authState.url),
|
||||
companyId = state.account.defaultCompanyId,
|
||||
companies = {
|
||||
for (var userCompany in state.userCompanyStates
|
||||
.where((state) => state.company.hasName))
|
||||
userCompany.company.id: WidgetCompany.fromUserCompany(
|
||||
userCompanyState: userCompany,
|
||||
staticState: state.staticState,
|
||||
)
|
||||
},
|
||||
dateRanges = Map.fromIterable(
|
||||
DateRange.values.where((value) => value != DateRange.custom),
|
||||
key: (dynamic item) => toSnakeCase('$item'),
|
||||
value: (dynamic item) => localization.lookup('$item'));
|
||||
|
||||
WidgetData.fromJson(Map<String, dynamic> json)
|
||||
: url = json['url'],
|
||||
companyId = json['company_id'],
|
||||
companies = json['companies'],
|
||||
dateRanges = json['date_ranges'];
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'companies': companies,
|
||||
'company_id': companyId,
|
||||
'url': url,
|
||||
'date_ranges': dateRanges,
|
||||
};
|
||||
|
||||
final String url;
|
||||
final String companyId;
|
||||
final Map<String, WidgetCompany> companies;
|
||||
final Map<String, String> dateRanges;
|
||||
}
|
||||
|
||||
class WidgetCompany {
|
||||
WidgetCompany(
|
||||
{this.id,
|
||||
this.name,
|
||||
this.token,
|
||||
this.accentColor,
|
||||
this.firstMonthOfYear,
|
||||
this.currencyId,
|
||||
this.currencies});
|
||||
|
||||
WidgetCompany.fromUserCompany(
|
||||
{UserCompanyState userCompanyState, StaticState staticState})
|
||||
: id = userCompanyState.userCompany.company.id,
|
||||
name = userCompanyState.userCompany.company.displayName,
|
||||
token = userCompanyState.userCompany.token.token,
|
||||
accentColor = userCompanyState.userCompany.settings.validatedAccentColor,
|
||||
firstMonthOfYear =
|
||||
parseInt(userCompanyState.userCompany.company.firstMonthOfYear),
|
||||
currencyId = userCompanyState.userCompany.company.currencyId,
|
||||
currencies = {
|
||||
for (var currencyId in getCurrencyIds(
|
||||
userCompanyState.userCompany.company,
|
||||
userCompanyState.clientState.map,
|
||||
userCompanyState.groupState.map,
|
||||
).where((currencyId) => currencyId != kCurrencyAll))
|
||||
currencyId: WidgetCurrency.fromCurrency(
|
||||
staticState.currencyMap[currencyId],
|
||||
)
|
||||
};
|
||||
|
||||
WidgetCompany.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'],
|
||||
name = json['name'],
|
||||
token = json['token'],
|
||||
accentColor = json['accent_color'],
|
||||
currencies = json['currencies'],
|
||||
currencyId = json['currency_id'],
|
||||
firstMonthOfYear = json['first_month_of_year'];
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'id': id,
|
||||
'name': name,
|
||||
'token': token,
|
||||
'accent_color': accentColor,
|
||||
'currencies': currencies,
|
||||
'currency_id': currencyId,
|
||||
'first_month_of_year': firstMonthOfYear,
|
||||
};
|
||||
|
||||
final String id;
|
||||
final String name;
|
||||
final String token;
|
||||
final String accentColor;
|
||||
final String currencyId;
|
||||
final int firstMonthOfYear;
|
||||
final Map<String, WidgetCurrency> currencies;
|
||||
}
|
||||
|
||||
class WidgetCurrency {
|
||||
WidgetCurrency({
|
||||
this.id,
|
||||
this.name,
|
||||
this.code,
|
||||
this.exchangeRate,
|
||||
});
|
||||
|
||||
WidgetCurrency.fromCurrency(CurrencyEntity currency)
|
||||
: id = currency.id,
|
||||
name = currency.name,
|
||||
code = currency.code,
|
||||
exchangeRate = currency.exchangeRate;
|
||||
|
||||
WidgetCurrency.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'],
|
||||
name = json['name'],
|
||||
code = json['code'],
|
||||
exchangeRate = json['exchange_rate'];
|
||||
|
||||
Map<String, dynamic> toJson() => <String, dynamic>{
|
||||
'id': id,
|
||||
'name': name,
|
||||
'code': code,
|
||||
'exchange_rate': exchangeRate,
|
||||
};
|
||||
|
||||
final String id;
|
||||
final String name;
|
||||
final String code;
|
||||
final double exchangeRate;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue