Skip to content

Commit

Permalink
Slot export (#329)
Browse files Browse the repository at this point in the history
* fix: fix copy paste error and option new

* feat: rebuild CardSave from slot

* fix: add freq chooser, recover card POC

* Improve card export and code quality

* Expose CardSearchDelegate

* Update saved card (finish card export), improve code quality

* Legacy linux workflow (seems to be frequently asked)

* Modify new card name

---------

Co-authored-by: GameTec_live <[email protected]>
  • Loading branch information
Foxushka and GameTec-live authored Oct 13, 2023
1 parent 32d985e commit ca21210
Show file tree
Hide file tree
Showing 13 changed files with 669 additions and 332 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ on:
pull_request:

jobs:
check:
runs-on: ubuntu-latest
outputs:
found: ${{ steps.PR.outputs.pr_found }}
steps:
- uses: 8BitJonny/[email protected]
id: PR

build-android:
needs: check
if: needs.check.outputs.found == 'false' && github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -29,6 +39,8 @@ jobs:
path: chameleonultragui/build/app/outputs/flutter-apk/app-release.apk

build-windows:
needs: check
if: needs.check.outputs.found == 'false' && github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: windows-latest
defaults:
run:
Expand All @@ -55,6 +67,8 @@ jobs:
path: chameleonultragui-setup-win.exe

build-linux:
needs: check
if: needs.check.outputs.found == 'false' && github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -79,7 +93,30 @@ jobs:
name: linux-debian
path: chameleonultragui/debian/packages

build-linux-legacy:
needs: check
if: needs.check.outputs.found == 'false' && github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: ubuntu-20.04
defaults:
run:
working-directory: ./chameleonultragui
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
- run: sudo apt-get update -y && sudo apt-get install -y ninja-build libgtk-3-dev clang
- run: flutter config --enable-linux-desktop
- run: flutter build linux --build-number ${{ github.run_number }}
- run: flutter test
- uses: actions/upload-artifact@v3
with:
name: linux-legacy
path: chameleonultragui/build/linux/x64/release

build-macos:
needs: check
if: needs.check.outputs.found == 'false' && github.event_name == 'push' || github.event_name == 'pull_request'
runs-on: macos-latest
defaults:
run:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/update-translations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ jobs:
body: "Update translations"
commit-message: "feat: Update translations"
title: "feat: Update translations"
author: "Chameleon Helper <[email protected]>"
committer: "Chameleon Helper <[email protected]>"
delete-branch: true
174 changes: 174 additions & 0 deletions chameleonultragui/lib/gui/component/card_list.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import 'package:chameleonultragui/bridge/chameleon.dart';
import 'package:chameleonultragui/helpers/general.dart';
import 'package:chameleonultragui/helpers/mifare_classic/general.dart';
import 'package:chameleonultragui/sharedprefsprovider.dart';
import 'package:flutter/material.dart';

// Localizations
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

enum SearchFilter { all, hf, lf }

class CardSearchDelegate extends SearchDelegate<String> {
final List<CardSave> cards;
final dynamic onTap;
SearchFilter filter;

CardSearchDelegate(
{required this.cards,
required this.onTap,
this.filter = SearchFilter.all});

@override
List<Widget> buildActions(BuildContext context) {
var localizations = AppLocalizations.of(context)!;

return [
StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return DropdownButton(
items: [
DropdownMenuItem(
value: SearchFilter.all,
child: Text(
localizations.all,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
DropdownMenuItem(
value: SearchFilter.hf,
child: Text(
localizations.hf,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
DropdownMenuItem(
value: SearchFilter.lf,
child: Text(
localizations.lf,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
],
onChanged: (SearchFilter? value) {
if (value != null) {
setState(() {
filter = value;
});
}
},
value: filter,
);
},
),
IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
query = '';
},
),
];
}

@override
Widget buildLeading(BuildContext context) {
return IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () {
close(context, '');
},
);
}

@override
Widget buildResults(BuildContext context) {
final results = cards.where((card) =>
(((card.name.toLowerCase().contains(query.toLowerCase())) ||
(chameleonTagToString(card.tag)
.toLowerCase()
.contains(query.toLowerCase()))) &&
((filter == SearchFilter.all) ||
(filter == SearchFilter.hf &&
chameleonTagToFrequency(card.tag) == TagFrequency.hf) ||
(filter == SearchFilter.lf &&
chameleonTagToFrequency(card.tag) == TagFrequency.lf))));

return ListView.builder(
itemCount: results.length,
itemBuilder: (BuildContext context, int index) {
final card = results.elementAt(index);
return Column(
children: [
ElevatedButton(
onPressed: () {
// Set card here
Navigator.pop(context);
},
child: ListTile(
leading: Icon(
(chameleonTagToFrequency(card.tag) == TagFrequency.hf)
? Icons.credit_card
: Icons.wifi,
color: card.color),
title: Text(
card.name,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
subtitle: Text(
chameleonTagToString(card.tag),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
),
const SizedBox(height: 10),
],
);
},
);
}

@override
Widget buildSuggestions(BuildContext context) {
final results = cards.where((card) =>
(((card.name.toLowerCase().contains(query.toLowerCase())) ||
(chameleonTagToString(card.tag)
.toLowerCase()
.contains(query.toLowerCase()))) &&
((filter == SearchFilter.all) ||
(filter == SearchFilter.hf &&
chameleonTagToFrequency(card.tag) == TagFrequency.hf) ||
(filter == SearchFilter.lf &&
chameleonTagToFrequency(card.tag) == TagFrequency.lf))));

return ListView.builder(
itemCount: results.length,
itemBuilder: (BuildContext context, int index) {
final card = results.elementAt(index);
return ListTile(
leading: Icon(
(chameleonTagToFrequency(card.tag) == TagFrequency.hf)
? Icons.credit_card
: Icons.wifi,
color: card.color),
title: Text(card.name),
subtitle: Text(
chameleonTagToString(card.tag) +
((chameleonTagSaveCheckForMifareClassicEV1(card))
? " EV1"
: ""),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
onTap: () async {
onTap(card, close);
},
);
},
);
}
}
28 changes: 14 additions & 14 deletions chameleonultragui/lib/gui/menu/card_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class CardEditMenu extends StatefulWidget {
final CardSave tagSave;
final bool isNew;

const CardEditMenu({Key? key, required this.tagSave}) : super(key: key);
const CardEditMenu({Key? key, required this.tagSave, this.isNew = false})
: super(key: key);

@override
CardEditMenuState createState() => CardEditMenuState();
Expand Down Expand Up @@ -289,29 +291,27 @@ class CardEditMenuState extends State<CardEditMenu> {
}

var tag = CardSave(
id: widget.tagSave.uid,
id: widget.tagSave.id,
name: nameController.text,
sak: chameleonTagToFrequency(selectedType) == TagFrequency.lf
? widget.tagSave.sak
: hexToBytes(sakController.text.replaceAll(" ", ""))[0],
atqa: hexToBytes(atqaController.text.replaceAll(" ", "")),
uid: uidController.text,
: hexToBytesSpace(sakController.text)[0],
atqa: hexToBytesSpace(atqaController.text),
uid: bytesToHexSpace(hexToBytesSpace(uidController.text)),
tag: selectedType,
data: widget.tagSave.data,
color: currentColor,
ats: hexToBytes(atsController.text.replaceAll(" ", "")));
ats: hexToBytesSpace(atsController.text));

var tags = appState.sharedPreferencesProvider.getCards();
List<CardSave> output = [];
for (var tagTest in tags) {
if (tagTest.id != widget.tagSave.id) {
output.add(tagTest);
} else {
output.add(tag);
}
var index =
tags.indexWhere((element) => element.id == widget.tagSave.id);

if (index != -1) {
tags[index] = tag;
}

appState.sharedPreferencesProvider.setCards(output);
appState.sharedPreferencesProvider.setCards(tags);
appState.changesMade();
Navigator.pop(context);
},
Expand Down
2 changes: 0 additions & 2 deletions chameleonultragui/lib/gui/menu/dictionary_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:chameleonultragui/sharedprefsprovider.dart';
import 'dart:typed_data';
import 'package:provider/provider.dart';
import 'package:chameleonultragui/main.dart';
import 'package:uuid/uuid.dart';
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
import 'package:chameleonultragui/helpers/general.dart';

Expand Down Expand Up @@ -168,7 +167,6 @@ class DictionaryEditMenuState extends State<DictionaryEditMenu> {
}

Dictionary dict = Dictionary(
id: const Uuid().v4(),
name: nameController.text,
keys: stringToDict(keysController.text),
color: currentColor,
Expand Down
Loading

0 comments on commit ca21210

Please sign in to comment.