|
|
|
@ -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,21 +131,33 @@ class ViewMyQRCodeFragment : Fragment() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun shareQRCode() {
|
|
|
|
|
val directory = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES)
|
|
|
|
|
val fileName = "$hexEncodedPublicKey.png"
|
|
|
|
|
val file = File(directory, fileName)
|
|
|
|
|
file.createNewFile()
|
|
|
|
|
val fos = FileOutputStream(file)
|
|
|
|
|
val size = toPx(240, resources)
|
|
|
|
|
val qrCode = QRCodeUtilities.encode(hexEncodedPublicKey, size, false)
|
|
|
|
|
qrCode.compress(Bitmap.CompressFormat.PNG, 100, fos)
|
|
|
|
|
fos.flush()
|
|
|
|
|
fos.close()
|
|
|
|
|
val intent = Intent(Intent.ACTION_SEND)
|
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, FileProviderUtil.getUriFor(activity!!, file))
|
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
|
|
intent.type = "image/png"
|
|
|
|
|
startActivity(Intent.createChooser(intent, "Share QR Code"))
|
|
|
|
|
fun proceed() {
|
|
|
|
|
val directory = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES)
|
|
|
|
|
val fileName = "$hexEncodedPublicKey.png"
|
|
|
|
|
val file = File(directory, fileName)
|
|
|
|
|
file.createNewFile()
|
|
|
|
|
val fos = FileOutputStream(file)
|
|
|
|
|
val size = toPx(240, resources)
|
|
|
|
|
val qrCode = QRCodeUtilities.encode(hexEncodedPublicKey, size, false)
|
|
|
|
|
qrCode.compress(Bitmap.CompressFormat.PNG, 100, fos)
|
|
|
|
|
fos.flush()
|
|
|
|
|
fos.close()
|
|
|
|
|
val intent = Intent(Intent.ACTION_SEND)
|
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, FileProviderUtil.getUriFor(activity!!, file))
|
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
|
|
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
|