mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Can create YouTube posts
This commit is contained in:
@ -5,8 +5,9 @@ import 'package:comunic/enums/post_target.dart';
|
||||
import 'package:comunic/enums/post_visibility_level.dart';
|
||||
import 'package:comunic/helpers/posts_helper.dart';
|
||||
import 'package:comunic/models/new_post.dart';
|
||||
import 'package:comunic/ui/dialogs/input_url_dialog.dart';
|
||||
import 'package:comunic/ui/dialogs/input_youtube_link_dialog.dart';
|
||||
import 'package:comunic/ui/dialogs/new_survey_dialog.dart';
|
||||
import 'package:comunic/ui/dialogs/url_dialog.dart';
|
||||
import 'package:comunic/utils/files_utils.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/post_utils.dart';
|
||||
@ -54,6 +55,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
List<int> _postPDF;
|
||||
DateTime _timeEnd;
|
||||
NewSurvey _postSurvey;
|
||||
String _youtubeID;
|
||||
|
||||
bool get hasImage => _postImage != null;
|
||||
|
||||
@ -65,6 +67,8 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
|
||||
bool get hasSurvey => _postSurvey != null;
|
||||
|
||||
bool get hasYoutTubeID => _youtubeID != null;
|
||||
|
||||
bool get canSubmitForm =>
|
||||
!_isCreating && _postTextController.text.length > 5 ||
|
||||
postKind != PostKind.TEXT;
|
||||
@ -80,6 +84,8 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
return PostKind.COUNTDOWN;
|
||||
else if (hasSurvey)
|
||||
return PostKind.SURVEY;
|
||||
else if (hasYoutTubeID)
|
||||
return PostKind.YOUTUBE;
|
||||
else
|
||||
return PostKind.TEXT;
|
||||
}
|
||||
@ -158,6 +164,13 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
selected: postKind == PostKind.SURVEY,
|
||||
onTap: _pickSurvey,
|
||||
),
|
||||
|
||||
// Specify YouTube video ID
|
||||
_PostOptionWidget(
|
||||
icon: Icons.ondemand_video,
|
||||
selected: postKind == PostKind.YOUTUBE,
|
||||
onTap: _pickYouTubeVideo,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -222,6 +235,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
_postPDF = null;
|
||||
_timeEnd = null;
|
||||
_postSurvey = null;
|
||||
_youtubeID = null;
|
||||
});
|
||||
}
|
||||
|
||||
@ -322,6 +336,20 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
});
|
||||
}
|
||||
|
||||
/// Pick a new YouTube video
|
||||
Future<void> _pickYouTubeVideo() async {
|
||||
|
||||
final youtubeID = await showInputYouTubeIDDialog(context, _youtubeID);
|
||||
|
||||
if (youtubeID == null) return;
|
||||
|
||||
_resetPostSelection();
|
||||
setState(() {
|
||||
_youtubeID = youtubeID;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/// Submit new post
|
||||
Future<void> _submitForm() async {
|
||||
if (!canSubmitForm)
|
||||
@ -331,16 +359,18 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
||||
|
||||
try {
|
||||
await _postHelper.createPost(NewPost(
|
||||
target: widget.postTarget,
|
||||
targetID: widget.targetID,
|
||||
visibility: _postVisibilityLevel,
|
||||
content: _postTextController.text,
|
||||
kind: postKind,
|
||||
image: _postImage,
|
||||
url: _postURL,
|
||||
pdf: _postPDF,
|
||||
timeEnd: _timeEnd,
|
||||
survey: _postSurvey));
|
||||
target: widget.postTarget,
|
||||
targetID: widget.targetID,
|
||||
visibility: _postVisibilityLevel,
|
||||
content: _postTextController.text,
|
||||
kind: postKind,
|
||||
image: _postImage,
|
||||
url: _postURL,
|
||||
pdf: _postPDF,
|
||||
timeEnd: _timeEnd,
|
||||
survey: _postSurvey,
|
||||
youtubeId: _youtubeID,
|
||||
));
|
||||
setState(() => _isCreating = false);
|
||||
|
||||
showSimpleSnack(context, tr("The post has been successfully created!"));
|
||||
|
Reference in New Issue
Block a user