use of com.github.dedis.popstellar.model.qrcode.ConnectToLao in project popstellar by dedis.
the class HomeViewModel method onQRCodeDetected.
@Override
public void onQRCodeDetected(Barcode barcode) {
Log.d(TAG, "Detected barcode with value: " + barcode.rawValue);
ConnectToLao data;
try {
data = ConnectToLao.extractFrom(gson, barcode.rawValue);
} catch (JsonParseException e) {
Log.e(TAG, "Invalid QRCode data", e);
Toast.makeText(getApplication().getApplicationContext(), "Invalid QRCode data", Toast.LENGTH_LONG).show();
return;
}
networkManager.connect(data.server);
Lao lao = new Lao(data.lao);
disposables.add(networkManager.getMessageSender().subscribe(lao.getChannel()).doFinally(this::openHome).subscribe(() -> {
Log.d(TAG, "subscribing to LAO with id " + lao.getId());
// Create the new LAO and add it to the LAORepository LAO lists
laoRepository.getLaoById().put(lao.getId(), new LAOState(lao));
laoRepository.setAllLaoSubject();
Log.d(TAG, "got success result for subscribe to lao");
}, error -> ErrorUtils.logAndShow(getApplication(), TAG, error, R.string.error_subscribe_lao)));
setConnectingLao(lao.getId());
openConnecting();
}
use of com.github.dedis.popstellar.model.qrcode.ConnectToLao in project popstellar by dedis.
the class LaoDetailActivityTest method showPropertyButtonShowsConnectQRCode.
@Test
public void showPropertyButtonShowsConnectQRCode() {
showPropertiesButton().perform(click());
propertiesLayout().check(matches(isDisplayed()));
String expectedQRCode = gson.toJson(new ConnectToLao(networkManager.getCurrentUrl(), LAO_ID));
connectQrCode().check(matches(withQrCode(expectedQRCode)));
}
use of com.github.dedis.popstellar.model.qrcode.ConnectToLao in project popstellar by dedis.
the class LaoDetailFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setupWitnessMessageButton();
setupPropertiesButton();
setupEditPropertiesButton();
setupConfirmEditButton();
setupCancelEditButton();
setupAddWitnessButton();
setupEventListAdapter();
setupEventListUpdates();
setupWitnessListAdapter();
setupWitnessListUpdates();
// TODO: Add witness handler
// Subscribe to "show/hide properties" event
mLaoDetailViewModel.getShowPropertiesEvent().observe(getViewLifecycleOwner(), booleanEvent -> {
Boolean action = booleanEvent.getContentIfNotHandled();
if (action != null) {
showHideProperties(action);
}
});
// Subscribe to "edit properties" event
mLaoDetailViewModel.getEditPropertiesEvent().observe(getViewLifecycleOwner(), booleanEvent -> {
Boolean action = booleanEvent.getContentIfNotHandled();
if (action != null) {
editProperties(action);
}
});
mLaoDetailViewModel.getLaoEvents().observe(requireActivity(), events -> {
Log.d(TAG, "Got a list update for LAO events");
mEventListViewEventAdapter.replaceList(events);
});
mLaoDetailViewModel.getCurrentLao().observe(requireActivity(), lao -> {
ConnectToLao data = new ConnectToLao(networkManager.getCurrentUrl(), lao.getId());
Bitmap myBitmap = QRCode.from(gson.toJson(data)).bitmap();
mLaoDetailFragBinding.channelQrCode.setImageBitmap(myBitmap);
});
}
Aggregations