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