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")));
|
type: MediaType.parse("application/pdf")));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PostKind.COUNTDOWN:
|
||||||
|
request.addInt(
|
||||||
|
"time-end", (post.timeEnd.millisecondsSinceEpoch / 1000).floor());
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw Exception("Unsupported post type :" + post.kind.toString());
|
throw Exception("Unsupported post type :" + post.kind.toString());
|
||||||
break;
|
break;
|
||||||
|
@ -17,6 +17,7 @@ class NewPost {
|
|||||||
final File image;
|
final File image;
|
||||||
final List<int> pdf;
|
final List<int> pdf;
|
||||||
final PostKind kind;
|
final PostKind kind;
|
||||||
|
final DateTime timeEnd;
|
||||||
|
|
||||||
const NewPost({
|
const NewPost({
|
||||||
@required this.target,
|
@required this.target,
|
||||||
@ -26,11 +27,13 @@ class NewPost {
|
|||||||
@required this.kind,
|
@required this.kind,
|
||||||
@required this.image,
|
@required this.image,
|
||||||
@required this.pdf,
|
@required this.pdf,
|
||||||
|
@required this.timeEnd,
|
||||||
}) : assert(target != null),
|
}) : assert(target != null),
|
||||||
assert(targetID != null),
|
assert(targetID != null),
|
||||||
assert(visibility != null),
|
assert(visibility != null),
|
||||||
assert(content != null),
|
assert(content != null),
|
||||||
assert(kind != PostKind.TEXT || content.length > 3),
|
assert(kind != PostKind.TEXT || content.length > 3),
|
||||||
assert(kind != PostKind.IMAGE || image != null),
|
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;
|
PostVisibilityLevel _postVisibilityLevel;
|
||||||
File _postImage;
|
File _postImage;
|
||||||
List<int> _postPDF;
|
List<int> _postPDF;
|
||||||
|
DateTime _timeEnd;
|
||||||
|
|
||||||
bool get hasImage => _postImage != null;
|
bool get hasImage => _postImage != null;
|
||||||
|
|
||||||
bool get hasPDF => _postPDF != null;
|
bool get hasPDF => _postPDF != null;
|
||||||
|
|
||||||
|
bool get hasTimeEnd => _timeEnd != null;
|
||||||
|
|
||||||
bool get canSubmitForm =>
|
bool get canSubmitForm =>
|
||||||
!_isCreating && _postTextController.text.length > 5 ||
|
!_isCreating && _postTextController.text.length > 5 ||
|
||||||
postKind != PostKind.TEXT;
|
postKind != PostKind.TEXT;
|
||||||
@ -63,6 +66,8 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
|||||||
return PostKind.IMAGE;
|
return PostKind.IMAGE;
|
||||||
else if (hasPDF)
|
else if (hasPDF)
|
||||||
return PostKind.PDF;
|
return PostKind.PDF;
|
||||||
|
else if (hasTimeEnd)
|
||||||
|
return PostKind.COUNTDOWN;
|
||||||
else
|
else
|
||||||
return PostKind.TEXT;
|
return PostKind.TEXT;
|
||||||
}
|
}
|
||||||
@ -116,6 +121,13 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
|||||||
onTap: _pickPDFForPost,
|
onTap: _pickPDFForPost,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Add countdown timer
|
||||||
|
_PostOptionWidget(
|
||||||
|
icon: Icons.timer,
|
||||||
|
selected: postKind == PostKind.COUNTDOWN,
|
||||||
|
onTap: _pickCountdownTime,
|
||||||
|
),
|
||||||
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Container(),
|
child: Container(),
|
||||||
),
|
),
|
||||||
@ -174,6 +186,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
_postImage = null;
|
_postImage = null;
|
||||||
_postPDF = 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
|
/// Submit new post
|
||||||
Future<void> _submitForm() async {
|
Future<void> _submitForm() async {
|
||||||
if (!canSubmitForm)
|
if (!canSubmitForm)
|
||||||
@ -227,6 +275,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
|||||||
kind: postKind,
|
kind: postKind,
|
||||||
image: _postImage,
|
image: _postImage,
|
||||||
pdf: _postPDF,
|
pdf: _postPDF,
|
||||||
|
timeEnd: _timeEnd,
|
||||||
));
|
));
|
||||||
setState(() => _isCreating = false);
|
setState(() => _isCreating = false);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user