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!",
|
||||
"installingMessage": "Installing update!",
|
||||
"errorDownloadMessage": "Unable to download update!",
|
||||
"errorInstallMessage": "Unable to download update!"
|
||||
"errorInstallMessage": "Unable to download update!",
|
||||
"noConnection": "No internet connection"
|
||||
},
|
||||
"applicationItem": {
|
||||
"patchButton": "Patch",
|
||||
|
@ -17,13 +17,13 @@ class HomeView extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<HomeViewModel>.reactive(
|
||||
disposeViewModel: false,
|
||||
onModelReady: (model) => model.initialize(),
|
||||
onModelReady: (model) => model.initialize(context),
|
||||
viewModelBuilder: () => locator<HomeViewModel>(),
|
||||
builder: (context, model, child) => Scaffold(
|
||||
body: RefreshIndicator(
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||
onRefresh: () => model.forceRefresh(),
|
||||
onRefresh: () => model.forceRefresh(context),
|
||||
child: CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
CustomSliverAppBar(
|
||||
|
@ -1,6 +1,7 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'dart:io';
|
||||
import 'package:app_installer/app_installer.dart';
|
||||
import 'package:cross_connectivity/cross_connectivity.dart';
|
||||
import 'package:device_apps/device_apps.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
@ -29,13 +30,24 @@ class HomeViewModel extends BaseViewModel {
|
||||
List<PatchedApplication> patchedInstalledApps = [];
|
||||
List<PatchedApplication> patchedUpdatableApps = [];
|
||||
|
||||
Future<void> initialize() async {
|
||||
Future<void> initialize(BuildContext context) async {
|
||||
await flutterLocalNotificationsPlugin.initialize(
|
||||
const InitializationSettings(
|
||||
android: AndroidInitializationSettings('ic_notification'),
|
||||
),
|
||||
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();
|
||||
_managerAPI.reAssessSavedApps().then((_) => _getPatchedApps());
|
||||
}
|
||||
@ -176,12 +188,12 @@ class HomeViewModel extends BaseViewModel {
|
||||
return _managerAPI.getLatestManagerReleaseTime();
|
||||
}
|
||||
|
||||
Future<void> forceRefresh() async {
|
||||
Future<void> forceRefresh(BuildContext context) async {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
if (_lastUpdate == null ||
|
||||
_lastUpdate!.difference(DateTime.now()).inSeconds > 60) {
|
||||
_managerAPI.clearAllData();
|
||||
}
|
||||
initialize();
|
||||
initialize(context);
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ class AppInfoViewModel extends BaseViewModel {
|
||||
label: I18nText('okButton'),
|
||||
onPressed: () {
|
||||
uninstallApp(app);
|
||||
locator<HomeViewModel>().initialize();
|
||||
locator<HomeViewModel>().initialize(context);
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
|
@ -12,6 +12,7 @@ environment:
|
||||
dependencies:
|
||||
animations: ^2.0.4
|
||||
app_installer: ^1.1.0
|
||||
cross_connectivity: ^3.0.5
|
||||
device_apps:
|
||||
git:
|
||||
url: https://github.com/ponces/flutter_plugin_device_apps
|
||||
|
Loading…
Reference in New Issue
Block a user