Add missing permission request
This commit is contained in:
parent
5dc83d64c1
commit
ba589e7961
@ -66,6 +66,7 @@ const val PERMISSION_REQUEST_CODE_AUDIO_CALL = 571
|
|||||||
const val PERMISSION_REQUEST_CODE_VIDEO_CALL = 572
|
const val PERMISSION_REQUEST_CODE_VIDEO_CALL = 572
|
||||||
const val PERMISSION_REQUEST_CODE_EXPORT_KEYS = 573
|
const val PERMISSION_REQUEST_CODE_EXPORT_KEYS = 573
|
||||||
const val PERMISSION_REQUEST_CODE_CHANGE_AVATAR = 574
|
const val PERMISSION_REQUEST_CODE_CHANGE_AVATAR = 574
|
||||||
|
const val PERMISSION_REQUEST_CODE_DOWNLOAD_FILE = 575
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log the used permissions statuses.
|
* Log the used permissions statuses.
|
||||||
|
@ -27,7 +27,7 @@ import im.vector.riotx.R
|
|||||||
import im.vector.riotx.core.dialogs.ExportKeysDialog
|
import im.vector.riotx.core.dialogs.ExportKeysDialog
|
||||||
import im.vector.riotx.core.extensions.observeEvent
|
import im.vector.riotx.core.extensions.observeEvent
|
||||||
import im.vector.riotx.core.platform.SimpleFragmentActivity
|
import im.vector.riotx.core.platform.SimpleFragmentActivity
|
||||||
import im.vector.riotx.core.utils.toast
|
import im.vector.riotx.core.utils.*
|
||||||
import im.vector.riotx.features.crypto.keys.KeysExporter
|
import im.vector.riotx.features.crypto.keys.KeysExporter
|
||||||
|
|
||||||
class KeysBackupSetupActivity : SimpleFragmentActivity() {
|
class KeysBackupSetupActivity : SimpleFragmentActivity() {
|
||||||
@ -132,39 +132,48 @@ class KeysBackupSetupActivity : SimpleFragmentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun exportKeysManually() {
|
private fun exportKeysManually() {
|
||||||
ExportKeysDialog().show(this, object : ExportKeysDialog.ExportKeyDialogListener {
|
if (checkPermissions(PERMISSIONS_FOR_WRITING_FILES, this, PERMISSION_REQUEST_CODE_EXPORT_KEYS)) {
|
||||||
override fun onPassphrase(passphrase: String) {
|
ExportKeysDialog().show(this, object : ExportKeysDialog.ExportKeyDialogListener {
|
||||||
showWaitingView()
|
override fun onPassphrase(passphrase: String) {
|
||||||
|
showWaitingView()
|
||||||
|
|
||||||
KeysExporter(session)
|
KeysExporter(session)
|
||||||
.export(this@KeysBackupSetupActivity,
|
.export(this@KeysBackupSetupActivity,
|
||||||
passphrase,
|
passphrase,
|
||||||
object : MatrixCallback<String> {
|
object : MatrixCallback<String> {
|
||||||
|
|
||||||
override fun onSuccess(data: String) {
|
override fun onSuccess(data: String) {
|
||||||
hideWaitingView()
|
hideWaitingView()
|
||||||
|
|
||||||
AlertDialog.Builder(this@KeysBackupSetupActivity)
|
AlertDialog.Builder(this@KeysBackupSetupActivity)
|
||||||
.setMessage(getString(R.string.encryption_export_saved_as, data))
|
.setMessage(getString(R.string.encryption_export_saved_as, data))
|
||||||
.setCancelable(false)
|
.setCancelable(false)
|
||||||
.setPositiveButton(R.string.ok) { dialog, which ->
|
.setPositiveButton(R.string.ok) { dialog, which ->
|
||||||
val resultIntent = Intent()
|
val resultIntent = Intent()
|
||||||
resultIntent.putExtra(MANUAL_EXPORT, true)
|
resultIntent.putExtra(MANUAL_EXPORT, true)
|
||||||
setResult(RESULT_OK, resultIntent)
|
setResult(RESULT_OK, resultIntent)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(failure: Throwable) {
|
override fun onFailure(failure: Throwable) {
|
||||||
toast(failure.localizedMessage)
|
toast(failure.localizedMessage)
|
||||||
hideWaitingView()
|
hideWaitingView()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
|
||||||
|
if (allGranted(grantResults)) {
|
||||||
|
if (requestCode == PERMISSION_REQUEST_CODE_EXPORT_KEYS) {
|
||||||
|
exportKeysManually()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
if (viewModel.shouldPromptOnBack) {
|
if (viewModel.shouldPromptOnBack) {
|
||||||
|
@ -621,7 +621,26 @@ class RoomDetailFragment :
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onFileMessageClicked(eventId: String, messageFileContent: MessageFileContent) {
|
override fun onFileMessageClicked(eventId: String, messageFileContent: MessageFileContent) {
|
||||||
roomDetailViewModel.process(RoomDetailActions.DownloadFile(eventId, messageFileContent))
|
val action = RoomDetailActions.DownloadFile(eventId, messageFileContent)
|
||||||
|
// We need WRITE_EXTERNAL permission
|
||||||
|
if (checkPermissions(PERMISSIONS_FOR_WRITING_FILES, this, PERMISSION_REQUEST_CODE_DOWNLOAD_FILE)) {
|
||||||
|
roomDetailViewModel.process(action)
|
||||||
|
} else {
|
||||||
|
roomDetailViewModel.pendingAction = action
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||||
|
if (allGranted(grantResults)) {
|
||||||
|
if (requestCode == PERMISSION_REQUEST_CODE_DOWNLOAD_FILE) {
|
||||||
|
val action = roomDetailViewModel.pendingAction
|
||||||
|
|
||||||
|
if (action != null) {
|
||||||
|
roomDetailViewModel.pendingAction = null
|
||||||
|
roomDetailViewModel.process(action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAudioMessageClicked(messageAudioContent: MessageAudioContent) {
|
override fun onAudioMessageClicked(messageAudioContent: MessageAudioContent) {
|
||||||
|
@ -75,6 +75,9 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
|
|||||||
}
|
}
|
||||||
private var timeline = room.createTimeline(eventId, allowedTypes)
|
private var timeline = room.createTimeline(eventId, allowedTypes)
|
||||||
|
|
||||||
|
// Slot to keep a pending action during permission request
|
||||||
|
var pendingAction: RoomDetailActions? = null
|
||||||
|
|
||||||
@AssistedInject.Factory
|
@AssistedInject.Factory
|
||||||
interface Factory {
|
interface Factory {
|
||||||
fun create(initialState: RoomDetailViewState): RoomDetailViewModel
|
fun create(initialState: RoomDetailViewState): RoomDetailViewModel
|
||||||
|
Loading…
x
Reference in New Issue
Block a user