mirror of
https://gitlab.com/openlp/openlp-mobile-remote.git
synced 2024-12-22 03:42:48 +00:00
some changes in display options
This commit is contained in:
parent
7e4c623ae2
commit
419302a77b
@ -26,6 +26,8 @@ import 'package:meta/meta.dart';
|
||||
|
||||
import '../network/api.dart' as api;
|
||||
|
||||
enum DisplayOptionsState { none, success, failure }
|
||||
|
||||
@immutable
|
||||
abstract class SetDisplayTypeEvent extends Equatable {
|
||||
final String type;
|
||||
@ -49,11 +51,10 @@ class SetDisplayTypeShowEvent extends SetDisplayTypeEvent {
|
||||
SetDisplayTypeShowEvent() : super('show');
|
||||
}
|
||||
|
||||
class DisplayOptionDialogBloc extends Bloc<SetDisplayTypeEvent, void> {
|
||||
class DisplayOptionsDialogBloc
|
||||
extends Bloc<SetDisplayTypeEvent, DisplayOptionsState> {
|
||||
@override
|
||||
void get initialState {
|
||||
return;
|
||||
}
|
||||
DisplayOptionsState get initialState => DisplayOptionsState.none;
|
||||
|
||||
void setBlankScreen() {
|
||||
dispatch(SetDisplayTypeBlankEvent());
|
||||
@ -72,7 +73,14 @@ class DisplayOptionDialogBloc extends Bloc<SetDisplayTypeEvent, void> {
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<void> mapEventToState(SetDisplayTypeEvent event) async* {
|
||||
api.setDisplayState(event.type);
|
||||
Stream<DisplayOptionsState> mapEventToState(
|
||||
SetDisplayTypeEvent event) async* {
|
||||
try {
|
||||
await api.setDisplayState(event.type);
|
||||
yield DisplayOptionsState.success;
|
||||
} catch (e) {
|
||||
yield DisplayOptionsState.failure;
|
||||
}
|
||||
yield DisplayOptionsState.none;
|
||||
}
|
||||
}
|
||||
|
@ -55,84 +55,88 @@ Uri _uri(String path, {Map<String, String> queryParams}) {
|
||||
);
|
||||
}
|
||||
|
||||
Future<http.Response> _get(String path,
|
||||
{Map<String, String> queryParams}) async {
|
||||
Future<String> _get(String path, {Map<String, String> queryParams}) {
|
||||
Uri uri = _uri(path, queryParams: queryParams);
|
||||
final response = await http.get(uri, headers: _headers());
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<PollState> pollState() async {
|
||||
final response = await _get('api/poll');
|
||||
if (response.statusCode != 200) {
|
||||
return null;
|
||||
}
|
||||
final jsonResponse = convert.jsonDecode(response.body);
|
||||
return PollState.fromJson(jsonResponse['results']);
|
||||
}
|
||||
|
||||
Future<List<SearchResult>> search(Plugin plugin, String query) async {
|
||||
final response = await _get('api/${plugin.id}/search', queryParams: {
|
||||
'data': '{"request":{"text":"$query"}}',
|
||||
return http.get(uri, headers: _headers()).then((response) {
|
||||
if (response.statusCode == 200) {
|
||||
return response.body;
|
||||
}
|
||||
throw Exception('Invalid request.');
|
||||
});
|
||||
if (response.statusCode != 200) {
|
||||
return [];
|
||||
}
|
||||
final jsonResponse = convert.jsonDecode(response.body);
|
||||
return (jsonResponse['results']['items'] as List)
|
||||
.map((i) => SearchResult.fromJson(i))
|
||||
.toList();
|
||||
// final response = await http.get(uri, headers: _headers());
|
||||
// return response;
|
||||
}
|
||||
|
||||
Future<void> projectItem(Plugin plugin, String itemId) async {
|
||||
final response = await _get('api/${plugin.id}/live', queryParams: {
|
||||
'data': '{"request": {"id": $itemId}}',
|
||||
// Future<PollState> pollState() async {
|
||||
// final response = await _get('api/poll');
|
||||
// if (response.statusCode != 200) {
|
||||
// return null;
|
||||
// }
|
||||
// final jsonResponse = convert.jsonDecode(response.body);
|
||||
// return PollState.fromJson(jsonResponse['results']);
|
||||
// }
|
||||
|
||||
// Future<List<SearchResult>> search(Plugin plugin, String query) async {
|
||||
// final response = await _get('api/${plugin.id}/search', queryParams: {
|
||||
// 'data': '{"request":{"text":"$query"}}',
|
||||
// });
|
||||
// if (response.statusCode != 200) {
|
||||
// return [];
|
||||
// }
|
||||
// final jsonResponse = convert.jsonDecode(response.body);
|
||||
// return (jsonResponse['results']['items'] as List)
|
||||
// .map((i) => SearchResult.fromJson(i))
|
||||
// .toList();
|
||||
// }
|
||||
|
||||
// Future<void> projectItem(Plugin plugin, String itemId) async {
|
||||
// final response = await _get('api/${plugin.id}/live', queryParams: {
|
||||
// 'data': '{"request": {"id": $itemId}}',
|
||||
// });
|
||||
// if (response.statusCode != 200) {
|
||||
// // Do some stuff...
|
||||
// }
|
||||
// }
|
||||
|
||||
// Future<void> addItemToService(Plugin plugin, String itemId) async {
|
||||
// final response = await _get('api/${plugin.id}/add', queryParams: {
|
||||
// 'data': '{"request": {"id": $itemId}}',
|
||||
// });
|
||||
// if (response.statusCode != 200) {
|
||||
// // Do some stuff...
|
||||
// }
|
||||
// }
|
||||
|
||||
// Future<bool> alert(String text) async {
|
||||
// final response = await _get('api/alert', queryParams: {
|
||||
// 'data': '{"request": {"text": "$text"}}',
|
||||
// });
|
||||
// if (response.statusCode != 200) {
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
|
||||
Future<void> setDisplayState(String state) {
|
||||
return _get('api/display/$state').then((_) {
|
||||
return;
|
||||
});
|
||||
if (response.statusCode != 200) {
|
||||
// Do some stuff...
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addItemToService(Plugin plugin, String itemId) async {
|
||||
final response = await _get('api/${plugin.id}/add', queryParams: {
|
||||
'data': '{"request": {"id": $itemId}}',
|
||||
});
|
||||
if (response.statusCode != 200) {
|
||||
// Do some stuff...
|
||||
}
|
||||
}
|
||||
// Future<void> setServiceItem(int itemIndex) async {
|
||||
// final response = await _get('api/service/set', queryParams: {
|
||||
// 'data': '{"request": {"id": $itemIndex}}',
|
||||
// });
|
||||
// if (response.statusCode != 200) {
|
||||
// // Do some stuff...
|
||||
// }
|
||||
// }
|
||||
|
||||
Future<bool> alert(String text) async {
|
||||
final response = await _get('api/alert', queryParams: {
|
||||
'data': '{"request": {"text": "$text"}}',
|
||||
});
|
||||
if (response.statusCode != 200) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> setDisplayState(String state) async {
|
||||
final response = await _get('api/display/$state');
|
||||
if (response.statusCode != 200) {
|
||||
// Do some stuff...
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setServiceItem(int itemIndex) async {
|
||||
final response = await _get('api/service/set', queryParams: {
|
||||
'data': '{"request": {"id": $itemIndex}}',
|
||||
});
|
||||
if (response.statusCode != 200) {
|
||||
// Do some stuff...
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setLiveSlide(int slideIndex) async {
|
||||
final response = await _get('api/controller/live/set', queryParams: {
|
||||
'data': '{"request": {"id": $slideIndex}}',
|
||||
});
|
||||
if (response.statusCode != 200) {
|
||||
// Do some stuff...
|
||||
}
|
||||
}
|
||||
// Future<void> setLiveSlide(int slideIndex) async {
|
||||
// final response = await _get('api/controller/live/set', queryParams: {
|
||||
// 'data': '{"request": {"id": $slideIndex}}',
|
||||
// });
|
||||
// if (response.statusCode != 200) {
|
||||
// // Do some stuff...
|
||||
// }
|
||||
// }
|
||||
|
@ -21,13 +21,14 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../bloc/display_options_dialog_bloc.dart';
|
||||
import '../configurations/app_localizations.dart';
|
||||
|
||||
class _Action {
|
||||
String titleKey;
|
||||
Function(DisplayOptionDialogBloc) callback;
|
||||
Function(DisplayOptionsDialogBloc) callback;
|
||||
_Action({@required this.titleKey, @required this.callback});
|
||||
}
|
||||
|
||||
@ -61,21 +62,43 @@ class DisplayOptionsDialog extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bloc = DisplayOptionDialogBloc();
|
||||
return SimpleDialog(
|
||||
contentPadding: EdgeInsets.all(20.0),
|
||||
children: _actions
|
||||
.map((action) => OutlineButton(
|
||||
borderSide: BorderSide(color: Theme.of(context).primaryColor),
|
||||
textColor: Theme.of(context).primaryColor,
|
||||
child: Text(
|
||||
AppLocalizations.of(context).translate(action.titleKey)),
|
||||
onPressed: () {
|
||||
action.callback(bloc);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
))
|
||||
.toList(),
|
||||
final bloc = DisplayOptionsDialogBloc();
|
||||
return BlocListener<DisplayOptionsDialogBloc, DisplayOptionsState>(
|
||||
bloc: bloc,
|
||||
condition: (previous, current) => current != DisplayOptionsState.none,
|
||||
listener: (context, state) {
|
||||
print(state);
|
||||
switch (state) {
|
||||
case DisplayOptionsState.success:
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Text('Sucesso!'),
|
||||
));
|
||||
break;
|
||||
case DisplayOptionsState.failure:
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Text('Falha!'),
|
||||
backgroundColor: Colors.red,
|
||||
));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
child: SimpleDialog(
|
||||
contentPadding: EdgeInsets.all(20.0),
|
||||
children: _actions
|
||||
.map((action) => OutlineButton(
|
||||
borderSide: BorderSide(color: Theme.of(context).primaryColor),
|
||||
textColor: Theme.of(context).primaryColor,
|
||||
child: Text(
|
||||
AppLocalizations.of(context).translate(action.titleKey)),
|
||||
onPressed: () {
|
||||
action.callback(bloc);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user