169 lines
4.5 KiB
Dart
169 lines
4.5 KiB
Dart
|
|
import 'package:cloud_firestore/cloud_firestore.dart';
|
||
|
|
|
||
|
|
import 'bank_account.dart';
|
||
|
|
|
||
|
|
List<Day> dayLists = [
|
||
|
|
Day(id: 1, name: 'Sun'),
|
||
|
|
Day(id: 2, name: 'Mon'),
|
||
|
|
Day(id: 3, name: 'Tue'),
|
||
|
|
Day(id: 4, name: 'Wed'),
|
||
|
|
Day(id: 5, name: 'Thu'),
|
||
|
|
Day(id: 6, name: 'Fri'),
|
||
|
|
Day(id: 7, name: 'Sat'),
|
||
|
|
];
|
||
|
|
|
||
|
|
class Setting {
|
||
|
|
final int supportBuildNum;
|
||
|
|
final String okEnergyId;
|
||
|
|
final String about;
|
||
|
|
final String terms;
|
||
|
|
int poExpireInHours;
|
||
|
|
int doExpireInHours;
|
||
|
|
int poOpenAt;
|
||
|
|
int poCloseAt;
|
||
|
|
List<int> poCloseOn;
|
||
|
|
int latestDeliveryDay;
|
||
|
|
int firstStorageChargeIn;
|
||
|
|
int firstStorageCharge;
|
||
|
|
int secondStorageChargeIn;
|
||
|
|
int secondStorageCharge;
|
||
|
|
int deliveryStartWaitMin;
|
||
|
|
String reportURL;
|
||
|
|
String helpVersion;
|
||
|
|
String helpURL;
|
||
|
|
|
||
|
|
List<String> phones;
|
||
|
|
String deliveryPhone;
|
||
|
|
String address;
|
||
|
|
String email;
|
||
|
|
String website;
|
||
|
|
String facebook;
|
||
|
|
DateTime priceLastUpdate;
|
||
|
|
String bankAccountInfo;
|
||
|
|
List<BankAccount> bankAccounts;
|
||
|
|
|
||
|
|
String get getPoOpenAt => poOpenAt > 12
|
||
|
|
? (poOpenAt - 12).toString() + "PM"
|
||
|
|
: poOpenAt.toString() + "AM";
|
||
|
|
|
||
|
|
String get getPoCloseAt => poCloseAt > 12
|
||
|
|
? (poCloseAt - 12).toString() + "PM"
|
||
|
|
: poCloseAt.toString() + "AM";
|
||
|
|
|
||
|
|
String get getPoCloseOn => poCloseOn.fold(
|
||
|
|
"", (p, e) => p + (p == "" ? "" : ", ") + dayLists[e - 1].name);
|
||
|
|
|
||
|
|
String get getPoOpenOn => dayLists.fold(
|
||
|
|
"",
|
||
|
|
(p, e) =>
|
||
|
|
p +
|
||
|
|
(p == "" ? "" : poCloseOn.contains(e.id) ? "" : ", ") +
|
||
|
|
(poCloseOn.contains(e.id) ? "" : e.name));
|
||
|
|
|
||
|
|
bool get isPOClose {
|
||
|
|
DateTime now = DateTime.now();
|
||
|
|
// dart starts from monday width starting index one
|
||
|
|
// server starts from sunday with starting index one
|
||
|
|
var day = (now.weekday + 1) == 8 ? 1 : now.weekday + 1;
|
||
|
|
return poCloseOn.contains(day) ||
|
||
|
|
(now.hour < poOpenAt || now.hour >= poCloseAt);
|
||
|
|
}
|
||
|
|
|
||
|
|
Setting(
|
||
|
|
{this.supportBuildNum,
|
||
|
|
this.about,
|
||
|
|
this.okEnergyId,
|
||
|
|
this.terms,
|
||
|
|
this.poExpireInHours,
|
||
|
|
this.doExpireInHours,
|
||
|
|
this.poOpenAt,
|
||
|
|
this.poCloseAt,
|
||
|
|
this.poCloseOn,
|
||
|
|
this.latestDeliveryDay,
|
||
|
|
this.firstStorageCharge,
|
||
|
|
this.firstStorageChargeIn,
|
||
|
|
this.secondStorageCharge,
|
||
|
|
this.secondStorageChargeIn,
|
||
|
|
this.deliveryStartWaitMin,
|
||
|
|
this.reportURL,
|
||
|
|
this.helpVersion,
|
||
|
|
this.helpURL,
|
||
|
|
this.phones,
|
||
|
|
this.email,
|
||
|
|
this.website,
|
||
|
|
this.facebook,
|
||
|
|
this.priceLastUpdate,
|
||
|
|
this.bankAccountInfo,
|
||
|
|
this.bankAccounts,
|
||
|
|
this.deliveryPhone,
|
||
|
|
this.address});
|
||
|
|
|
||
|
|
factory Setting.fromMap(Map<String, dynamic> map) {
|
||
|
|
var ts = (map['price_last_update'] as Timestamp);
|
||
|
|
var list = (map['bank_accounts'] as List);
|
||
|
|
List<BankAccount> bankAccounts = [];
|
||
|
|
if (list != null) {
|
||
|
|
list.asMap().forEach((index, item) {
|
||
|
|
bankAccounts
|
||
|
|
.add(BankAccount.fromMap(index, item.cast<String, dynamic>()));
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
return Setting(
|
||
|
|
priceLastUpdate: ts?.toDate(),
|
||
|
|
supportBuildNum: map['support_build_number'],
|
||
|
|
about: map['about'],
|
||
|
|
terms: map['terms'],
|
||
|
|
okEnergyId: map['ok_energy_id'],
|
||
|
|
poExpireInHours: map['po_expire_hours'],
|
||
|
|
doExpireInHours: map['do_expire_hours'],
|
||
|
|
poOpenAt: map['po_open_at'],
|
||
|
|
poCloseAt: map['po_close_at'],
|
||
|
|
poCloseOn: List.from(map['po_close_on']),
|
||
|
|
latestDeliveryDay: map['latest_delivery_days'],
|
||
|
|
firstStorageChargeIn: map['first_storage_charge_in'],
|
||
|
|
firstStorageCharge: map['first_storage_charge'],
|
||
|
|
secondStorageChargeIn: map['second_storage_charge_in'],
|
||
|
|
secondStorageCharge: map['second_storage_charge'],
|
||
|
|
deliveryStartWaitMin: map['delivery_start_wait_min'],
|
||
|
|
reportURL: map['report_url'],
|
||
|
|
helpVersion: map['help_version'],
|
||
|
|
helpURL: map['help_url'],
|
||
|
|
phones: List.from(map['phones']),
|
||
|
|
email: map['email'],
|
||
|
|
deliveryPhone: map['delivery_phone'],
|
||
|
|
address: map['address'],
|
||
|
|
website: map['website'],
|
||
|
|
facebook: map['facebook'],
|
||
|
|
bankAccountInfo: map['bank_account_info'],
|
||
|
|
bankAccounts: bankAccounts);
|
||
|
|
}
|
||
|
|
|
||
|
|
Map<String, dynamic> toMap() {
|
||
|
|
return {
|
||
|
|
'terms': terms,
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
String helpFileName() {
|
||
|
|
return "help-v$helpVersion.zip";
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
String toString() {
|
||
|
|
return 'Setting{supportBuildNum:$supportBuildNum,about:$about,okEnergyId:$okEnergyId}';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
class Day {
|
||
|
|
int id;
|
||
|
|
String name;
|
||
|
|
bool isChecked = false;
|
||
|
|
Day({this.id, this.name, this.isChecked});
|
||
|
|
|
||
|
|
@override
|
||
|
|
String toString() {
|
||
|
|
return 'Day{id:$id,name:$name,isChecked:$isChecked}';
|
||
|
|
}
|
||
|
|
}
|