Я использую от Dagger
и MVP
в моем проекте, и я использую код из kotlin
и java
вместе.
Ниже - мой MainView.kt
:
interface MainView : MessageView, VersionCheckView {
fun showUserStatus(userStatus: UserStatus)
fun setupUserAccountInfo(uiModel: NavHeaderUiModel)
fun setupServerAccountList(serverAccountList: List<Account>)
fun closeServerSelection()
fun invalidateToken(token: String)
fun showProgress()
fun hideProgress()
}
А ниже мой presenter
:
class MainPresenter @Inject constructor(
private val view: MainView,
private val strategy: CancelStrategy,
private val navigator: MainNavigator,
private val tokenRepository: TokenRepository,
private val serverInteractor: GetCurrentServerInteractor,
private val refreshSettingsInteractor: RefreshSettingsInteractor,
private val refreshPermissionsInteractor: RefreshPermissionsInteractor,
private val localRepository: LocalRepository,
private val navHeaderMapper: NavHeaderUiModelMapper,
private val saveAccountInteractor: SaveAccountInteractor,
private val getAccountsInteractor: GetAccountsInteractor,
private val removeAccountInteractor: RemoveAccountInteractor,
private val factory: RocketChatClientFactory,
private val groupedPush: GroupedPush,
dbManagerFactory: DatabaseManagerFactory,
getSettingsInteractor: GetSettingsInteractor,
managerFactory: ConnectionManagerFactory
) :....{
....
}
Выше кода хорошая работа в моем MainActivty.kt
, но когда я использую в MainActivityMou.java
, выведите меня ниже:
.MainView cannot be provided without an @Provides-annotated method.
А ниже MainModule.kt
:
@Module
class MainModule {
@Provides
@PerActivity
fun provideJob() = Job()
@Provides
@PerActivity
fun provideMainNavigator(activity: MainActivity) = MainNavigator(activity)
@Provides
fun provideMainView(activity: MainActivity): MainView = activity
@Named("MainActivityMou")
@Provides
fun provideMainMOUView(activity: MainActivityMou): MainView = activity
@Provides
fun provideLifecycleOwner(activity: MainActivity): LifecycleOwner = activity
@Provides
fun provideCancelStrategy(owner: LifecycleOwner, jobs: Job): CancelStrategy =
CancelStrategy(owner, jobs)
}
Мой MainActivityMou.java
похож на:
public class MainActivityMou extends DaggerAppCompatActivity implements
MainView {
@Inject
MainPresenter mainPresenter;
....
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
AndroidInjection.inject(this);
}
....
}