From b2aae44645d10cc58f91b80b8a90f8ec3b0ca010 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 29 Jun 2017 14:01:12 +0200 Subject: [PATCH] show scan button in TrustKeys only if there is something to scan --- .../conversations/ui/TrustKeysActivity.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java index 5e8954c93..2fff0e40f 100644 --- a/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/TrustKeysActivity.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; @@ -52,6 +53,8 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat private Button mSaveButton; private Button mCancelButton; + private AtomicBoolean mUseCameraHintShown = new AtomicBoolean(false); + private AxolotlService.FetchStatus lastFetchReport = AxolotlService.FetchStatus.SUCCESS; private final Map ownKeysToTrust = new HashMap<>(); @@ -114,11 +117,16 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.trust_keys, menu); + MenuItem scanQrCode = menu.findItem(R.id.action_scan_qr_code); + scanQrCode.setVisible(ownKeysToTrust.size() > 0 || foreignActuallyHasKeys()); + return super.onCreateOptionsMenu(menu); + } + + private void showCameraToast() { mUseCameraHintToast = Toast.makeText(this,R.string.use_camera_icon_to_scan_barcode,Toast.LENGTH_LONG); ActionBar actionBar = getActionBar(); mUseCameraHintToast.setGravity(Gravity.TOP | Gravity.END, 0 ,actionBar == null ? 0 : actionBar.getHeight()); mUseCameraHintToast.show(); - return super.onCreateOptionsMenu(menu); } @Override @@ -218,6 +226,10 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat } } + if ((hasOwnKeys || foreignActuallyHasKeys()) && mUseCameraHintShown.compareAndSet(false,true)) { + showCameraToast(); + } + ownKeysTitle.setText(mAccount.getJid().toBareJid().toString()); ownKeysCard.setVisibility(hasOwnKeys ? View.VISIBLE : View.GONE); foreignKeys.setVisibility(hasForeignKeys ? View.VISIBLE : View.GONE); @@ -243,6 +255,17 @@ public class TrustKeysActivity extends OmemoActivity implements OnKeyStatusUpdat } } + private boolean foreignActuallyHasKeys() { + synchronized (this.foreignKeysToTrust) { + for (Map.Entry> entry : foreignKeysToTrust.entrySet()) { + if (entry.getValue().size() > 0) { + return true; + } + } + } + return false; + } + private boolean reloadFingerprints() { List acceptedTargets = mConversation == null ? new ArrayList() : mConversation.getAcceptedCryptoTargets(); ownKeysToTrust.clear();