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:
28
lib/ui/dialogs/input_url_dialog.dart
Normal file
28
lib/ui/dialogs/input_url_dialog.dart
Normal file
@ -0,0 +1,28 @@
|
||||
import 'package:comunic/ui/dialogs/single_input_dialog.dart';
|
||||
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) => SingleInputDialog(
|
||||
title: title,
|
||||
icon: Icons.link,
|
||||
initialValue: initialURL,
|
||||
label: "http://...",
|
||||
checkInput: (s) => validateUrl(s),
|
||||
errorMessage: tr("Invalid URL!"),
|
||||
),
|
||||
);
|
||||
}
|
29
lib/ui/dialogs/input_youtube_link_dialog.dart
Normal file
29
lib/ui/dialogs/input_youtube_link_dialog.dart
Normal file
@ -0,0 +1,29 @@
|
||||
import 'package:comunic/ui/dialogs/single_input_dialog.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Add YouTube link dialog
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
/// Ask the user to input a YouTube ID
|
||||
Future<String> showInputYouTubeIDDialog(
|
||||
BuildContext context, String initialID) async {
|
||||
final value = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (b) => SingleInputDialog(
|
||||
title: tr("Input YouTube URL"),
|
||||
icon: Icons.ondemand_video,
|
||||
initialValue: initialID == null
|
||||
? null
|
||||
: "https://www.youtube.com/watch/?v=" + initialID,
|
||||
label: tr("https://www.youtube.com/watch/?v="),
|
||||
checkInput: (s) => RegExp(r'watch\/\?v=[\w\-\_]+').hasMatch(s),
|
||||
errorMessage: tr("Invalid YouTube link!"),
|
||||
));
|
||||
|
||||
if (value == null) return null;
|
||||
|
||||
return value.split("v=")[1].split("&")[0].split("#")[0];
|
||||
}
|
@ -1,52 +1,45 @@
|
||||
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 {
|
||||
class SingleInputDialog extends StatefulWidget {
|
||||
final String title;
|
||||
final String initialURL;
|
||||
final IconData icon;
|
||||
final String initialValue;
|
||||
final String label;
|
||||
final bool Function(String) checkInput;
|
||||
final String errorMessage;
|
||||
|
||||
const _InputURLDialog({
|
||||
const SingleInputDialog({
|
||||
Key key,
|
||||
@required this.title,
|
||||
@required this.initialURL,
|
||||
@required this.icon,
|
||||
@required this.initialValue,
|
||||
@required this.label,
|
||||
@required this.checkInput,
|
||||
@required this.errorMessage,
|
||||
}) : assert(title != null),
|
||||
assert(icon != null),
|
||||
assert(label != null),
|
||||
assert(checkInput != null),
|
||||
assert(errorMessage != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
__InputURLDialogState createState() => __InputURLDialogState();
|
||||
}
|
||||
|
||||
class __InputURLDialogState extends State<_InputURLDialog> {
|
||||
class __InputURLDialogState extends State<SingleInputDialog> {
|
||||
TextEditingController _controller;
|
||||
|
||||
bool get _isValid =>
|
||||
_controller.text.isNotEmpty && validateUrl(_controller.text);
|
||||
_controller.text.isNotEmpty && widget.checkInput(_controller.text);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = new TextEditingController(text: widget.initialURL);
|
||||
_controller = new TextEditingController(text: widget.initialValue);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -57,11 +50,11 @@ class __InputURLDialogState extends State<_InputURLDialog> {
|
||||
controller: _controller,
|
||||
onChanged: (s) => setState(() {}),
|
||||
decoration: InputDecoration(
|
||||
icon: Icon(Icons.link),
|
||||
icon: Icon(widget.icon),
|
||||
alignLabelWithHint: true,
|
||||
labelText: "http://...",
|
||||
labelText: widget.label,
|
||||
errorText: _controller.text.isNotEmpty && !_isValid
|
||||
? tr("Invalid URL!")
|
||||
? widget.errorMessage
|
||||
: null,
|
||||
),
|
||||
),
|
Reference in New Issue
Block a user