crash fixes
This commit is contained in:
parent
c914564712
commit
7c6e75d8ef
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,17 @@ class AccountDetailsLoader(
|
|||
context: Context,
|
||||
val filter: (AccountDetails.() -> Boolean)? = null
|
||||
) : FixedAsyncTaskLoader<List<AccountDetails>>(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<AccountDetails> {
|
||||
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
accountType.setImageResource(AccountUtils.getAccountTypeIcon(details.type))
|
||||
toggle.isChecked = details.activated
|
||||
toggle.setOnCheckedChangeListener(adapter.checkedChangeListener)
|
||||
|
|
|
@ -1205,6 +1205,7 @@
|
|||
<string name="title_statuses">Tweets</string>
|
||||
<string name="title_statuses_and_replies">Tweets & replies</string>
|
||||
<string name="title_statuses_scheduling">Tweets scheduling</string>
|
||||
<string name="title_gif_sharing">GIF sharing</string>
|
||||
<string name="title_streaming">Streaming</string>
|
||||
<string name="title_subscription_name">Name</string>
|
||||
<string name="title_subscription_url">URL</string>
|
||||
|
|
Loading…
Reference in New Issue