mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-01-31 08:54:57 +01:00
fixed account changed listener
This commit is contained in:
parent
39a15739b4
commit
433b414d9f
@ -35,8 +35,8 @@ android {
|
||||
applicationId "org.mariotaku.twidere"
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 25
|
||||
versionCode 232
|
||||
versionName '3.3.14'
|
||||
versionCode 233
|
||||
versionName '3.3.15'
|
||||
multiDexEnabled true
|
||||
|
||||
buildConfigField 'boolean', 'LEAK_CANARY_ENABLED', 'Boolean.parseBoolean("true")'
|
||||
|
@ -86,7 +86,7 @@ import org.mariotaku.twidere.view.TabPagerIndicator
|
||||
|
||||
class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, SupportFragmentCallback, OnLongClickListener, DrawerLayout.DrawerListener {
|
||||
|
||||
private val accountChangeObserver = AccountChangeObserver(this)
|
||||
private val accountUpdatedListener = AccountUpdatedListener(this)
|
||||
|
||||
private var selectedAccountToSearch: AccountDetails? = null
|
||||
private var tabColumns: Int = 0
|
||||
@ -389,7 +389,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
multiSelectHandler.dispatchOnStart()
|
||||
AccountManager.get(this).addOnAccountsUpdatedListener(accountChangeObserver, null, false)
|
||||
AccountManager.get(this).addOnAccountsUpdatedListener(accountUpdatedListener, null, false)
|
||||
bus.register(this)
|
||||
|
||||
readStateManager.registerOnSharedPreferenceChangeListener(readStateChangeListener)
|
||||
@ -406,7 +406,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
||||
multiSelectHandler.dispatchOnStop()
|
||||
readStateManager.unregisterOnSharedPreferenceChangeListener(readStateChangeListener)
|
||||
bus.unregister(this)
|
||||
AccountManager.get(this).removeOnAccountsUpdatedListener(accountChangeObserver)
|
||||
AccountManager.get(this).removeOnAccountsUpdatedListener(accountUpdatedListener)
|
||||
preferences.edit().putInt(SharedPreferenceConstants.KEY_SAVED_TAB_POSITION, mainPager.currentItem).apply()
|
||||
|
||||
super.onStop()
|
||||
@ -814,7 +814,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
||||
actionsButton.contentDescription = getString(title)
|
||||
}
|
||||
|
||||
private class AccountChangeObserver(private val activity: HomeActivity) : OnAccountsUpdateListener {
|
||||
private class AccountUpdatedListener(private val activity: HomeActivity) : OnAccountsUpdateListener {
|
||||
|
||||
override fun onAccountsUpdated(accounts: Array<out Account>?) {
|
||||
activity.notifyAccountsChanged()
|
||||
|
@ -114,23 +114,33 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
contentObserver = object : ContentObserver(Handler()) {
|
||||
override fun onChange(selfChange: Boolean) {
|
||||
if (contentObserver == null) {
|
||||
contentObserver = object : ContentObserver(Handler()) {
|
||||
override fun onChange(selfChange: Boolean) {
|
||||
reloadActivities()
|
||||
}
|
||||
}
|
||||
context.contentResolver.registerContentObserver(Filters.CONTENT_URI, true, contentObserver)
|
||||
}
|
||||
if (accountListener == null) {
|
||||
accountListener = OnAccountsUpdateListener { accounts ->
|
||||
reloadActivities()
|
||||
}
|
||||
AccountManager.get(context).addOnAccountsUpdatedListener(accountListener, null, false)
|
||||
}
|
||||
accountListener = OnAccountsUpdateListener { accounts ->
|
||||
reloadActivities()
|
||||
}
|
||||
context.contentResolver.registerContentObserver(Filters.CONTENT_URI, true, contentObserver)
|
||||
AccountManager.get(context).addOnAccountsUpdatedListener(accountListener, null, false)
|
||||
updateRefreshState()
|
||||
reloadActivities()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
context.contentResolver.unregisterContentObserver(contentObserver)
|
||||
AccountManager.get(context).removeOnAccountsUpdatedListener(accountListener)
|
||||
if (contentObserver != null) {
|
||||
context.contentResolver.unregisterContentObserver(contentObserver)
|
||||
contentObserver = null
|
||||
}
|
||||
if (accountListener != null) {
|
||||
AccountManager.get(context).removeOnAccountsUpdatedListener(accountListener)
|
||||
accountListener = null
|
||||
}
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
|
@ -121,23 +121,33 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
contentObserver = object : ContentObserver(Handler()) {
|
||||
override fun onChange(selfChange: Boolean) {
|
||||
if (contentObserver == null) {
|
||||
contentObserver = object : ContentObserver(Handler()) {
|
||||
override fun onChange(selfChange: Boolean) {
|
||||
reloadStatuses()
|
||||
}
|
||||
}
|
||||
context.contentResolver.registerContentObserver(Filters.CONTENT_URI, true, contentObserver)
|
||||
}
|
||||
if (accountListener == null) {
|
||||
accountListener = OnAccountsUpdateListener { accounts ->
|
||||
reloadStatuses()
|
||||
}
|
||||
AccountManager.get(context).addOnAccountsUpdatedListener(accountListener, null, false)
|
||||
}
|
||||
accountListener = OnAccountsUpdateListener { accounts ->
|
||||
reloadStatuses()
|
||||
}
|
||||
context.contentResolver.registerContentObserver(Filters.CONTENT_URI, true, contentObserver)
|
||||
AccountManager.get(context).addOnAccountsUpdatedListener(accountListener, null, false)
|
||||
updateRefreshState()
|
||||
reloadStatuses()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
context.contentResolver.unregisterContentObserver(contentObserver)
|
||||
AccountManager.get(context).removeOnAccountsUpdatedListener(accountListener)
|
||||
if (contentObserver != null) {
|
||||
context.contentResolver.unregisterContentObserver(contentObserver)
|
||||
contentObserver = null
|
||||
}
|
||||
if (accountListener != null) {
|
||||
AccountManager.get(context).removeOnAccountsUpdatedListener(accountListener)
|
||||
accountListener = null
|
||||
}
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
|
@ -228,17 +228,22 @@ class DirectMessagesFragment : AbsContentListRecyclerViewFragment<MessageEntries
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
accountListener = OnAccountsUpdateListener { accounts ->
|
||||
if (accountListener == null) {
|
||||
accountListener = OnAccountsUpdateListener { accounts ->
|
||||
|
||||
}
|
||||
AccountManager.get(context).addOnAccountsUpdatedListener(accountListener, null, false)
|
||||
}
|
||||
AccountManager.get(context).addOnAccountsUpdatedListener(accountListener, null, false)
|
||||
bus.register(this)
|
||||
adapter.updateReadState()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
bus.unregister(this)
|
||||
AccountManager.get(context).removeOnAccountsUpdatedListener(accountListener)
|
||||
if (accountListener != null) {
|
||||
AccountManager.get(context).removeOnAccountsUpdatedListener(accountListener)
|
||||
accountListener = null
|
||||
}
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user