| author | Da Risk <da_risk@geekorum.com> |
| Wed, 12 Jan 2022 17:29:59 -0400 | |
| changeset 882 | 7a74abf66c49 |
| parent 846 | ac0863af5ef6 |
| child 943 | 298742859784 |
| permissions | -rw-r--r-- |
|
137
5464f07a306c
Update copyright headers for 2019
Da Risk <da_risk@geekorum.com>
parents:
104
diff
changeset
|
1 |
/* |
| 0 | 2 |
* Geekttrss is a RSS feed reader application on the Android Platform. |
3 |
* |
|
| 882 | 4 |
* Copyright (C) 2017-2022 by Frederic-Charles Barthelery. |
| 0 | 5 |
* |
6 |
* This file is part of Geekttrss. |
|
7 |
* |
|
8 |
* Geekttrss is free software: you can redistribute it and/or modify |
|
9 |
* it under the terms of the GNU General Public License as published by |
|
10 |
* the Free Software Foundation, either version 3 of the License, or |
|
11 |
* (at your option) any later version. |
|
12 |
* |
|
13 |
* Geekttrss is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with Geekttrss. If not, see <http://www.gnu.org/licenses/>. |
|
20 |
*/ |
|
21 |
package com.geekorum.ttrss.accounts |
|
22 |
||
23 |
import android.accounts.Account |
|
24 |
import android.accounts.AccountManager |
|
25 |
import com.geekorum.geekdroid.security.SecretEncryption |
|
|
521
2a5be03dd6bc
Use CoroutineDispatchersProvider everywhere
Da Risk <da_risk@geekorum.com>
parents:
417
diff
changeset
|
26 |
import com.geekorum.ttrss.core.CoroutineDispatchersProvider |
| 0 | 27 |
import com.geekorum.ttrss.network.TinyrssApiModule |
|
312
acd822d279e3
app: use Webapi and remove network/impl based api
Da Risk <da_risk@geekorum.com>
parents:
244
diff
changeset
|
28 |
import com.geekorum.ttrss.webapi.LoggedRequestInterceptorFactory |
|
acd822d279e3
app: use Webapi and remove network/impl based api
Da Risk <da_risk@geekorum.com>
parents:
244
diff
changeset
|
29 |
import com.geekorum.ttrss.webapi.TinyRssApi |
| 734 | 30 |
import com.geekorum.ttrss.webapi.TokenRetriever |
| 0 | 31 |
import dagger.Module |
32 |
import dagger.Provides |
|
33 |
import dagger.Subcomponent |
|
|
723
43c8fb8d1528
accounts: use hilt AndroidEntryPoint for AuthenticatorService
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
34 |
import dagger.hilt.InstallIn |
|
43c8fb8d1528
accounts: use hilt AndroidEntryPoint for AuthenticatorService
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
35 |
import dagger.hilt.android.components.ServiceComponent |
| 769 | 36 |
import dagger.hilt.components.SingletonComponent |
| 734 | 37 |
import dagger.hilt.migration.DisableInstallInCheck |
38 |
import javax.inject.Scope |
|
39 |
import kotlin.annotation.AnnotationRetention.RUNTIME |
|
| 0 | 40 |
|
41 |
/** |
|
42 |
* Dependency injection pieces for the account authenticator functionality. |
|
43 |
* |
|
44 |
* AuthenticatorService has a SubComponent of the ApplicationComponent. |
|
45 |
* The AuthenticatorNetworkComponent is a SubSubComponent that allows to do network |
|
46 |
* request with the Account backend |
|
47 |
* |
|
48 |
*/ |
|
49 |
||
50 |
@Retention(RUNTIME) |
|
51 |
@MustBeDocumented |
|
52 |
@Scope |
|
53 |
annotation class PerAccount |
|
54 |
||
55 |
@Module |
|
| 769 | 56 |
@InstallIn(SingletonComponent::class) |
| 560 | 57 |
object AndroidTinyrssAccountManagerModule {
|
| 0 | 58 |
|
| 560 | 59 |
private const val KEY_ALIAS = "com.geekorum.geekttrss.accounts.AccountManagerKey" |
| 0 | 60 |
|
61 |
@Provides |
|
62 |
fun providesAndroidTinyrssAccountManager(accountManager: AccountManager, secretEncryption: SecretEncryption): AndroidTinyrssAccountManager {
|
|
63 |
val secretCipher = secretEncryption.getSecretCipher(KEY_ALIAS) |
|
64 |
return AndroidTinyrssAccountManager(accountManager, secretCipher) |
|
65 |
} |
|
66 |
||
67 |
// may be replaced by a @Bind but it complicates the syntax in kotlin |
|
68 |
@Provides |
|
69 |
fun providesTinyrssAccountManager(androidTinyrssAccountManager: AndroidTinyrssAccountManager): TinyrssAccountManager {
|
|
70 |
return androidTinyrssAccountManager |
|
71 |
} |
|
72 |
} |
|
73 |
||
74 |
||
75 |
@Module |
|
| 734 | 76 |
@DisableInstallInCheck |
| 560 | 77 |
object NetworkLoginModule {
|
| 0 | 78 |
|
79 |
@Provides |
|
80 |
@PerAccount |
|
|
521
2a5be03dd6bc
Use CoroutineDispatchersProvider everywhere
Da Risk <da_risk@geekorum.com>
parents:
417
diff
changeset
|
81 |
fun providesTokenRetriever(dispatchers: CoroutineDispatchersProvider, |
|
2a5be03dd6bc
Use CoroutineDispatchersProvider everywhere
Da Risk <da_risk@geekorum.com>
parents:
417
diff
changeset
|
82 |
accountManager: AccountManager, account: Account): TokenRetriever {
|
|
2a5be03dd6bc
Use CoroutineDispatchersProvider everywhere
Da Risk <da_risk@geekorum.com>
parents:
417
diff
changeset
|
83 |
return TinyrssAccountTokenRetriever(dispatchers, accountManager, account) |
| 0 | 84 |
} |
85 |
||
86 |
@Provides |
|
87 |
@PerAccount |
|
|
417
8ba896069f2f
Account: Use webapi TokenRetriever
Da Risk <da_risk@geekorum.com>
parents:
312
diff
changeset
|
88 |
fun providesLoggedRequestInterceptorFactory(tokenRetriever: TokenRetriever): LoggedRequestInterceptorFactory {
|
| 0 | 89 |
return LoggedRequestInterceptorFactory(tokenRetriever) |
90 |
} |
|
91 |
||
92 |
@Provides |
|
|
104
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
93 |
fun providesServerInformation(accountManager: AndroidTinyrssAccountManager, account: Account): ServerInformation {
|
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
94 |
return with(accountManager) {
|
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
95 |
val ttRssAccount = fromAndroidAccount(account) |
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
96 |
getServerInformation(ttRssAccount) |
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
97 |
} |
| 0 | 98 |
} |
99 |
||
100 |
} |
|
101 |
||
102 |
||
103 |
@Module(subcomponents = [AuthenticatorNetworkComponent::class]) |
|
|
723
43c8fb8d1528
accounts: use hilt AndroidEntryPoint for AuthenticatorService
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
104 |
@InstallIn(ServiceComponent::class) |
|
43c8fb8d1528
accounts: use hilt AndroidEntryPoint for AuthenticatorService
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
105 |
internal object AuthenticatorServiceModule |
| 0 | 106 |
|
107 |
@Module(subcomponents = [AuthenticatorNetworkComponent::class]) |
|
| 769 | 108 |
@InstallIn(SingletonComponent::class) |
| 734 | 109 |
internal object AuthenticatorActivityModule |
| 0 | 110 |
|
|
104
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
111 |
@Subcomponent(modules = [TinyRssServerInformationModule::class, TinyrssApiModule::class]) |
| 0 | 112 |
internal interface AuthenticatorNetworkComponent {
|
113 |
fun getTinyRssApi(): TinyRssApi |
|
114 |
||
115 |
@Subcomponent.Builder |
|
116 |
interface Builder {
|
|
117 |
fun build(): AuthenticatorNetworkComponent |
|
118 |
||
|
104
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
119 |
fun tinyRssServerInformationModule(module: TinyRssServerInformationModule): Builder |
| 0 | 120 |
} |
121 |
} |
|
122 |
||
123 |
@Module |
|
| 734 | 124 |
@DisableInstallInCheck |
|
104
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
125 |
internal class TinyRssServerInformationModule(val serverInformation: ServerInformation) {
|
| 0 | 126 |
@Provides |
|
104
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
127 |
fun providesServerInformation(): ServerInformation {
|
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
128 |
return serverInformation |
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
129 |
} |
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
130 |
|
| 0 | 131 |
} |
132 |