Avoid requesting storage permission to share payment request.
This commit is contained in:
parent
23f4170628
commit
8a4b8c1bbd
13 changed files with 19 additions and 75 deletions
|
@ -1,7 +1,6 @@
|
||||||
package cy.agorise.bitsybitshareswallet.fragments
|
package cy.agorise.bitsybitshareswallet.fragments
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
|
||||||
import android.graphics.drawable.Animatable
|
import android.graphics.drawable.Animatable
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
@ -22,7 +21,6 @@ import cy.agorise.bitsybitshareswallet.databinding.FragmentReceiveTransactionBin
|
||||||
import cy.agorise.bitsybitshareswallet.utils.Constants
|
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||||
import cy.agorise.bitsybitshareswallet.utils.Helper
|
import cy.agorise.bitsybitshareswallet.utils.Helper
|
||||||
import cy.agorise.bitsybitshareswallet.utils.showKeyboard
|
import cy.agorise.bitsybitshareswallet.utils.showKeyboard
|
||||||
import cy.agorise.bitsybitshareswallet.utils.toast
|
|
||||||
import cy.agorise.bitsybitshareswallet.viewmodels.ReceiveTransactionViewModel
|
import cy.agorise.bitsybitshareswallet.viewmodels.ReceiveTransactionViewModel
|
||||||
import cy.agorise.graphenej.*
|
import cy.agorise.graphenej.*
|
||||||
import cy.agorise.graphenej.api.ConnectionStatusUpdate
|
import cy.agorise.graphenej.api.ConnectionStatusUpdate
|
||||||
|
@ -34,23 +32,10 @@ import java.text.DecimalFormat
|
||||||
import java.text.DecimalFormatSymbols
|
import java.text.DecimalFormatSymbols
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class ReceiveTransactionFragment : ConnectedFragment() {
|
class ReceiveTransactionFragment : ConnectedFragment() {
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val TAG = "ReceiveTransactionFrag"
|
|
||||||
|
|
||||||
private const val RESPONSE_LIST_ASSETS = 1
|
|
||||||
private const val REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION = 100
|
|
||||||
|
|
||||||
/** Number of assets to request from the NetworkService to show as suggestions in the AutoCompleteTextView */
|
|
||||||
private const val AUTO_SUGGEST_ASSET_LIMIT = 5
|
|
||||||
|
|
||||||
private const val OTHER_ASSET = "other_asset"
|
|
||||||
}
|
|
||||||
|
|
||||||
private val viewModel: ReceiveTransactionViewModel by viewModels()
|
private val viewModel: ReceiveTransactionViewModel by viewModels()
|
||||||
|
|
||||||
private var _binding: FragmentReceiveTransactionBinding? = null
|
private var _binding: FragmentReceiveTransactionBinding? = null
|
||||||
|
@ -120,11 +105,11 @@ class ReceiveTransactionFragment : ConnectedFragment() {
|
||||||
val userId = PreferenceManager.getDefaultSharedPreferences(context)
|
val userId = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
.getString(Constants.KEY_CURRENT_ACCOUNT_ID, "")
|
.getString(Constants.KEY_CURRENT_ACCOUNT_ID, "")
|
||||||
|
|
||||||
viewModel.getUserAccount(userId!!).observe(viewLifecycleOwner, { user ->
|
viewModel.getUserAccount(userId!!).observe(viewLifecycleOwner) { user ->
|
||||||
mUserAccount = UserAccount(user.id, user.name)
|
mUserAccount = UserAccount(user.id, user.name)
|
||||||
})
|
}
|
||||||
|
|
||||||
viewModel.getAllNonZero().observe(viewLifecycleOwner, { assets ->
|
viewModel.getAllNonZero().observe(viewLifecycleOwner) { assets ->
|
||||||
mAssets.clear()
|
mAssets.clear()
|
||||||
mAssets.addAll(assets)
|
mAssets.addAll(assets)
|
||||||
|
|
||||||
|
@ -155,11 +140,11 @@ class ReceiveTransactionFragment : ConnectedFragment() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
viewModel.qrCodeBitmap.observe(viewLifecycleOwner, { bitmap ->
|
viewModel.qrCodeBitmap.observe(viewLifecycleOwner) { bitmap ->
|
||||||
binding.ivQR.setImageBitmap(bitmap)
|
binding.ivQR.setImageBitmap(bitmap)
|
||||||
})
|
}
|
||||||
|
|
||||||
binding.spAsset.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
binding.spAsset.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
||||||
|
@ -351,47 +336,12 @@ class ReceiveTransactionFragment : ConnectedFragment() {
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
if (item.itemId == R.id.menu_share) {
|
if (item.itemId == R.id.menu_share) {
|
||||||
verifyStoragePermission()
|
shareQRScreenshot()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun verifyStoragePermission() {
|
|
||||||
if (ContextCompat.checkSelfPermission(
|
|
||||||
requireActivity(),
|
|
||||||
android.Manifest.permission.WRITE_EXTERNAL_STORAGE
|
|
||||||
)
|
|
||||||
!= PackageManager.PERMISSION_GRANTED
|
|
||||||
) {
|
|
||||||
// Permission is not already granted
|
|
||||||
requestPermissions(
|
|
||||||
arrayOf(android.Manifest.permission.WRITE_EXTERNAL_STORAGE),
|
|
||||||
REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// Permission is already granted
|
|
||||||
shareQRScreenshot()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onRequestPermissionsResult(
|
|
||||||
requestCode: Int,
|
|
||||||
permissions: Array<out String>,
|
|
||||||
grantResults: IntArray
|
|
||||||
) {
|
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
|
||||||
|
|
||||||
if (requestCode == REQUEST_WRITE_EXTERNAL_STORAGE_PERMISSION) {
|
|
||||||
if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
|
|
||||||
shareQRScreenshot()
|
|
||||||
} else {
|
|
||||||
context?.toast(getString(R.string.msg__storage_permission_necessary_share))
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function takes a screenshot as a bitmap, saves it into a temporal cache image and then
|
* This function takes a screenshot as a bitmap, saves it into a temporal cache image and then
|
||||||
* sends an intent so the user can select the desired method to share the image.
|
* sends an intent so the user can select the desired method to share the image.
|
||||||
|
@ -421,4 +371,15 @@ class ReceiveTransactionFragment : ConnectedFragment() {
|
||||||
shareIntent.type = "*/*"
|
shareIntent.type = "*/*"
|
||||||
startActivity(Intent.createChooser(shareIntent, getString(R.string.text__share_with)))
|
startActivity(Intent.createChooser(shareIntent, getString(R.string.text__share_with)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "ReceiveTransactionFrag"
|
||||||
|
|
||||||
|
private const val RESPONSE_LIST_ASSETS = 1
|
||||||
|
|
||||||
|
/** Number of assets to request from the NetworkService to show as suggestions in the AutoCompleteTextView */
|
||||||
|
private const val AUTO_SUGGEST_ASSET_LIMIT = 5
|
||||||
|
|
||||||
|
private const val OTHER_ASSET = "other_asset"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,7 @@ class CSVGenerationTask(context: Context) : AsyncTask<List<TransferDetail>, Int,
|
||||||
private fun createCSVDocument(transferDetails: List<TransferDetail>): String {
|
private fun createCSVDocument(transferDetails: List<TransferDetail>): String {
|
||||||
return try {
|
return try {
|
||||||
// Create and configure a new CSV file to save the transfers list
|
// Create and configure a new CSV file to save the transfers list
|
||||||
val externalStorageFolder = Environment.getExternalStorageDirectory().absolutePath + File.separator +
|
val externalStorageFolder = Environment.getExternalStorageDirectory().absolutePath + File.separator
|
||||||
Constants.EXTERNAL_STORAGE_FOLDER
|
|
||||||
val fileName = mContext.get()?.resources?.let {
|
val fileName = mContext.get()?.resources?.let {
|
||||||
"${it.getString(R.string.app_name)}-${it.getString(R.string.title_transactions)}"} + ".csv"
|
"${it.getString(R.string.app_name)}-${it.getString(R.string.title_transactions)}"} + ".csv"
|
||||||
val file = File(externalStorageFolder, fileName)
|
val file = File(externalStorageFolder, fileName)
|
||||||
|
|
|
@ -48,9 +48,6 @@ object Constants {
|
||||||
/** Coingecko's API URL */
|
/** Coingecko's API URL */
|
||||||
const val COINGECKO_URL = "https://api.coingecko.com"
|
const val COINGECKO_URL = "https://api.coingecko.com"
|
||||||
|
|
||||||
/** Key used to store and retrieve a cache of the coingecko supported currencies */
|
|
||||||
const val KEY_COINGECKO_CURRENCIES_CACHE = "key_coingecko_currencies_cache"
|
|
||||||
|
|
||||||
/** The fee to send in every transfer (0.01%) */
|
/** The fee to send in every transfer (0.01%) */
|
||||||
const val FEE_PERCENTAGE = 0.0001
|
const val FEE_PERCENTAGE = 0.0001
|
||||||
|
|
||||||
|
@ -122,9 +119,6 @@ object Constants {
|
||||||
/** Constant used to decide whether or not to update the tellers and merchants info from the webservice */
|
/** Constant used to decide whether or not to update the tellers and merchants info from the webservice */
|
||||||
const val MERCHANTS_UPDATE_PERIOD = 1000L * 60 * 60 + 3 // 3 hours
|
const val MERCHANTS_UPDATE_PERIOD = 1000L * 60 * 60 + 3 // 3 hours
|
||||||
|
|
||||||
/** Name of the external storage folder used to save files like PDF and CSV exports and Backups **/
|
|
||||||
const val EXTERNAL_STORAGE_FOLDER = "BiTSy"
|
|
||||||
|
|
||||||
/** Constant used to check if the current connected node is out of sync */
|
/** Constant used to check if the current connected node is out of sync */
|
||||||
const val CHECK_NODE_OUT_OF_SYNC = 10 // 10 seconds
|
const val CHECK_NODE_OUT_OF_SYNC = 10 // 10 seconds
|
||||||
|
|
||||||
|
|
|
@ -125,7 +125,6 @@
|
||||||
<string name="msg__invoice_subject">BiTSy Rechnung von %1$s</string>
|
<string name="msg__invoice_subject">BiTSy Rechnung von %1$s</string>
|
||||||
<string name="title_share">Aktie</string>
|
<string name="title_share">Aktie</string>
|
||||||
<string name="text__share_with">Teilen mit</string>
|
<string name="text__share_with">Teilen mit</string>
|
||||||
<string name="msg__storage_permission_necessary_share">Für die Freigabe von Bildern ist eine Speichererlaubnis erforderlich.</string>
|
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="title_settings">Einstellungen</string>
|
<string name="title_settings">Einstellungen</string>
|
||||||
|
|
|
@ -124,7 +124,6 @@
|
||||||
<string name="msg__invoice_subject">Invoice BiTSy de %1$s</string>
|
<string name="msg__invoice_subject">Invoice BiTSy de %1$s</string>
|
||||||
<string name="title_share">Compartir</string>
|
<string name="title_share">Compartir</string>
|
||||||
<string name="text__share_with">Compartir con</string>
|
<string name="text__share_with">Compartir con</string>
|
||||||
<string name="msg__storage_permission_necessary_share">El permiso de almacenamiento es necesario para compartir imágenes.</string>
|
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="title_settings">Ajustes</string>
|
<string name="title_settings">Ajustes</string>
|
||||||
|
|
|
@ -125,7 +125,6 @@
|
||||||
<string name="msg__invoice_subject">Facture biTSy de %1$s</string>
|
<string name="msg__invoice_subject">Facture biTSy de %1$s</string>
|
||||||
<string name="title_share">Partager</string>
|
<string name="title_share">Partager</string>
|
||||||
<string name="text__share_with">Partager avec</string>
|
<string name="text__share_with">Partager avec</string>
|
||||||
<string name="msg__storage_permission_necessary_share">Une autorisation de stockage est nécessaire pour partager des images.</string>
|
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="title_settings">Réglages</string>
|
<string name="title_settings">Réglages</string>
|
||||||
|
|
|
@ -125,7 +125,6 @@
|
||||||
<string name="msg__invoice_subject">%1$s से बीटीएसआई चालान</string>
|
<string name="msg__invoice_subject">%1$s से बीटीएसआई चालान</string>
|
||||||
<string name="title_share">शेयर</string>
|
<string name="title_share">शेयर</string>
|
||||||
<string name="text__share_with">के साथ शेयर करें</string>
|
<string name="text__share_with">के साथ शेयर करें</string>
|
||||||
<string name="msg__storage_permission_necessary_share">छवियों को साझा करने के लिए भंडारण की अनुमति आवश्यक है।</string>
|
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="title_settings">सेटिंग्स</string>
|
<string name="title_settings">सेटिंग्स</string>
|
||||||
|
|
|
@ -125,7 +125,6 @@
|
||||||
<string name="msg__invoice_subject">%1$sからのBiTSy請求書</string>
|
<string name="msg__invoice_subject">%1$sからのBiTSy請求書</string>
|
||||||
<string name="title_share">シェア</string>
|
<string name="title_share">シェア</string>
|
||||||
<string name="text__share_with">と共有する</string>
|
<string name="text__share_with">と共有する</string>
|
||||||
<string name="msg__storage_permission_necessary_share">画像を共有するには保存許可が必要です。</string>
|
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="title_settings">設定</string>
|
<string name="title_settings">設定</string>
|
||||||
|
|
|
@ -125,7 +125,6 @@
|
||||||
<string name="msg__invoice_subject">%1$s ਦਾ ਬੀ.ਟੀ.ਸੀ ਚਲਾਨ</string>
|
<string name="msg__invoice_subject">%1$s ਦਾ ਬੀ.ਟੀ.ਸੀ ਚਲਾਨ</string>
|
||||||
<string name="title_share">ਸਾਂਝਾ ਕਰੋ</string>
|
<string name="title_share">ਸਾਂਝਾ ਕਰੋ</string>
|
||||||
<string name="text__share_with">ਨਾਲ ਸਾਂਝਾ ਕਰੋ</string>
|
<string name="text__share_with">ਨਾਲ ਸਾਂਝਾ ਕਰੋ</string>
|
||||||
<string name="msg__storage_permission_necessary_share">ਤਸਵੀਰਾਂ ਨੂੰ ਸਾਂਝਾ ਕਰਨ ਲਈ ਸਟੋਰੇਜ਼ ਦੀ ਆਗਿਆ ਜ਼ਰੂਰੀ ਹੈ.</string>
|
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="title_settings">ਸੈਟਿੰਗਜ਼</string>
|
<string name="title_settings">ਸੈਟਿੰਗਜ਼</string>
|
||||||
|
|
|
@ -125,7 +125,6 @@
|
||||||
<string name="msg__invoice_subject">Fatura BiTSy de %1$s</string>
|
<string name="msg__invoice_subject">Fatura BiTSy de %1$s</string>
|
||||||
<string name="title_share">Compartilhar</string>
|
<string name="title_share">Compartilhar</string>
|
||||||
<string name="text__share_with">Compartilhar com</string>
|
<string name="text__share_with">Compartilhar com</string>
|
||||||
<string name="msg__storage_permission_necessary_share">É necessária permissão de armazenamento para compartilhar imagens.</string>
|
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="title_settings">Definições</string>
|
<string name="title_settings">Definições</string>
|
||||||
|
|
|
@ -125,7 +125,6 @@
|
||||||
<string name="msg__invoice_subject">Счет BiTSy от %1$s</string>
|
<string name="msg__invoice_subject">Счет BiTSy от %1$s</string>
|
||||||
<string name="title_share">Поделиться</string>
|
<string name="title_share">Поделиться</string>
|
||||||
<string name="text__share_with">Поделиться с</string>
|
<string name="text__share_with">Поделиться с</string>
|
||||||
<string name="msg__storage_permission_necessary_share">Разрешение на хранение необходимо для обмена изображениями.</string>
|
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="title_settings">настройки</string>
|
<string name="title_settings">настройки</string>
|
||||||
|
|
|
@ -125,7 +125,6 @@
|
||||||
<string name="msg__invoice_subject">来自%1$s的BiTSy发票</string>
|
<string name="msg__invoice_subject">来自%1$s的BiTSy发票</string>
|
||||||
<string name="title_share">分享</string>
|
<string name="title_share">分享</string>
|
||||||
<string name="text__share_with">与某人分享</string>
|
<string name="text__share_with">与某人分享</string>
|
||||||
<string name="msg__storage_permission_necessary_share">共享图像需要存储权限。</string>
|
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="title_settings">设置</string>
|
<string name="title_settings">设置</string>
|
||||||
|
|
|
@ -127,7 +127,6 @@
|
||||||
<string name="msg__invoice_subject">BiTSy invoice from %1$s</string>
|
<string name="msg__invoice_subject">BiTSy invoice from %1$s</string>
|
||||||
<string name="title_share">Share</string>
|
<string name="title_share">Share</string>
|
||||||
<string name="text__share_with">Share with</string>
|
<string name="text__share_with">Share with</string>
|
||||||
<string name="msg__storage_permission_necessary_share">Storage permission is necessary to share images.</string>
|
|
||||||
|
|
||||||
<!-- Settings -->
|
<!-- Settings -->
|
||||||
<string name="title_settings">Settings</string>
|
<string name="title_settings">Settings</string>
|
||||||
|
|
Loading…
Reference in a new issue