mirror of
https://github.com/etesync/android
synced 2024-11-22 07:58:09 +00:00
Revert "Don't rely on LOGIN_ACCOUNTS_CHANGED_ACTION"
Actually, let's not make this change just yet so we are sure we haven't
broken anything.
This reverts commit dda23fb484
.
This commit is contained in:
parent
dda23fb484
commit
d98d91a67f
@ -162,6 +162,20 @@
|
||||
android:enabled="true">
|
||||
</service>
|
||||
|
||||
<receiver android:name=".AccountsChangedReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".PackageChangedReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PACKAGE_ADDED"/>
|
||||
<action android:name="android.intent.action.PACKAGE_FULLY_REMOVED"/>
|
||||
<data android:scheme="package"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<activity
|
||||
android:name=".ui.AccountsActivity"
|
||||
android:label="@string/app_name"
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Public License v3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/gpl.html
|
||||
*/
|
||||
|
||||
package com.etesync.syncadapter
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.accounts.OnAccountsUpdateListener
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
||||
import java.util.LinkedList
|
||||
|
||||
class AccountsChangedReceiver : BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (AccountManager.LOGIN_ACCOUNTS_CHANGED_ACTION == intent.action) {
|
||||
val serviceIntent = Intent(context, AccountUpdateService::class.java)
|
||||
serviceIntent.action = AccountUpdateService.ACTION_ACCOUNTS_UPDATED
|
||||
context.startService(serviceIntent)
|
||||
|
||||
for (listener in listeners)
|
||||
listener.onAccountsUpdated(null)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
protected val listeners: MutableList<OnAccountsUpdateListener> = LinkedList()
|
||||
|
||||
fun registerListener(listener: OnAccountsUpdateListener, callImmediately: Boolean) {
|
||||
listeners.add(listener)
|
||||
if (callImmediately)
|
||||
listener.onAccountsUpdated(null)
|
||||
}
|
||||
|
||||
fun unregisterListener(listener: OnAccountsUpdateListener) {
|
||||
listeners.remove(listener)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -26,6 +26,7 @@ import android.widget.AbsListView
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.TextView
|
||||
import com.etesync.syncadapter.AccountsChangedReceiver
|
||||
import com.etesync.syncadapter.App
|
||||
import com.etesync.syncadapter.R
|
||||
|
||||
@ -79,11 +80,11 @@ class AccountListFragment : ListFragment(), LoaderManager.LoaderCallbacks<Array<
|
||||
}
|
||||
|
||||
override fun onStartLoading() {
|
||||
accountManager.addOnAccountsUpdatedListener(this, null, true)
|
||||
AccountsChangedReceiver.registerListener(this, true)
|
||||
}
|
||||
|
||||
override fun onStopLoading() {
|
||||
accountManager.removeOnAccountsUpdatedListener(this)
|
||||
AccountsChangedReceiver.unregisterListener(this)
|
||||
}
|
||||
|
||||
override fun onAccountsUpdated(accounts: Array<Account>) {
|
||||
|
Loading…
Reference in New Issue
Block a user