Fix QR code sharing

This commit is contained in:
Niels Andriesse 2020-01-07 09:35:14 +11:00
parent 7f0cda3b75
commit 23770f79a9

View File

@ -1,5 +1,6 @@
package org.thoughtcrime.securesms.loki.redesign.activities
import android.Manifest
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Typeface
@ -14,6 +15,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import com.tbruyelle.rxpermissions2.RxPermissions
import kotlinx.android.synthetic.main.activity_qr_code.*
import kotlinx.android.synthetic.main.fragment_view_my_qr_code.*
import network.loki.messenger.R
@ -129,6 +131,7 @@ class ViewMyQRCodeFragment : Fragment() {
}
private fun shareQRCode() {
fun proceed() {
val directory = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES)
val fileName = "$hexEncodedPublicKey.png"
val file = File(directory, fileName)
@ -145,5 +148,16 @@ class ViewMyQRCodeFragment : Fragment() {
intent.type = "image/png"
startActivity(Intent.createChooser(intent, "Share QR Code"))
}
if (RxPermissions(this).isGranted(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
proceed()
} else {
@SuppressWarnings("unused")
val unused = RxPermissions(this).request(Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe { isGranted ->
if (isGranted) {
proceed()
}
}
}
}
}
// endregion