Search in sources :

Example 1 with ConnectToLao

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();
}
Also used : MutableLiveData(androidx.lifecycle.MutableLiveData) JsonParseException(com.google.gson.JsonParseException) R(com.github.dedis.popstellar.R) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) ErrorUtils(com.github.dedis.popstellar.utility.error.ErrorUtils) SeedValidationException(com.github.dedis.popstellar.utility.error.keys.SeedValidationException) LiveDataReactiveStreams(androidx.lifecycle.LiveDataReactiveStreams) LAORepository(com.github.dedis.popstellar.repository.LAORepository) Inject(javax.inject.Inject) ConnectToLao(com.github.dedis.popstellar.model.qrcode.ConnectToLao) Manifest(android.Manifest) GeneralSecurityException(java.security.GeneralSecurityException) CreateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) Gson(com.google.gson.Gson) Toast(android.widget.Toast) AndroidViewModel(androidx.lifecycle.AndroidViewModel) Log(android.util.Log) LiveData(androidx.lifecycle.LiveData) Channel(com.github.dedis.popstellar.model.objects.Channel) BackpressureStrategy(io.reactivex.BackpressureStrategy) KeyManager(com.github.dedis.popstellar.utility.security.KeyManager) ActivityCompat(androidx.core.app.ActivityCompat) LAOState(com.github.dedis.popstellar.repository.LAOState) Barcode(com.google.android.gms.vision.barcode.Barcode) HiltViewModel(dagger.hilt.android.lifecycle.HiltViewModel) QRCodeScanningViewModel(com.github.dedis.popstellar.ui.qrcode.QRCodeScanningViewModel) ScanningAction(com.github.dedis.popstellar.ui.qrcode.ScanningAction) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Application(android.app.Application) SingleEvent(com.github.dedis.popstellar.SingleEvent) Wallet(com.github.dedis.popstellar.model.objects.Wallet) GlobalNetworkManager(com.github.dedis.popstellar.repository.remote.GlobalNetworkManager) CameraPermissionViewModel(com.github.dedis.popstellar.ui.qrcode.CameraPermissionViewModel) LAOState(com.github.dedis.popstellar.repository.LAOState) ConnectToLao(com.github.dedis.popstellar.model.qrcode.ConnectToLao) ConnectToLao(com.github.dedis.popstellar.model.qrcode.ConnectToLao) CreateLao(com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao) Lao(com.github.dedis.popstellar.model.objects.Lao) JsonParseException(com.google.gson.JsonParseException)

Example 2 with ConnectToLao

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)));
}
Also used : ConnectToLao(com.github.dedis.popstellar.model.qrcode.ConnectToLao) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HiltAndroidTest(dagger.hilt.android.testing.HiltAndroidTest) Test(org.junit.Test)

Example 3 with ConnectToLao

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);
    });
}
Also used : Bitmap(android.graphics.Bitmap) ConnectToLao(com.github.dedis.popstellar.model.qrcode.ConnectToLao)

Aggregations

ConnectToLao (com.github.dedis.popstellar.model.qrcode.ConnectToLao)3 Manifest (android.Manifest)1 Application (android.app.Application)1 PackageManager (android.content.pm.PackageManager)1 Bitmap (android.graphics.Bitmap)1 Log (android.util.Log)1 Toast (android.widget.Toast)1 NonNull (androidx.annotation.NonNull)1 ActivityCompat (androidx.core.app.ActivityCompat)1 AndroidViewModel (androidx.lifecycle.AndroidViewModel)1 LiveData (androidx.lifecycle.LiveData)1 LiveDataReactiveStreams (androidx.lifecycle.LiveDataReactiveStreams)1 MutableLiveData (androidx.lifecycle.MutableLiveData)1 R (com.github.dedis.popstellar.R)1 SingleEvent (com.github.dedis.popstellar.SingleEvent)1 CreateLao (com.github.dedis.popstellar.model.network.method.message.data.lao.CreateLao)1 Channel (com.github.dedis.popstellar.model.objects.Channel)1 Lao (com.github.dedis.popstellar.model.objects.Lao)1 Wallet (com.github.dedis.popstellar.model.objects.Wallet)1 LAORepository (com.github.dedis.popstellar.repository.LAORepository)1