mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
build: Bump dependencies to support patch option values (#1431)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
parent
dde402afbf
commit
ba44fa620f
@ -85,7 +85,7 @@ dependencies {
|
|||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
|
|
||||||
// ReVanced
|
// ReVanced
|
||||||
implementation "app.revanced:revanced-patcher:17.0.0"
|
implementation "app.revanced:revanced-patcher:19.0.0"
|
||||||
|
|
||||||
// Signing & aligning
|
// Signing & aligning
|
||||||
implementation("org.bouncycastle:bcpkix-jdk15on:1.70")
|
implementation("org.bouncycastle:bcpkix-jdk15on:1.70")
|
||||||
|
@ -15,7 +15,9 @@ import app.revanced.patcher.patch.PatchResult
|
|||||||
import io.flutter.embedding.android.FlutterActivity
|
import io.flutter.embedding.android.FlutterActivity
|
||||||
import io.flutter.embedding.engine.FlutterEngine
|
import io.flutter.embedding.engine.FlutterEngine
|
||||||
import io.flutter.plugin.common.MethodChannel
|
import io.flutter.plugin.common.MethodChannel
|
||||||
|
import kotlinx.coroutines.InternalCoroutinesApi
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
|
import kotlinx.coroutines.flow.FlowCollector
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
@ -25,6 +27,7 @@ import java.io.StringWriter
|
|||||||
import java.util.logging.LogRecord
|
import java.util.logging.LogRecord
|
||||||
import java.util.logging.Logger
|
import java.util.logging.Logger
|
||||||
|
|
||||||
|
|
||||||
class MainActivity : FlutterActivity() {
|
class MainActivity : FlutterActivity() {
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
private lateinit var installerChannel: MethodChannel
|
private lateinit var installerChannel: MethodChannel
|
||||||
@ -131,24 +134,34 @@ class MainActivity : FlutterActivity() {
|
|||||||
})
|
})
|
||||||
put("options", JSONArray().apply {
|
put("options", JSONArray().apply {
|
||||||
it.options.values.forEach { option ->
|
it.options.values.forEach { option ->
|
||||||
val optionJson = JSONObject().apply option@{
|
JSONObject().apply {
|
||||||
put("key", option.key)
|
put("key", option.key)
|
||||||
put("title", option.title)
|
put("title", option.title)
|
||||||
put("description", option.description)
|
put("description", option.description)
|
||||||
put("required", option.required)
|
put("required", option.required)
|
||||||
|
|
||||||
when (val value = option.value) {
|
fun JSONObject.putValue(
|
||||||
null -> put("value", null)
|
value: Any?,
|
||||||
is Array<*> -> put("value", JSONArray().apply {
|
key: String = "value"
|
||||||
|
) = if (value is Array<*>) put(
|
||||||
|
key,
|
||||||
|
JSONArray().apply {
|
||||||
value.forEach { put(it) }
|
value.forEach { put(it) }
|
||||||
})
|
})
|
||||||
else -> put("value", option.value)
|
else put(key, value)
|
||||||
}
|
|
||||||
|
|
||||||
put("optionClassType", option::class.simpleName)
|
putValue(option.default)
|
||||||
}
|
|
||||||
put(optionJson)
|
option.values?.let { values ->
|
||||||
|
put("values",
|
||||||
|
JSONObject().apply {
|
||||||
|
values.forEach { (key, value) ->
|
||||||
|
putValue(value, key)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} ?: put("values", null)
|
||||||
|
put("valueType", option.valueType)
|
||||||
|
}.let(::put)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}.let(::put)
|
}.let(::put)
|
||||||
@ -161,6 +174,7 @@ class MainActivity : FlutterActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(InternalCoroutinesApi::class)
|
||||||
private fun runPatcher(
|
private fun runPatcher(
|
||||||
result: MethodChannel.Result,
|
result: MethodChannel.Result,
|
||||||
originalFilePath: String,
|
originalFilePath: String,
|
||||||
@ -283,12 +297,12 @@ class MainActivity : FlutterActivity() {
|
|||||||
acceptPatches(patches)
|
acceptPatches(patches)
|
||||||
|
|
||||||
runBlocking {
|
runBlocking {
|
||||||
apply(false).collect { patchResult: PatchResult ->
|
apply(false).collect(FlowCollector { patchResult: PatchResult ->
|
||||||
if (cancel) {
|
if (cancel) {
|
||||||
handler.post { stopResult!!.success(null) }
|
handler.post { stopResult!!.success(null) }
|
||||||
this.cancel()
|
this.cancel()
|
||||||
this@apply.close()
|
this@apply.close()
|
||||||
return@collect
|
return@FlowCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
val msg = patchResult.exception?.let {
|
val msg = patchResult.exception?.let {
|
||||||
@ -301,7 +315,7 @@ class MainActivity : FlutterActivity() {
|
|||||||
|
|
||||||
updateProgress(progress, "", msg)
|
updateProgress(progress, "", msg)
|
||||||
progress += progressStep
|
progress += progressStep
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +135,7 @@
|
|||||||
"setRequiredOption": "Some patches require options to be set:\n\n{patches}\n\nPlease set them before continuing."
|
"setRequiredOption": "Some patches require options to be set:\n\n{patches}\n\nPlease set them before continuing."
|
||||||
},
|
},
|
||||||
"patchOptionsView": {
|
"patchOptionsView": {
|
||||||
|
"customValue": "Custom value",
|
||||||
"resetOptionsTooltip": "Reset patch options",
|
"resetOptionsTooltip": "Reset patch options",
|
||||||
"viewTitle": "Patch options",
|
"viewTitle": "Patch options",
|
||||||
"saveOptions": "Save",
|
"saveOptions": "Save",
|
||||||
|
@ -13,12 +13,15 @@ class Patch {
|
|||||||
});
|
});
|
||||||
|
|
||||||
factory Patch.fromJson(Map<String, dynamic> json) {
|
factory Patch.fromJson(Map<String, dynamic> json) {
|
||||||
// See: https://github.com/ReVanced/revanced-manager/issues/1364#issuecomment-1760414618
|
_migrateV16ToV17(json);
|
||||||
|
|
||||||
|
return _$PatchFromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _migrateV16ToV17(Map<String, dynamic> json) {
|
||||||
if (json['options'] == null) {
|
if (json['options'] == null) {
|
||||||
json['options'] = [];
|
json['options'] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return _$PatchFromJson(json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
@ -57,18 +60,34 @@ class Option {
|
|||||||
required this.title,
|
required this.title,
|
||||||
required this.description,
|
required this.description,
|
||||||
required this.value,
|
required this.value,
|
||||||
|
required this.values,
|
||||||
required this.required,
|
required this.required,
|
||||||
required this.optionClassType,
|
required this.valueType,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Option.fromJson(Map<String, dynamic> json) => _$OptionFromJson(json);
|
factory Option.fromJson(Map<String, dynamic> json) {
|
||||||
|
_migrateV17ToV19(json);
|
||||||
|
|
||||||
|
return _$OptionFromJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _migrateV17ToV19(Map<String, dynamic> json) {
|
||||||
|
if (json['valueType'] == null) {
|
||||||
|
json['valueType'] = json['optionClassType']
|
||||||
|
.replace('PatchOption', '')
|
||||||
|
.replace('List', 'Array');
|
||||||
|
|
||||||
|
json['optionClassType'] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final String key;
|
final String key;
|
||||||
final String title;
|
final String title;
|
||||||
final String description;
|
final String description;
|
||||||
dynamic value;
|
final dynamic value;
|
||||||
|
final Map<String, dynamic>? values;
|
||||||
final bool required;
|
final bool required;
|
||||||
final String optionClassType;
|
final String valueType;
|
||||||
|
|
||||||
Map toJson() => _$OptionToJson(this);
|
Map toJson() => _$OptionToJson(this);
|
||||||
}
|
}
|
||||||
|
@ -61,8 +61,8 @@ class PatchOptionsView extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
for (final Option option in model.visibleOptions)
|
for (final Option option in model.visibleOptions)
|
||||||
if (option.optionClassType == 'StringPatchOption' ||
|
if (option.valueType == 'String' ||
|
||||||
option.optionClassType == 'IntPatchOption')
|
option.valueType == 'Int')
|
||||||
IntAndStringPatchOption(
|
IntAndStringPatchOption(
|
||||||
patchOption: option,
|
patchOption: option,
|
||||||
removeOption: (option) {
|
removeOption: (option) {
|
||||||
@ -72,7 +72,7 @@ class PatchOptionsView extends StatelessWidget {
|
|||||||
model.modifyOptions(value, option);
|
model.modifyOptions(value, option);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
else if (option.optionClassType == 'BooleanPatchOption')
|
else if (option.valueType == 'Boolean')
|
||||||
BooleanPatchOption(
|
BooleanPatchOption(
|
||||||
patchOption: option,
|
patchOption: option,
|
||||||
removeOption: (option) {
|
removeOption: (option) {
|
||||||
@ -82,10 +82,10 @@ class PatchOptionsView extends StatelessWidget {
|
|||||||
model.modifyOptions(value, option);
|
model.modifyOptions(value, option);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
else if (option.optionClassType ==
|
else if (option.valueType ==
|
||||||
'StringListPatchOption' ||
|
'StringArray' ||
|
||||||
option.optionClassType == 'IntListPatchOption' ||
|
option.valueType == 'IntArray' ||
|
||||||
option.optionClassType == 'LongListPatchOption')
|
option.valueType == 'LongArray')
|
||||||
IntStringLongListPatchOption(
|
IntStringLongListPatchOption(
|
||||||
patchOption: option,
|
patchOption: option,
|
||||||
removeOption: (option) {
|
removeOption: (option) {
|
||||||
|
@ -62,7 +62,10 @@ class PatchOptionsViewModel extends BaseViewModel {
|
|||||||
for (final Option option in options) {
|
for (final Option option in options) {
|
||||||
if (!visibleOptions.any((vOption) => vOption.key == option.key)) {
|
if (!visibleOptions.any((vOption) => vOption.key == option.key)) {
|
||||||
_managerAPI.clearPatchOption(
|
_managerAPI.clearPatchOption(
|
||||||
selectedApp, _managerAPI.selectedPatch!.name, option.key);
|
selectedApp,
|
||||||
|
_managerAPI.selectedPatch!.name,
|
||||||
|
option.key,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final Option option in visibleOptions) {
|
for (final Option option in visibleOptions) {
|
||||||
@ -70,7 +73,10 @@ class PatchOptionsViewModel extends BaseViewModel {
|
|||||||
requiredNullOptions.add(option);
|
requiredNullOptions.add(option);
|
||||||
} else {
|
} else {
|
||||||
_managerAPI.setPatchOption(
|
_managerAPI.setPatchOption(
|
||||||
option, _managerAPI.selectedPatch!.name, selectedApp);
|
option,
|
||||||
|
_managerAPI.selectedPatch!.name,
|
||||||
|
selectedApp,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requiredNullOptions.isNotEmpty) {
|
if (requiredNullOptions.isNotEmpty) {
|
||||||
@ -89,7 +95,8 @@ class PatchOptionsViewModel extends BaseViewModel {
|
|||||||
final Option modifiedOption = Option(
|
final Option modifiedOption = Option(
|
||||||
title: option.title,
|
title: option.title,
|
||||||
description: option.description,
|
description: option.description,
|
||||||
optionClassType: option.optionClassType,
|
values: option.values,
|
||||||
|
valueType: option.valueType,
|
||||||
value: value,
|
value: value,
|
||||||
required: option.required,
|
required: option.required,
|
||||||
key: option.key,
|
key: option.key,
|
||||||
@ -107,7 +114,8 @@ class PatchOptionsViewModel extends BaseViewModel {
|
|||||||
final Option defaultOption = Option(
|
final Option defaultOption = Option(
|
||||||
title: option.title,
|
title: option.title,
|
||||||
description: option.description,
|
description: option.description,
|
||||||
optionClassType: option.optionClassType,
|
values: option.values,
|
||||||
|
valueType: option.valueType,
|
||||||
value: option.value is List ? option.value.toList() : option.value,
|
value: option.value is List ? option.value.toList() : option.value,
|
||||||
required: option.required,
|
required: option.required,
|
||||||
key: option.key,
|
key: option.key,
|
||||||
@ -172,21 +180,27 @@ class PatchOptionsViewModel extends BaseViewModel {
|
|||||||
},
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: Column(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Expanded(
|
||||||
e.title,
|
child: Column(
|
||||||
style: const TextStyle(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
fontSize: 16,
|
children: [
|
||||||
),
|
Text(
|
||||||
),
|
e.title,
|
||||||
const SizedBox(height: 4),
|
style: const TextStyle(
|
||||||
Text(
|
fontSize: 16,
|
||||||
e.description,
|
),
|
||||||
style: TextStyle(
|
),
|
||||||
fontSize: 14,
|
const SizedBox(height: 4),
|
||||||
color: Theme.of(context).colorScheme.onSurface,
|
Text(
|
||||||
|
e.description,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Theme.of(context).colorScheme.onSurface,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -229,7 +243,10 @@ Future<void> showRequiredOptionNullDialog(
|
|||||||
locator<PatcherViewModel>().notifyListeners();
|
locator<PatcherViewModel>().notifyListeners();
|
||||||
for (final option in options) {
|
for (final option in options) {
|
||||||
managerAPI.clearPatchOption(
|
managerAPI.clearPatchOption(
|
||||||
selectedApp, managerAPI.selectedPatch!.name, option.key);
|
selectedApp,
|
||||||
|
managerAPI.selectedPatch!.name,
|
||||||
|
option.key,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Navigator.of(context)
|
Navigator.of(context)
|
||||||
..pop()
|
..pop()
|
||||||
|
@ -59,13 +59,27 @@ class IntAndStringPatchOption extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final ValueNotifier patchOptionValue = ValueNotifier(patchOption.value);
|
final ValueNotifier patchOptionValue = ValueNotifier(patchOption.value);
|
||||||
|
String getKey() {
|
||||||
|
if (patchOption.value != null && patchOption.values != null) {
|
||||||
|
final List values = patchOption.values!.entries
|
||||||
|
.where((e) => e.value == patchOption.value)
|
||||||
|
.toList();
|
||||||
|
if (values.isNotEmpty) {
|
||||||
|
return values.first.key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
return PatchOption(
|
return PatchOption(
|
||||||
widget: Column(
|
widget: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
TextFieldForPatchOption(
|
TextFieldForPatchOption(
|
||||||
value: patchOption.value,
|
value: patchOption.value,
|
||||||
optionType: patchOption.optionClassType,
|
values: patchOption.values,
|
||||||
|
optionType: patchOption.valueType,
|
||||||
|
selectedKey: getKey(),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
patchOptionValue.value = value;
|
patchOptionValue.value = value;
|
||||||
onChanged(value, patchOption);
|
onChanged(value, patchOption);
|
||||||
@ -119,17 +133,41 @@ class IntStringLongListPatchOption extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final String type = patchOption.optionClassType;
|
final List<dynamic> values = List.from(patchOption.value ?? []);
|
||||||
final List<dynamic> values = patchOption.value ?? [];
|
|
||||||
final ValueNotifier patchOptionValue = ValueNotifier(values);
|
final ValueNotifier patchOptionValue = ValueNotifier(values);
|
||||||
|
final String type = patchOption.valueType;
|
||||||
|
|
||||||
|
String getKey(dynamic value) {
|
||||||
|
if (value != null && patchOption.values != null) {
|
||||||
|
final List values = patchOption.values!.entries
|
||||||
|
.where((e) => e.value.toString() == value)
|
||||||
|
.toList();
|
||||||
|
if (values.isNotEmpty) {
|
||||||
|
return values.first.key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isCustomValue() {
|
||||||
|
if (values.length == 1 && patchOption.values != null) {
|
||||||
|
if (getKey(values[0]) != '') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isTextFieldVisible = isCustomValue();
|
||||||
|
|
||||||
return PatchOption(
|
return PatchOption(
|
||||||
widget: Column(
|
widget: ValueListenableBuilder(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
valueListenable: patchOptionValue,
|
||||||
children: [
|
builder: (context, value, child) {
|
||||||
ValueListenableBuilder(
|
return Column(
|
||||||
valueListenable: patchOptionValue,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
builder: (context, value, child) {
|
children: [
|
||||||
return ListView.builder(
|
ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
itemCount: value.length,
|
itemCount: value.length,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
@ -137,16 +175,42 @@ class IntStringLongListPatchOption extends StatelessWidget {
|
|||||||
final e = values[index];
|
final e = values[index];
|
||||||
return TextFieldForPatchOption(
|
return TextFieldForPatchOption(
|
||||||
value: e.toString(),
|
value: e.toString(),
|
||||||
|
values: patchOption.values,
|
||||||
optionType: type,
|
optionType: type,
|
||||||
|
selectedKey: value.length > 1 ? '' : getKey(e),
|
||||||
|
showDropdown: index == 0,
|
||||||
onChanged: (newValue) {
|
onChanged: (newValue) {
|
||||||
values[index] = type == 'StringListPatchOption'
|
if (newValue is List) {
|
||||||
? newValue
|
values.clear();
|
||||||
: type == 'IntListPatchOption'
|
isTextFieldVisible = false;
|
||||||
? int.parse(newValue)
|
values.add(newValue.toString());
|
||||||
: num.parse(newValue);
|
} else {
|
||||||
|
isTextFieldVisible = true;
|
||||||
|
if (values.length == 1 &&
|
||||||
|
values[0].toString().startsWith('[') &&
|
||||||
|
type.contains('Array')) {
|
||||||
|
values.clear();
|
||||||
|
values.addAll(patchOption.value);
|
||||||
|
} else {
|
||||||
|
values[index] = type == 'StringArray'
|
||||||
|
? newValue
|
||||||
|
: type == 'IntArray'
|
||||||
|
? int.parse(
|
||||||
|
newValue.toString().isEmpty
|
||||||
|
? '0'
|
||||||
|
: newValue.toString(),
|
||||||
|
)
|
||||||
|
: num.parse(
|
||||||
|
newValue.toString().isEmpty
|
||||||
|
? '0'
|
||||||
|
: newValue.toString(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
patchOptionValue.value = List.from(values);
|
||||||
onChanged(values, patchOption);
|
onChanged(values, patchOption);
|
||||||
},
|
},
|
||||||
removeValue: (value) {
|
removeValue: () {
|
||||||
patchOptionValue.value = List.from(patchOptionValue.value)
|
patchOptionValue.value = List.from(patchOptionValue.value)
|
||||||
..removeAt(index);
|
..removeAt(index);
|
||||||
values.removeAt(index);
|
values.removeAt(index);
|
||||||
@ -154,44 +218,46 @@ class IntStringLongListPatchOption extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
),
|
||||||
},
|
if (isTextFieldVisible) ...[
|
||||||
),
|
const SizedBox(height: 4),
|
||||||
const SizedBox(height: 4),
|
Align(
|
||||||
Align(
|
alignment: Alignment.centerLeft,
|
||||||
alignment: Alignment.centerLeft,
|
child: TextButton(
|
||||||
child: TextButton(
|
onPressed: () {
|
||||||
onPressed: () {
|
if (type == 'StringArray') {
|
||||||
if (type == 'StringListPatchOption') {
|
patchOptionValue.value =
|
||||||
patchOptionValue.value = List.from(patchOptionValue.value)
|
List.from(patchOptionValue.value)..add('');
|
||||||
..add('');
|
values.add('');
|
||||||
values.add('');
|
} else {
|
||||||
} else {
|
patchOptionValue.value =
|
||||||
patchOptionValue.value = List.from(patchOptionValue.value)
|
List.from(patchOptionValue.value)..add(0);
|
||||||
..add(0);
|
values.add(0);
|
||||||
values.add(0);
|
}
|
||||||
}
|
onChanged(values, patchOption);
|
||||||
onChanged(values, patchOption);
|
},
|
||||||
},
|
child: Row(
|
||||||
child: Row(
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisSize: MainAxisSize.min,
|
children: [
|
||||||
children: [
|
const Icon(Icons.add, size: 20),
|
||||||
const Icon(Icons.add, size: 20),
|
I18nText(
|
||||||
I18nText(
|
'add',
|
||||||
'add',
|
child: const Text(
|
||||||
child: const Text(
|
'',
|
||||||
'',
|
style: TextStyle(
|
||||||
style: TextStyle(
|
fontSize: 14,
|
||||||
fontSize: 14,
|
fontWeight: FontWeight.w600,
|
||||||
fontWeight: FontWeight.w600,
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
),
|
],
|
||||||
),
|
);
|
||||||
],
|
},
|
||||||
),
|
),
|
||||||
patchOption: patchOption,
|
patchOption: patchOption,
|
||||||
removeOption: (Option option) {
|
removeOption: (Option option) {
|
||||||
@ -203,6 +269,7 @@ class IntStringLongListPatchOption extends StatelessWidget {
|
|||||||
|
|
||||||
class UnsupportedPatchOption extends StatelessWidget {
|
class UnsupportedPatchOption extends StatelessWidget {
|
||||||
const UnsupportedPatchOption({super.key, required this.patchOption});
|
const UnsupportedPatchOption({super.key, required this.patchOption});
|
||||||
|
|
||||||
final Option patchOption;
|
final Option patchOption;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -302,14 +369,20 @@ class TextFieldForPatchOption extends StatefulWidget {
|
|||||||
const TextFieldForPatchOption({
|
const TextFieldForPatchOption({
|
||||||
super.key,
|
super.key,
|
||||||
required this.value,
|
required this.value,
|
||||||
|
required this.values,
|
||||||
this.removeValue,
|
this.removeValue,
|
||||||
required this.onChanged,
|
required this.onChanged,
|
||||||
required this.optionType,
|
required this.optionType,
|
||||||
|
required this.selectedKey,
|
||||||
|
this.showDropdown = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String? value;
|
final String? value;
|
||||||
|
final Map<String, dynamic>? values;
|
||||||
final String optionType;
|
final String optionType;
|
||||||
final void Function(dynamic value)? removeValue;
|
final String selectedKey;
|
||||||
|
final bool showDropdown;
|
||||||
|
final void Function()? removeValue;
|
||||||
final void Function(dynamic value) onChanged;
|
final void Function(dynamic value) onChanged;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -319,75 +392,156 @@ class TextFieldForPatchOption extends StatefulWidget {
|
|||||||
|
|
||||||
class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
|
class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
|
||||||
final TextEditingController controller = TextEditingController();
|
final TextEditingController controller = TextEditingController();
|
||||||
|
String? selectedKey;
|
||||||
|
String? defaultValue;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final bool isStringOption = widget.optionType.contains('String');
|
final bool isStringOption = widget.optionType.contains('String');
|
||||||
final bool isListOption = widget.optionType.contains('List');
|
final bool isArrayOption = widget.optionType.contains('Array');
|
||||||
controller.text = widget.value ?? '';
|
selectedKey ??= widget.selectedKey;
|
||||||
return TextFormField(
|
controller.text = !isStringOption && isArrayOption && selectedKey == '' &&
|
||||||
inputFormatters: [
|
(widget.value != null && widget.value.toString().startsWith('['))
|
||||||
if (widget.optionType.contains('Int'))
|
? ''
|
||||||
FilteringTextInputFormatter.allow(RegExp(r'[0-9]')),
|
: widget.value ?? '';
|
||||||
if (widget.optionType.contains('Long'))
|
defaultValue ??= controller.text;
|
||||||
FilteringTextInputFormatter.allow(RegExp(r'^[0-9]*\.?[0-9]*')),
|
return Column(
|
||||||
],
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
controller: controller,
|
children: [
|
||||||
keyboardType: isStringOption ? TextInputType.text : TextInputType.number,
|
if (widget.showDropdown && (widget.values?.isNotEmpty ?? false))
|
||||||
decoration: InputDecoration(
|
DropdownButton<String>(
|
||||||
suffixIcon: PopupMenuButton(
|
style: const TextStyle(
|
||||||
tooltip: FlutterI18n.translate(
|
fontSize: 16,
|
||||||
context,
|
),
|
||||||
'patchOptionsView.tooltip',
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
dropdownColor: Theme.of(context).colorScheme.secondaryContainer,
|
||||||
|
isExpanded: true,
|
||||||
|
value: selectedKey,
|
||||||
|
items: widget.values!.entries
|
||||||
|
.map(
|
||||||
|
(e) => DropdownMenuItem(
|
||||||
|
value: e.key,
|
||||||
|
child: RichText(
|
||||||
|
text: TextSpan(
|
||||||
|
text: e.key,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
children: [
|
||||||
|
TextSpan(
|
||||||
|
text: ' ${e.value}',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.onSecondaryContainer
|
||||||
|
.withOpacity(0.6),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList()
|
||||||
|
..add(
|
||||||
|
DropdownMenuItem(
|
||||||
|
value: '',
|
||||||
|
child: I18nText(
|
||||||
|
'patchOptionsView.customValue',
|
||||||
|
child: const Text(
|
||||||
|
'',
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onChanged: (value) {
|
||||||
|
if (value == '') {
|
||||||
|
controller.text = defaultValue!;
|
||||||
|
widget.onChanged(controller.text);
|
||||||
|
} else {
|
||||||
|
controller.text = widget.values![value].toString();
|
||||||
|
widget.onChanged(
|
||||||
|
isArrayOption ? widget.values![value] : controller.text,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
setState(() {
|
||||||
|
selectedKey = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
),
|
),
|
||||||
itemBuilder: (BuildContext context) {
|
if (selectedKey == '')
|
||||||
return [
|
TextFormField(
|
||||||
if (isListOption)
|
inputFormatters: [
|
||||||
PopupMenuItem(
|
if (widget.optionType.contains('Int'))
|
||||||
value: 'remove',
|
FilteringTextInputFormatter.allow(RegExp(r'[0-9]')),
|
||||||
child: I18nText('remove'),
|
if (widget.optionType.contains('Long'))
|
||||||
|
FilteringTextInputFormatter.allow(RegExp(r'^[0-9]*\.?[0-9]*')),
|
||||||
|
],
|
||||||
|
controller: controller,
|
||||||
|
keyboardType:
|
||||||
|
isStringOption ? TextInputType.text : TextInputType.number,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
suffixIcon: PopupMenuButton(
|
||||||
|
tooltip: FlutterI18n.translate(
|
||||||
|
context,
|
||||||
|
'patchOptionsView.tooltip',
|
||||||
),
|
),
|
||||||
if (isStringOption && !isListOption) ...[
|
itemBuilder: (BuildContext context) {
|
||||||
PopupMenuItem(
|
return [
|
||||||
value: 'patchOptionsView.selectFilePath',
|
if (isArrayOption)
|
||||||
child: I18nText('patchOptionsView.selectFilePath'),
|
PopupMenuItem(
|
||||||
),
|
value: 'remove',
|
||||||
PopupMenuItem(
|
child: I18nText('remove'),
|
||||||
value: 'patchOptionsView.selectFolder',
|
),
|
||||||
child: I18nText('patchOptionsView.selectFolder'),
|
if (isStringOption) ...[
|
||||||
),
|
PopupMenuItem(
|
||||||
],
|
value: 'patchOptionsView.selectFilePath',
|
||||||
];
|
child: I18nText('patchOptionsView.selectFilePath'),
|
||||||
},
|
),
|
||||||
onSelected: (String selection) async {
|
PopupMenuItem(
|
||||||
switch (selection) {
|
value: 'patchOptionsView.selectFolder',
|
||||||
case 'patchOptionsView.selectFilePath':
|
child: I18nText('patchOptionsView.selectFolder'),
|
||||||
final result = await FilePicker.platform.pickFiles();
|
),
|
||||||
if (result != null && result.files.single.path != null) {
|
],
|
||||||
controller.text = result.files.single.path.toString();
|
];
|
||||||
widget.onChanged(controller.text);
|
},
|
||||||
}
|
onSelected: (String selection) async {
|
||||||
break;
|
switch (selection) {
|
||||||
case 'patchOptionsView.selectFolder':
|
case 'patchOptionsView.selectFilePath':
|
||||||
final result = await FilePicker.platform.getDirectoryPath();
|
final result = await FilePicker.platform.pickFiles();
|
||||||
if (result != null) {
|
if (result != null && result.files.single.path != null) {
|
||||||
controller.text = result;
|
controller.text = result.files.single.path.toString();
|
||||||
widget.onChanged(controller.text);
|
widget.onChanged(controller.text);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'remove':
|
case 'patchOptionsView.selectFolder':
|
||||||
widget.removeValue!(widget.value);
|
final result =
|
||||||
break;
|
await FilePicker.platform.getDirectoryPath();
|
||||||
}
|
if (result != null) {
|
||||||
},
|
controller.text = result;
|
||||||
),
|
widget.onChanged(controller.text);
|
||||||
hintStyle: TextStyle(
|
}
|
||||||
fontSize: 14,
|
break;
|
||||||
color: Theme.of(context).colorScheme.onSecondaryContainer,
|
case 'remove':
|
||||||
),
|
widget.removeValue!();
|
||||||
),
|
break;
|
||||||
onChanged: (String value) {
|
}
|
||||||
widget.onChanged(value);
|
},
|
||||||
},
|
),
|
||||||
|
hintStyle: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Theme.of(context).colorScheme.onSecondaryContainer,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onChanged: (String value) {
|
||||||
|
widget.onChanged(value);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,12 @@ bool isPatchSupported(Patch patch) {
|
|||||||
bool hasUnsupportedRequiredOption(List<Option> options, Patch patch) {
|
bool hasUnsupportedRequiredOption(List<Option> options, Patch patch) {
|
||||||
final List<String> requiredOptionsType = [];
|
final List<String> requiredOptionsType = [];
|
||||||
final List<String> supportedOptionsType = [
|
final List<String> supportedOptionsType = [
|
||||||
'StringPatchOption',
|
'String',
|
||||||
'BooleanPatchOption',
|
'Boolean',
|
||||||
'IntPatchOption',
|
'Int',
|
||||||
'StringListPatchOption',
|
'StringArray',
|
||||||
'IntListPatchOption',
|
'IntArray',
|
||||||
'LongListPatchOption',
|
'LongArray',
|
||||||
];
|
];
|
||||||
for (final Option option in options) {
|
for (final Option option in options) {
|
||||||
if (option.required &&
|
if (option.required &&
|
||||||
@ -33,7 +33,7 @@ bool hasUnsupportedRequiredOption(List<Option> options, Patch patch) {
|
|||||||
patch.name,
|
patch.name,
|
||||||
option.key,
|
option.key,
|
||||||
) == null) {
|
) == null) {
|
||||||
requiredOptionsType.add(option.optionClassType);
|
requiredOptionsType.add(option.valueType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final String optionType in requiredOptionsType) {
|
for (final String optionType in requiredOptionsType) {
|
||||||
|
Loading…
Reference in New Issue
Block a user