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() { private void showQrCodeFragment() {
LOG.info("showQrCodeFragment called");
FragmentManager fm = getSupportFragmentManager(); FragmentManager fm = getSupportFragmentManager();
if (fm.findFragmentByTag(OwnerReturnShardFragment.TAG) == null) { if (fm.findFragmentByTag(OwnerReturnShardFragment.TAG) == null) {
BaseFragment f = OwnerReturnShardFragment.newInstance(); BaseFragment f = OwnerReturnShardFragment.newInstance();

View File

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

View File

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