|
@@ -15,7 +15,7 @@ import 'package:table_calendar/table_calendar.dart';
|
|
import 'dart:async';
|
|
import 'dart:async';
|
|
import 'package:dartz/dartz.dart';
|
|
import 'package:dartz/dartz.dart';
|
|
import 'package:protobuf/protobuf.dart';
|
|
import 'package:protobuf/protobuf.dart';
|
|
-import 'package:fixnum/fixnum.dart' as $fixnum;
|
|
|
|
|
|
+
|
|
part 'date_cal_bloc.freezed.dart';
|
|
part 'date_cal_bloc.freezed.dart';
|
|
|
|
|
|
class DateCellCalendarBloc
|
|
class DateCellCalendarBloc
|
|
@@ -42,13 +42,13 @@ class DateCellCalendarBloc
|
|
emit(state.copyWith(focusedDay: focusedDay));
|
|
emit(state.copyWith(focusedDay: focusedDay));
|
|
},
|
|
},
|
|
didReceiveCellUpdate: (DateCellDataPB? cellData) {
|
|
didReceiveCellUpdate: (DateCellDataPB? cellData) {
|
|
- final calData = calDataFromCellData(cellData);
|
|
|
|
- final time = calData.foldRight(
|
|
|
|
|
|
+ final dateCellData = calDataFromCellData(cellData);
|
|
|
|
+ final time = dateCellData.foldRight(
|
|
"", (dateData, previous) => dateData.time ?? '');
|
|
"", (dateData, previous) => dateData.time ?? '');
|
|
- emit(state.copyWith(calData: calData, time: time));
|
|
|
|
|
|
+ emit(state.copyWith(dateCellData: dateCellData, time: time));
|
|
},
|
|
},
|
|
setIncludeTime: (includeTime) async {
|
|
setIncludeTime: (includeTime) async {
|
|
- await _updateTypeOption(emit, includeTime: includeTime);
|
|
|
|
|
|
+ await _updateDateData(emit, includeTime: includeTime);
|
|
},
|
|
},
|
|
setDateFormat: (dateFormat) async {
|
|
setDateFormat: (dateFormat) async {
|
|
await _updateTypeOption(emit, dateFormat: dateFormat);
|
|
await _updateTypeOption(emit, dateFormat: dateFormat);
|
|
@@ -57,14 +57,14 @@ class DateCellCalendarBloc
|
|
await _updateTypeOption(emit, timeFormat: timeFormat);
|
|
await _updateTypeOption(emit, timeFormat: timeFormat);
|
|
},
|
|
},
|
|
setTime: (time) async {
|
|
setTime: (time) async {
|
|
- if (state.calData.isSome()) {
|
|
|
|
|
|
+ if (state.dateCellData.isSome()) {
|
|
await _updateDateData(emit, time: time);
|
|
await _updateDateData(emit, time: time);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
didUpdateCalData:
|
|
didUpdateCalData:
|
|
- (Option<CalendarData> data, Option<String> timeFormatError) {
|
|
|
|
|
|
+ (Option<DateCellData> data, Option<String> timeFormatError) {
|
|
emit(state.copyWith(
|
|
emit(state.copyWith(
|
|
- calData: data, timeFormatError: timeFormatError));
|
|
|
|
|
|
+ dateCellData: data, timeFormatError: timeFormatError));
|
|
},
|
|
},
|
|
);
|
|
);
|
|
},
|
|
},
|
|
@@ -72,9 +72,13 @@ class DateCellCalendarBloc
|
|
}
|
|
}
|
|
|
|
|
|
Future<void> _updateDateData(Emitter<DateCellCalendarState> emit,
|
|
Future<void> _updateDateData(Emitter<DateCellCalendarState> emit,
|
|
- {DateTime? date, String? time}) {
|
|
|
|
- final CalendarData newDateData = state.calData.fold(
|
|
|
|
- () => CalendarData(date: date ?? DateTime.now(), time: time),
|
|
|
|
|
|
+ {DateTime? date, String? time, bool? includeTime}) {
|
|
|
|
+ final DateCellData newDateData = state.dateCellData.fold(
|
|
|
|
+ () => DateCellData(
|
|
|
|
+ date: date ?? DateTime.now(),
|
|
|
|
+ time: time,
|
|
|
|
+ includeTime: includeTime ?? false,
|
|
|
|
+ ),
|
|
(dateData) {
|
|
(dateData) {
|
|
var newDateData = dateData;
|
|
var newDateData = dateData;
|
|
if (date != null && !isSameDay(newDateData.date, date)) {
|
|
if (date != null && !isSameDay(newDateData.date, date)) {
|
|
@@ -84,6 +88,11 @@ class DateCellCalendarBloc
|
|
if (newDateData.time != time) {
|
|
if (newDateData.time != time) {
|
|
newDateData = newDateData.copyWith(time: time);
|
|
newDateData = newDateData.copyWith(time: time);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (includeTime != null && newDateData.includeTime != includeTime) {
|
|
|
|
+ newDateData = newDateData.copyWith(includeTime: includeTime);
|
|
|
|
+ }
|
|
|
|
+
|
|
return newDateData;
|
|
return newDateData;
|
|
},
|
|
},
|
|
);
|
|
);
|
|
@@ -92,15 +101,16 @@ class DateCellCalendarBloc
|
|
}
|
|
}
|
|
|
|
|
|
Future<void> _saveDateData(
|
|
Future<void> _saveDateData(
|
|
- Emitter<DateCellCalendarState> emit, CalendarData newCalData) async {
|
|
|
|
- if (state.calData == Some(newCalData)) {
|
|
|
|
|
|
+ Emitter<DateCellCalendarState> emit, DateCellData newCalData) async {
|
|
|
|
+ if (state.dateCellData == Some(newCalData)) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
updateCalData(
|
|
updateCalData(
|
|
- Option<CalendarData> calData, Option<String> timeFormatError) {
|
|
|
|
|
|
+ Option<DateCellData> dateCellData, Option<String> timeFormatError) {
|
|
if (!isClosed) {
|
|
if (!isClosed) {
|
|
- add(DateCellCalendarEvent.didUpdateCalData(calData, timeFormatError));
|
|
|
|
|
|
+ add(DateCellCalendarEvent.didUpdateCalData(
|
|
|
|
+ dateCellData, timeFormatError));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -110,7 +120,7 @@ class DateCellCalendarBloc
|
|
(err) {
|
|
(err) {
|
|
switch (ErrorCode.valueOf(err.code)!) {
|
|
switch (ErrorCode.valueOf(err.code)!) {
|
|
case ErrorCode.InvalidDateTimeFormat:
|
|
case ErrorCode.InvalidDateTimeFormat:
|
|
- updateCalData(state.calData, Some(timeFormatPrompt(err)));
|
|
|
|
|
|
+ updateCalData(state.dateCellData, Some(timeFormatPrompt(err)));
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
Log.error(err);
|
|
Log.error(err);
|
|
@@ -159,7 +169,6 @@ class DateCellCalendarBloc
|
|
Emitter<DateCellCalendarState> emit, {
|
|
Emitter<DateCellCalendarState> emit, {
|
|
DateFormat? dateFormat,
|
|
DateFormat? dateFormat,
|
|
TimeFormat? timeFormat,
|
|
TimeFormat? timeFormat,
|
|
- bool? includeTime,
|
|
|
|
}) async {
|
|
}) async {
|
|
state.dateTypeOptionPB.freeze();
|
|
state.dateTypeOptionPB.freeze();
|
|
final newDateTypeOption = state.dateTypeOptionPB.rebuild((typeOption) {
|
|
final newDateTypeOption = state.dateTypeOptionPB.rebuild((typeOption) {
|
|
@@ -170,10 +179,6 @@ class DateCellCalendarBloc
|
|
if (timeFormat != null) {
|
|
if (timeFormat != null) {
|
|
typeOption.timeFormat = timeFormat;
|
|
typeOption.timeFormat = timeFormat;
|
|
}
|
|
}
|
|
-
|
|
|
|
- if (includeTime != null) {
|
|
|
|
- typeOption.includeTime = includeTime;
|
|
|
|
- }
|
|
|
|
});
|
|
});
|
|
|
|
|
|
final result = await FieldBackendService.updateFieldTypeOption(
|
|
final result = await FieldBackendService.updateFieldTypeOption(
|
|
@@ -208,7 +213,7 @@ class DateCellCalendarEvent with _$DateCellCalendarEvent {
|
|
const factory DateCellCalendarEvent.didReceiveCellUpdate(
|
|
const factory DateCellCalendarEvent.didReceiveCellUpdate(
|
|
DateCellDataPB? data) = _DidReceiveCellUpdate;
|
|
DateCellDataPB? data) = _DidReceiveCellUpdate;
|
|
const factory DateCellCalendarEvent.didUpdateCalData(
|
|
const factory DateCellCalendarEvent.didUpdateCalData(
|
|
- Option<CalendarData> data, Option<String> timeFormatError) =
|
|
|
|
|
|
+ Option<DateCellData> data, Option<String> timeFormatError) =
|
|
_DidUpdateCalData;
|
|
_DidUpdateCalData;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -219,7 +224,7 @@ class DateCellCalendarState with _$DateCellCalendarState {
|
|
required CalendarFormat format,
|
|
required CalendarFormat format,
|
|
required DateTime focusedDay,
|
|
required DateTime focusedDay,
|
|
required Option<String> timeFormatError,
|
|
required Option<String> timeFormatError,
|
|
- required Option<CalendarData> calData,
|
|
|
|
|
|
+ required Option<DateCellData> dateCellData,
|
|
required String? time,
|
|
required String? time,
|
|
required String timeHintText,
|
|
required String timeHintText,
|
|
}) = _DateCellCalendarState;
|
|
}) = _DateCellCalendarState;
|
|
@@ -228,15 +233,15 @@ class DateCellCalendarState with _$DateCellCalendarState {
|
|
DateTypeOptionPB dateTypeOptionPB,
|
|
DateTypeOptionPB dateTypeOptionPB,
|
|
DateCellDataPB? cellData,
|
|
DateCellDataPB? cellData,
|
|
) {
|
|
) {
|
|
- Option<CalendarData> calData = calDataFromCellData(cellData);
|
|
|
|
|
|
+ Option<DateCellData> dateCellData = calDataFromCellData(cellData);
|
|
final time =
|
|
final time =
|
|
- calData.foldRight("", (dateData, previous) => dateData.time ?? '');
|
|
|
|
|
|
+ dateCellData.foldRight("", (dateData, previous) => dateData.time ?? '');
|
|
return DateCellCalendarState(
|
|
return DateCellCalendarState(
|
|
dateTypeOptionPB: dateTypeOptionPB,
|
|
dateTypeOptionPB: dateTypeOptionPB,
|
|
format: CalendarFormat.month,
|
|
format: CalendarFormat.month,
|
|
focusedDay: DateTime.now(),
|
|
focusedDay: DateTime.now(),
|
|
time: time,
|
|
time: time,
|
|
- calData: calData,
|
|
|
|
|
|
+ dateCellData: dateCellData,
|
|
timeFormatError: none(),
|
|
timeFormatError: none(),
|
|
timeHintText: _timeHintText(dateTypeOptionPB),
|
|
timeHintText: _timeHintText(dateTypeOptionPB),
|
|
);
|
|
);
|
|
@@ -249,30 +254,30 @@ String _timeHintText(DateTypeOptionPB typeOption) {
|
|
return LocaleKeys.document_date_timeHintTextInTwelveHour.tr();
|
|
return LocaleKeys.document_date_timeHintTextInTwelveHour.tr();
|
|
case TimeFormat.TwentyFourHour:
|
|
case TimeFormat.TwentyFourHour:
|
|
return LocaleKeys.document_date_timeHintTextInTwentyFourHour.tr();
|
|
return LocaleKeys.document_date_timeHintTextInTwentyFourHour.tr();
|
|
|
|
+ default:
|
|
|
|
+ return "";
|
|
}
|
|
}
|
|
- return "";
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-Option<CalendarData> calDataFromCellData(DateCellDataPB? cellData) {
|
|
|
|
|
|
+Option<DateCellData> calDataFromCellData(DateCellDataPB? cellData) {
|
|
String? time = timeFromCellData(cellData);
|
|
String? time = timeFromCellData(cellData);
|
|
- Option<CalendarData> calData = none();
|
|
|
|
|
|
+ Option<DateCellData> dateData = none();
|
|
if (cellData != null) {
|
|
if (cellData != null) {
|
|
final timestamp = cellData.timestamp * 1000;
|
|
final timestamp = cellData.timestamp * 1000;
|
|
final date = DateTime.fromMillisecondsSinceEpoch(timestamp.toInt());
|
|
final date = DateTime.fromMillisecondsSinceEpoch(timestamp.toInt());
|
|
- calData = Some(CalendarData(date: date, time: time));
|
|
|
|
|
|
+ dateData = Some(DateCellData(
|
|
|
|
+ date: date,
|
|
|
|
+ time: time,
|
|
|
|
+ includeTime: cellData.includeTime,
|
|
|
|
+ ));
|
|
}
|
|
}
|
|
- return calData;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-$fixnum.Int64 timestampFromDateTime(DateTime dateTime) {
|
|
|
|
- final timestamp = (dateTime.millisecondsSinceEpoch ~/ 1000);
|
|
|
|
- return $fixnum.Int64(timestamp);
|
|
|
|
|
|
+ return dateData;
|
|
}
|
|
}
|
|
|
|
|
|
String? timeFromCellData(DateCellDataPB? cellData) {
|
|
String? timeFromCellData(DateCellDataPB? cellData) {
|
|
- String? time;
|
|
|
|
- if (cellData?.hasTime() ?? false) {
|
|
|
|
- time = cellData?.time;
|
|
|
|
|
|
+ if (cellData == null || !cellData.hasTime()) {
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
- return time;
|
|
|
|
|
|
+
|
|
|
|
+ return cellData.time;
|
|
}
|
|
}
|