mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 19:36:08 +03:00
Ask for permission
This commit is contained in:
parent
c67fd508e7
commit
94340a49d7
1 changed files with 26 additions and 5 deletions
|
@ -21,6 +21,7 @@ import android.content.Intent
|
|||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.view.isVisible
|
||||
|
@ -35,6 +36,10 @@ import im.vector.riotx.core.extensions.cleanup
|
|||
import im.vector.riotx.core.extensions.configureWith
|
||||
import im.vector.riotx.core.extensions.exhaustive
|
||||
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||
import im.vector.riotx.core.utils.PERMISSIONS_FOR_WRITING_FILES
|
||||
import im.vector.riotx.core.utils.PERMISSION_REQUEST_CODE_PICK_ATTACHMENT
|
||||
import im.vector.riotx.core.utils.allGranted
|
||||
import im.vector.riotx.core.utils.checkPermissions
|
||||
import im.vector.riotx.features.attachments.AttachmentsHelper
|
||||
import im.vector.riotx.features.login.LoginActivity
|
||||
import kotlinx.android.synthetic.main.fragment_incoming_share.*
|
||||
|
@ -72,10 +77,10 @@ class IncomingShareFragment @Inject constructor(
|
|||
isShareManaged = handleTextShare(intent)
|
||||
}
|
||||
if (!isShareManaged) {
|
||||
cannotManageShare()
|
||||
cannotManageShare(R.string.error_handling_incoming_share)
|
||||
}
|
||||
} else {
|
||||
cannotManageShare()
|
||||
cannotManageShare(R.string.error_handling_incoming_share)
|
||||
}
|
||||
|
||||
incomingShareSearchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
|
@ -98,6 +103,22 @@ class IncomingShareFragment @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// We need the read file permission
|
||||
checkPermissions(PERMISSIONS_FOR_WRITING_FILES, this, PERMISSION_REQUEST_CODE_PICK_ATTACHMENT)
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
|
||||
if (requestCode == PERMISSION_REQUEST_CODE_PICK_ATTACHMENT && !allGranted(grantResults)) {
|
||||
// Permission is mandatory
|
||||
cannotManageShare(R.string.missing_permissions_error)
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleShareToRoom(event: IncomingShareViewEvents.ShareToRoom) {
|
||||
if (event.showAlert) {
|
||||
showConfirmationDialog(event.roomSummary, event.sharedData)
|
||||
|
@ -127,11 +148,11 @@ class IncomingShareFragment @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onAttachmentsProcessFailed() {
|
||||
cannotManageShare()
|
||||
cannotManageShare(R.string.error_handling_incoming_share)
|
||||
}
|
||||
|
||||
private fun cannotManageShare() {
|
||||
Toast.makeText(requireContext(), R.string.error_handling_incoming_share, Toast.LENGTH_LONG).show()
|
||||
private fun cannotManageShare(@StringRes messageResId: Int) {
|
||||
Toast.makeText(requireContext(), messageResId, Toast.LENGTH_LONG).show()
|
||||
requireActivity().finish()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue