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"
|
applicationId "org.mariotaku.twidere"
|
||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
versionCode 232
|
versionCode 233
|
||||||
versionName '3.3.14'
|
versionName '3.3.15'
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
|
|
||||||
buildConfigField 'boolean', 'LEAK_CANARY_ENABLED', 'Boolean.parseBoolean("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 {
|
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 selectedAccountToSearch: AccountDetails? = null
|
||||||
private var tabColumns: Int = 0
|
private var tabColumns: Int = 0
|
||||||
@ -389,7 +389,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
multiSelectHandler.dispatchOnStart()
|
multiSelectHandler.dispatchOnStart()
|
||||||
AccountManager.get(this).addOnAccountsUpdatedListener(accountChangeObserver, null, false)
|
AccountManager.get(this).addOnAccountsUpdatedListener(accountUpdatedListener, null, false)
|
||||||
bus.register(this)
|
bus.register(this)
|
||||||
|
|
||||||
readStateManager.registerOnSharedPreferenceChangeListener(readStateChangeListener)
|
readStateManager.registerOnSharedPreferenceChangeListener(readStateChangeListener)
|
||||||
@ -406,7 +406,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||||||
multiSelectHandler.dispatchOnStop()
|
multiSelectHandler.dispatchOnStop()
|
||||||
readStateManager.unregisterOnSharedPreferenceChangeListener(readStateChangeListener)
|
readStateManager.unregisterOnSharedPreferenceChangeListener(readStateChangeListener)
|
||||||
bus.unregister(this)
|
bus.unregister(this)
|
||||||
AccountManager.get(this).removeOnAccountsUpdatedListener(accountChangeObserver)
|
AccountManager.get(this).removeOnAccountsUpdatedListener(accountUpdatedListener)
|
||||||
preferences.edit().putInt(SharedPreferenceConstants.KEY_SAVED_TAB_POSITION, mainPager.currentItem).apply()
|
preferences.edit().putInt(SharedPreferenceConstants.KEY_SAVED_TAB_POSITION, mainPager.currentItem).apply()
|
||||||
|
|
||||||
super.onStop()
|
super.onStop()
|
||||||
@ -814,7 +814,7 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
|||||||
actionsButton.contentDescription = getString(title)
|
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>?) {
|
override fun onAccountsUpdated(accounts: Array<out Account>?) {
|
||||||
activity.notifyAccountsChanged()
|
activity.notifyAccountsChanged()
|
||||||
|
@ -114,23 +114,33 @@ abstract class CursorActivitiesFragment : AbsActivitiesFragment() {
|
|||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
if (contentObserver == null) {
|
||||||
contentObserver = object : ContentObserver(Handler()) {
|
contentObserver = object : ContentObserver(Handler()) {
|
||||||
override fun onChange(selfChange: Boolean) {
|
override fun onChange(selfChange: Boolean) {
|
||||||
reloadActivities()
|
reloadActivities()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
context.contentResolver.registerContentObserver(Filters.CONTENT_URI, true, contentObserver)
|
||||||
|
}
|
||||||
|
if (accountListener == null) {
|
||||||
accountListener = OnAccountsUpdateListener { accounts ->
|
accountListener = OnAccountsUpdateListener { accounts ->
|
||||||
reloadActivities()
|
reloadActivities()
|
||||||
}
|
}
|
||||||
context.contentResolver.registerContentObserver(Filters.CONTENT_URI, true, contentObserver)
|
|
||||||
AccountManager.get(context).addOnAccountsUpdatedListener(accountListener, null, false)
|
AccountManager.get(context).addOnAccountsUpdatedListener(accountListener, null, false)
|
||||||
|
}
|
||||||
updateRefreshState()
|
updateRefreshState()
|
||||||
reloadActivities()
|
reloadActivities()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
|
if (contentObserver != null) {
|
||||||
context.contentResolver.unregisterContentObserver(contentObserver)
|
context.contentResolver.unregisterContentObserver(contentObserver)
|
||||||
|
contentObserver = null
|
||||||
|
}
|
||||||
|
if (accountListener != null) {
|
||||||
AccountManager.get(context).removeOnAccountsUpdatedListener(accountListener)
|
AccountManager.get(context).removeOnAccountsUpdatedListener(accountListener)
|
||||||
|
accountListener = null
|
||||||
|
}
|
||||||
super.onStop()
|
super.onStop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,23 +121,33 @@ abstract class CursorStatusesFragment : AbsStatusesFragment() {
|
|||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
if (contentObserver == null) {
|
||||||
contentObserver = object : ContentObserver(Handler()) {
|
contentObserver = object : ContentObserver(Handler()) {
|
||||||
override fun onChange(selfChange: Boolean) {
|
override fun onChange(selfChange: Boolean) {
|
||||||
reloadStatuses()
|
reloadStatuses()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
context.contentResolver.registerContentObserver(Filters.CONTENT_URI, true, contentObserver)
|
||||||
|
}
|
||||||
|
if (accountListener == null) {
|
||||||
accountListener = OnAccountsUpdateListener { accounts ->
|
accountListener = OnAccountsUpdateListener { accounts ->
|
||||||
reloadStatuses()
|
reloadStatuses()
|
||||||
}
|
}
|
||||||
context.contentResolver.registerContentObserver(Filters.CONTENT_URI, true, contentObserver)
|
|
||||||
AccountManager.get(context).addOnAccountsUpdatedListener(accountListener, null, false)
|
AccountManager.get(context).addOnAccountsUpdatedListener(accountListener, null, false)
|
||||||
|
}
|
||||||
updateRefreshState()
|
updateRefreshState()
|
||||||
reloadStatuses()
|
reloadStatuses()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
|
if (contentObserver != null) {
|
||||||
context.contentResolver.unregisterContentObserver(contentObserver)
|
context.contentResolver.unregisterContentObserver(contentObserver)
|
||||||
|
contentObserver = null
|
||||||
|
}
|
||||||
|
if (accountListener != null) {
|
||||||
AccountManager.get(context).removeOnAccountsUpdatedListener(accountListener)
|
AccountManager.get(context).removeOnAccountsUpdatedListener(accountListener)
|
||||||
|
accountListener = null
|
||||||
|
}
|
||||||
super.onStop()
|
super.onStop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,17 +228,22 @@ class DirectMessagesFragment : AbsContentListRecyclerViewFragment<MessageEntries
|
|||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
if (accountListener == null) {
|
||||||
accountListener = OnAccountsUpdateListener { accounts ->
|
accountListener = OnAccountsUpdateListener { accounts ->
|
||||||
|
|
||||||
}
|
}
|
||||||
AccountManager.get(context).addOnAccountsUpdatedListener(accountListener, null, false)
|
AccountManager.get(context).addOnAccountsUpdatedListener(accountListener, null, false)
|
||||||
|
}
|
||||||
bus.register(this)
|
bus.register(this)
|
||||||
adapter.updateReadState()
|
adapter.updateReadState()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
bus.unregister(this)
|
bus.unregister(this)
|
||||||
|
if (accountListener != null) {
|
||||||
AccountManager.get(context).removeOnAccountsUpdatedListener(accountListener)
|
AccountManager.get(context).removeOnAccountsUpdatedListener(accountListener)
|
||||||
|
accountListener = null
|
||||||
|
}
|
||||||
super.onStop()
|
super.onStop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user