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)
|
||||||
|
|
||||||
|
option.values?.let { values ->
|
||||||
|
put("values",
|
||||||
|
JSONObject().apply {
|
||||||
|
values.forEach { (key, value) ->
|
||||||
|
putValue(value, key)
|
||||||
}
|
}
|
||||||
put(optionJson)
|
})
|
||||||
|
} ?: 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,6 +180,9 @@ class PatchOptionsViewModel extends BaseViewModel {
|
|||||||
},
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@ -192,6 +203,9 @@ class PatchOptionsViewModel extends BaseViewModel {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
@ -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,
|
|
||||||
children: [
|
|
||||||
ValueListenableBuilder(
|
|
||||||
valueListenable: patchOptionValue,
|
valueListenable: patchOptionValue,
|
||||||
builder: (context, value, child) {
|
builder: (context, value, child) {
|
||||||
return ListView.builder(
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
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) {
|
||||||
|
values.clear();
|
||||||
|
isTextFieldVisible = false;
|
||||||
|
values.add(newValue.toString());
|
||||||
|
} 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
|
? newValue
|
||||||
: type == 'IntListPatchOption'
|
: type == 'IntArray'
|
||||||
? int.parse(newValue)
|
? int.parse(
|
||||||
: num.parse(newValue);
|
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,21 +218,20 @@ 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 == 'StringListPatchOption') {
|
if (type == 'StringArray') {
|
||||||
patchOptionValue.value = List.from(patchOptionValue.value)
|
patchOptionValue.value =
|
||||||
..add('');
|
List.from(patchOptionValue.value)..add('');
|
||||||
values.add('');
|
values.add('');
|
||||||
} else {
|
} else {
|
||||||
patchOptionValue.value = List.from(patchOptionValue.value)
|
patchOptionValue.value =
|
||||||
..add(0);
|
List.from(patchOptionValue.value)..add(0);
|
||||||
values.add(0);
|
values.add(0);
|
||||||
}
|
}
|
||||||
onChanged(values, patchOption);
|
onChanged(values, patchOption);
|
||||||
@ -192,6 +255,9 @@ class IntStringLongListPatchOption extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
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,12 +392,89 @@ 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 == '' &&
|
||||||
|
(widget.value != null && widget.value.toString().startsWith('['))
|
||||||
|
? ''
|
||||||
|
: widget.value ?? '';
|
||||||
|
defaultValue ??= controller.text;
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
if (widget.showDropdown && (widget.values?.isNotEmpty ?? false))
|
||||||
|
DropdownButton<String>(
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
if (selectedKey == '')
|
||||||
|
TextFormField(
|
||||||
inputFormatters: [
|
inputFormatters: [
|
||||||
if (widget.optionType.contains('Int'))
|
if (widget.optionType.contains('Int'))
|
||||||
FilteringTextInputFormatter.allow(RegExp(r'[0-9]')),
|
FilteringTextInputFormatter.allow(RegExp(r'[0-9]')),
|
||||||
@ -332,7 +482,8 @@ class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
|
|||||||
FilteringTextInputFormatter.allow(RegExp(r'^[0-9]*\.?[0-9]*')),
|
FilteringTextInputFormatter.allow(RegExp(r'^[0-9]*\.?[0-9]*')),
|
||||||
],
|
],
|
||||||
controller: controller,
|
controller: controller,
|
||||||
keyboardType: isStringOption ? TextInputType.text : TextInputType.number,
|
keyboardType:
|
||||||
|
isStringOption ? TextInputType.text : TextInputType.number,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
suffixIcon: PopupMenuButton(
|
suffixIcon: PopupMenuButton(
|
||||||
tooltip: FlutterI18n.translate(
|
tooltip: FlutterI18n.translate(
|
||||||
@ -341,12 +492,12 @@ class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
|
|||||||
),
|
),
|
||||||
itemBuilder: (BuildContext context) {
|
itemBuilder: (BuildContext context) {
|
||||||
return [
|
return [
|
||||||
if (isListOption)
|
if (isArrayOption)
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: 'remove',
|
value: 'remove',
|
||||||
child: I18nText('remove'),
|
child: I18nText('remove'),
|
||||||
),
|
),
|
||||||
if (isStringOption && !isListOption) ...[
|
if (isStringOption) ...[
|
||||||
PopupMenuItem(
|
PopupMenuItem(
|
||||||
value: 'patchOptionsView.selectFilePath',
|
value: 'patchOptionsView.selectFilePath',
|
||||||
child: I18nText('patchOptionsView.selectFilePath'),
|
child: I18nText('patchOptionsView.selectFilePath'),
|
||||||
@ -368,14 +519,15 @@ class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'patchOptionsView.selectFolder':
|
case 'patchOptionsView.selectFolder':
|
||||||
final result = await FilePicker.platform.getDirectoryPath();
|
final result =
|
||||||
|
await FilePicker.platform.getDirectoryPath();
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
controller.text = result;
|
controller.text = result;
|
||||||
widget.onChanged(controller.text);
|
widget.onChanged(controller.text);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'remove':
|
case 'remove':
|
||||||
widget.removeValue!(widget.value);
|
widget.removeValue!();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -388,6 +540,8 @@ class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
|
|||||||
onChanged: (String value) {
|
onChanged: (String value) {
|
||||||
widget.onChanged(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