1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 08:15:16 +00:00

Can create weblink posts

This commit is contained in:
2020-04-25 14:38:15 +02:00
parent d79e132420
commit 622258802b
4 changed files with 127 additions and 0 deletions

View File

@ -6,6 +6,7 @@ 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/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';
@ -49,12 +50,15 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
final TextEditingController _postTextController = TextEditingController();
PostVisibilityLevel _postVisibilityLevel;
File _postImage;
String _postURL;
List<int> _postPDF;
DateTime _timeEnd;
NewSurvey _postSurvey;
bool get hasImage => _postImage != null;
bool get hasURL => _postURL != null;
bool get hasPDF => _postPDF != null;
bool get hasTimeEnd => _timeEnd != null;
@ -70,6 +74,8 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
return PostKind.IMAGE;
else if (hasPDF)
return PostKind.PDF;
else if (hasURL)
return PostKind.WEB_LINK;
else if (hasTimeEnd)
return PostKind.COUNTDOWN;
else if (hasSurvey)
@ -125,6 +131,13 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
onTap: _pickImageForPost,
),
// Web link
_PostOptionWidget(
icon: Icons.link,
selected: postKind == PostKind.WEB_LINK,
onTap: _pickURLForPost,
),
// Include PDF button
_PostOptionWidget(
icon: Icons.picture_as_pdf,
@ -150,6 +163,8 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
),
),
Container(width: 20),
// Post visibility level
_PostOptionWidget(
icon: PostVisibilityLevelsMapIcons[_postVisibilityLevel],
@ -203,6 +218,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
void _resetPostSelection() {
setState(() {
_postImage = null;
_postURL = null;
_postPDF = null;
_timeEnd = null;
_postSurvey = null;
@ -222,6 +238,23 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
});
}
/// Choose a new URL for the post
Future<void> _pickURLForPost() async {
final url = await showInputURLDialog(
context: context,
title: tr("Specify URL"),
initialURL: _postURL,
);
if (url == null) return;
_resetPostSelection();
setState(() {
_postURL = url;
});
}
/// Pick a PDF for the new post
Future<void> _pickPDFForPost() async {
try {
@ -304,6 +337,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
content: _postTextController.text,
kind: postKind,
image: _postImage,
url: _postURL,
pdf: _postPDF,
timeEnd: _timeEnd,
survey: _postSurvey));