@@ -10,25 +10,30 @@ import com.crossbowffs.quotelock.account.syncadapter.getSyncTimestamp
10
10
import com.crossbowffs.quotelock.account.syncadapter.setServerSyncMarker
11
11
import com.crossbowffs.quotelock.data.modules.collections.QuoteCollectionRepository
12
12
import com.crossbowffs.quotelock.data.modules.collections.database.QuoteCollectionContract
13
- import com.crossbowffs.quotelock.di.IoDispatcher
13
+ import com.crossbowffs.quotelock.di.DISPATCHER_IO
14
14
import com.crossbowffs.quotelock.utils.Xlog
15
15
import com.crossbowffs.quotelock.utils.className
16
16
import com.yubyf.quotelockx.BuildConfig
17
17
import kotlinx.coroutines.CoroutineDispatcher
18
18
import kotlinx.coroutines.CoroutineScope
19
19
import kotlinx.coroutines.launch
20
- import javax.inject.Inject
20
+ import org.koin.core.annotation.Named
21
+ import org.koin.core.annotation.Single
21
22
22
23
/* *
23
24
* @author Yubyf
24
25
* @date 2021/6/20.
25
26
*/
26
- class SyncAccountManager @Inject constructor(
27
+ @Single(createdAtStart = true )
28
+ class SyncAccountManager (
27
29
private val accountManager : AccountManager ,
28
30
private val collectionRepository : QuoteCollectionRepository ,
29
- @IoDispatcher private val dispatcher : CoroutineDispatcher ,
31
+ @Named( DISPATCHER_IO ) private val dispatcher : CoroutineDispatcher ,
30
32
) {
31
33
34
+ private val accountType: String
35
+ get() = BuildConfig .APPLICATION_ID + " .account"
36
+
32
37
fun initialize () {
33
38
CoroutineScope (dispatcher).launch {
34
39
collectionRepository.getAllStream().collect {
@@ -38,7 +43,8 @@ class SyncAccountManager @Inject constructor(
38
43
* changeUri is null.
39
44
*/
40
45
Xlog .d(TAG , " Data on change, requesting sync..." )
41
- ContentResolver .requestSync(currentSyncAccount,
46
+ ContentResolver .requestSync(
47
+ currentSyncAccount,
42
48
QuoteCollectionContract .AUTHORITY , Bundle ()
43
49
)
44
50
}
@@ -57,7 +63,7 @@ class SyncAccountManager @Inject constructor(
57
63
clearAccountUserData(account)
58
64
}
59
65
} else {
60
- account = Account (name, ACCOUNT_TYPE )
66
+ account = Account (name, accountType )
61
67
accountManager.addAccountExplicitly(account, null , null )
62
68
Xlog .d(TAG , " Added account of name $name " )
63
69
clearAccountUserData(account)
@@ -110,11 +116,10 @@ class SyncAccountManager @Inject constructor(
110
116
}
111
117
112
118
private val currentSyncAccount: Account ?
113
- get() = accountManager.getAccountsByType(ACCOUNT_TYPE )
119
+ get() = accountManager.getAccountsByType(accountType )
114
120
.run { if (isNotEmpty()) this [0 ] else null }
115
121
116
122
companion object {
117
123
private val TAG = className<SyncAccountManager >()
118
- private const val ACCOUNT_TYPE = BuildConfig .APPLICATION_ID + " .account"
119
124
}
120
125
}
0 commit comments