mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 04:37:37 +02:00
feat: Allow changing languages (#1488)
Co-authored-by: validcube <pun.butrach@gmail.com>
This commit is contained in:
@ -1,16 +1,17 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/app/app.router.dart';
|
||||
import 'package:revanced_manager/gen/strings.g.dart';
|
||||
import 'package:revanced_manager/models/patched_application.dart';
|
||||
import 'package:revanced_manager/services/github_api.dart';
|
||||
import 'package:revanced_manager/services/manager_api.dart';
|
||||
@ -68,12 +69,12 @@ class HomeViewModel extends BaseViewModel {
|
||||
),
|
||||
onDidReceiveNotificationResponse: (response) async {
|
||||
if (response.id == 0) {
|
||||
_toast.showBottom('homeView.installingMessage');
|
||||
_toast.showBottom(t.homeView.installingMessage);
|
||||
final File? managerApk = await _managerAPI.downloadManager();
|
||||
if (managerApk != null) {
|
||||
await _patcherAPI.installApk(context, managerApk.path);
|
||||
} else {
|
||||
_toast.showBottom('homeView.errorDownloadMessage');
|
||||
_toast.showBottom(t.homeView.errorDownloadMessage);
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -82,22 +83,21 @@ class HomeViewModel extends BaseViewModel {
|
||||
.resolvePlatformSpecificImplementation<
|
||||
AndroidFlutterLocalNotificationsPlugin>()
|
||||
?.requestNotificationsPermission();
|
||||
|
||||
final bool isConnected =
|
||||
await Connectivity().checkConnectivity() != ConnectivityResult.none;
|
||||
if (!isConnected) {
|
||||
_toast.showBottom('homeView.noConnection');
|
||||
_toast.showBottom(t.homeView.noConnection);
|
||||
}
|
||||
|
||||
final NotificationAppLaunchDetails? notificationAppLaunchDetails =
|
||||
await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
|
||||
if (notificationAppLaunchDetails?.didNotificationLaunchApp ?? false) {
|
||||
_toast.showBottom('homeView.installingMessage');
|
||||
_toast.showBottom(t.homeView.installingMessage);
|
||||
final File? managerApk = await _managerAPI.downloadManager();
|
||||
if (managerApk != null) {
|
||||
await _patcherAPI.installApk(context, managerApk.path);
|
||||
} else {
|
||||
_toast.showBottom('homeView.errorDownloadMessage');
|
||||
_toast.showBottom(t.homeView.errorDownloadMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -183,7 +183,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
builder: (context) => PopScope(
|
||||
canPop: false,
|
||||
child: AlertDialog(
|
||||
title: I18nText('homeView.downloadConsentDialogTitle'),
|
||||
title: Text(t.homeView.downloadConsentDialogTitle),
|
||||
content: ValueListenableBuilder(
|
||||
valueListenable: autoUpdate,
|
||||
builder: (context, value, child) {
|
||||
@ -191,31 +191,24 @@ class HomeViewModel extends BaseViewModel {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
I18nText(
|
||||
'homeView.downloadConsentDialogText',
|
||||
child: Text(
|
||||
'',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
Text(
|
||||
t.homeView.downloadConsentDialogText,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: I18nText(
|
||||
'homeView.downloadConsentDialogText2',
|
||||
translationParams: {
|
||||
'url': _managerAPI.defaultApiUrl.split('/')[2],
|
||||
},
|
||||
child: Text(
|
||||
'',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
child: Text(
|
||||
t.homeView.downloadConsentDialogText2(
|
||||
url: _managerAPI.defaultApiUrl.split('/')[2],
|
||||
),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -229,7 +222,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
_managerAPI.setDownloadConsent(false);
|
||||
SystemNavigator.pop();
|
||||
},
|
||||
child: I18nText('quitButton'),
|
||||
child: Text(t.quitButton),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () async {
|
||||
@ -237,7 +230,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
_managerAPI.setPatchesAutoUpdate(autoUpdate.value);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: I18nText('okButton'),
|
||||
child: Text(t.okButton),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -251,7 +244,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (innerContext) => AlertDialog(
|
||||
title: I18nText('homeView.updateDialogTitle'),
|
||||
title: Text(t.homeView.updateDialogTitle),
|
||||
content: ValueListenableBuilder(
|
||||
valueListenable: noShow,
|
||||
builder: (context, value, child) {
|
||||
@ -259,33 +252,25 @@ class HomeViewModel extends BaseViewModel {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
I18nText(
|
||||
'homeView.updateDialogText',
|
||||
translationParams: {
|
||||
'file': isPatches ? 'ReVanced Patches' : 'ReVanced Manager',
|
||||
'version': isPatches
|
||||
Text(
|
||||
t.homeView.updateDialogText(
|
||||
file: isPatches ? 'ReVanced Patches' : 'ReVanced Manager',
|
||||
version: isPatches
|
||||
? _currentPatchesVersion
|
||||
: _currentManagerVersion,
|
||||
},
|
||||
child: Text(
|
||||
'',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
HapticCheckboxListTile(
|
||||
value: value,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: I18nText(
|
||||
'noShowAgain',
|
||||
),
|
||||
subtitle: I18nText(
|
||||
'homeView.changeLaterSubtitle',
|
||||
),
|
||||
title: Text(t.noShowAgain),
|
||||
subtitle: Text(t.homeView.changeLaterSubtitle),
|
||||
onChanged: (selected) {
|
||||
noShow.value = selected!;
|
||||
},
|
||||
@ -300,7 +285,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
_managerAPI.setShowUpdateDialog(!noShow.value);
|
||||
Navigator.pop(innerContext);
|
||||
},
|
||||
child: I18nText('dismissButton'), // Decide later
|
||||
child: Text(t.dismissButton), // Decide later
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () async {
|
||||
@ -308,7 +293,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
Navigator.pop(innerContext);
|
||||
await showUpdateConfirmationDialog(context, isPatches);
|
||||
},
|
||||
child: I18nText('showUpdateButton'),
|
||||
child: Text(t.showUpdateButton),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -316,7 +301,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
}
|
||||
|
||||
Future<void> updatePatches(BuildContext context) async {
|
||||
_toast.showBottom('homeView.downloadingMessage');
|
||||
_toast.showBottom(t.homeView.downloadingMessage);
|
||||
final String patchesVersion =
|
||||
await _managerAPI.getLatestPatchesVersion() ?? '0.0.0';
|
||||
final String integrationsVersion =
|
||||
@ -324,27 +309,27 @@ class HomeViewModel extends BaseViewModel {
|
||||
if (patchesVersion != '0.0.0' && integrationsVersion != '0.0.0') {
|
||||
await _managerAPI.setCurrentPatchesVersion(patchesVersion);
|
||||
await _managerAPI.setCurrentIntegrationsVersion(integrationsVersion);
|
||||
_toast.showBottom('homeView.downloadedMessage');
|
||||
_toast.showBottom(t.homeView.downloadedMessage);
|
||||
forceRefresh(context);
|
||||
} else {
|
||||
_toast.showBottom('homeView.errorDownloadMessage');
|
||||
_toast.showBottom(t.homeView.errorDownloadMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateManager(BuildContext context) async {
|
||||
final ValueNotifier<bool> downloaded = ValueNotifier(false);
|
||||
try {
|
||||
_toast.showBottom('homeView.downloadingMessage');
|
||||
_toast.showBottom(t.homeView.downloadingMessage);
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => ValueListenableBuilder(
|
||||
valueListenable: downloaded,
|
||||
builder: (context, value, child) {
|
||||
return AlertDialog(
|
||||
title: I18nText(
|
||||
title: Text(
|
||||
!value
|
||||
? 'homeView.downloadingMessage'
|
||||
: 'homeView.downloadedMessage',
|
||||
? t.homeView.downloadingMessage
|
||||
: t.homeView.downloadedMessage,
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@ -373,7 +358,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
_revancedAPI.disposeManagerUpdateProgress();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: I18nText('cancelButton'),
|
||||
child: Text(t.cancelButton),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -382,15 +367,12 @@ class HomeViewModel extends BaseViewModel {
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
I18nText(
|
||||
'homeView.installUpdate',
|
||||
child: Text(
|
||||
'',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
Text(
|
||||
t.homeView.installUpdate,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16.0),
|
||||
@ -403,7 +385,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: I18nText('cancelButton'),
|
||||
child: Text(t.cancelButton),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8.0),
|
||||
@ -416,7 +398,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
downloadedApk!.path,
|
||||
);
|
||||
},
|
||||
child: I18nText('updateButton'),
|
||||
child: Text(t.updateButton),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -457,21 +439,21 @@ class HomeViewModel extends BaseViewModel {
|
||||
// uiLocalNotificationDateInterpretation:
|
||||
// UILocalNotificationDateInterpretation.absoluteTime,
|
||||
// );
|
||||
_toast.showBottom('homeView.installingMessage');
|
||||
_toast.showBottom(t.homeView.installingMessage);
|
||||
await _patcherAPI.installApk(context, managerApk.path);
|
||||
} else {
|
||||
_toast.showBottom('homeView.errorDownloadMessage');
|
||||
_toast.showBottom(t.homeView.errorDownloadMessage);
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e);
|
||||
}
|
||||
_toast.showBottom('homeView.errorInstallMessage');
|
||||
_toast.showBottom(t.homeView.errorInstallMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void updatesAreDisabled() {
|
||||
_toast.showBottom('homeView.updatesDisabled');
|
||||
_toast.showBottom(t.homeView.updatesDisabled);
|
||||
}
|
||||
|
||||
Future<void> showUpdateConfirmationDialog(
|
||||
@ -510,7 +492,7 @@ class HomeViewModel extends BaseViewModel {
|
||||
|
||||
Future<void> forceRefresh(BuildContext context) async {
|
||||
_managerAPI.clearAllData();
|
||||
_toast.showBottom('homeView.refreshSuccess');
|
||||
_toast.showBottom(t.homeView.refreshSuccess);
|
||||
initialize(context);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user