diff --git a/twidere/src/main/kotlin/org/mariotaku/ktextension/AccountManagerExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/ktextension/AccountManagerExtensions.kt index cafee2587..f3cede529 100644 --- a/twidere/src/main/kotlin/org/mariotaku/ktextension/AccountManagerExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/ktextension/AccountManagerExtensions.kt @@ -9,13 +9,14 @@ import android.os.Handler */ fun AccountManager.addOnAccountsUpdatedListenerSafe(listener: OnAccountsUpdateListener, - handler: Handler? = null, - updateImmediately: Boolean = false): Boolean { + handler: Handler? = null, updateImmediately: Boolean = false): Boolean { try { this.addOnAccountsUpdatedListener(listener, handler, updateImmediately) return true } catch (e: IllegalStateException) { return false + } catch (e: IllegalArgumentException) { + return false } } @@ -25,5 +26,7 @@ fun AccountManager.removeOnAccountsUpdatedListenerSafe(listener: OnAccountsUpdat return true } catch (e: IllegalStateException) { return false + } catch (e: IllegalArgumentException) { + return false } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/AccountDetailsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/AccountDetailsLoader.kt index fbee6bd93..68e3a6feb 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/AccountDetailsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/AccountDetailsLoader.kt @@ -16,10 +16,18 @@ class AccountDetailsLoader( context: Context, val filter: (AccountDetails.() -> Boolean)? = null ) : FixedAsyncTaskLoader>(context) { + private val am: AccountManager = AccountManager.get(context) - private val accountUpdateListener = OnAccountsUpdateListener { - onContentChanged() - } + + private var accountUpdateListener: OnAccountsUpdateListener? = null + set(value) { + field?.let { + am.removeOnAccountsUpdatedListenerSafe(it) + } + if (value != null) { + am.addOnAccountsUpdatedListenerSafe(value, updateImmediately = true) + } + } override fun loadInBackground(): List { return AccountUtils.getAllAccountDetails(am, true).filter { @@ -30,11 +38,13 @@ class AccountDetailsLoader( override fun onReset() { super.onReset() onStopLoading() - am.removeOnAccountsUpdatedListenerSafe(accountUpdateListener) + accountUpdateListener = null } override fun onStartLoading() { - am.addOnAccountsUpdatedListenerSafe(accountUpdateListener, updateImmediately = true) + accountUpdateListener = OnAccountsUpdateListener { + onContentChanged() + } if (takeContentChanged()) { forceLoad() } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/AccountViewHolder.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/AccountViewHolder.kt index 22cad87a4..2745daa6b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/AccountViewHolder.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/holder/AccountViewHolder.kt @@ -63,13 +63,9 @@ class AccountViewHolder( name.text = details.user.name screenName.text = String.format("@%s", details.user.screen_name) setAccountColor(details.color) - if (adapter.profileImageEnabled) { - profileImage.visibility = View.VISIBLE - adapter.requestManager.loadProfileImage(adapter.context, details, adapter.profileImageStyle, - profileImage.cornerRadius, profileImage.cornerRadiusRatio).into(profileImage) - } else { - profileImage.visibility = View.GONE - } + profileImage.visibility = View.VISIBLE + adapter.requestManager.loadProfileImage(adapter.context, details, adapter.profileImageStyle, + profileImage.cornerRadius, profileImage.cornerRadiusRatio).into(profileImage) accountType.setImageResource(AccountUtils.getAccountTypeIcon(details.type)) toggle.isChecked = details.activated toggle.setOnCheckedChangeListener(adapter.checkedChangeListener) diff --git a/twidere/src/main/res/values/strings.xml b/twidere/src/main/res/values/strings.xml index 7fddd3a65..da2754a2d 100644 --- a/twidere/src/main/res/values/strings.xml +++ b/twidere/src/main/res/values/strings.xml @@ -1205,6 +1205,7 @@ Tweets Tweets & replies Tweets scheduling + GIF sharing Streaming Name URL