| author | Da Risk <da_risk@geekorum.com> |
| Thu, 11 Jun 2020 02:30:30 -0400 | |
| changeset 723 | 43c8fb8d1528 |
| parent 611 | 91b8d76c03cd |
| child 728 | c7885cda3244 |
| 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 |
* |
|
| 611 | 4 |
* Copyright (C) 2017-2020 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 android.app.Activity |
|
26 |
import android.content.Context |
|
27 |
import androidx.lifecycle.ViewModel |
|
|
164
2d6e9f2063cd
Replace ViewModelsFactory by DaggerDelegateViewModelFactory
Da Risk <da_risk@geekorum.com>
parents:
137
diff
changeset
|
28 |
import com.geekorum.geekdroid.dagger.ViewModelKey |
| 0 | 29 |
import com.geekorum.geekdroid.security.SecretEncryption |
|
521
2a5be03dd6bc
Use CoroutineDispatchersProvider everywhere
Da Risk <da_risk@geekorum.com>
parents:
417
diff
changeset
|
30 |
import com.geekorum.ttrss.core.CoroutineDispatchersProvider |
| 0 | 31 |
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
|
32 |
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
|
33 |
import com.geekorum.ttrss.webapi.TinyRssApi |
| 0 | 34 |
import dagger.Binds |
35 |
import dagger.Module |
|
36 |
import dagger.Provides |
|
37 |
import dagger.Subcomponent |
|
38 |
import dagger.android.ContributesAndroidInjector |
|
39 |
import dagger.multibindings.IntoMap |
|
40 |
import javax.inject.Scope |
|
41 |
import kotlin.annotation.AnnotationRetention.RUNTIME |
|
|
417
8ba896069f2f
Account: Use webapi TokenRetriever
Da Risk <da_risk@geekorum.com>
parents:
312
diff
changeset
|
42 |
import com.geekorum.ttrss.webapi.TokenRetriever |
|
723
43c8fb8d1528
accounts: use hilt AndroidEntryPoint for AuthenticatorService
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
43 |
import dagger.hilt.InstallIn |
|
43c8fb8d1528
accounts: use hilt AndroidEntryPoint for AuthenticatorService
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
44 |
import dagger.hilt.android.components.ServiceComponent |
| 0 | 45 |
|
46 |
/** |
|
47 |
* Dependency injection pieces for the account authenticator functionality. |
|
48 |
* |
|
49 |
* AuthenticatorService has a SubComponent of the ApplicationComponent. |
|
50 |
* The AuthenticatorNetworkComponent is a SubSubComponent that allows to do network |
|
51 |
* request with the Account backend |
|
52 |
* |
|
53 |
*/ |
|
54 |
||
55 |
@Retention(RUNTIME) |
|
56 |
@MustBeDocumented |
|
57 |
@Scope |
|
58 |
annotation class PerAccount |
|
59 |
||
60 |
@Module |
|
| 560 | 61 |
object AndroidTinyrssAccountManagerModule {
|
| 0 | 62 |
|
| 560 | 63 |
private const val KEY_ALIAS = "com.geekorum.geekttrss.accounts.AccountManagerKey" |
| 0 | 64 |
|
65 |
@Provides |
|
66 |
fun providesAndroidTinyrssAccountManager(accountManager: AccountManager, secretEncryption: SecretEncryption): AndroidTinyrssAccountManager {
|
|
67 |
val secretCipher = secretEncryption.getSecretCipher(KEY_ALIAS) |
|
68 |
return AndroidTinyrssAccountManager(accountManager, secretCipher) |
|
69 |
} |
|
70 |
||
71 |
// may be replaced by a @Bind but it complicates the syntax in kotlin |
|
72 |
@Provides |
|
73 |
fun providesTinyrssAccountManager(androidTinyrssAccountManager: AndroidTinyrssAccountManager): TinyrssAccountManager {
|
|
74 |
return androidTinyrssAccountManager |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
/** |
|
79 |
* Provides the Services injectors subcomponents. |
|
80 |
*/ |
|
81 |
@Module |
|
82 |
abstract class ServicesInjectorModule {
|
|
83 |
||
84 |
@ContributesAndroidInjector(modules = [AuthenticatorActivityModule::class, ViewModelsModule::class]) |
|
85 |
internal abstract fun contributesLoginActivityInjector(): LoginActivity |
|
86 |
||
87 |
} |
|
88 |
||
89 |
||
90 |
@Module |
|
| 560 | 91 |
object NetworkLoginModule {
|
| 0 | 92 |
|
93 |
@Provides |
|
94 |
@PerAccount |
|
|
521
2a5be03dd6bc
Use CoroutineDispatchersProvider everywhere
Da Risk <da_risk@geekorum.com>
parents:
417
diff
changeset
|
95 |
fun providesTokenRetriever(dispatchers: CoroutineDispatchersProvider, |
|
2a5be03dd6bc
Use CoroutineDispatchersProvider everywhere
Da Risk <da_risk@geekorum.com>
parents:
417
diff
changeset
|
96 |
accountManager: AccountManager, account: Account): TokenRetriever {
|
|
2a5be03dd6bc
Use CoroutineDispatchersProvider everywhere
Da Risk <da_risk@geekorum.com>
parents:
417
diff
changeset
|
97 |
return TinyrssAccountTokenRetriever(dispatchers, accountManager, account) |
| 0 | 98 |
} |
99 |
||
100 |
@Provides |
|
101 |
@PerAccount |
|
|
417
8ba896069f2f
Account: Use webapi TokenRetriever
Da Risk <da_risk@geekorum.com>
parents:
312
diff
changeset
|
102 |
fun providesLoggedRequestInterceptorFactory(tokenRetriever: TokenRetriever): LoggedRequestInterceptorFactory {
|
| 0 | 103 |
return LoggedRequestInterceptorFactory(tokenRetriever) |
104 |
} |
|
105 |
||
106 |
@Provides |
|
|
104
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
107 |
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
|
108 |
return with(accountManager) {
|
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
109 |
val ttRssAccount = fromAndroidAccount(account) |
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
110 |
getServerInformation(ttRssAccount) |
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
111 |
} |
| 0 | 112 |
} |
113 |
||
114 |
} |
|
115 |
||
116 |
||
117 |
@Module(subcomponents = [AuthenticatorNetworkComponent::class]) |
|
|
723
43c8fb8d1528
accounts: use hilt AndroidEntryPoint for AuthenticatorService
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
118 |
@InstallIn(ServiceComponent::class) |
|
43c8fb8d1528
accounts: use hilt AndroidEntryPoint for AuthenticatorService
Da Risk <da_risk@geekorum.com>
parents:
611
diff
changeset
|
119 |
internal object AuthenticatorServiceModule |
| 0 | 120 |
|
121 |
@Module(subcomponents = [AuthenticatorNetworkComponent::class]) |
|
| 560 | 122 |
internal object AuthenticatorActivityModule {
|
| 0 | 123 |
@Provides |
124 |
fun providesContext(activity: Activity): Context {
|
|
125 |
return activity |
|
126 |
} |
|
127 |
} |
|
128 |
||
129 |
||
|
104
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
130 |
@Subcomponent(modules = [TinyRssServerInformationModule::class, TinyrssApiModule::class]) |
| 0 | 131 |
internal interface AuthenticatorNetworkComponent {
|
132 |
fun getTinyRssApi(): TinyRssApi |
|
133 |
||
134 |
@Subcomponent.Builder |
|
135 |
interface Builder {
|
|
136 |
fun build(): AuthenticatorNetworkComponent |
|
137 |
||
|
104
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
138 |
fun tinyRssServerInformationModule(module: TinyRssServerInformationModule): Builder |
| 0 | 139 |
} |
140 |
} |
|
141 |
||
142 |
@Module |
|
|
104
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
143 |
internal class TinyRssServerInformationModule(val serverInformation: ServerInformation) {
|
| 0 | 144 |
@Provides |
|
104
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
145 |
fun providesServerInformation(): ServerInformation {
|
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
146 |
return serverInformation |
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
147 |
} |
|
8b4047ebec59
Accounts: store a ServerInformation in the account manager
Da Risk <da_risk@geekorum.com>
parents:
0
diff
changeset
|
148 |
|
| 0 | 149 |
} |
150 |
||
151 |
@Module |
|
152 |
private abstract class ViewModelsModule {
|
|
153 |
@Binds |
|
154 |
@IntoMap |
|
|
164
2d6e9f2063cd
Replace ViewModelsFactory by DaggerDelegateViewModelFactory
Da Risk <da_risk@geekorum.com>
parents:
137
diff
changeset
|
155 |
@ViewModelKey(LoginViewModel::class) |
| 0 | 156 |
abstract fun getLoginViewModel(loginViewModel: LoginViewModel): ViewModel |
157 |
||
158 |
} |