Search in sources :

Example 1 with SingleEvent

use of com.github.dedis.popstellar.SingleEvent in project popstellar by dedis.

the class LaoDetailViewModel method onQRCodeDetected.

@Override
public void onQRCodeDetected(Barcode barcode) {
    Log.d(TAG, "Detected barcode with value: " + barcode.rawValue);
    PublicKey attendee;
    try {
        attendee = new PublicKey(barcode.rawValue);
    } catch (IllegalArgumentException e) {
        mScanWarningEvent.postValue(new SingleEvent<>("Invalid QR code. Please try again."));
        return;
    }
    if (attendees.contains(attendee) || Objects.requireNonNull(mWitnesses.getValue()).contains(attendee)) {
        mScanWarningEvent.postValue(new SingleEvent<>("This QR code has already been scanned. Please try again."));
        return;
    }
    if (scanningAction == (ScanningAction.ADD_ROLL_CALL_ATTENDEE)) {
        attendees.add(attendee);
        mAttendeeScanConfirmEvent.postValue(new SingleEvent<>("Attendee has been added."));
        mNbAttendeesEvent.postValue(new SingleEvent<>(attendees.size()));
    } else if (scanningAction == (ScanningAction.ADD_WITNESS)) {
        witnesses.add(attendee);
        mWitnessScanConfirmEvent.postValue(new SingleEvent<>(true));
        updateLaoWitnesses();
    }
}
Also used : PublicKey(com.github.dedis.popstellar.model.objects.security.PublicKey) SingleEvent(com.github.dedis.popstellar.SingleEvent)

Aggregations

SingleEvent (com.github.dedis.popstellar.SingleEvent)1 PublicKey (com.github.dedis.popstellar.model.objects.security.PublicKey)1