fixed a serious crash in link handler

This commit is contained in:
Mariotaku Lee 2017-03-07 20:31:04 +08:00
parent 150e07d373
commit da5b276e16
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
1 changed files with 11 additions and 7 deletions

View File

@ -27,6 +27,7 @@ import android.graphics.Rect
import android.net.Uri
import android.os.BadParcelableException
import android.os.Bundle
import android.support.design.widget.FloatingActionButton
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentManager.FragmentLifecycleCallbacks
@ -104,10 +105,11 @@ class LinkHandlerActivity : BaseActivity(), SystemWindowsInsetsCallback, IContro
return
}
val linkId = TwidereLinkMatcher.match(uri)
var transactionRequired = false
intent.setExtrasClassLoader(classLoader)
val fragment: Fragment
try {
fragment = createFragmentForIntent(this, linkId, intent) ?: run {
val fragment: Fragment = currentVisibleFragment ?: try {
transactionRequired = true
createFragmentForIntent(this, linkId, intent) ?: run {
finish()
return
}
@ -153,9 +155,11 @@ class LinkHandlerActivity : BaseActivity(), SystemWindowsInsetsCallback, IContro
setupActionBarOption()
Utils.logOpenNotificationFromUri(this, uri)
val ft = supportFragmentManager.beginTransaction()
ft.replace(contentFragmentId, fragment, "content_fragment")
ft.commit()
if (transactionRequired) {
val ft = supportFragmentManager.beginTransaction()
ft.replace(contentFragmentId, fragment, "content_fragment")
ft.commit()
}
setTitle(linkId, uri)
finishOnly = uri.getQueryParameter(QUERY_PARAM_FINISH_ONLY)?.toBoolean() ?: false
@ -507,7 +511,7 @@ class LinkHandlerActivity : BaseActivity(), SystemWindowsInsetsCallback, IContro
}
private fun updateActionsButton() {
val fab = this.actionsButton ?: return
val fab = window.findViewById(R.id.actionButtons) as? FloatingActionButton ?: return
val fragment = currentVisibleFragment as? IFloatingActionButtonFragment
val info = fragment?.getActionInfo("link_handler") ?: run {
fab.visibility = View.GONE