Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions lib/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import 'dart:convert';
import 'dart:io';

import 'package:bluecherry_client/api/api_helpers.dart';
import 'package:bluecherry_client/l10n/generated/app_localizations.dart';
import 'package:bluecherry_client/models/device.dart';
import 'package:bluecherry_client/models/server.dart';
import 'package:bluecherry_client/providers/settings_provider.dart';
import 'package:bluecherry_client/utils/logging.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart' show BuildContext;
import 'package:http/http.dart' as http;
import 'package:xml2json/xml2json.dart';

Expand All @@ -47,7 +49,19 @@ enum ServerAdditionResponse {
unknown,

/// The server took too long to respond.
timeout,
timeout;

String description(BuildContext context, Server server) {
final loc = AppLocalizations.of(context);
return switch (this) {
ServerAdditionResponse.versionMismatch => loc.serverVersionMismatch,
ServerAdditionResponse.wrongCredentials => loc.serverWrongCredentials,
ServerAdditionResponse.unknown || _ => loc.serverNotAddedErrorDescription(
server.port.toString(),
server.rtspPort.toString(),
),
};
}
}

class API {
Expand Down Expand Up @@ -262,11 +276,11 @@ class API {
try {
assert(server.serverUUID != null && server.hasCookies);
final response = await client.get(
Uri.https(
'${Uri.encodeComponent(server.login)}:${Uri.encodeComponent(server.password)}@${server.ip}:${server.port}',
'/mobile-app-config.json',
),
headers: {if (server.cookie != null) API.cookieHeader: server.cookie!},
Uri.https('${server.ip}:${server.port}', '/mobile-app-config.json'),
headers: {
if (server.cookie != null) API.cookieHeader: server.cookie!,
...server.headers,
},
);
final body = jsonDecode(response.body);
return body['notification_api_endpoint'];
Expand Down
61 changes: 29 additions & 32 deletions lib/api/ptz.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,39 +76,35 @@ extension PtzApiExtension on API {

final server = device.server;

final url = Uri.https(
'${Uri.encodeComponent(server.login)}:${Uri.encodeComponent(server.password)}@${server.ip}:${server.port}',
'/media/ptz.php',
{
'id': '${device.id}',
'command': command.name,

// commands
if (movement == Movement.moveNorth)
'tilt':
'u' //up
else if (movement == Movement.moveSouth)
'tilt':
'd' //down
else if (movement == Movement.moveWest)
'pan':
'l' //left
else if (movement == Movement.moveEast)
'pan':
'r' //right
else if (movement == Movement.moveWide)
'zoom':
'w' //wide
else if (movement == Movement.moveTele)
'zoom': 't', //tight
// speeds
if (command == PTZCommand.move) ...{
if (panSpeed > 0) 'panspeed': '$panSpeed',
if (tiltSpeed > 0) 'tiltspeed': '$tiltSpeed',
if (duration >= -1) 'duration': '$duration',
},
final url = Uri.https('${server.ip}:${server.port}', '/media/ptz.php', {
'id': '${device.id}',
'command': command.name,

// commands
if (movement == Movement.moveNorth)
'tilt':
'u' //up
else if (movement == Movement.moveSouth)
'tilt':
'd' //down
else if (movement == Movement.moveWest)
'pan':
'l' //left
else if (movement == Movement.moveEast)
'pan':
'r' //right
else if (movement == Movement.moveWide)
'zoom':
'w' //wide
else if (movement == Movement.moveTele)
'zoom': 't', //tight
// speeds
if (command == PTZCommand.move) ...{
if (panSpeed > 0) 'panspeed': '$panSpeed',
if (tiltSpeed > 0) 'tiltspeed': '$tiltSpeed',
if (duration >= -1) 'duration': '$duration',
},
);
});

debugPrint(url.toString());

Expand All @@ -117,6 +113,7 @@ extension PtzApiExtension on API {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
if (server.cookie != null) API.cookieHeader: server.cookie!,
...server.headers,
},
);

Expand Down
49 changes: 19 additions & 30 deletions lib/l10n/generated/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,15 @@ import 'app_localizations_pt.dart';
/// be consistent with the languages listed in the AppLocalizations.supportedLocales
/// property.
abstract class AppLocalizations {
AppLocalizations(String locale)
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
AppLocalizations(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());

final String localeName;

static AppLocalizations of(BuildContext context) {
return Localizations.of<AppLocalizations>(context, AppLocalizations)!;
}

static const LocalizationsDelegate<AppLocalizations> delegate =
_AppLocalizationsDelegate();
static const LocalizationsDelegate<AppLocalizations> delegate = _AppLocalizationsDelegate();

/// A list of this localizations delegate along with the default localizations
/// delegates.
Expand All @@ -86,20 +84,19 @@ abstract class AppLocalizations {
/// Additional delegates can be added by appending to this list in
/// MaterialApp. This list does not have to be used at all if a custom list
/// of delegates is preferred or required.
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
<LocalizationsDelegate<dynamic>>[
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
];
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
];

/// A list of this localizations delegate's supported locales.
static const List<Locale> supportedLocales = <Locale>[
Locale('en'),
Locale('fr'),
Locale('pl'),
Locale('pt'),
Locale('pt')
];

/// No description provided for @welcome.
Expand Down Expand Up @@ -970,11 +967,7 @@ abstract class AppLocalizations {
///
/// In en, this message translates to:
/// **'While attempting to import {layoutName}, we found a device that is connected to a server you are not connected to. Please, connect to the server and try again.\nServer: {server_ip}:{server_port}'**
String failedToImportMessage(
String layoutName,
String server_ip,
int server_port,
);
String failedToImportMessage(String layoutName, String server_ip, int server_port);

/// No description provided for @layoutImportFileCorrupted.
///
Expand Down Expand Up @@ -2645,8 +2638,7 @@ abstract class AppLocalizations {
String get licenses;
}

class _AppLocalizationsDelegate
extends LocalizationsDelegate<AppLocalizations> {
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
const _AppLocalizationsDelegate();

@override
Expand All @@ -2655,30 +2647,27 @@ class _AppLocalizationsDelegate
}

@override
bool isSupported(Locale locale) =>
<String>['en', 'fr', 'pl', 'pt'].contains(locale.languageCode);
bool isSupported(Locale locale) => <String>['en', 'fr', 'pl', 'pt'].contains(locale.languageCode);

@override
bool shouldReload(_AppLocalizationsDelegate old) => false;
}

AppLocalizations lookupAppLocalizations(Locale locale) {


// Lookup logic when only language code is specified.
switch (locale.languageCode) {
case 'en':
return AppLocalizationsEn();
case 'fr':
return AppLocalizationsFr();
case 'pl':
return AppLocalizationsPl();
case 'pt':
return AppLocalizationsPt();
case 'en': return AppLocalizationsEn();
case 'fr': return AppLocalizationsFr();
case 'pl': return AppLocalizationsPl();
case 'pt': return AppLocalizationsPt();
}

throw FlutterError(
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.',
'that was used.'
);
}
Loading
Loading