2022-11-12 21:25:33 +05:30
|
|
|
// ignore_for_file: use_build_context_synchronously
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
2024-02-12 02:22:25 +03:00
|
|
|
import 'package:revanced_manager/gen/strings.g.dart';
|
2022-11-12 21:25:33 +05:30
|
|
|
import 'package:revanced_manager/services/manager_api.dart';
|
2023-04-18 13:27:26 +05:30
|
|
|
import 'package:revanced_manager/services/toast.dart';
|
2022-11-12 21:25:33 +05:30
|
|
|
import 'package:revanced_manager/ui/widgets/settingsView/settings_tile_dialog.dart';
|
|
|
|
import 'package:stacked/stacked.dart';
|
|
|
|
|
|
|
|
class SManageSources extends BaseViewModel {
|
|
|
|
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
2023-04-18 13:27:26 +05:30
|
|
|
final Toast _toast = locator<Toast>();
|
2022-11-12 21:25:33 +05:30
|
|
|
|
|
|
|
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 18:05:06 +05:30
|
|
|
final String patchesRepo = _managerAPI.getPatchesRepo();
|
|
|
|
final String integrationsRepo = _managerAPI.getIntegrationsRepo();
|
2022-11-12 21:25:33 +05:30
|
|
|
_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>[
|
2024-02-12 02:22:25 +03:00
|
|
|
Text(t.settingsView.sourcesLabel),
|
2022-11-12 21:25:33 +05:30
|
|
|
const Spacer(),
|
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.manage_history_outlined),
|
|
|
|
onPressed: () => showResetConfirmationDialog(context),
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
2023-08-06 14:39:46 +07:00
|
|
|
),
|
2022-11-12 21:25:33 +05:30
|
|
|
],
|
|
|
|
),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
2023-12-30 13:23:15 +07:00
|
|
|
TextField(
|
|
|
|
controller: _orgPatSourceController,
|
|
|
|
autocorrect: false,
|
2022-11-12 21:25:33 +05:30
|
|
|
onChanged: (value) => notifyListeners(),
|
2023-12-30 13:23:15 +07:00
|
|
|
decoration: InputDecoration(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.extension_outlined,
|
|
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
|
|
),
|
|
|
|
border: const OutlineInputBorder(),
|
2024-02-12 02:22:25 +03:00
|
|
|
labelText: t.settingsView.orgPatchesLabel,
|
2023-12-30 13:23:15 +07:00
|
|
|
hintText: patchesRepo.split('/')[0],
|
2022-11-12 21:25:33 +05:30
|
|
|
),
|
2023-12-30 13:23:15 +07:00
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
// Patches repository's name
|
|
|
|
TextField(
|
|
|
|
controller: _patSourceController,
|
|
|
|
autocorrect: false,
|
2022-11-12 21:25:33 +05:30
|
|
|
onChanged: (value) => notifyListeners(),
|
2023-12-30 13:23:15 +07:00
|
|
|
decoration: InputDecoration(
|
|
|
|
icon: const Icon(
|
|
|
|
Icons.extension_outlined,
|
|
|
|
color: Colors.transparent,
|
|
|
|
),
|
|
|
|
border: const OutlineInputBorder(),
|
2024-02-12 02:22:25 +03:00
|
|
|
labelText: t.settingsView.sourcesPatchesLabel,
|
2023-12-30 13:23:15 +07:00
|
|
|
hintText: patchesRepo.split('/')[1],
|
|
|
|
),
|
2022-11-12 21:25:33 +05:30
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
2023-12-30 13:23:15 +07:00
|
|
|
// Integrations owner's name
|
|
|
|
TextField(
|
|
|
|
controller: _orgIntSourceController,
|
|
|
|
autocorrect: false,
|
|
|
|
onChanged: (value) => notifyListeners(),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.merge_outlined,
|
|
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
|
|
),
|
|
|
|
border: const OutlineInputBorder(),
|
2024-02-12 02:22:25 +03:00
|
|
|
labelText: t.settingsView.orgIntegrationsLabel,
|
2023-12-30 13:23:15 +07:00
|
|
|
hintText: integrationsRepo.split('/')[0],
|
2022-11-12 21:25:33 +05:30
|
|
|
),
|
2023-12-30 13:23:15 +07:00
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
// Integrations repository's name
|
|
|
|
TextField(
|
|
|
|
controller: _intSourceController,
|
|
|
|
autocorrect: false,
|
2022-11-12 21:25:33 +05:30
|
|
|
onChanged: (value) => notifyListeners(),
|
2023-12-30 13:23:15 +07:00
|
|
|
decoration: InputDecoration(
|
|
|
|
icon: const Icon(
|
|
|
|
Icons.merge_outlined,
|
|
|
|
color: Colors.transparent,
|
|
|
|
),
|
|
|
|
border: const OutlineInputBorder(),
|
2024-02-12 02:22:25 +03:00
|
|
|
labelText: t.settingsView.sourcesIntegrationsLabel,
|
2023-12-30 13:23:15 +07:00
|
|
|
hintText: integrationsRepo.split('/')[1],
|
|
|
|
),
|
2022-11-12 21:25:33 +05:30
|
|
|
),
|
2023-08-04 02:08:56 +05:45
|
|
|
const SizedBox(height: 20),
|
2024-02-12 02:22:25 +03:00
|
|
|
Text(t.settingsView.sourcesUpdateNote),
|
2022-11-12 21:25:33 +05:30
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
2023-12-22 20:34:03 +07:00
|
|
|
TextButton(
|
2022-11-12 21:25:33 +05:30
|
|
|
onPressed: () {
|
|
|
|
_orgPatSourceController.clear();
|
|
|
|
_patSourceController.clear();
|
|
|
|
_orgIntSourceController.clear();
|
|
|
|
_intSourceController.clear();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
2024-02-12 02:22:25 +03:00
|
|
|
child: Text(t.cancelButton),
|
2022-11-12 21:25:33 +05:30
|
|
|
),
|
2023-12-22 20:34:03 +07:00
|
|
|
FilledButton(
|
2022-11-12 21:25:33 +05:30
|
|
|
onPressed: () {
|
|
|
|
_managerAPI.setPatchesRepo(
|
2023-04-18 17:15:04 +07:00
|
|
|
'${_orgPatSourceController.text.trim()}/${_patSourceController.text.trim()}',
|
2022-11-12 21:25:33 +05:30
|
|
|
);
|
|
|
|
_managerAPI.setIntegrationsRepo(
|
2023-04-18 17:15:04 +07:00
|
|
|
'${_orgIntSourceController.text.trim()}/${_intSourceController.text.trim()}',
|
2022-11-12 21:25:33 +05:30
|
|
|
);
|
2023-08-04 02:08:56 +05:45
|
|
|
_managerAPI.setCurrentPatchesVersion('0.0.0');
|
2023-08-11 06:56:19 +05:45
|
|
|
_managerAPI.setCurrentIntegrationsVersion('0.0.0');
|
2024-02-12 02:22:25 +03:00
|
|
|
_toast.showBottom(t.settingsView.restartAppForChanges);
|
2022-11-12 21:25:33 +05:30
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
2024-02-12 02:22:25 +03:00
|
|
|
child: Text(t.okButton),
|
2023-08-06 14:39:46 +07:00
|
|
|
),
|
2022-11-12 21:25:33 +05:30
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> showResetConfirmationDialog(BuildContext context) async {
|
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
2024-02-12 02:22:25 +03:00
|
|
|
title: Text(t.settingsView.sourcesResetDialogTitle),
|
|
|
|
content: Text(t.settingsView.sourcesResetDialogText),
|
2022-11-12 21:25:33 +05:30
|
|
|
actions: <Widget>[
|
2023-12-22 20:34:03 +07:00
|
|
|
TextButton(
|
2022-11-12 21:25:33 +05:30
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
2024-02-12 02:22:25 +03:00
|
|
|
child: Text(t.noButton),
|
2022-11-12 21:25:33 +05:30
|
|
|
),
|
2023-12-22 20:34:03 +07:00
|
|
|
FilledButton(
|
2022-11-12 21:25:33 +05:30
|
|
|
onPressed: () {
|
|
|
|
_managerAPI.setPatchesRepo('');
|
|
|
|
_managerAPI.setIntegrationsRepo('');
|
2023-08-04 02:08:56 +05:45
|
|
|
_managerAPI.setCurrentPatchesVersion('0.0.0');
|
2023-08-11 06:56:19 +05:45
|
|
|
_managerAPI.setCurrentIntegrationsVersion('0.0.0');
|
2024-02-12 02:22:25 +03:00
|
|
|
_toast.showBottom(t.settingsView.restartAppForChanges);
|
2023-04-21 01:59:37 +07:00
|
|
|
Navigator.of(context)
|
|
|
|
..pop()
|
|
|
|
..pop();
|
2022-11-12 21:25:33 +05:30
|
|
|
},
|
2024-02-12 02:22:25 +03:00
|
|
|
child: Text(t.yesButton),
|
2023-08-06 14:39:46 +07:00
|
|
|
),
|
2022-11-12 21:25:33 +05:30
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
2024-02-12 02:22:25 +03:00
|
|
|
title: t.settingsView.sourcesLabel,
|
|
|
|
subtitle: t.settingsView.sourcesLabelHint,
|
2022-11-12 21:25:33 +05:30
|
|
|
onTap: () => sManageSources.showSourcesDialog(context),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|