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