mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
feat: Add connectivity status toast message on Home View
This commit is contained in:
parent
92a84c3bfb
commit
6665095b2e
@ -25,7 +25,8 @@
|
|||||||
"downloadingMessage": "Downloading update!",
|
"downloadingMessage": "Downloading update!",
|
||||||
"installingMessage": "Installing update!",
|
"installingMessage": "Installing update!",
|
||||||
"errorDownloadMessage": "Unable to download update!",
|
"errorDownloadMessage": "Unable to download update!",
|
||||||
"errorInstallMessage": "Unable to download update!"
|
"errorInstallMessage": "Unable to download update!",
|
||||||
|
"noConnection": "No internet connection"
|
||||||
},
|
},
|
||||||
"applicationItem": {
|
"applicationItem": {
|
||||||
"patchButton": "Patch",
|
"patchButton": "Patch",
|
||||||
|
@ -17,13 +17,13 @@ class HomeView extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ViewModelBuilder<HomeViewModel>.reactive(
|
return ViewModelBuilder<HomeViewModel>.reactive(
|
||||||
disposeViewModel: false,
|
disposeViewModel: false,
|
||||||
onModelReady: (model) => model.initialize(),
|
onModelReady: (model) => model.initialize(context),
|
||||||
viewModelBuilder: () => locator<HomeViewModel>(),
|
viewModelBuilder: () => locator<HomeViewModel>(),
|
||||||
builder: (context, model, child) => Scaffold(
|
builder: (context, model, child) => Scaffold(
|
||||||
body: RefreshIndicator(
|
body: RefreshIndicator(
|
||||||
color: Theme.of(context).colorScheme.secondary,
|
color: Theme.of(context).colorScheme.secondary,
|
||||||
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||||
onRefresh: () => model.forceRefresh(),
|
onRefresh: () => model.forceRefresh(context),
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
slivers: <Widget>[
|
slivers: <Widget>[
|
||||||
CustomSliverAppBar(
|
CustomSliverAppBar(
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// ignore_for_file: use_build_context_synchronously
|
// ignore_for_file: use_build_context_synchronously
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:app_installer/app_installer.dart';
|
import 'package:app_installer/app_installer.dart';
|
||||||
|
import 'package:cross_connectivity/cross_connectivity.dart';
|
||||||
import 'package:device_apps/device_apps.dart';
|
import 'package:device_apps/device_apps.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||||
@ -29,13 +30,24 @@ class HomeViewModel extends BaseViewModel {
|
|||||||
List<PatchedApplication> patchedInstalledApps = [];
|
List<PatchedApplication> patchedInstalledApps = [];
|
||||||
List<PatchedApplication> patchedUpdatableApps = [];
|
List<PatchedApplication> patchedUpdatableApps = [];
|
||||||
|
|
||||||
Future<void> initialize() async {
|
Future<void> initialize(BuildContext context) async {
|
||||||
await flutterLocalNotificationsPlugin.initialize(
|
await flutterLocalNotificationsPlugin.initialize(
|
||||||
const InitializationSettings(
|
const InitializationSettings(
|
||||||
android: AndroidInitializationSettings('ic_notification'),
|
android: AndroidInitializationSettings('ic_notification'),
|
||||||
),
|
),
|
||||||
onSelectNotification: (p) => DeviceApps.openApp('app.revanced.manager'),
|
onSelectNotification: (p) => DeviceApps.openApp('app.revanced.manager'),
|
||||||
);
|
);
|
||||||
|
bool isConnected = await Connectivity().checkConnection();
|
||||||
|
if (!isConnected) {
|
||||||
|
Fluttertoast.showToast(
|
||||||
|
msg: FlutterI18n.translate(
|
||||||
|
context,
|
||||||
|
'homeView.noConnection',
|
||||||
|
),
|
||||||
|
toastLength: Toast.LENGTH_LONG,
|
||||||
|
gravity: ToastGravity.CENTER,
|
||||||
|
);
|
||||||
|
}
|
||||||
_getPatchedApps();
|
_getPatchedApps();
|
||||||
_managerAPI.reAssessSavedApps().then((_) => _getPatchedApps());
|
_managerAPI.reAssessSavedApps().then((_) => _getPatchedApps());
|
||||||
}
|
}
|
||||||
@ -176,12 +188,12 @@ class HomeViewModel extends BaseViewModel {
|
|||||||
return _managerAPI.getLatestManagerReleaseTime();
|
return _managerAPI.getLatestManagerReleaseTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> forceRefresh() async {
|
Future<void> forceRefresh(BuildContext context) async {
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
if (_lastUpdate == null ||
|
if (_lastUpdate == null ||
|
||||||
_lastUpdate!.difference(DateTime.now()).inSeconds > 60) {
|
_lastUpdate!.difference(DateTime.now()).inSeconds > 60) {
|
||||||
_managerAPI.clearAllData();
|
_managerAPI.clearAllData();
|
||||||
}
|
}
|
||||||
initialize();
|
initialize(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ class AppInfoViewModel extends BaseViewModel {
|
|||||||
label: I18nText('okButton'),
|
label: I18nText('okButton'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
uninstallApp(app);
|
uninstallApp(app);
|
||||||
locator<HomeViewModel>().initialize();
|
locator<HomeViewModel>().initialize(context);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
|
@ -12,6 +12,7 @@ environment:
|
|||||||
dependencies:
|
dependencies:
|
||||||
animations: ^2.0.4
|
animations: ^2.0.4
|
||||||
app_installer: ^1.1.0
|
app_installer: ^1.1.0
|
||||||
|
cross_connectivity: ^3.0.5
|
||||||
device_apps:
|
device_apps:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/ponces/flutter_plugin_device_apps
|
url: https://github.com/ponces/flutter_plugin_device_apps
|
||||||
|
Loading…
Reference in New Issue
Block a user