mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-25 22:39:22 +00:00
Can create weblink posts
This commit is contained in:
parent
d79e132420
commit
622258802b
@ -146,6 +146,10 @@ class PostsHelper {
|
|||||||
request.addFile("image", post.image);
|
request.addFile("image", post.image);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PostKind.WEB_LINK:
|
||||||
|
request.addString("url", post.url);
|
||||||
|
break;
|
||||||
|
|
||||||
case PostKind.PDF:
|
case PostKind.PDF:
|
||||||
request.addBytesFile(
|
request.addBytesFile(
|
||||||
"pdf",
|
"pdf",
|
||||||
|
@ -26,6 +26,7 @@ class NewPost {
|
|||||||
final PostVisibilityLevel visibility;
|
final PostVisibilityLevel visibility;
|
||||||
final String content;
|
final String content;
|
||||||
final File image;
|
final File image;
|
||||||
|
final String url;
|
||||||
final List<int> pdf;
|
final List<int> pdf;
|
||||||
final PostKind kind;
|
final PostKind kind;
|
||||||
final DateTime timeEnd;
|
final DateTime timeEnd;
|
||||||
@ -38,6 +39,7 @@ class NewPost {
|
|||||||
@required this.content,
|
@required this.content,
|
||||||
@required this.kind,
|
@required this.kind,
|
||||||
@required this.image,
|
@required this.image,
|
||||||
|
@required this.url,
|
||||||
@required this.pdf,
|
@required this.pdf,
|
||||||
@required this.timeEnd,
|
@required this.timeEnd,
|
||||||
@required this.survey,
|
@required this.survey,
|
||||||
@ -47,6 +49,7 @@ class NewPost {
|
|||||||
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.WEB_LINK || url != null),
|
||||||
assert(kind != PostKind.PDF || pdf != null),
|
assert(kind != PostKind.PDF || pdf != null),
|
||||||
assert(kind != PostKind.COUNTDOWN || timeEnd != null),
|
assert(kind != PostKind.COUNTDOWN || timeEnd != null),
|
||||||
assert(kind != PostKind.SURVEY || survey != null);
|
assert(kind != PostKind.SURVEY || survey != null);
|
||||||
|
86
lib/ui/dialogs/url_dialog.dart
Normal file
86
lib/ui/dialogs/url_dialog.dart
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
import 'package:comunic/utils/input_utils.dart';
|
||||||
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// Ask the user to enter an URL
|
||||||
|
///
|
||||||
|
/// @author Pierre Hubert
|
||||||
|
|
||||||
|
/// Ask the user to enter an URL
|
||||||
|
Future<String> showInputURLDialog({
|
||||||
|
@required BuildContext context,
|
||||||
|
@required String title,
|
||||||
|
String initialURL,
|
||||||
|
}) async {
|
||||||
|
return await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (c) => _InputURLDialog(
|
||||||
|
title: title,
|
||||||
|
initialURL: initialURL,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _InputURLDialog extends StatefulWidget {
|
||||||
|
final String title;
|
||||||
|
final String initialURL;
|
||||||
|
|
||||||
|
const _InputURLDialog({
|
||||||
|
Key key,
|
||||||
|
@required this.title,
|
||||||
|
@required this.initialURL,
|
||||||
|
}) : assert(title != null),
|
||||||
|
super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
__InputURLDialogState createState() => __InputURLDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class __InputURLDialogState extends State<_InputURLDialog> {
|
||||||
|
TextEditingController _controller;
|
||||||
|
|
||||||
|
bool get _isValid =>
|
||||||
|
_controller.text.isNotEmpty && validateUrl(_controller.text);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_controller = new TextEditingController(text: widget.initialURL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(widget.title),
|
||||||
|
content: TextField(
|
||||||
|
controller: _controller,
|
||||||
|
onChanged: (s) => setState(() {}),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
icon: Icon(Icons.link),
|
||||||
|
alignLabelWithHint: true,
|
||||||
|
labelText: "http://...",
|
||||||
|
errorText: _controller.text.isNotEmpty && !_isValid
|
||||||
|
? tr("Invalid URL!")
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: <Widget>[
|
||||||
|
// Cancel
|
||||||
|
MaterialButton(
|
||||||
|
child: Text(tr("Cancel").toUpperCase()),
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
textColor: Colors.red,
|
||||||
|
),
|
||||||
|
|
||||||
|
// Confirm
|
||||||
|
MaterialButton(
|
||||||
|
child: Text(tr("Confirm").toUpperCase()),
|
||||||
|
onPressed: _isValid
|
||||||
|
? () => Navigator.of(context).pop(_controller.text)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ import 'package:comunic/enums/post_visibility_level.dart';
|
|||||||
import 'package:comunic/helpers/posts_helper.dart';
|
import 'package:comunic/helpers/posts_helper.dart';
|
||||||
import 'package:comunic/models/new_post.dart';
|
import 'package:comunic/models/new_post.dart';
|
||||||
import 'package:comunic/ui/dialogs/new_survey_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/files_utils.dart';
|
||||||
import 'package:comunic/utils/intl_utils.dart';
|
import 'package:comunic/utils/intl_utils.dart';
|
||||||
import 'package:comunic/utils/post_utils.dart';
|
import 'package:comunic/utils/post_utils.dart';
|
||||||
@ -49,12 +50,15 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
|||||||
final TextEditingController _postTextController = TextEditingController();
|
final TextEditingController _postTextController = TextEditingController();
|
||||||
PostVisibilityLevel _postVisibilityLevel;
|
PostVisibilityLevel _postVisibilityLevel;
|
||||||
File _postImage;
|
File _postImage;
|
||||||
|
String _postURL;
|
||||||
List<int> _postPDF;
|
List<int> _postPDF;
|
||||||
DateTime _timeEnd;
|
DateTime _timeEnd;
|
||||||
NewSurvey _postSurvey;
|
NewSurvey _postSurvey;
|
||||||
|
|
||||||
bool get hasImage => _postImage != null;
|
bool get hasImage => _postImage != null;
|
||||||
|
|
||||||
|
bool get hasURL => _postURL != null;
|
||||||
|
|
||||||
bool get hasPDF => _postPDF != null;
|
bool get hasPDF => _postPDF != null;
|
||||||
|
|
||||||
bool get hasTimeEnd => _timeEnd != null;
|
bool get hasTimeEnd => _timeEnd != null;
|
||||||
@ -70,6 +74,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 (hasURL)
|
||||||
|
return PostKind.WEB_LINK;
|
||||||
else if (hasTimeEnd)
|
else if (hasTimeEnd)
|
||||||
return PostKind.COUNTDOWN;
|
return PostKind.COUNTDOWN;
|
||||||
else if (hasSurvey)
|
else if (hasSurvey)
|
||||||
@ -125,6 +131,13 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
|||||||
onTap: _pickImageForPost,
|
onTap: _pickImageForPost,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Web link
|
||||||
|
_PostOptionWidget(
|
||||||
|
icon: Icons.link,
|
||||||
|
selected: postKind == PostKind.WEB_LINK,
|
||||||
|
onTap: _pickURLForPost,
|
||||||
|
),
|
||||||
|
|
||||||
// Include PDF button
|
// Include PDF button
|
||||||
_PostOptionWidget(
|
_PostOptionWidget(
|
||||||
icon: Icons.picture_as_pdf,
|
icon: Icons.picture_as_pdf,
|
||||||
@ -150,6 +163,8 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
Container(width: 20),
|
||||||
|
|
||||||
// Post visibility level
|
// Post visibility level
|
||||||
_PostOptionWidget(
|
_PostOptionWidget(
|
||||||
icon: PostVisibilityLevelsMapIcons[_postVisibilityLevel],
|
icon: PostVisibilityLevelsMapIcons[_postVisibilityLevel],
|
||||||
@ -203,6 +218,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
|||||||
void _resetPostSelection() {
|
void _resetPostSelection() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_postImage = null;
|
_postImage = null;
|
||||||
|
_postURL = null;
|
||||||
_postPDF = null;
|
_postPDF = null;
|
||||||
_timeEnd = null;
|
_timeEnd = null;
|
||||||
_postSurvey = 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
|
/// Pick a PDF for the new post
|
||||||
Future<void> _pickPDFForPost() async {
|
Future<void> _pickPDFForPost() async {
|
||||||
try {
|
try {
|
||||||
@ -304,6 +337,7 @@ class _PostCreateFormWidgetState extends State<PostCreateFormWidget> {
|
|||||||
content: _postTextController.text,
|
content: _postTextController.text,
|
||||||
kind: postKind,
|
kind: postKind,
|
||||||
image: _postImage,
|
image: _postImage,
|
||||||
|
url: _postURL,
|
||||||
pdf: _postPDF,
|
pdf: _postPDF,
|
||||||
timeEnd: _timeEnd,
|
timeEnd: _timeEnd,
|
||||||
survey: _postSurvey));
|
survey: _postSurvey));
|
||||||
|
Loading…
Reference in New Issue
Block a user