mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-10-26 19:23:45 +01:00
Started switching additionaldata to map
This commit is contained in:
@@ -27,9 +27,9 @@ class _AddAppPageState extends State<AddAppPage> {
|
||||
String userInput = '';
|
||||
String searchQuery = '';
|
||||
AppSource? pickedSource;
|
||||
List<String> sourceSpecificAdditionalData = [];
|
||||
Map<String, String> sourceSpecificAdditionalData = {};
|
||||
bool sourceSpecificDataIsValid = true;
|
||||
List<String> otherAdditionalData = [];
|
||||
Map<String, String> otherAdditionalData = {};
|
||||
bool otherAdditionalDataIsValid = true;
|
||||
|
||||
@override
|
||||
@@ -44,7 +44,7 @@ class _AddAppPageState extends State<AddAppPage> {
|
||||
if (pickedSource.runtimeType != source.runtimeType) {
|
||||
pickedSource = source;
|
||||
sourceSpecificAdditionalData =
|
||||
source != null ? source.additionalSourceAppSpecificDefaults : [];
|
||||
source != null ? source.additionalSourceAppSpecificDefaults : {};
|
||||
sourceSpecificDataIsValid = source != null
|
||||
? !sourceProvider.ifSourceAppsRequireAdditionalData(source)
|
||||
: true;
|
||||
@@ -66,16 +66,10 @@ class _AddAppPageState extends State<AddAppPage> {
|
||||
});
|
||||
var settingsProvider = context.read<SettingsProvider>();
|
||||
() async {
|
||||
var userPickedTrackOnly = findGeneratedFormValueByKey(
|
||||
pickedSource!.additionalAppSpecificSourceAgnosticFormItems,
|
||||
otherAdditionalData,
|
||||
'trackOnlyFormItemKey') ==
|
||||
'true';
|
||||
var userPickedNoVersionDetection = findGeneratedFormValueByKey(
|
||||
pickedSource!.additionalAppSpecificSourceAgnosticFormItems,
|
||||
otherAdditionalData,
|
||||
'noVersionDetectionKey') ==
|
||||
'true';
|
||||
var userPickedTrackOnly =
|
||||
otherAdditionalData['trackOnlyFormItemKey'] == 'true';
|
||||
var userPickedNoVersionDetection =
|
||||
otherAdditionalData['noVersionDetectionKey'] == 'true';
|
||||
var cont = true;
|
||||
if ((userPickedTrackOnly || pickedSource!.enforceTrackOnly) &&
|
||||
await showDialog(
|
||||
@@ -88,7 +82,7 @@ class _AddAppPageState extends State<AddAppPage> {
|
||||
: tr('app')
|
||||
]),
|
||||
items: const [],
|
||||
defaultValues: const [],
|
||||
defaultValues: const {},
|
||||
message:
|
||||
'${pickedSource!.enforceTrackOnly ? tr('appsFromSourceAreTrackOnly') : tr('youPickedTrackOnly')}\n\n${tr('trackOnlyAppDescription')}',
|
||||
);
|
||||
@@ -100,10 +94,10 @@ class _AddAppPageState extends State<AddAppPage> {
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext ctx) {
|
||||
return GeneratedFormModal(
|
||||
return const GeneratedFormModal(
|
||||
title: 'Disable Version Detection', // TODO
|
||||
items: const [],
|
||||
defaultValues: const [],
|
||||
items: [],
|
||||
defaultValues: {},
|
||||
message: 'TODO',
|
||||
);
|
||||
}) ==
|
||||
@@ -177,7 +171,7 @@ class _AddAppPageState extends State<AddAppPage> {
|
||||
child: GeneratedForm(
|
||||
items: [
|
||||
[
|
||||
GeneratedFormItem(
|
||||
GeneratedFormItem('appSourceURL',
|
||||
label: tr('appSourceURL'),
|
||||
additionalValidators: [
|
||||
(value) {
|
||||
@@ -200,10 +194,10 @@ class _AddAppPageState extends State<AddAppPage> {
|
||||
]
|
||||
],
|
||||
onValueChanges: (values, valid, isBuilding) {
|
||||
changeUserInput(
|
||||
values[0], valid, isBuilding);
|
||||
changeUserInput(values['appSourceURL']!,
|
||||
valid, isBuilding);
|
||||
},
|
||||
defaultValues: const [])),
|
||||
defaultValues: const {'appSourceURL': ''})),
|
||||
const SizedBox(
|
||||
width: 16,
|
||||
),
|
||||
@@ -244,7 +238,7 @@ class _AddAppPageState extends State<AddAppPage> {
|
||||
child: GeneratedForm(
|
||||
items: [
|
||||
[
|
||||
GeneratedFormItem(
|
||||
GeneratedFormItem('searchSomeSources',
|
||||
label: tr('searchSomeSourcesLabel'),
|
||||
required: false),
|
||||
]
|
||||
@@ -252,11 +246,14 @@ class _AddAppPageState extends State<AddAppPage> {
|
||||
onValueChanges: (values, valid, isBuilding) {
|
||||
if (values.isNotEmpty && valid) {
|
||||
setState(() {
|
||||
searchQuery = values[0].trim();
|
||||
searchQuery =
|
||||
values['searchSomeSources']!.trim();
|
||||
});
|
||||
}
|
||||
},
|
||||
defaultValues: const ['']),
|
||||
defaultValues: const {
|
||||
'searchSomeSources': ''
|
||||
}),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 16,
|
||||
|
||||
@@ -208,7 +208,7 @@ class _AppPageState extends State<AppPage> {
|
||||
onPressed: app?.downloadProgress != null
|
||||
? null
|
||||
: () {
|
||||
showDialog<List<String>>(
|
||||
showDialog<Map<String, String>>(
|
||||
context: context,
|
||||
builder: (BuildContext ctx) {
|
||||
return GeneratedFormModal(
|
||||
|
||||
@@ -349,7 +349,7 @@ class AppsPageState extends State<AppsPage> {
|
||||
return GeneratedFormModal(
|
||||
title: tr('removeSelectedAppsQuestion'),
|
||||
items: const [],
|
||||
defaultValues: const [],
|
||||
defaultValues: const {},
|
||||
initValid: true,
|
||||
message: tr(
|
||||
'xWillBeRemovedButRemainInstalled',
|
||||
@@ -377,40 +377,37 @@ class AppsPageState extends State<AppsPage> {
|
||||
: () {
|
||||
HapticFeedback.heavyImpact();
|
||||
List<GeneratedFormItem> formInputs = [];
|
||||
List<String> defaultValues = [];
|
||||
Map<String, String> defaultValues = {};
|
||||
if (existingUpdateIdsAllOrSelected.isNotEmpty) {
|
||||
formInputs.add(GeneratedFormItem(
|
||||
formInputs.add(GeneratedFormItem('updates',
|
||||
label: tr('updateX', args: [
|
||||
plural('apps',
|
||||
existingUpdateIdsAllOrSelected.length)
|
||||
]),
|
||||
type: FormItemType.bool,
|
||||
key: 'updates'));
|
||||
defaultValues.add('true');
|
||||
type: FormItemType.bool));
|
||||
defaultValues['updates'] = 'true';
|
||||
}
|
||||
if (newInstallIdsAllOrSelected.isNotEmpty) {
|
||||
formInputs.add(GeneratedFormItem(
|
||||
formInputs.add(GeneratedFormItem('installs',
|
||||
label: tr('installX', args: [
|
||||
plural('apps',
|
||||
newInstallIdsAllOrSelected.length)
|
||||
]),
|
||||
type: FormItemType.bool,
|
||||
key: 'installs'));
|
||||
defaultValues
|
||||
.add(defaultValues.isEmpty ? 'true' : '');
|
||||
type: FormItemType.bool));
|
||||
defaultValues['installs'] =
|
||||
defaultValues.isEmpty ? 'true' : '';
|
||||
}
|
||||
if (trackOnlyUpdateIdsAllOrSelected.isNotEmpty) {
|
||||
formInputs.add(GeneratedFormItem(
|
||||
formInputs.add(GeneratedFormItem('trackonlies',
|
||||
label: tr('markXTrackOnlyAsUpdated', args: [
|
||||
plural('apps',
|
||||
trackOnlyUpdateIdsAllOrSelected.length)
|
||||
]),
|
||||
type: FormItemType.bool,
|
||||
key: 'trackonlies'));
|
||||
defaultValues
|
||||
.add(defaultValues.isEmpty ? 'true' : '');
|
||||
type: FormItemType.bool));
|
||||
defaultValues['trackonlies'] =
|
||||
defaultValues.isEmpty ? 'true' : '';
|
||||
}
|
||||
showDialog<List<String>?>(
|
||||
showDialog<Map<String, String>?>(
|
||||
context: context,
|
||||
builder: (BuildContext ctx) {
|
||||
var totalApps = existingUpdateIdsAllOrSelected
|
||||
@@ -430,17 +427,11 @@ class AppsPageState extends State<AppsPage> {
|
||||
values = defaultValues;
|
||||
}
|
||||
bool shouldInstallUpdates =
|
||||
findGeneratedFormValueByKey(
|
||||
formInputs, values, 'updates') ==
|
||||
'true';
|
||||
values['updates'] == 'true';
|
||||
bool shouldInstallNew =
|
||||
findGeneratedFormValueByKey(
|
||||
formInputs, values, 'installs') ==
|
||||
'true';
|
||||
values['installs'] == 'true';
|
||||
bool shouldMarkTrackOnlies =
|
||||
findGeneratedFormValueByKey(formInputs,
|
||||
values, 'trackonlies') ==
|
||||
'true';
|
||||
values['trackonlies'] == 'true';
|
||||
(() async {
|
||||
if (shouldInstallNew ||
|
||||
shouldInstallUpdates) {
|
||||
@@ -613,7 +604,7 @@ class AppsPageState extends State<AppsPage> {
|
||||
title: tr(
|
||||
'resetInstallStatusForSelectedAppsQuestion'),
|
||||
items: const [],
|
||||
defaultValues: const [],
|
||||
defaultValues: const {},
|
||||
initValid: true,
|
||||
message: tr(
|
||||
'installStatusOfXWillBeResetExplanation',
|
||||
@@ -683,36 +674,36 @@ class AppsPageState extends State<AppsPage> {
|
||||
: FontWeight.bold),
|
||||
),
|
||||
onPressed: () {
|
||||
showDialog<List<String>?>(
|
||||
showDialog<Map<String, String>?>(
|
||||
context: context,
|
||||
builder: (BuildContext ctx) {
|
||||
return GeneratedFormModal(
|
||||
title: tr('filterApps'),
|
||||
items: [
|
||||
[
|
||||
GeneratedFormItem(
|
||||
GeneratedFormItem('appName',
|
||||
label: tr('appName'), required: false),
|
||||
GeneratedFormItem(
|
||||
GeneratedFormItem('author',
|
||||
label: tr('author'), required: false)
|
||||
],
|
||||
[
|
||||
GeneratedFormItem(
|
||||
GeneratedFormItem('upToDateApps',
|
||||
label: tr('upToDateApps'),
|
||||
type: FormItemType.bool)
|
||||
],
|
||||
[
|
||||
GeneratedFormItem(
|
||||
GeneratedFormItem('nonInstalledApps',
|
||||
label: tr('nonInstalledApps'),
|
||||
type: FormItemType.bool)
|
||||
]
|
||||
],
|
||||
defaultValues: filter == null
|
||||
? AppsFilter().toValuesArray()
|
||||
: filter!.toValuesArray());
|
||||
? AppsFilter().toValuesMap()
|
||||
: filter!.toValuesMap());
|
||||
}).then((values) {
|
||||
if (values != null) {
|
||||
setState(() {
|
||||
filter = AppsFilter.fromValuesArray(values);
|
||||
filter = AppsFilter.fromValuesMap(values);
|
||||
if (AppsFilter().isIdenticalTo(filter!)) {
|
||||
filter = null;
|
||||
}
|
||||
@@ -740,20 +731,20 @@ class AppsFilter {
|
||||
this.includeUptodate = true,
|
||||
this.includeNonInstalled = true});
|
||||
|
||||
List<String> toValuesArray() {
|
||||
return [
|
||||
nameFilter,
|
||||
authorFilter,
|
||||
includeUptodate ? 'true' : '',
|
||||
includeNonInstalled ? 'true' : ''
|
||||
];
|
||||
Map<String, String> toValuesMap() {
|
||||
return {
|
||||
'appName': nameFilter,
|
||||
'author': authorFilter,
|
||||
'upToDateApps': includeUptodate ? 'true' : '',
|
||||
'nonInstalledApps': includeNonInstalled ? 'true' : ''
|
||||
};
|
||||
}
|
||||
|
||||
AppsFilter.fromValuesArray(List<String> values) {
|
||||
nameFilter = values[0];
|
||||
authorFilter = values[1];
|
||||
includeUptodate = values[2] == 'true';
|
||||
includeNonInstalled = values[3] == 'true';
|
||||
AppsFilter.fromValuesMap(Map<String, String> values) {
|
||||
nameFilter = values['appName']!;
|
||||
authorFilter = values['author']!;
|
||||
includeUptodate = values['upToDateApps'] == 'true';
|
||||
includeNonInstalled = values['nonInstalledApps'] == 'true';
|
||||
}
|
||||
|
||||
bool isIdenticalTo(AppsFilter other) =>
|
||||
|
||||
@@ -145,7 +145,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
||||
title: tr('importFromURLList'),
|
||||
items: [
|
||||
[
|
||||
GeneratedFormItem(
|
||||
GeneratedFormItem('appURLList',
|
||||
label: tr('appURLList'),
|
||||
max: 7,
|
||||
additionalValidators: [
|
||||
@@ -172,7 +172,7 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
||||
])
|
||||
]
|
||||
],
|
||||
defaultValues: const [],
|
||||
defaultValues: const {},
|
||||
);
|
||||
}).then((values) {
|
||||
if (values != null) {
|
||||
@@ -237,11 +237,12 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
||||
items: [
|
||||
[
|
||||
GeneratedFormItem(
|
||||
'searchQuery',
|
||||
label: tr(
|
||||
'searchQuery'))
|
||||
]
|
||||
],
|
||||
defaultValues: const [],
|
||||
defaultValues: const {},
|
||||
);
|
||||
});
|
||||
if (values != null &&
|
||||
@@ -346,10 +347,11 @@ class _ImportExportPageState extends State<ImportExportPage> {
|
||||
.requiredArgs
|
||||
.map(
|
||||
(e) => [
|
||||
GeneratedFormItem(label: e)
|
||||
GeneratedFormItem(e,
|
||||
label: e)
|
||||
])
|
||||
.toList(),
|
||||
defaultValues: const [],
|
||||
defaultValues: const {},
|
||||
);
|
||||
});
|
||||
if (values != null) {
|
||||
|
||||
@@ -143,16 +143,16 @@ class _SettingsPageState extends State<SettingsPage> {
|
||||
.toList(),
|
||||
onValueChanges: (values, valid, isBuilding) {
|
||||
if (valid) {
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
settingsProvider.setSettingString(
|
||||
e.additionalSourceSpecificSettingFormItems[i].id,
|
||||
values[i]);
|
||||
}
|
||||
values.forEach((key, value) {
|
||||
settingsProvider.setSettingString(key, value);
|
||||
});
|
||||
}
|
||||
},
|
||||
defaultValues: e.additionalSourceSpecificSettingFormItems.map((e) {
|
||||
return settingsProvider.getSettingString(e.id) ?? '';
|
||||
}).toList());
|
||||
defaultValues: Map.fromEntries(
|
||||
e.additionalSourceSpecificSettingFormItems.map((e) {
|
||||
return MapEntry(
|
||||
e.key, settingsProvider.getSettingString(e.key) ?? '');
|
||||
})));
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user