diff --git a/res/layout/fragment_qr_code.xml b/res/layout/fragment_qr_code.xml
deleted file mode 100644
index 8a3df0f20b..0000000000
--- a/res/layout/fragment_qr_code.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/res/layout/view_qr_code.xml b/res/layout/view_qr_code.xml
new file mode 100644
index 0000000000..57cfc4b024
--- /dev/null
+++ b/res/layout/view_qr_code.xml
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 13f06cc71c..3a247866c8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1606,13 +1606,14 @@
Pending Friend Request…
New Message
-
- Your QR Code
- This is your personal QR code. Other people can scan it to start a secure conversation with you.
- Loki Messenger needs camera access to scan QR codes.
+
+ Your QR Code
+ This is your personal QR code. Other people can scan it to start a secure conversation with you.
+ Cancel
Scan QR Code
Scan the QR code of the person you\'d like to securely message. They can find their QR code by going into Loki Messenger\'s in-app settings and clicking \"Show QR Code\".
+ Loki Messenger needs camera access to scan QR codes.
Copy public key
diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java
index 89df173c6f..d1f006b86a 100644
--- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java
+++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java
@@ -40,7 +40,7 @@ import android.support.v7.preference.Preference;
import android.widget.Toast;
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil;
-import org.thoughtcrime.securesms.loki.QRCodeFragment;
+import org.thoughtcrime.securesms.loki.QRCodeDialog;
import org.thoughtcrime.securesms.preferences.AppProtectionPreferenceFragment;
import org.thoughtcrime.securesms.preferences.ChatsPreferenceFragment;
import org.thoughtcrime.securesms.preferences.CorrectedPreferenceFragment;
@@ -317,7 +317,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA
startActivity(shareIntent);
break;
case PREFERENCE_CATEGORY_QR_CODE:
- fragment = new QRCodeFragment();
+ QRCodeDialog.INSTANCE.show(getContext());
break;
case PREFERENCE_CATEGORY_SEED:
File languageFileDirectory = new File(getContext().getApplicationInfo().dataDir);
diff --git a/src/org/thoughtcrime/securesms/loki/NewConversationActivity.kt b/src/org/thoughtcrime/securesms/loki/NewConversationActivity.kt
index e67efcdde7..bacbdaa5f4 100644
--- a/src/org/thoughtcrime/securesms/loki/NewConversationActivity.kt
+++ b/src/org/thoughtcrime/securesms/loki/NewConversationActivity.kt
@@ -50,13 +50,13 @@ class NewConversationActivity : PassphraseRequiredActionBarActivity(), ScanListe
Permissions.with(this)
.request(Manifest.permission.CAMERA)
.ifNecessary()
- .withPermanentDenialDialog(getString(R.string.fragment_qr_code_camera_permission_dialog_message))
+ .withPermanentDenialDialog(getString(R.string.fragment_scan_qr_code_camera_permission_dialog_message))
.onAllGranted {
val fragment = ScanQRCodeFragment()
fragment.scanListener = this
supportFragmentManager.beginTransaction().replace(android.R.id.content, fragment).addToBackStack(null).commitAllowingStateLoss()
}
- .onAnyDenied { Toast.makeText(this, R.string.fragment_qr_code_camera_permission_dialog_message, Toast.LENGTH_SHORT).show() }
+ .onAnyDenied { Toast.makeText(this, R.string.fragment_scan_qr_code_camera_permission_dialog_message, Toast.LENGTH_SHORT).show() }
.execute()
}
diff --git a/src/org/thoughtcrime/securesms/loki/QRCodeDialog.kt b/src/org/thoughtcrime/securesms/loki/QRCodeDialog.kt
new file mode 100644
index 0000000000..cf71a1312e
--- /dev/null
+++ b/src/org/thoughtcrime/securesms/loki/QRCodeDialog.kt
@@ -0,0 +1,39 @@
+package org.thoughtcrime.securesms.loki
+
+import android.content.Context
+import android.support.v7.app.AlertDialog
+import android.util.AttributeSet
+import android.util.DisplayMetrics
+import android.widget.LinearLayout
+import kotlinx.android.synthetic.main.view_qr_code.view.*
+import network.loki.messenger.R
+import org.thoughtcrime.securesms.qr.QrCode
+import org.thoughtcrime.securesms.util.ServiceUtil
+import org.thoughtcrime.securesms.util.TextSecurePreferences
+
+object QRCodeDialog {
+
+ fun show(context: Context) {
+ val view = QRCodeView(context)
+ val dialog = AlertDialog.Builder(context).setView(view).show()
+ view.onCancel = { dialog.dismiss() }
+ }
+}
+
+class QRCodeView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) {
+ var onCancel: (() -> Unit)? = null
+
+ constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
+ constructor(context: Context) : this(context, null)
+
+ init {
+ inflate(getContext(), R.layout.view_qr_code, this)
+ val hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
+ val displayMetrics = DisplayMetrics()
+ ServiceUtil.getWindowManager(context).defaultDisplay.getMetrics(displayMetrics)
+ val size = displayMetrics.widthPixels - 2 * toPx(96, resources)
+ val qrCode = QrCode.create(hexEncodedPublicKey, size)
+ qrCodeImageView.setImageBitmap(qrCode)
+ cancelButton.setOnClickListener { onCancel?.invoke() }
+ }
+}
\ No newline at end of file
diff --git a/src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt b/src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt
deleted file mode 100644
index 3e15a97059..0000000000
--- a/src/org/thoughtcrime/securesms/loki/QRCodeFragment.kt
+++ /dev/null
@@ -1,37 +0,0 @@
-package org.thoughtcrime.securesms.loki
-
-import android.os.Bundle
-import android.support.v4.app.Fragment
-import android.util.DisplayMetrics
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import kotlinx.android.synthetic.main.fragment_qr_code.*
-import network.loki.messenger.R
-import org.thoughtcrime.securesms.ApplicationPreferencesActivity
-import org.thoughtcrime.securesms.qr.QrCode
-import org.thoughtcrime.securesms.util.ServiceUtil.getWindowManager
-import org.thoughtcrime.securesms.util.TextSecurePreferences
-
-class QRCodeFragment : Fragment() {
-
- override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
- return inflater.inflate(R.layout.fragment_qr_code, container, false)
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- super.onViewCreated(view, savedInstanceState)
- val hexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
- val displayMetrics = DisplayMetrics()
- getWindowManager(context).defaultDisplay.getMetrics(displayMetrics)
- val size = displayMetrics.widthPixels - 2 * toPx(32, resources)
- val qrCode = QrCode.create(hexEncodedPublicKey, size)
- qrCodeImageView.setImageBitmap(qrCode)
- }
-
- override fun onResume() {
- super.onResume()
- val activity = activity as ApplicationPreferencesActivity
- activity.supportActionBar!!.setTitle(R.string.fragment_qr_code_title)
- }
-}
\ No newline at end of file