2022-11-12 16:55:33 +01:00
|
|
|
// ignore_for_file: use_build_context_synchronously
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
|
|
|
import 'package:revanced_manager/services/manager_api.dart';
|
2023-04-18 09:57:26 +02:00
|
|
|
import 'package:revanced_manager/services/toast.dart';
|
2022-11-12 16:55:33 +01:00
|
|
|
import 'package:revanced_manager/ui/widgets/settingsView/custom_text_field.dart';
|
|
|
|
import 'package:revanced_manager/ui/widgets/settingsView/settings_tile_dialog.dart';
|
|
|
|
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
|
|
|
|
import 'package:stacked/stacked.dart';
|
|
|
|
|
|
|
|
class SManageSources extends BaseViewModel {
|
|
|
|
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
2023-04-18 09:57:26 +02:00
|
|
|
final Toast _toast = locator<Toast>();
|
2022-11-12 16:55:33 +01:00
|
|
|
|
2022-12-09 13:10:43 +01:00
|
|
|
final TextEditingController _hostSourceController = TextEditingController();
|
2022-11-12 16:55:33 +01:00
|
|
|
final TextEditingController _orgPatSourceController = TextEditingController();
|
|
|
|
final TextEditingController _patSourceController = TextEditingController();
|
|
|
|
final TextEditingController _orgIntSourceController = TextEditingController();
|
|
|
|
final TextEditingController _intSourceController = TextEditingController();
|
|
|
|
|
|
|
|
Future<void> showSourcesDialog(BuildContext context) async {
|
2023-01-30 13:35:06 +01:00
|
|
|
final String hostRepository = _managerAPI.getRepoUrl();
|
|
|
|
final String patchesRepo = _managerAPI.getPatchesRepo();
|
|
|
|
final String integrationsRepo = _managerAPI.getIntegrationsRepo();
|
2022-12-09 13:10:43 +01:00
|
|
|
_hostSourceController.text = hostRepository;
|
2022-11-12 16:55:33 +01:00
|
|
|
_orgPatSourceController.text = patchesRepo.split('/')[0];
|
|
|
|
_patSourceController.text = patchesRepo.split('/')[1];
|
|
|
|
_orgIntSourceController.text = integrationsRepo.split('/')[0];
|
|
|
|
_intSourceController.text = integrationsRepo.split('/')[1];
|
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
title: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
I18nText('settingsView.sourcesLabel'),
|
|
|
|
const Spacer(),
|
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.manage_history_outlined),
|
|
|
|
onPressed: () => showResetConfirmationDialog(context),
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
2023-08-06 09:39:46 +02:00
|
|
|
),
|
2022-11-12 16:55:33 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
2022-12-09 13:10:43 +01:00
|
|
|
CustomTextField(
|
|
|
|
leadingIcon: const Icon(
|
|
|
|
Icons.extension_outlined,
|
|
|
|
color: Colors.transparent,
|
|
|
|
),
|
|
|
|
inputController: _hostSourceController,
|
|
|
|
label: I18nText('settingsView.hostRepositoryLabel'),
|
|
|
|
hint: hostRepository,
|
|
|
|
onChanged: (value) => notifyListeners(),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
2022-11-12 16:55:33 +01:00
|
|
|
CustomTextField(
|
|
|
|
leadingIcon: Icon(
|
|
|
|
Icons.extension_outlined,
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
|
|
|
inputController: _orgPatSourceController,
|
|
|
|
label: I18nText('settingsView.orgPatchesLabel'),
|
|
|
|
hint: patchesRepo.split('/')[0],
|
|
|
|
onChanged: (value) => notifyListeners(),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
CustomTextField(
|
|
|
|
leadingIcon: const Icon(
|
|
|
|
Icons.extension_outlined,
|
|
|
|
color: Colors.transparent,
|
|
|
|
),
|
|
|
|
inputController: _patSourceController,
|
|
|
|
label: I18nText('settingsView.sourcesPatchesLabel'),
|
|
|
|
hint: patchesRepo.split('/')[1],
|
|
|
|
onChanged: (value) => notifyListeners(),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
CustomTextField(
|
|
|
|
leadingIcon: Icon(
|
|
|
|
Icons.merge_outlined,
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
|
|
|
inputController: _orgIntSourceController,
|
|
|
|
label: I18nText('settingsView.orgIntegrationsLabel'),
|
|
|
|
hint: integrationsRepo.split('/')[0],
|
|
|
|
onChanged: (value) => notifyListeners(),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
CustomTextField(
|
|
|
|
leadingIcon: const Icon(
|
|
|
|
Icons.merge_outlined,
|
|
|
|
color: Colors.transparent,
|
|
|
|
),
|
|
|
|
inputController: _intSourceController,
|
|
|
|
label: I18nText('settingsView.sourcesIntegrationsLabel'),
|
|
|
|
hint: integrationsRepo.split('/')[1],
|
|
|
|
onChanged: (value) => notifyListeners(),
|
|
|
|
),
|
2023-08-03 22:23:56 +02:00
|
|
|
const SizedBox(height: 20),
|
2023-08-06 09:39:46 +02:00
|
|
|
I18nText('settingsView.sourcesUpdateNote'),
|
2022-11-12 16:55:33 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
CustomMaterialButton(
|
|
|
|
isFilled: false,
|
|
|
|
label: I18nText('cancelButton'),
|
|
|
|
onPressed: () {
|
|
|
|
_orgPatSourceController.clear();
|
|
|
|
_patSourceController.clear();
|
|
|
|
_orgIntSourceController.clear();
|
|
|
|
_intSourceController.clear();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
CustomMaterialButton(
|
|
|
|
label: I18nText('okButton'),
|
|
|
|
onPressed: () {
|
2023-04-18 12:15:04 +02:00
|
|
|
_managerAPI.setRepoUrl(_hostSourceController.text.trim());
|
2022-11-12 16:55:33 +01:00
|
|
|
_managerAPI.setPatchesRepo(
|
2023-04-18 12:15:04 +02:00
|
|
|
'${_orgPatSourceController.text.trim()}/${_patSourceController.text.trim()}',
|
2022-11-12 16:55:33 +01:00
|
|
|
);
|
|
|
|
_managerAPI.setIntegrationsRepo(
|
2023-04-18 12:15:04 +02:00
|
|
|
'${_orgIntSourceController.text.trim()}/${_intSourceController.text.trim()}',
|
2022-11-12 16:55:33 +01:00
|
|
|
);
|
2023-08-03 22:23:56 +02:00
|
|
|
_managerAPI.setCurrentPatchesVersion('0.0.0');
|
2023-08-11 03:11:19 +02:00
|
|
|
_managerAPI.setCurrentIntegrationsVersion('0.0.0');
|
2023-04-18 09:57:26 +02:00
|
|
|
_toast.showBottom('settingsView.restartAppForChanges');
|
2022-11-12 16:55:33 +01:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
2023-08-06 09:39:46 +02:00
|
|
|
),
|
2022-11-12 16:55:33 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> showResetConfirmationDialog(BuildContext context) async {
|
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
title: I18nText('settingsView.sourcesResetDialogTitle'),
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
|
|
|
content: I18nText('settingsView.sourcesResetDialogText'),
|
|
|
|
actions: <Widget>[
|
|
|
|
CustomMaterialButton(
|
|
|
|
isFilled: false,
|
|
|
|
label: I18nText('noButton'),
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
),
|
|
|
|
CustomMaterialButton(
|
|
|
|
label: I18nText('yesButton'),
|
|
|
|
onPressed: () {
|
2022-12-09 13:10:43 +01:00
|
|
|
_managerAPI.setRepoUrl('');
|
2022-11-12 16:55:33 +01:00
|
|
|
_managerAPI.setPatchesRepo('');
|
|
|
|
_managerAPI.setIntegrationsRepo('');
|
2023-08-03 22:23:56 +02:00
|
|
|
_managerAPI.setCurrentPatchesVersion('0.0.0');
|
2023-08-11 03:11:19 +02:00
|
|
|
_managerAPI.setCurrentIntegrationsVersion('0.0.0');
|
2023-04-18 09:57:26 +02:00
|
|
|
_toast.showBottom('settingsView.restartAppForChanges');
|
2023-04-20 20:59:37 +02:00
|
|
|
Navigator.of(context)
|
|
|
|
..pop()
|
|
|
|
..pop();
|
2022-11-12 16:55:33 +01:00
|
|
|
},
|
2023-08-06 09:39:46 +02:00
|
|
|
),
|
2022-11-12 16:55:33 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final sManageSources = SManageSources();
|
|
|
|
|
|
|
|
class SManageSourcesUI extends StatelessWidget {
|
|
|
|
const SManageSourcesUI({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SettingsTileDialog(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
|
|
|
title: 'settingsView.sourcesLabel',
|
|
|
|
subtitle: 'settingsView.sourcesLabelHint',
|
|
|
|
onTap: () => sManageSources.showSourcesDialog(context),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|