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