|
|
|
@ -1,18 +1,20 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:background_fetch/background_fetch.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
|
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
|
|
|
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
|
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
|
|
|
import 'package:opencanteen/lang/lang_cz.dart';
|
|
|
|
|
import 'package:opencanteen/loginmanager.dart';
|
|
|
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
|
|
|
import 'package:canteenlib/canteenlib.dart';
|
|
|
|
|
import 'package:opencanteen/okna/offline_jidelnicek.dart';
|
|
|
|
|
import 'package:opencanteen/okna/welcome.dart';
|
|
|
|
|
import 'package:opencanteen/util.dart';
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
|
|
import 'lang/lang.dart';
|
|
|
|
|
import 'lang/lang_en.dart';
|
|
|
|
@ -35,14 +37,75 @@ Copyright (C) 2022 Matyáš Caras a přispěvatelé
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
|
|
|
|
|
FlutterLocalNotificationsPlugin();
|
|
|
|
|
|
|
|
|
|
// Pouze pro Android
|
|
|
|
|
void backgroundFetchHeadlessTask(HeadlessTask task) async {
|
|
|
|
|
String taskId = task.taskId;
|
|
|
|
|
bool isTimeout = task.timeout;
|
|
|
|
|
if (isTimeout) {
|
|
|
|
|
// Timeout
|
|
|
|
|
debugPrint("[BackgroundFetch] Headless task má time-out: $taskId");
|
|
|
|
|
BackgroundFetch.finish(taskId);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var prefs = await SharedPreferences.getInstance();
|
|
|
|
|
debugPrint('[BackgroundFetch] Přišel headless event.');
|
|
|
|
|
|
|
|
|
|
if (prefs.getBool("oznamit") ?? false) {
|
|
|
|
|
// Oznámení před obědem
|
|
|
|
|
if (prefs.getBool("offline") ?? false) {
|
|
|
|
|
// TODO možnost brát z offline dat
|
|
|
|
|
} else {
|
|
|
|
|
// bere online
|
|
|
|
|
var d = await LoginManager.getDetails(); // získat údaje
|
|
|
|
|
if (d != null) {
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BackgroundFetch.finish(taskId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
const AndroidInitializationSettings initializationSettingsAndroid =
|
|
|
|
|
AndroidInitializationSettings('notif_icon');
|
|
|
|
|
|
|
|
|
|
/// Note: permissions aren't requested here just to demonstrate that can be
|
|
|
|
|
/// done later
|
|
|
|
|
final IOSInitializationSettings initializationSettingsIOS =
|
|
|
|
|
IOSInitializationSettings(
|
|
|
|
|
requestAlertPermission: false,
|
|
|
|
|
requestBadgePermission: false,
|
|
|
|
|
requestSoundPermission: false,
|
|
|
|
|
onDidReceiveLocalNotification: (
|
|
|
|
|
int id,
|
|
|
|
|
String? title,
|
|
|
|
|
String? body,
|
|
|
|
|
String? payload,
|
|
|
|
|
) async {
|
|
|
|
|
debugPrint(body);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
final InitializationSettings initializationSettings = InitializationSettings(
|
|
|
|
|
android: initializationSettingsAndroid,
|
|
|
|
|
iOS: initializationSettingsIOS,
|
|
|
|
|
);
|
|
|
|
|
await flutterLocalNotificationsPlugin.initialize(initializationSettings,
|
|
|
|
|
onSelectNotification: (String? payload) async {
|
|
|
|
|
if (payload != null) {
|
|
|
|
|
debugPrint('notification payload: $payload');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
runApp(const MyApp());
|
|
|
|
|
BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
|
|
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
// This widget is the root of your application.
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return MaterialApp(
|
|
|
|
@ -78,22 +141,49 @@ class _LoginPageState extends State<LoginPage> {
|
|
|
|
|
TextEditingController canteenControl = TextEditingController();
|
|
|
|
|
bool rememberMe = false;
|
|
|
|
|
|
|
|
|
|
void nastavitPozadi() async {
|
|
|
|
|
// Configure BackgroundFetch.
|
|
|
|
|
int status = await BackgroundFetch.configure(
|
|
|
|
|
BackgroundFetchConfig(
|
|
|
|
|
minimumFetchInterval: 15,
|
|
|
|
|
stopOnTerminate: false,
|
|
|
|
|
enableHeadless: true,
|
|
|
|
|
requiresBatteryNotLow: false,
|
|
|
|
|
requiresCharging: false,
|
|
|
|
|
requiresStorageNotLow: false,
|
|
|
|
|
requiresDeviceIdle: false,
|
|
|
|
|
requiredNetworkType: NetworkType.ANY), (String taskId) async {
|
|
|
|
|
// Callback
|
|
|
|
|
debugPrint("[BackgroundFetch] Event získán $taskId");
|
|
|
|
|
var d = await LoginManager.getDetails();
|
|
|
|
|
if (d != null) {
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
BackgroundFetch.finish(taskId);
|
|
|
|
|
}, (String taskId) async {
|
|
|
|
|
debugPrint("[BackgroundFetch] TASK TIMEOUT taskId: $taskId");
|
|
|
|
|
BackgroundFetch.finish(taskId);
|
|
|
|
|
});
|
|
|
|
|
debugPrint('[BackgroundFetch] úspěšně nakonfigurováno: $status');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
LoginManager.getDetails().then((r) async {
|
|
|
|
|
var connectivityResult = await (Connectivity().checkConnectivity());
|
|
|
|
|
if (connectivityResult == ConnectivityResult.none) {
|
|
|
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
|
SnackBar(
|
|
|
|
|
content: Text(Languages.of(context)!.errorContacting),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
goOffline();
|
|
|
|
|
if (Platform.isIOS) {
|
|
|
|
|
// žádat o oprávnění na iOS
|
|
|
|
|
await flutterLocalNotificationsPlugin
|
|
|
|
|
.resolvePlatformSpecificImplementation<
|
|
|
|
|
IOSFlutterLocalNotificationsPlugin>()
|
|
|
|
|
?.requestPermissions(
|
|
|
|
|
alert: true,
|
|
|
|
|
badge: true,
|
|
|
|
|
sound: true,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (r != null) {
|
|
|
|
|
// Automaticky přihlásit
|
|
|
|
|
showDialog(
|
|
|
|
|
context: context,
|
|
|
|
|
barrierDismissible: false,
|
|
|
|
@ -123,6 +213,7 @@ class _LoginPageState extends State<LoginPage> {
|
|
|
|
|
}
|
|
|
|
|
const storage = FlutterSecureStorage();
|
|
|
|
|
var odsouhlasil = await storage.read(key: "oc_souhlas");
|
|
|
|
|
nastavitPozadi();
|
|
|
|
|
if (odsouhlasil == null || odsouhlasil != "ano") {
|
|
|
|
|
Navigator.pushReplacement(
|
|
|
|
|
context,
|
|
|
|
@ -260,6 +351,7 @@ class _LoginPageState extends State<LoginPage> {
|
|
|
|
|
LoginManager.setDetails(userControl.text,
|
|
|
|
|
passControl.text, canteenControl.text);
|
|
|
|
|
}
|
|
|
|
|
nastavitPozadi();
|
|
|
|
|
// souhlas
|
|
|
|
|
const storage = FlutterSecureStorage();
|
|
|
|
|
var odsouhlasil =
|
|
|
|
|