Compose activity fixes (#1707)

* cleanup media keyboard code

* fix crash in ComposeActivity when rotating phone while taking photo

* fix poll button in ComposeActivity being invisible when disabled
This commit is contained in:
Konrad Pozniak 2020-02-24 22:03:00 +01:00 committed by GitHub
parent 74119aed30
commit aba36ca6f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 38 deletions

View File

@ -103,8 +103,6 @@ class ComposeActivity : BaseActivity(),
// this only exists when a status is trying to be sent, but uploads are still occurring
private var finishingUploadDialog: ProgressDialog? = null
private var currentInputContentInfo: InputContentInfoCompat? = null
private var currentFlags: Int = 0
private var photoUploadUri: Uri? = null
@VisibleForTesting
var maximumTootCharacters = DEFAULT_CHARACTER_LIMIT
@ -147,6 +145,8 @@ class ComposeActivity : BaseActivity(),
subscribeToUpdates(mediaAdapter)
setupButtons()
photoUploadUri = savedInstanceState?.getParcelable(PHOTO_UPLOAD_URI_KEY)
/* If the composer is started up as a reply to another post, override the "starting" state
* based on what the intent from the reply request passes. */
if (intent != null) {
@ -473,14 +473,7 @@ class ComposeActivity : BaseActivity(),
}
override fun onSaveInstanceState(outState: Bundle) {
if (currentInputContentInfo != null) {
outState.putParcelable("commitContentInputContentInfo",
currentInputContentInfo!!.unwrap() as Parcelable?)
outState.putInt("commitContentFlags", currentFlags)
}
currentInputContentInfo = null
currentFlags = 0
outState.putParcelable("photoUploadUri", photoUploadUri)
outState.putParcelable(PHOTO_UPLOAD_URI_KEY, photoUploadUri)
super.onSaveInstanceState(outState)
}
@ -708,23 +701,13 @@ class ComposeActivity : BaseActivity(),
}
/** This is for the fancy keyboards which can insert images and stuff. */
override fun onCommitContent(inputContentInfo: InputContentInfoCompat, flags: Int, opts: Bundle): Boolean {
try {
currentInputContentInfo?.releasePermission()
} catch (e: Exception) {
Log.e(TAG, "InputContentInfoCompat#releasePermission() failed." + e.message)
} finally {
currentInputContentInfo = null
}
override fun onCommitContent(inputContentInfo: InputContentInfoCompat, flags: Int, opts: Bundle?): Boolean {
// Verify the returned content's type is of the correct MIME type
val supported = inputContentInfo.description.hasMimeType("image/*")
return supported && onCommitContentInternal(inputContentInfo, flags)
}
private fun onCommitContentInternal(inputContentInfo: InputContentInfoCompat, flags: Int): Boolean {
if (flags and InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION != 0) {
if(supported) {
val lacksPermission = (flags and InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0
if(lacksPermission) {
try {
inputContentInfo.requestPermission()
} catch (e: Exception) {
@ -732,16 +715,13 @@ class ComposeActivity : BaseActivity(),
return false
}
}
// Determine the file size before putting handing it off to be put in the queue.
pickMedia(inputContentInfo.contentUri)
currentInputContentInfo = inputContentInfo
currentFlags = flags
pickMedia(inputContentInfo.contentUri, inputContentInfo)
return true
}
return false
}
private fun sendStatus() {
val contentText = composeEditField.text.toString()
var spoilerText = ""
@ -849,9 +829,12 @@ class ComposeActivity : BaseActivity(),
}
}
private fun pickMedia(uri: Uri) {
private fun pickMedia(uri: Uri, contentInfoCompat: InputContentInfoCompat? = null) {
withLifecycleContext {
viewModel.pickMedia(uri).observe { exceptionOrItem ->
contentInfoCompat?.releasePermission()
exceptionOrItem.asLeftOrNull()?.let {
val errorId = when (it) {
is VideoSizeException -> {
@ -1026,6 +1009,7 @@ class ComposeActivity : BaseActivity(),
private const val PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 1
private const val COMPOSE_OPTIONS_EXTRA = "COMPOSE_OPTIONS"
private const val PHOTO_UPLOAD_URI_KEY = "PHOTO_UPLOAD_URI"
// Mastodon only counts URLs as this long in terms of status character limits
@VisibleForTesting

View File

@ -10,7 +10,7 @@
<color name="textColorPrimary">@color/white</color>
<color name="textColorSecondary">@color/tusky_grey_90</color>
<color name="textColorTertiary">@color/tusky_grey_70</color>
<color name="textColorDisabled">@color/tusky_grey_30</color>
<color name="textColorDisabled">@color/tusky_grey_40</color>
<color name="iconColor">@color/tusky_grey_70</color>