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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> changeDisplayState(String state) async {
|
Future<void> setDisplayState(String state) async {
|
||||||
final response = await _get('api/display/$state');
|
final response = await _get('api/display/$state');
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200) {
|
||||||
return false;
|
// Do some stuff...
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setServiceItem(int itemIndex) async {
|
Future<void> setServiceItem(int itemIndex) async {
|
||||||
|
@ -22,11 +22,12 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import '../bloc/display_options_dialog_bloc.dart';
|
||||||
import '../configurations/app_localizations.dart';
|
import '../configurations/app_localizations.dart';
|
||||||
|
|
||||||
class _Action {
|
class _Action {
|
||||||
String titleKey;
|
String titleKey;
|
||||||
VoidCallback callback;
|
Function(DisplayOptionDialogBloc) callback;
|
||||||
_Action({@required this.titleKey, @required this.callback});
|
_Action({@required this.titleKey, @required this.callback});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,32 +35,33 @@ class DisplayOptionsDialog extends StatelessWidget {
|
|||||||
final List<_Action> _actions = [
|
final List<_Action> _actions = [
|
||||||
_Action(
|
_Action(
|
||||||
titleKey: 'display_option_blank',
|
titleKey: 'display_option_blank',
|
||||||
callback: () {
|
callback: (bloc) {
|
||||||
print('Blank screen');
|
bloc.setBlankScreen();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
_Action(
|
_Action(
|
||||||
titleKey: 'display_option_theme',
|
titleKey: 'display_option_theme',
|
||||||
callback: () {
|
callback: (bloc) {
|
||||||
print('Theme screen');
|
bloc.setThemeScreen();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
_Action(
|
_Action(
|
||||||
titleKey: 'display_option_desktop',
|
titleKey: 'display_option_desktop',
|
||||||
callback: () {
|
callback: (bloc) {
|
||||||
print('Desktop screen');
|
bloc.setDesktopScreen();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
_Action(
|
_Action(
|
||||||
titleKey: 'display_option_show',
|
titleKey: 'display_option_show',
|
||||||
callback: () {
|
callback: (bloc) {
|
||||||
print('Show screen');
|
bloc.setFullProjection();
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final bloc = DisplayOptionDialogBloc();
|
||||||
return SimpleDialog(
|
return SimpleDialog(
|
||||||
contentPadding: EdgeInsets.all(20.0),
|
contentPadding: EdgeInsets.all(20.0),
|
||||||
children: _actions
|
children: _actions
|
||||||
@ -69,7 +71,7 @@ class DisplayOptionsDialog extends StatelessWidget {
|
|||||||
child: Text(
|
child: Text(
|
||||||
AppLocalizations.of(context).translate(action.titleKey)),
|
AppLocalizations.of(context).translate(action.titleKey)),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
action.callback();
|
action.callback(bloc);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
Loading…
Reference in New Issue
Block a user