fixed some progress dialog crash
This commit is contained in:
parent
b312a703fb
commit
99c74f7bcb
|
@ -36,8 +36,8 @@ android {
|
|||
applicationId "org.mariotaku.twidere"
|
||||
minSdkVersion project.properties['overrideMinSdkVersion'] ?: 14
|
||||
targetSdkVersion 25
|
||||
versionCode 305
|
||||
versionName '3.4.43'
|
||||
versionCode 306
|
||||
versionName '3.4.44'
|
||||
multiDexEnabled true
|
||||
|
||||
buildConfigField 'boolean', 'LEAK_CANARY_ENABLED', 'Boolean.parseBoolean("true")'
|
||||
|
|
|
@ -41,6 +41,7 @@ import android.view.KeyEvent
|
|||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import com.squareup.otto.Bus
|
||||
import nl.komponents.kovenant.Promise
|
||||
import org.mariotaku.chameleon.Chameleon
|
||||
import org.mariotaku.chameleon.Chameleon.Theme.LightStatusBarMode
|
||||
import org.mariotaku.chameleon.ChameleonActivity
|
||||
|
@ -264,8 +265,8 @@ open class BaseActivity : ChameleonActivity(), IBaseActivity<BaseActivity>, IThe
|
|||
actionHelper.dispatchOnResumeFragments()
|
||||
}
|
||||
|
||||
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (BaseActivity) -> Unit) {
|
||||
actionHelper.executeAfterFragmentResumed(useHandler, action)
|
||||
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (BaseActivity) -> Unit): Promise<Unit, Exception> {
|
||||
return actionHelper.executeAfterFragmentResumed(useHandler, action)
|
||||
}
|
||||
|
||||
override final val currentThemeBackgroundAlpha by lazy {
|
||||
|
|
|
@ -121,8 +121,7 @@ class DataExportActivity : BaseActivity(), DataExportImportTypeSelectorDialogFra
|
|||
|
||||
override fun onPreExecute() {
|
||||
activity.executeAfterFragmentResumed {
|
||||
val activity = it as DataExportActivity
|
||||
ProgressDialogFragment.show(activity.supportFragmentManager, FRAGMENT_TAG).isCancelable = false
|
||||
ProgressDialogFragment.show(it.supportFragmentManager, FRAGMENT_TAG).isCancelable = false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -123,8 +123,7 @@ class DataImportActivity : BaseActivity(), DataExportImportTypeSelectorDialogFra
|
|||
|
||||
override fun onPreExecute() {
|
||||
activity.executeAfterFragmentResumed {
|
||||
val activity = it as DataImportActivity
|
||||
ProgressDialogFragment.show(activity.supportFragmentManager, FRAGMENT_TAG).isCancelable = false
|
||||
ProgressDialogFragment.show(it.supportFragmentManager, FRAGMENT_TAG).isCancelable = false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,8 +169,7 @@ class DataImportActivity : BaseActivity(), DataExportImportTypeSelectorDialogFra
|
|||
|
||||
override fun onPreExecute() {
|
||||
activity.executeAfterFragmentResumed {
|
||||
val activity = it as DataImportActivity
|
||||
ProgressDialogFragment.show(activity.supportFragmentManager, FRAGMENT_TAG).isCancelable = false
|
||||
ProgressDialogFragment.show(it.supportFragmentManager, FRAGMENT_TAG).isCancelable = false
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import com.bumptech.glide.Glide
|
|||
import com.bumptech.glide.RequestManager
|
||||
import kotlinx.android.synthetic.main.activity_premium_dashboard.*
|
||||
import kotlinx.android.synthetic.main.card_item_extra_feature.view.*
|
||||
import nl.komponents.kovenant.combine.and
|
||||
import nl.komponents.kovenant.task
|
||||
import nl.komponents.kovenant.ui.alwaysUi
|
||||
import nl.komponents.kovenant.ui.failUi
|
||||
|
@ -110,10 +111,11 @@ class PremiumDashboardActivity : BaseActivity() {
|
|||
if (!BuildConfig.DEBUG) {
|
||||
return true
|
||||
}
|
||||
ProgressDialogFragment.show(supportFragmentManager, "consume_purchase_progress")
|
||||
val weakThis = WeakReference(this)
|
||||
val recreate = AtomicBoolean()
|
||||
task {
|
||||
executeAfterFragmentResumed {
|
||||
ProgressDialogFragment.show(it.supportFragmentManager, "consume_purchase_progress")
|
||||
} and task {
|
||||
val activity = weakThis.get() ?: throw IllegalStateException()
|
||||
if (!activity.extraFeaturesService.destroyPurchase()) {
|
||||
throw IllegalStateException()
|
||||
|
|
|
@ -51,6 +51,7 @@ import android.widget.TextView
|
|||
import android.widget.Toast
|
||||
import com.bluelinelabs.logansquare.LoganSquare
|
||||
import kotlinx.android.synthetic.main.activity_sign_in.*
|
||||
import nl.komponents.kovenant.combine.and
|
||||
import nl.komponents.kovenant.task
|
||||
import nl.komponents.kovenant.ui.alwaysUi
|
||||
import nl.komponents.kovenant.ui.successUi
|
||||
|
@ -410,8 +411,9 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher, APIEditorDi
|
|||
|
||||
private fun updateDefaultFeatures() {
|
||||
val weakThis = WeakReference(this)
|
||||
ProgressDialogFragment.show(supportFragmentManager, FRAGMENT_TAG_LOADING_DEFAULT_FEATURES)
|
||||
task {
|
||||
executeAfterFragmentResumed {
|
||||
ProgressDialogFragment.show(it.supportFragmentManager, FRAGMENT_TAG_LOADING_DEFAULT_FEATURES)
|
||||
} and task {
|
||||
val activity = weakThis.get() ?: return@task
|
||||
if (activity.isFinishing) return@task
|
||||
activity.defaultFeatures.loadRemoteSettings(activity.restHttpClient)
|
||||
|
|
|
@ -17,6 +17,7 @@ import android.view.ViewGroup
|
|||
import android.widget.BaseExpandableListAdapter
|
||||
import android.widget.ExpandableListView
|
||||
import android.widget.TextView
|
||||
import nl.komponents.kovenant.combine.and
|
||||
import nl.komponents.kovenant.task
|
||||
import nl.komponents.kovenant.ui.alwaysUi
|
||||
import nl.komponents.kovenant.ui.failUi
|
||||
|
@ -54,10 +55,9 @@ class TrendsLocationSelectorActivity : BaseActivity() {
|
|||
|
||||
if (savedInstanceState != null) return
|
||||
val weakThis = WeakReference(this)
|
||||
ProgressDialogFragment.show(supportFragmentManager, PROGRESS_FRAGMENT_TAG).apply {
|
||||
isCancelable = false
|
||||
}
|
||||
task {
|
||||
executeAfterFragmentResumed {
|
||||
ProgressDialogFragment.show(it.supportFragmentManager, PROGRESS_FRAGMENT_TAG).isCancelable = false
|
||||
} and task {
|
||||
val activity = weakThis.get() ?: throw InterruptedException()
|
||||
val twitter = MicroBlogAPIFactory.getInstance(activity, accountKey)
|
||||
?: throw MicroBlogException("No account")
|
||||
|
|
|
@ -22,6 +22,8 @@ package org.mariotaku.twidere.activity.iface
|
|||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.support.v4.app.FragmentActivity
|
||||
import nl.komponents.kovenant.Promise
|
||||
import nl.komponents.kovenant.deferred
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
|
@ -29,7 +31,7 @@ import java.util.*
|
|||
*/
|
||||
interface IBaseActivity<out A : FragmentActivity> {
|
||||
|
||||
fun executeAfterFragmentResumed(useHandler: Boolean = false, action: (A) -> Unit)
|
||||
fun executeAfterFragmentResumed(useHandler: Boolean = false, action: (A) -> Unit): Promise<Unit, Exception>
|
||||
|
||||
class ActionHelper<out A : FragmentActivity>(private val activity: A) {
|
||||
|
||||
|
@ -54,20 +56,33 @@ interface IBaseActivity<out A : FragmentActivity> {
|
|||
val cur = actionQueue.poll()
|
||||
cur?.let { cur ->
|
||||
if (cur.useHandler) {
|
||||
handler.post { cur.action(activity) }
|
||||
handler.post { cur.invoke(activity) }
|
||||
} else {
|
||||
cur.action(activity)
|
||||
cur.invoke(activity)
|
||||
}
|
||||
}
|
||||
info = cur
|
||||
} while (info != null)
|
||||
}
|
||||
|
||||
fun executeAfterFragmentResumed(useHandler: Boolean = false, action: (A) -> Unit) {
|
||||
actionQueue.add(ExecuteInfo(action, useHandler))
|
||||
fun executeAfterFragmentResumed(useHandler: Boolean = false, action: (A) -> Unit)
|
||||
: Promise<Unit, Exception> {
|
||||
val info = ExecuteInfo(action, useHandler)
|
||||
actionQueue.add(info)
|
||||
executePending()
|
||||
return info.promise
|
||||
}
|
||||
|
||||
private data class ExecuteInfo<in A : FragmentActivity>(val action: (A) -> Unit, val useHandler: Boolean)
|
||||
private data class ExecuteInfo<in A : FragmentActivity>(private val action: (A) -> Unit, val useHandler: Boolean) {
|
||||
|
||||
private val deferredInstance = deferred<Unit, Exception>()
|
||||
|
||||
val promise: Promise<Unit, Exception> get() = deferredInstance.promise
|
||||
|
||||
fun invoke(activity: A) {
|
||||
action(activity)
|
||||
deferredInstance.resolve(Unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import android.graphics.Canvas
|
|||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import com.bumptech.glide.Glide
|
||||
import nl.komponents.kovenant.combine.and
|
||||
import nl.komponents.kovenant.ui.failUi
|
||||
import nl.komponents.kovenant.ui.successUi
|
||||
import org.mariotaku.kpreferences.get
|
||||
|
@ -161,8 +162,9 @@ class CreateQuickAccessShortcutActivity : BaseActivity() {
|
|||
shapeStyle = preferences[profileImageStyleKey], cornerRadiusRatio = 0.1f,
|
||||
size = getString(R.string.profile_image_size)).into(DeferredTarget())
|
||||
val weakThis = WeakReference(this)
|
||||
ProgressDialogFragment.show(supportFragmentManager, TAG_LOAD_ICON_PROGRESS)
|
||||
deferred.promise.successUi { drawable ->
|
||||
executeAfterFragmentResumed {
|
||||
ProgressDialogFragment.show(it.supportFragmentManager, TAG_LOAD_ICON_PROGRESS)
|
||||
} and deferred.promise.successUi { drawable ->
|
||||
val activity = weakThis.get() ?: return@successUi
|
||||
val launchIntent = IntentUtils.userProfile(accountKey, user.key,
|
||||
user.screen_name, profileUrl = user.extras?.statusnet_profile_url)
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.support.v4.app.Fragment
|
|||
import android.support.v4.text.BidiFormatter
|
||||
import com.squareup.otto.Bus
|
||||
import com.twitter.Validator
|
||||
import nl.komponents.kovenant.Promise
|
||||
import org.mariotaku.twidere.fragment.iface.IBaseFragment
|
||||
import org.mariotaku.twidere.model.DefaultFeatures
|
||||
import org.mariotaku.twidere.util.*
|
||||
|
@ -76,8 +77,9 @@ open class BaseFragment : Fragment(), IBaseFragment<BaseFragment> {
|
|||
GeneralComponentHelper.build(context!!).inject(this)
|
||||
}
|
||||
|
||||
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (BaseFragment) -> Unit) {
|
||||
actionHelper.executeAfterFragmentResumed(useHandler, action)
|
||||
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (BaseFragment) -> Unit)
|
||||
: Promise<Unit, Exception> {
|
||||
return actionHelper.executeAfterFragmentResumed(useHandler, action)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
|
|
@ -30,6 +30,7 @@ import android.provider.Settings
|
|||
import android.support.v7.preference.Preference
|
||||
import android.support.v7.preference.PreferenceFragmentCompat
|
||||
import com.squareup.otto.Bus
|
||||
import nl.komponents.kovenant.Promise
|
||||
import org.mariotaku.kpreferences.KPreferences
|
||||
import org.mariotaku.twidere.fragment.iface.IBaseFragment
|
||||
import org.mariotaku.twidere.preference.RingtonePreference
|
||||
|
@ -119,8 +120,9 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat(), IBaseFragmen
|
|||
return super.onPreferenceTreeClick(preference)
|
||||
}
|
||||
|
||||
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (BasePreferenceFragment) -> Unit) {
|
||||
actionHelper.executeAfterFragmentResumed(useHandler, action)
|
||||
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (BasePreferenceFragment) -> Unit)
|
||||
: Promise<Unit, Exception> {
|
||||
return actionHelper.executeAfterFragmentResumed(useHandler, action)
|
||||
}
|
||||
|
||||
override fun fitSystemWindows(insets: Rect) {
|
||||
|
|
|
@ -78,7 +78,6 @@ import nl.komponents.kovenant.task
|
|||
import nl.komponents.kovenant.then
|
||||
import nl.komponents.kovenant.ui.alwaysUi
|
||||
import nl.komponents.kovenant.ui.failUi
|
||||
import nl.komponents.kovenant.ui.promiseOnUi
|
||||
import nl.komponents.kovenant.ui.successUi
|
||||
import org.mariotaku.chameleon.Chameleon
|
||||
import org.mariotaku.chameleon.ChameleonUtils
|
||||
|
@ -945,10 +944,8 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||
SetUserNicknameDialogFragment.show(fragmentManager, user.key, nick)
|
||||
}
|
||||
R.id.add_to_list -> {
|
||||
promiseOnUi {
|
||||
executeAfterFragmentResumed {
|
||||
ProgressDialogFragment.show(fragmentManager, "get_list_progress")
|
||||
}
|
||||
ProgressDialogFragment.show(it.fragmentManager, "get_list_progress")
|
||||
}.then {
|
||||
fun MicroBlog.getUserListOwnerMemberships(id: String): ArrayList<UserList> {
|
||||
val result = ArrayList<UserList>()
|
||||
|
@ -1671,11 +1668,8 @@ class UserFragment : BaseFragment(), OnClickListener, OnLinkClickListener,
|
|||
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener {
|
||||
val checkedPositions = dialog.listView.checkedItemPositions
|
||||
val weakActivity = WeakReference(activity)
|
||||
promiseOnUi {
|
||||
val activity = weakActivity.get() as? IBaseActivity<*> ?: return@promiseOnUi
|
||||
activity.executeAfterFragmentResumed { activity ->
|
||||
ProgressDialogFragment.show(activity.supportFragmentManager, "update_lists_progress")
|
||||
}
|
||||
(activity as IBaseActivity<*>).executeAfterFragmentResumed {
|
||||
ProgressDialogFragment.show(it.supportFragmentManager, "update_lists_progress")
|
||||
}.then {
|
||||
val activity = weakActivity.get() ?: throw IllegalStateException()
|
||||
val twitter = MicroBlogAPIFactory.getInstance(activity, accountKey)
|
||||
|
|
|
@ -15,6 +15,7 @@ import android.widget.CheckBox
|
|||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import com.bumptech.glide.Glide
|
||||
import nl.komponents.kovenant.combine.and
|
||||
import nl.komponents.kovenant.task
|
||||
import nl.komponents.kovenant.ui.alwaysUi
|
||||
import org.mariotaku.ktextension.*
|
||||
|
@ -194,9 +195,10 @@ abstract class BaseFiltersImportFragment : AbsContentListRecyclerViewFragment<Se
|
|||
return@mapNotNull user
|
||||
}
|
||||
selectedUsers.forEach { it.is_filtered = true }
|
||||
ProgressDialogFragment.show(childFragmentManager, "import_progress")
|
||||
val weakThis = WeakReference(this)
|
||||
task {
|
||||
executeAfterFragmentResumed {
|
||||
ProgressDialogFragment.show(it.childFragmentManager, "import_progress")
|
||||
} and task {
|
||||
val context = weakThis.get()?.context ?: return@task
|
||||
DataStoreUtils.addToFilter(context, selectedUsers, filterEverywhere)
|
||||
}.alwaysUi {
|
||||
|
|
|
@ -24,6 +24,8 @@ import android.os.Bundle
|
|||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.support.v4.app.Fragment
|
||||
import nl.komponents.kovenant.Promise
|
||||
import nl.komponents.kovenant.deferred
|
||||
import org.mariotaku.twidere.constant.IntentConstants
|
||||
import java.util.*
|
||||
|
||||
|
@ -64,7 +66,7 @@ interface IBaseFragment<out F : Fragment> {
|
|||
fun getSystemWindowsInsets(insets: Rect): Boolean
|
||||
}
|
||||
|
||||
fun executeAfterFragmentResumed(useHandler: Boolean = false, action: (F) -> Unit)
|
||||
fun executeAfterFragmentResumed(useHandler: Boolean = false, action: (F) -> Unit): Promise<Unit, Exception>
|
||||
|
||||
class ActionHelper<out F : Fragment>(private val fragment: F) {
|
||||
|
||||
|
@ -89,20 +91,32 @@ interface IBaseFragment<out F : Fragment> {
|
|||
val cur = actionQueue.poll()
|
||||
cur?.let { cur ->
|
||||
if (cur.useHandler) {
|
||||
handler.post { cur.action(fragment) }
|
||||
handler.post { cur.invoke(fragment) }
|
||||
} else {
|
||||
cur.action(fragment)
|
||||
cur.invoke(fragment)
|
||||
}
|
||||
}
|
||||
info = cur
|
||||
} while (info != null)
|
||||
}
|
||||
|
||||
fun executeAfterFragmentResumed(useHandler: Boolean = false, action: (F) -> Unit) {
|
||||
actionQueue.add(ExecuteInfo(action, useHandler))
|
||||
fun executeAfterFragmentResumed(useHandler: Boolean = false, action: (F) -> Unit)
|
||||
: Promise<Unit, Exception> {
|
||||
val info = ExecuteInfo(action, useHandler)
|
||||
actionQueue.add(info)
|
||||
executePending()
|
||||
return info.promise
|
||||
}
|
||||
|
||||
private data class ExecuteInfo<in F : Fragment>(val action: (F) -> Unit, val useHandler: Boolean)
|
||||
private data class ExecuteInfo<in F : Fragment>(private val action: (F) -> Unit, val useHandler: Boolean) {
|
||||
private val deferredInstance = deferred<Unit, Exception>()
|
||||
|
||||
val promise: Promise<Unit, Exception> get() = deferredInstance.promise
|
||||
|
||||
fun invoke(fragment: F) {
|
||||
action(fragment)
|
||||
deferredInstance.resolve(Unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -242,9 +242,7 @@ class ExoPlayerPageFragment : MediaViewerFragment(), IBaseFragment<ExoPlayerPage
|
|||
requestFitSystemWindows()
|
||||
}
|
||||
|
||||
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (ExoPlayerPageFragment) -> Unit) {
|
||||
// No-op
|
||||
}
|
||||
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (ExoPlayerPageFragment) -> Unit) = TODO()
|
||||
|
||||
override fun isMediaLoaded(): Boolean {
|
||||
return !playerHasError
|
||||
|
|
|
@ -337,9 +337,7 @@ class VideoPageFragment : CacheDownloadMediaViewerFragment(), IBaseFragment<Vide
|
|||
}
|
||||
}
|
||||
|
||||
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (VideoPageFragment) -> Unit) {
|
||||
// No-op
|
||||
}
|
||||
override fun executeAfterFragmentResumed(useHandler: Boolean, action: (VideoPageFragment) -> Unit) = TODO()
|
||||
|
||||
|
||||
private fun updatePlayerState() {
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.mariotaku.twidere.util.content.ContentResolverUtils.bulkInsert
|
|||
import java.util.*
|
||||
|
||||
/**
|
||||
* Get local trends
|
||||
* Created by mariotaku on 16/2/24.
|
||||
*/
|
||||
class GetTrendsTask(
|
||||
|
@ -59,8 +60,8 @@ class GetTrendsTask(
|
|||
val details = getAccountDetails(AccountManager.get(context), accountKey, true) ?: return
|
||||
val twitter = details.newMicroBlogInstance(context, cls = MicroBlog::class.java)
|
||||
try {
|
||||
val trends = when {
|
||||
details.type == FANFOU -> twitter.fanfouTrends
|
||||
val trends = when (details.type) {
|
||||
FANFOU -> twitter.fanfouTrends
|
||||
else -> twitter.getLocationTrends(woeId).firstOrNull()
|
||||
} ?: return
|
||||
storeTrends(context.contentResolver, CachedTrends.Local.CONTENT_URI, trends)
|
||||
|
|
Loading…
Reference in New Issue