mirror of
https://gitlab.com/openlp/openlp-mobile-remote.git
synced 2024-12-22 20:02:53 +00:00
display options api integration
This commit is contained in:
parent
faaec9a7c4
commit
7e4c623ae2
78
lib/src/bloc/display_options_dialog_bloc.dart
Normal file
78
lib/src/bloc/display_options_dialog_bloc.dart
Normal file
@ -0,0 +1,78 @@
|
||||
// OpenLP Mobile Remote
|
||||
// ---------------------------------------------------------------------------
|
||||
// Copyright (c) 2008-2019 OpenLP Developers
|
||||
// ---------------------------------------------------------------------------
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../network/api.dart' as api;
|
||||
|
||||
@immutable
|
||||
abstract class SetDisplayTypeEvent extends Equatable {
|
||||
final String type;
|
||||
SetDisplayTypeEvent(this.type, [List props = const <dynamic>[]])
|
||||
: super(props);
|
||||
}
|
||||
|
||||
class SetDisplayTypeBlankEvent extends SetDisplayTypeEvent {
|
||||
SetDisplayTypeBlankEvent() : super('blank');
|
||||
}
|
||||
|
||||
class SetDisplayTypeThemeEvent extends SetDisplayTypeEvent {
|
||||
SetDisplayTypeThemeEvent() : super('theme');
|
||||
}
|
||||
|
||||
class SetDisplayTypeDesktopEvent extends SetDisplayTypeEvent {
|
||||
SetDisplayTypeDesktopEvent() : super('desktop');
|
||||
}
|
||||
|
||||
class SetDisplayTypeShowEvent extends SetDisplayTypeEvent {
|
||||
SetDisplayTypeShowEvent() : super('show');
|
||||
}
|
||||
|
||||
class DisplayOptionDialogBloc extends Bloc<SetDisplayTypeEvent, void> {
|
||||
@override
|
||||
void get initialState {
|
||||
return;
|
||||
}
|
||||
|
||||
void setBlankScreen() {
|
||||
dispatch(SetDisplayTypeBlankEvent());
|
||||
}
|
||||
|
||||
void setThemeScreen() {
|
||||
dispatch(SetDisplayTypeThemeEvent());
|
||||
}
|
||||
|
||||
void setDesktopScreen() {
|
||||
dispatch(SetDisplayTypeDesktopEvent());
|
||||
}
|
||||
|
||||
void setFullProjection() {
|
||||
dispatch(SetDisplayTypeShowEvent());
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<void> mapEventToState(SetDisplayTypeEvent event) async* {
|
||||
api.setDisplayState(event.type);
|
||||
}
|
||||
}
|
@ -112,12 +112,11 @@ Future<bool> alert(String text) async {
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<bool> changeDisplayState(String state) async {
|
||||
Future<void> setDisplayState(String state) async {
|
||||
final response = await _get('api/display/$state');
|
||||
if (response.statusCode != 200) {
|
||||
return false;
|
||||
// Do some stuff...
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> setServiceItem(int itemIndex) async {
|
||||
|
@ -22,11 +22,12 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../bloc/display_options_dialog_bloc.dart';
|
||||
import '../configurations/app_localizations.dart';
|
||||
|
||||
class _Action {
|
||||
String titleKey;
|
||||
VoidCallback callback;
|
||||
Function(DisplayOptionDialogBloc) callback;
|
||||
_Action({@required this.titleKey, @required this.callback});
|
||||
}
|
||||
|
||||
@ -34,32 +35,33 @@ class DisplayOptionsDialog extends StatelessWidget {
|
||||
final List<_Action> _actions = [
|
||||
_Action(
|
||||
titleKey: 'display_option_blank',
|
||||
callback: () {
|
||||
print('Blank screen');
|
||||
callback: (bloc) {
|
||||
bloc.setBlankScreen();
|
||||
},
|
||||
),
|
||||
_Action(
|
||||
titleKey: 'display_option_theme',
|
||||
callback: () {
|
||||
print('Theme screen');
|
||||
callback: (bloc) {
|
||||
bloc.setThemeScreen();
|
||||
},
|
||||
),
|
||||
_Action(
|
||||
titleKey: 'display_option_desktop',
|
||||
callback: () {
|
||||
print('Desktop screen');
|
||||
callback: (bloc) {
|
||||
bloc.setDesktopScreen();
|
||||
},
|
||||
),
|
||||
_Action(
|
||||
titleKey: 'display_option_show',
|
||||
callback: () {
|
||||
print('Show screen');
|
||||
callback: (bloc) {
|
||||
bloc.setFullProjection();
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bloc = DisplayOptionDialogBloc();
|
||||
return SimpleDialog(
|
||||
contentPadding: EdgeInsets.all(20.0),
|
||||
children: _actions
|
||||
@ -69,7 +71,7 @@ class DisplayOptionsDialog extends StatelessWidget {
|
||||
child: Text(
|
||||
AppLocalizations.of(context).translate(action.titleKey)),
|
||||
onPressed: () {
|
||||
action.callback();
|
||||
action.callback(bloc);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
))
|
||||
|
Loading…
Reference in New Issue
Block a user