mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-23 22:49:30 +02:00
Made defaultvallue part of formitem
This commit is contained in:
@@ -49,20 +49,18 @@ class GitHub extends AppSource {
|
|||||||
])
|
])
|
||||||
];
|
];
|
||||||
|
|
||||||
additionalSourceAppSpecificDefaults = {
|
|
||||||
'includePrereleases': 'true',
|
|
||||||
'fallbackToOlderReleases': 'true',
|
|
||||||
'filterReleaseTitlesByRegEx': ''
|
|
||||||
};
|
|
||||||
|
|
||||||
additionalSourceAppSpecificFormItems = [
|
additionalSourceAppSpecificFormItems = [
|
||||||
[
|
[
|
||||||
GeneratedFormItem('includePrereleases',
|
GeneratedFormItem('includePrereleases',
|
||||||
label: tr('includePrereleases'), type: FormItemType.bool)
|
label: tr('includePrereleases'),
|
||||||
|
type: FormItemType.bool,
|
||||||
|
defaultValue: 'true')
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
GeneratedFormItem('fallbackToOlderReleases',
|
GeneratedFormItem('fallbackToOlderReleases',
|
||||||
label: tr('fallbackToOlderReleases'), type: FormItemType.bool)
|
label: tr('fallbackToOlderReleases'),
|
||||||
|
type: FormItemType.bool,
|
||||||
|
defaultValue: 'true')
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
GeneratedFormItem('filterReleaseTitlesByRegEx',
|
GeneratedFormItem('filterReleaseTitlesByRegEx',
|
||||||
|
@@ -16,6 +16,7 @@ class GeneratedFormItem {
|
|||||||
late List<Widget> belowWidgets;
|
late List<Widget> belowWidgets;
|
||||||
late String? hint;
|
late String? hint;
|
||||||
late List<MapEntry<String, String>>? opts;
|
late List<MapEntry<String, String>>? opts;
|
||||||
|
late String? defaultValue;
|
||||||
|
|
||||||
GeneratedFormItem(this.key,
|
GeneratedFormItem(this.key,
|
||||||
{this.label = 'Input',
|
{this.label = 'Input',
|
||||||
@@ -25,7 +26,8 @@ class GeneratedFormItem {
|
|||||||
this.additionalValidators = const [],
|
this.additionalValidators = const [],
|
||||||
this.belowWidgets = const [],
|
this.belowWidgets = const [],
|
||||||
this.hint,
|
this.hint,
|
||||||
this.opts}) {
|
this.opts,
|
||||||
|
this.defaultValue}) {
|
||||||
if (type != FormItemType.string) {
|
if (type != FormItemType.string) {
|
||||||
required = false;
|
required = false;
|
||||||
}
|
}
|
||||||
@@ -34,14 +36,10 @@ class GeneratedFormItem {
|
|||||||
|
|
||||||
class GeneratedForm extends StatefulWidget {
|
class GeneratedForm extends StatefulWidget {
|
||||||
const GeneratedForm(
|
const GeneratedForm(
|
||||||
{super.key,
|
{super.key, required this.items, required this.onValueChanges});
|
||||||
required this.items,
|
|
||||||
required this.onValueChanges,
|
|
||||||
required this.defaultValues});
|
|
||||||
|
|
||||||
final List<List<GeneratedFormItem>> items;
|
final List<List<GeneratedFormItem>> items;
|
||||||
final OnValueChanges onValueChanges;
|
final OnValueChanges onValueChanges;
|
||||||
final Map<String, String> defaultValues;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<GeneratedForm> createState() => _GeneratedFormState();
|
State<GeneratedForm> createState() => _GeneratedFormState();
|
||||||
@@ -82,7 +80,7 @@ class _GeneratedFormState extends State<GeneratedForm> {
|
|||||||
int j = 0;
|
int j = 0;
|
||||||
for (var row in widget.items) {
|
for (var row in widget.items) {
|
||||||
for (var e in row) {
|
for (var e in row) {
|
||||||
values[e.key] = widget.defaultValues[e.key] ?? e.opts?.first.key ?? '';
|
values[e.key] = e.defaultValue ?? e.opts?.first.key ?? '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -59,8 +59,7 @@ class _GeneratedFormModalState extends State<GeneratedFormModal> {
|
|||||||
this.valid = valid;
|
this.valid = valid;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
defaultValues: widget.defaultValues)
|
|
||||||
]),
|
]),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
|
@@ -43,8 +43,10 @@ class _AddAppPageState extends State<AddAppPage> {
|
|||||||
var source = valid ? sourceProvider.getSource(userInput) : null;
|
var source = valid ? sourceProvider.getSource(userInput) : null;
|
||||||
if (pickedSource.runtimeType != source.runtimeType) {
|
if (pickedSource.runtimeType != source.runtimeType) {
|
||||||
pickedSource = source;
|
pickedSource = source;
|
||||||
sourceSpecificAdditionalData =
|
sourceSpecificAdditionalData = source != null
|
||||||
source != null ? source.additionalSourceAppSpecificDefaults : {};
|
? getDefaultValuesFromFormItems(
|
||||||
|
source.additionalSourceAppSpecificFormItems)
|
||||||
|
: {};
|
||||||
sourceSpecificDataIsValid = source != null
|
sourceSpecificDataIsValid = source != null
|
||||||
? !sourceProvider.ifSourceAppsRequireAdditionalData(source)
|
? !sourceProvider.ifSourceAppsRequireAdditionalData(source)
|
||||||
: true;
|
: true;
|
||||||
@@ -196,8 +198,7 @@ class _AddAppPageState extends State<AddAppPage> {
|
|||||||
onValueChanges: (values, valid, isBuilding) {
|
onValueChanges: (values, valid, isBuilding) {
|
||||||
changeUserInput(values['appSourceURL']!,
|
changeUserInput(values['appSourceURL']!,
|
||||||
valid, isBuilding);
|
valid, isBuilding);
|
||||||
},
|
})),
|
||||||
defaultValues: const {'appSourceURL': ''})),
|
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 16,
|
width: 16,
|
||||||
),
|
),
|
||||||
@@ -211,7 +212,7 @@ class _AddAppPageState extends State<AddAppPage> {
|
|||||||
.isNotEmpty &&
|
.isNotEmpty &&
|
||||||
!sourceSpecificDataIsValid) ||
|
!sourceSpecificDataIsValid) ||
|
||||||
(pickedSource!
|
(pickedSource!
|
||||||
.additionalAppSpecificSourceAgnosticDefaults
|
.additionalAppSpecificSourceAgnosticFormItems
|
||||||
.isNotEmpty &&
|
.isNotEmpty &&
|
||||||
!otherAdditionalDataIsValid)
|
!otherAdditionalDataIsValid)
|
||||||
? null
|
? null
|
||||||
@@ -250,9 +251,6 @@ class _AddAppPageState extends State<AddAppPage> {
|
|||||||
values['searchSomeSources']!.trim();
|
values['searchSomeSources']!.trim();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
|
||||||
defaultValues: const {
|
|
||||||
'searchSomeSources': ''
|
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
@@ -309,7 +307,7 @@ class _AddAppPageState extends State<AddAppPage> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (pickedSource != null &&
|
if (pickedSource != null &&
|
||||||
(pickedSource!.additionalSourceAppSpecificDefaults
|
(pickedSource!.additionalSourceAppSpecificFormItems
|
||||||
.isNotEmpty ||
|
.isNotEmpty ||
|
||||||
pickedSource!
|
pickedSource!
|
||||||
.additionalAppSpecificSourceAgnosticFormItems
|
.additionalAppSpecificSourceAgnosticFormItems
|
||||||
@@ -346,11 +344,9 @@ class _AddAppPageState extends State<AddAppPage> {
|
|||||||
sourceSpecificDataIsValid = valid;
|
sourceSpecificDataIsValid = valid;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
defaultValues: pickedSource!
|
|
||||||
.additionalSourceAppSpecificDefaults),
|
|
||||||
if (pickedSource!
|
if (pickedSource!
|
||||||
.additionalAppSpecificSourceAgnosticDefaults
|
.additionalAppSpecificSourceAgnosticFormItems
|
||||||
.isNotEmpty)
|
.isNotEmpty)
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 8,
|
height: 8,
|
||||||
@@ -370,9 +366,7 @@ class _AddAppPageState extends State<AddAppPage> {
|
|||||||
otherAdditionalDataIsValid = valid;
|
otherAdditionalDataIsValid = valid;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
defaultValues: pickedSource!
|
|
||||||
.additionalAppSpecificSourceAgnosticDefaults),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
|
@@ -217,8 +217,9 @@ class _AppPageState extends State<AppPage> {
|
|||||||
.additionalSourceAppSpecificFormItems,
|
.additionalSourceAppSpecificFormItems,
|
||||||
defaultValues: app != null
|
defaultValues: app != null
|
||||||
? app.app.additionalData
|
? app.app.additionalData
|
||||||
: source
|
: getDefaultValuesFromFormItems(
|
||||||
.additionalSourceAppSpecificDefaults);
|
source
|
||||||
|
.additionalSourceAppSpecificFormItems));
|
||||||
}).then((values) {
|
}).then((values) {
|
||||||
if (app != null && values != null) {
|
if (app != null && values != null) {
|
||||||
var changedApp = app.app;
|
var changedApp = app.app;
|
||||||
|
@@ -147,12 +147,7 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||||||
settingsProvider.setSettingString(key, value);
|
settingsProvider.setSettingString(key, value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
defaultValues: Map.fromEntries(
|
|
||||||
e.additionalSourceSpecificSettingFormItems.map((e) {
|
|
||||||
return MapEntry(
|
|
||||||
e.key, settingsProvider.getSettingString(e.key) ?? '');
|
|
||||||
})));
|
|
||||||
} else {
|
} else {
|
||||||
return Container();
|
return Container();
|
||||||
}
|
}
|
||||||
|
@@ -83,9 +83,9 @@ class App {
|
|||||||
: List<String>.from(jsonDecode(json['apkUrls'])),
|
: List<String>.from(jsonDecode(json['apkUrls'])),
|
||||||
json['preferredApkIndex'] == null ? 0 : json['preferredApkIndex'] as int,
|
json['preferredApkIndex'] == null ? 0 : json['preferredApkIndex'] as int,
|
||||||
json['additionalData'] == null
|
json['additionalData'] == null
|
||||||
? SourceProvider()
|
? getDefaultValuesFromFormItems(SourceProvider()
|
||||||
.getSource(json['url'])
|
.getSource(json['url'])
|
||||||
.additionalSourceAppSpecificDefaults
|
.additionalSourceAppSpecificFormItems)
|
||||||
: Map<String, String>.from(jsonDecode(json['additionalData'])),
|
: Map<String, String>.from(jsonDecode(json['additionalData'])),
|
||||||
json['lastUpdateCheck'] == null
|
json['lastUpdateCheck'] == null
|
||||||
? null
|
? null
|
||||||
@@ -141,6 +141,12 @@ List<String> getLinksFromParsedHTML(
|
|||||||
.map((e) => '$prependToLinks${e.attributes['href']!}')
|
.map((e) => '$prependToLinks${e.attributes['href']!}')
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
getDefaultValuesFromFormItems(List<List<GeneratedFormItem>> items) {
|
||||||
|
Map.fromEntries(items
|
||||||
|
.map((row) => row.map((el) => MapEntry(el.key, el.defaultValue ?? '')))
|
||||||
|
.reduce((value, element) => [...value, ...element]));
|
||||||
|
}
|
||||||
|
|
||||||
class AppSource {
|
class AppSource {
|
||||||
String? host;
|
String? host;
|
||||||
late String name;
|
late String name;
|
||||||
@@ -162,7 +168,6 @@ class AppSource {
|
|||||||
|
|
||||||
// Different Sources may need different kinds of additional data for Apps
|
// Different Sources may need different kinds of additional data for Apps
|
||||||
List<List<GeneratedFormItem>> additionalSourceAppSpecificFormItems = [];
|
List<List<GeneratedFormItem>> additionalSourceAppSpecificFormItems = [];
|
||||||
Map<String, String> additionalSourceAppSpecificDefaults = {};
|
|
||||||
|
|
||||||
// Some additional data may be needed for Apps regardless of Source
|
// Some additional data may be needed for Apps regardless of Source
|
||||||
final List<GeneratedFormItem> additionalAppSpecificSourceAgnosticFormItems = [
|
final List<GeneratedFormItem> additionalAppSpecificSourceAgnosticFormItems = [
|
||||||
@@ -175,10 +180,6 @@ class AppSource {
|
|||||||
label: 'Do not attempt version detection', // TODO
|
label: 'Do not attempt version detection', // TODO
|
||||||
type: FormItemType.bool)
|
type: FormItemType.bool)
|
||||||
];
|
];
|
||||||
final Map<String, String> additionalAppSpecificSourceAgnosticDefaults = {
|
|
||||||
'trackOnlyFormItemKey': '',
|
|
||||||
'noVersionDetectionKey': ''
|
|
||||||
};
|
|
||||||
|
|
||||||
// Some Sources may have additional settings at the Source level (not specific to Apps) - these use SettingsProvider
|
// Some Sources may have additional settings at the Source level (not specific to Apps) - these use SettingsProvider
|
||||||
List<GeneratedFormItem> additionalSourceSpecificSettingFormItems = [];
|
List<GeneratedFormItem> additionalSourceSpecificSettingFormItems = [];
|
||||||
@@ -332,7 +333,10 @@ class SourceProvider {
|
|||||||
try {
|
try {
|
||||||
var source = getSource(url);
|
var source = getSource(url);
|
||||||
apps.add(await getApp(
|
apps.add(await getApp(
|
||||||
source, url, source.additionalSourceAppSpecificDefaults));
|
source,
|
||||||
|
url,
|
||||||
|
getDefaultValuesFromFormItems(
|
||||||
|
source.additionalSourceAppSpecificFormItems)));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errors.addAll(<String, dynamic>{url: e});
|
errors.addAll(<String, dynamic>{url: e});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user