|
|
@ -1,17 +1,15 @@
|
|
|
|
package org.thoughtcrime.securesms.loki.activities
|
|
|
|
package org.thoughtcrime.securesms.loki.activities
|
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.content.Intent
|
|
|
|
import android.graphics.Bitmap
|
|
|
|
import android.graphics.Bitmap
|
|
|
|
|
|
|
|
import android.net.Uri
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.os.Environment
|
|
|
|
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
|
|
|
import androidx.fragment.app.FragmentPagerAdapter
|
|
|
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.Toast
|
|
|
|
import android.widget.Toast
|
|
|
|
import com.tbruyelle.rxpermissions2.RxPermissions
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
|
|
|
import androidx.fragment.app.FragmentPagerAdapter
|
|
|
|
import kotlinx.android.synthetic.main.activity_qr_code.*
|
|
|
|
import kotlinx.android.synthetic.main.activity_qr_code.*
|
|
|
|
import kotlinx.android.synthetic.main.fragment_view_my_qr_code.*
|
|
|
|
import kotlinx.android.synthetic.main.fragment_view_my_qr_code.*
|
|
|
|
import network.loki.messenger.R
|
|
|
|
import network.loki.messenger.R
|
|
|
@ -106,8 +104,8 @@ class ViewMyQRCodeFragment : Fragment() {
|
|
|
|
|
|
|
|
|
|
|
|
private val hexEncodedPublicKey: String
|
|
|
|
private val hexEncodedPublicKey: String
|
|
|
|
get() {
|
|
|
|
get() {
|
|
|
|
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context!!)
|
|
|
|
val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(requireContext())
|
|
|
|
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context!!)
|
|
|
|
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(requireContext())
|
|
|
|
return masterHexEncodedPublicKey ?: userHexEncodedPublicKey
|
|
|
|
return masterHexEncodedPublicKey ?: userHexEncodedPublicKey
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -127,8 +125,7 @@ class ViewMyQRCodeFragment : Fragment() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun shareQRCode() {
|
|
|
|
private fun shareQRCode() {
|
|
|
|
fun proceed() {
|
|
|
|
val directory = requireContext().externalCacheDir
|
|
|
|
val directory = File(Environment.getExternalStorageDirectory(), Environment.DIRECTORY_PICTURES)
|
|
|
|
|
|
|
|
val fileName = "$hexEncodedPublicKey.png"
|
|
|
|
val fileName = "$hexEncodedPublicKey.png"
|
|
|
|
val file = File(directory, fileName)
|
|
|
|
val file = File(directory, fileName)
|
|
|
|
file.createNewFile()
|
|
|
|
file.createNewFile()
|
|
|
@ -139,21 +136,11 @@ class ViewMyQRCodeFragment : Fragment() {
|
|
|
|
fos.flush()
|
|
|
|
fos.flush()
|
|
|
|
fos.close()
|
|
|
|
fos.close()
|
|
|
|
val intent = Intent(Intent.ACTION_SEND)
|
|
|
|
val intent = Intent(Intent.ACTION_SEND)
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, FileProviderUtil.getUriFor(activity!!, file))
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, FileProviderUtil.getUriFor(requireActivity(), file))
|
|
|
|
|
|
|
|
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file))
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
|
|
intent.type = "image/png"
|
|
|
|
intent.type = "image/png"
|
|
|
|
startActivity(Intent.createChooser(intent, resources.getString(R.string.fragment_view_my_qr_code_share_title)))
|
|
|
|
startActivity(Intent.createChooser(intent, resources.getString(R.string.fragment_view_my_qr_code_share_title)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
// endregion
|