@ -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