ensure that qr code is ready when start button is pressed

This commit is contained in:
ameba23
2021-04-13 08:52:42 +02:00
parent e106166cfe
commit 01bcc6d491
3 changed files with 21 additions and 11 deletions

View File

@@ -129,6 +129,7 @@ public class OwnerReturnShardActivity extends BaseActivity
}
private void showQrCodeFragment() {
LOG.info("showQrCodeFragment called");
FragmentManager fm = getSupportFragmentManager();
if (fm.findFragmentByTag(OwnerReturnShardFragment.TAG) == null) {
BaseFragment f = OwnerReturnShardFragment.newInstance();

View File

@@ -7,14 +7,11 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.R;
import org.briarproject.briar.android.activity.ActivityComponent;
import org.briarproject.briar.android.contact.add.nearby.CameraException;
import org.briarproject.briar.android.contact.add.nearby.CameraView;
import org.briarproject.briar.android.fragment.BaseFragment;
import org.briarproject.briar.android.view.QrCodeView;
import org.briarproject.briar.api.socialbackup.recovery.SecretOwnerTask;
@@ -86,6 +83,10 @@ public class OwnerReturnShardFragment extends BaseFragment
viewModel.getState().observe(getViewLifecycleOwner(),
this::onReturnShardStateChanged);
Bitmap qrCodeBitmap = viewModel.getQrCodeBitmap();
if (qrCodeBitmap != null) {
qrCodeView.setQrCode(qrCodeBitmap);
}
}
@Override
@@ -107,15 +108,21 @@ public class OwnerReturnShardFragment extends BaseFragment
if (fullscreen) {
// Grow the QR code view to fill its parent
statusParams = new LinearLayout.LayoutParams(0, 0, 0f);
qrCodeParams = new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT, 1f);
qrCodeParams =
new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT,
1f);
} else {
// Shrink the QR code view to fill half its parent
if (cameraOverlay.getOrientation() == HORIZONTAL) {
statusParams = new LinearLayout.LayoutParams(0, MATCH_PARENT, 1f);
qrCodeParams = new LinearLayout.LayoutParams(0, MATCH_PARENT, 1f);
statusParams =
new LinearLayout.LayoutParams(0, MATCH_PARENT, 1f);
qrCodeParams =
new LinearLayout.LayoutParams(0, MATCH_PARENT, 1f);
} else {
statusParams = new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1f);
qrCodeParams = new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1f);
statusParams =
new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1f);
qrCodeParams =
new LinearLayout.LayoutParams(MATCH_PARENT, 0, 1f);
}
}
statusView.setLayoutParams(statusParams);
@@ -124,7 +131,8 @@ public class OwnerReturnShardFragment extends BaseFragment
}
@UiThread
private void onReturnShardStateChanged(@Nullable SecretOwnerTask.State state) {
private void onReturnShardStateChanged(
@Nullable SecretOwnerTask.State state) {
if (state instanceof SecretOwnerTask.State.Listening) {
Bitmap qrCode = viewModel.getQrCodeBitmap();
qrCodeView.setQrCode(qrCode);

View File

@@ -60,6 +60,7 @@ class OwnerReturnShardViewModel extends AndroidViewModel implements SecretOwnerT
this.ioExecutor = ioExecutor;
this.task = task;
// IntentFilter filter = new IntentFilter(ACTION_SCAN_MODE_CHANGED);
startListening();
}
@Override
@@ -81,7 +82,7 @@ class OwnerReturnShardViewModel extends AndroidViewModel implements SecretOwnerT
wasContinueClicked = false;
// If we return to the intro fragment, we may need to enable wifi and
// hasEnabledWifi = false;
startListening();
showQrCodeFragment.setEvent(true);
}
@UiThread
@@ -208,6 +209,7 @@ class OwnerReturnShardViewModel extends AndroidViewModel implements SecretOwnerT
}
public Bitmap getQrCodeBitmap() {
LOG.info("getting qrCodeBitmap");
return qrCodeBitmap;
}
@@ -225,7 +227,6 @@ class OwnerReturnShardViewModel extends AndroidViewModel implements SecretOwnerT
String content = new String(payloadBytes, ISO_8859_1);
qrCodeBitmap = QrCodeUtils.createQrCode(dm, content);
});
showQrCodeFragment.setEvent(true);
}
}
}