mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-11-04 07:13:28 +01:00 
			
		
		
		
	More fixes to prev commit
This commit is contained in:
		@@ -8,14 +8,12 @@ class GeneratedFormModal extends StatefulWidget {
 | 
			
		||||
      {super.key,
 | 
			
		||||
      required this.title,
 | 
			
		||||
      required this.items,
 | 
			
		||||
      required this.defaultValues,
 | 
			
		||||
      this.initValid = false,
 | 
			
		||||
      this.message = ''});
 | 
			
		||||
 | 
			
		||||
  final String title;
 | 
			
		||||
  final String message;
 | 
			
		||||
  final List<List<GeneratedFormItem>> items;
 | 
			
		||||
  final Map<String, String> defaultValues;
 | 
			
		||||
  final bool initValid;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
@@ -29,9 +27,6 @@ class _GeneratedFormModalState extends State<GeneratedFormModal> {
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
    super.initState();
 | 
			
		||||
    widget.defaultValues.forEach((key, value) {
 | 
			
		||||
      values[key] = value;
 | 
			
		||||
    });
 | 
			
		||||
    valid = widget.initValid || widget.items.isEmpty;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -84,7 +84,6 @@ class _AddAppPageState extends State<AddAppPage> {
 | 
			
		||||
                              : tr('app')
 | 
			
		||||
                        ]),
 | 
			
		||||
                        items: const [],
 | 
			
		||||
                        defaultValues: const {},
 | 
			
		||||
                        message:
 | 
			
		||||
                            '${pickedSource!.enforceTrackOnly ? tr('appsFromSourceAreTrackOnly') : tr('youPickedTrackOnly')}\n\n${tr('trackOnlyAppDescription')}',
 | 
			
		||||
                      );
 | 
			
		||||
@@ -99,7 +98,6 @@ class _AddAppPageState extends State<AddAppPage> {
 | 
			
		||||
                      return const GeneratedFormModal(
 | 
			
		||||
                        title: 'Disable Version Detection', // TODO
 | 
			
		||||
                        items: [],
 | 
			
		||||
                        defaultValues: {},
 | 
			
		||||
                        message: 'TODO',
 | 
			
		||||
                      );
 | 
			
		||||
                    }) ==
 | 
			
		||||
 
 | 
			
		||||
@@ -214,12 +214,7 @@ class _AppPageState extends State<AppPage> {
 | 
			
		||||
                                            return GeneratedFormModal(
 | 
			
		||||
                                                title: 'Additional Options',
 | 
			
		||||
                                                items: source
 | 
			
		||||
                                                    .additionalSourceAppSpecificFormItems,
 | 
			
		||||
                                                defaultValues: app != null
 | 
			
		||||
                                                    ? app.app.additionalData
 | 
			
		||||
                                                    : getDefaultValuesFromFormItems(
 | 
			
		||||
                                                        source
 | 
			
		||||
                                                            .additionalSourceAppSpecificFormItems));
 | 
			
		||||
                                                    .additionalSourceAppSpecificFormItems);
 | 
			
		||||
                                          }).then((values) {
 | 
			
		||||
                                        if (app != null && values != null) {
 | 
			
		||||
                                          var changedApp = app.app;
 | 
			
		||||
 
 | 
			
		||||
@@ -349,7 +349,6 @@ class AppsPageState extends State<AppsPage> {
 | 
			
		||||
                                return GeneratedFormModal(
 | 
			
		||||
                                  title: tr('removeSelectedAppsQuestion'),
 | 
			
		||||
                                  items: const [],
 | 
			
		||||
                                  defaultValues: const {},
 | 
			
		||||
                                  initValid: true,
 | 
			
		||||
                                  message: tr(
 | 
			
		||||
                                      'xWillBeRemovedButRemainInstalled',
 | 
			
		||||
@@ -376,36 +375,40 @@ class AppsPageState extends State<AppsPage> {
 | 
			
		||||
                        ? null
 | 
			
		||||
                        : () {
 | 
			
		||||
                            HapticFeedback.heavyImpact();
 | 
			
		||||
                            List<GeneratedFormItem> formInputs = [];
 | 
			
		||||
                            Map<String, String> defaultValues = {};
 | 
			
		||||
                            List<GeneratedFormItem> formItems = [];
 | 
			
		||||
                            if (existingUpdateIdsAllOrSelected.isNotEmpty) {
 | 
			
		||||
                              formInputs.add(GeneratedFormItem('updates',
 | 
			
		||||
                              formItems.add(GeneratedFormItem('updates',
 | 
			
		||||
                                  label: tr('updateX', args: [
 | 
			
		||||
                                    plural('apps',
 | 
			
		||||
                                        existingUpdateIdsAllOrSelected.length)
 | 
			
		||||
                                  ]),
 | 
			
		||||
                                  type: FormItemType.bool));
 | 
			
		||||
                              defaultValues['updates'] = 'true';
 | 
			
		||||
                                  type: FormItemType.bool,
 | 
			
		||||
                                  defaultValue: 'true'));
 | 
			
		||||
                            }
 | 
			
		||||
                            if (newInstallIdsAllOrSelected.isNotEmpty) {
 | 
			
		||||
                              formInputs.add(GeneratedFormItem('installs',
 | 
			
		||||
                              formItems.add(GeneratedFormItem('installs',
 | 
			
		||||
                                  label: tr('installX', args: [
 | 
			
		||||
                                    plural('apps',
 | 
			
		||||
                                        newInstallIdsAllOrSelected.length)
 | 
			
		||||
                                  ]),
 | 
			
		||||
                                  type: FormItemType.bool));
 | 
			
		||||
                              defaultValues['installs'] =
 | 
			
		||||
                                  defaultValues.isEmpty ? 'true' : '';
 | 
			
		||||
                                  type: FormItemType.bool,
 | 
			
		||||
                                  defaultValue:
 | 
			
		||||
                                      existingUpdateIdsAllOrSelected.isNotEmpty
 | 
			
		||||
                                          ? 'true'
 | 
			
		||||
                                          : ''));
 | 
			
		||||
                            }
 | 
			
		||||
                            if (trackOnlyUpdateIdsAllOrSelected.isNotEmpty) {
 | 
			
		||||
                              formInputs.add(GeneratedFormItem('trackonlies',
 | 
			
		||||
                              formItems.add(GeneratedFormItem('trackonlies',
 | 
			
		||||
                                  label: tr('markXTrackOnlyAsUpdated', args: [
 | 
			
		||||
                                    plural('apps',
 | 
			
		||||
                                        trackOnlyUpdateIdsAllOrSelected.length)
 | 
			
		||||
                                  ]),
 | 
			
		||||
                                  type: FormItemType.bool));
 | 
			
		||||
                              defaultValues['trackonlies'] =
 | 
			
		||||
                                  defaultValues.isEmpty ? 'true' : '';
 | 
			
		||||
                                  type: FormItemType.bool,
 | 
			
		||||
                                  defaultValue: existingUpdateIdsAllOrSelected
 | 
			
		||||
                                              .isNotEmpty ||
 | 
			
		||||
                                          newInstallIdsAllOrSelected.isNotEmpty
 | 
			
		||||
                                      ? 'true'
 | 
			
		||||
                                      : ''));
 | 
			
		||||
                            }
 | 
			
		||||
                            showDialog<Map<String, String>?>(
 | 
			
		||||
                                context: context,
 | 
			
		||||
@@ -417,14 +420,14 @@ class AppsPageState extends State<AppsPage> {
 | 
			
		||||
                                  return GeneratedFormModal(
 | 
			
		||||
                                    title: tr('changeX',
 | 
			
		||||
                                        args: [plural('apps', totalApps)]),
 | 
			
		||||
                                    items: formInputs.map((e) => [e]).toList(),
 | 
			
		||||
                                    defaultValues: defaultValues,
 | 
			
		||||
                                    items: formItems.map((e) => [e]).toList(),
 | 
			
		||||
                                    initValid: true,
 | 
			
		||||
                                  );
 | 
			
		||||
                                }).then((values) {
 | 
			
		||||
                              if (values != null) {
 | 
			
		||||
                                if (values.isEmpty) {
 | 
			
		||||
                                  values = defaultValues;
 | 
			
		||||
                                  values = getDefaultValuesFromFormItems(
 | 
			
		||||
                                      [formItems]);
 | 
			
		||||
                                }
 | 
			
		||||
                                bool shouldInstallUpdates =
 | 
			
		||||
                                    values['updates'] == 'true';
 | 
			
		||||
@@ -604,7 +607,6 @@ class AppsPageState extends State<AppsPage> {
 | 
			
		||||
                                                      title: tr(
 | 
			
		||||
                                                          'resetInstallStatusForSelectedAppsQuestion'),
 | 
			
		||||
                                                      items: const [],
 | 
			
		||||
                                                      defaultValues: const {},
 | 
			
		||||
                                                      initValid: true,
 | 
			
		||||
                                                      message: tr(
 | 
			
		||||
                                                          'installStatusOfXWillBeResetExplanation',
 | 
			
		||||
@@ -677,29 +679,35 @@ class AppsPageState extends State<AppsPage> {
 | 
			
		||||
                      showDialog<Map<String, String>?>(
 | 
			
		||||
                          context: context,
 | 
			
		||||
                          builder: (BuildContext ctx) {
 | 
			
		||||
                            var vals = filter == null
 | 
			
		||||
                                ? AppsFilter().toValuesMap()
 | 
			
		||||
                                : filter!.toValuesMap();
 | 
			
		||||
                            return GeneratedFormModal(
 | 
			
		||||
                                title: tr('filterApps'),
 | 
			
		||||
                                items: [
 | 
			
		||||
                                  [
 | 
			
		||||
                                    GeneratedFormItem('appName',
 | 
			
		||||
                                        label: tr('appName'), required: false),
 | 
			
		||||
                                        label: tr('appName'),
 | 
			
		||||
                                        required: false,
 | 
			
		||||
                                        defaultValue: vals['appName']),
 | 
			
		||||
                                    GeneratedFormItem('author',
 | 
			
		||||
                                        label: tr('author'), required: false)
 | 
			
		||||
                                        label: tr('author'),
 | 
			
		||||
                                        required: false,
 | 
			
		||||
                                        defaultValue: vals['author'])
 | 
			
		||||
                                  ],
 | 
			
		||||
                                  [
 | 
			
		||||
                                    GeneratedFormItem('upToDateApps',
 | 
			
		||||
                                        label: tr('upToDateApps'),
 | 
			
		||||
                                        type: FormItemType.bool)
 | 
			
		||||
                                        type: FormItemType.bool,
 | 
			
		||||
                                        defaultValue: vals['upToDateApps'])
 | 
			
		||||
                                  ],
 | 
			
		||||
                                  [
 | 
			
		||||
                                    GeneratedFormItem('nonInstalledApps',
 | 
			
		||||
                                        label: tr('nonInstalledApps'),
 | 
			
		||||
                                        type: FormItemType.bool)
 | 
			
		||||
                                        type: FormItemType.bool,
 | 
			
		||||
                                        defaultValue: vals['nonInstalledApps'])
 | 
			
		||||
                                  ]
 | 
			
		||||
                                ],
 | 
			
		||||
                                defaultValues: filter == null
 | 
			
		||||
                                    ? AppsFilter().toValuesMap()
 | 
			
		||||
                                    : filter!.toValuesMap());
 | 
			
		||||
                                ]);
 | 
			
		||||
                          }).then((values) {
 | 
			
		||||
                        if (values != null) {
 | 
			
		||||
                          setState(() {
 | 
			
		||||
 
 | 
			
		||||
@@ -172,7 +172,6 @@ class _ImportExportPageState extends State<ImportExportPage> {
 | 
			
		||||
                                                  ])
 | 
			
		||||
                                            ]
 | 
			
		||||
                                          ],
 | 
			
		||||
                                          defaultValues: const {},
 | 
			
		||||
                                        );
 | 
			
		||||
                                      }).then((values) {
 | 
			
		||||
                                    if (values != null) {
 | 
			
		||||
@@ -242,7 +241,6 @@ class _ImportExportPageState extends State<ImportExportPage> {
 | 
			
		||||
                                                                      'searchQuery'))
 | 
			
		||||
                                                            ]
 | 
			
		||||
                                                          ],
 | 
			
		||||
                                                          defaultValues: const {},
 | 
			
		||||
                                                        );
 | 
			
		||||
                                                      });
 | 
			
		||||
                                                  if (values != null &&
 | 
			
		||||
@@ -351,7 +349,6 @@ class _ImportExportPageState extends State<ImportExportPage> {
 | 
			
		||||
                                                                                label: e)
 | 
			
		||||
                                                                          ])
 | 
			
		||||
                                                                  .toList(),
 | 
			
		||||
                                                          defaultValues: const {},
 | 
			
		||||
                                                        );
 | 
			
		||||
                                                      });
 | 
			
		||||
                                                  if (values != null) {
 | 
			
		||||
 
 | 
			
		||||
@@ -141,8 +141,9 @@ List<String> getLinksFromParsedHTML(
 | 
			
		||||
        .map((e) => '$prependToLinks${e.attributes['href']!}')
 | 
			
		||||
        .toList();
 | 
			
		||||
 | 
			
		||||
getDefaultValuesFromFormItems(List<List<GeneratedFormItem>> items) {
 | 
			
		||||
  Map.fromEntries(items
 | 
			
		||||
Map<String, String> getDefaultValuesFromFormItems(
 | 
			
		||||
    List<List<GeneratedFormItem>> items) {
 | 
			
		||||
  return Map.fromEntries(items
 | 
			
		||||
      .map((row) => row.map((el) => MapEntry(el.key, el.defaultValue ?? '')))
 | 
			
		||||
      .reduce((value, element) => [...value, ...element]));
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user