mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Can create countdown timers
This commit is contained in:
parent
60c135bf01
commit
ba07247ec4
@ -153,6 +153,11 @@ class PostsHelper {
|
||||
type: MediaType.parse("application/pdf")));
|
||||
break;
|
||||
|
||||
case PostKind.COUNTDOWN:
|
||||
request.addInt(
|
||||
"time-end", (post.timeEnd.millisecondsSinceEpoch / 1000).floor());
|
||||
break;
|
||||
|
||||
default:
|
||||
throw Exception("Unsupported post type :" + post.kind.toString());
|
||||
break;
|
||||
|
@ -17,6 +17,7 @@ class NewPost {
|
||||
final File image;
|
||||
final List<int> pdf;
|
||||
final PostKind kind;
|
||||
final DateTime timeEnd;
|
||||
|
||||
const NewPost({
|
||||
@required this.target,
|
||||
@ -26,11 +27,13 @@ class NewPost {
|
||||
@required this.kind,
|
||||
@required this.image,
|
||||
@required this.pdf,
|
||||
@required this.timeEnd,
|
||||
}) : assert(target != null),
|
||||
assert(targetID != null),
|
||||
assert(visibility != null),
|
||||
assert(content != null),
|
||||
assert(kind != PostKind.TEXT || content.length > 3),
|
||||
assert(kind != PostKind.IMAGE || image != null),
|
||||
assert(kind != PostKind.PDF || pdf != null);
|
||||
assert(kind != PostKind.PDF || pdf != null),
|
||||
assert(kind != PostKind.COUNTDOWN || timeEnd != null);
|
||||
}
|
||||
|
@ -49,11 +49,14 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
PostVisibilityLevel _postVisibilityLevel;
|
||||
File _postImage;
|
||||
List<int> _postPDF;
|
||||
DateTime _timeEnd;
|
||||
|
||||
bool get hasImage => _postImage != null;
|
||||
|
||||
bool get hasPDF => _postPDF != null;
|
||||
|
||||
bool get hasTimeEnd => _timeEnd != null;
|
||||
|
||||
bool get canSubmitForm =>
|
||||
!_isCreating && _postTextController.text.length > 5 ||
|
||||
postKind != PostKind.TEXT;
|
||||
@ -63,6 +66,8 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
return PostKind.IMAGE;
|
||||
else if (hasPDF)
|
||||
return PostKind.PDF;
|
||||
else if (hasTimeEnd)
|
||||
return PostKind.COUNTDOWN;
|
||||
else
|
||||
return PostKind.TEXT;
|
||||
}
|
||||
@ -116,6 +121,13 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
onTap: _pickPDFForPost,
|
||||
),
|
||||
|
||||
// Add countdown timer
|
||||
_PostOptionWidget(
|
||||
icon: Icons.timer,
|
||||
selected: postKind == PostKind.COUNTDOWN,
|
||||
onTap: _pickCountdownTime,
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: Container(),
|
||||
),
|
||||
@ -174,6 +186,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
setState(() {
|
||||
_postImage = null;
|
||||
_postPDF = null;
|
||||
_timeEnd = null;
|
||||
});
|
||||
}
|
||||
|
||||
@ -211,6 +224,41 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Pick countdown time
|
||||
Future<void> _pickCountdownTime() async {
|
||||
final initialDate =
|
||||
_timeEnd == null ? DateTime.now().add(Duration(minutes: 1)) : _timeEnd;
|
||||
|
||||
// Pick date
|
||||
final newDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: initialDate,
|
||||
firstDate: DateTime.now(),
|
||||
lastDate: DateTime.now().add(Duration(days: 5000)));
|
||||
|
||||
if (newDate == null) return;
|
||||
|
||||
// Pick time
|
||||
final newTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.fromDateTime(initialDate),
|
||||
);
|
||||
|
||||
if (newTime == null) return;
|
||||
|
||||
// Apply new selection
|
||||
_resetPostSelection();
|
||||
setState(() {
|
||||
_timeEnd = newDate.add(Duration(
|
||||
hours: newTime.hour - newDate.hour,
|
||||
minutes: newTime.minute - newDate.minute));
|
||||
|
||||
print(newDate.toString());
|
||||
print(newTime);
|
||||
print(_timeEnd);
|
||||
});
|
||||
}
|
||||
|
||||
/// Submit new post
|
||||
Future<void> _submitForm() async {
|
||||
if (!canSubmitForm)
|
||||
@ -227,6 +275,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
kind: postKind,
|
||||
image: _postImage,
|
||||
pdf: _postPDF,
|
||||
timeEnd: _timeEnd,
|
||||
));
|
||||
setState(() => _isCreating = false);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user