From 7b18c4e137e0beb1d905795869760c5aa5cf5681 Mon Sep 17 00:00:00 2001 From: "daniel.boehrs" Date: Fri, 10 May 2019 14:20:53 +0200 Subject: [PATCH] show a hint that qr-verification cannot be done without network #756 --- res/values/strings.xml | 2 ++ .../securesms/QrShowActivity.java | 33 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index a893c77fa..f487a46f8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -479,6 +479,8 @@ Scan this to join the group \"%1$s\". QR invite code Scan this to set up a contact with %1$s + QR code setup requires an internet connection. Please connect to a network before proceeding. + No internet connection, can\'t perform QR code setup. %1$s verified. Cannot verify %1$s diff --git a/src/org/thoughtcrime/securesms/QrShowActivity.java b/src/org/thoughtcrime/securesms/QrShowActivity.java index 4144432fe..1a41845dd 100644 --- a/src/org/thoughtcrime/securesms/QrShowActivity.java +++ b/src/org/thoughtcrime/securesms/QrShowActivity.java @@ -1,5 +1,9 @@ package org.thoughtcrime.securesms; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -44,6 +48,12 @@ public class QrShowActivity extends AppCompatActivity implements DcEventCenter.D ApplicationDcContext dcContext; + private String hint; + + private String errorHint; + + private TextView hintBelowQr; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -65,8 +75,8 @@ public class QrShowActivity extends AppCompatActivity implements DcEventCenter.D ActionBar supportActionBar = getSupportActionBar(); assert supportActionBar != null; supportActionBar.setDisplayHomeAsUpEnabled(true); + errorHint = getString(R.string.qrshow_join_contact_no_connection_hint); - String hint; if (chatId != 0) { // verified-group String groupName = dcContext.getChat(chatId).getName(); @@ -87,8 +97,8 @@ public class QrShowActivity extends AppCompatActivity implements DcEventCenter.D supportActionBar.setTitle(selfName); supportActionBar.setSubtitle(R.string.qrshow_join_contact_title); } - TextView hintBelowQr = findViewById(R.id.qrShowHint); - hintBelowQr.setText(Html.fromHtml(hint)); + hintBelowQr = findViewById(R.id.qrShowHint); + setHintText(); numJoiners = 0; @@ -101,6 +111,20 @@ public class QrShowActivity extends AppCompatActivity implements DcEventCenter.D } dcEventCenter.addObserver(DcContext.DC_EVENT_SECUREJOIN_INVITER_PROGRESS, this); + this.registerReceiver(new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + setHintText(); + } + }, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION)); + } + + private void setHintText() { + if (!dcContext.isNetworkConnected()) { + hintBelowQr.setText(Html.fromHtml(errorHint)); + } else { + hintBelowQr.setText(Html.fromHtml(hint)); + } } @Override @@ -108,6 +132,9 @@ public class QrShowActivity extends AppCompatActivity implements DcEventCenter.D super.onResume(); dynamicTheme.onResume(this); dynamicLanguage.onResume(this); + if (!dcContext.isNetworkConnected()) { + Toast.makeText(this, R.string.qrshow_join_contact_no_connection_toast, Toast.LENGTH_LONG).show(); + } } @Override