turn presenter into a dependency

This commit is contained in:
Vincent Breitmoser 2018-05-10 19:02:44 +02:00 committed by cketti
parent 303f0606d0
commit 8542119a91
8 changed files with 35 additions and 19 deletions

View file

@ -283,7 +283,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
RecipientMvpView recipientMvpView = new RecipientMvpView(this);
ComposePgpInlineDecider composePgpInlineDecider = new ComposePgpInlineDecider();
ComposePgpEnableByDefaultDecider composePgpEnableByDefaultDecider = new ComposePgpEnableByDefaultDecider();
OpenPgpApiManager openPgpApiManager = new OpenPgpApiManager(getApplicationContext(), getLifecycle());
OpenPgpApiManager openPgpApiManager = new OpenPgpApiManager(getApplicationContext(), this);
recipientPresenter = new RecipientPresenter(getApplicationContext(), getSupportLoaderManager(),
openPgpApiManager, recipientMvpView, account, composePgpInlineDecider, composePgpEnableByDefaultDecider,
AutocryptStatusInteractor.getInstance(), new ReplyToParser(), this

View file

@ -231,7 +231,7 @@ public class AccountSettings extends K9PreferenceActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
openPgpApiManager = new OpenPgpApiManager(getApplicationContext(), getLifecycle());
openPgpApiManager = new OpenPgpApiManager(getApplicationContext(), this);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
account = Preferences.getPreferences(this).getAccount(accountUuid);

View file

@ -4,5 +4,5 @@ import org.koin.dsl.module.applicationContext
import org.openintents.openpgp.OpenPgpApiManager
val openPgpModule = applicationContext {
factory { params -> OpenPgpApiManager(get(), params["lifecycle"]) }
factory { params -> OpenPgpApiManager(get(), params["lifecycleOwner"]) }
}

View file

@ -13,20 +13,16 @@ import android.view.View
import com.fsck.k9.R
import com.fsck.k9.activity.K9Activity
import com.fsck.k9.finishWithErrorToast
import com.fsck.k9.mail.TransportProvider
import com.fsck.k9.view.StatusIndicator
import kotlinx.android.synthetic.main.crypto_key_transfer.*
import org.koin.android.architecture.ext.viewModel
import org.koin.android.ext.android.inject
import org.openintents.openpgp.OpenPgpApiManager
import timber.log.Timber
class AutocryptKeyTransferActivity : K9Activity() {
private val viewModel: AutocryptKeyTransferViewModel by viewModel()
private val transportProvider: TransportProvider by inject()
private val openPgpApiManager: OpenPgpApiManager by inject { mapOf("lifecycle" to lifecycle) }
private lateinit var presenter: AutocryptKeyTransferPresenter
private val presenter: AutocryptKeyTransferPresenter by inject {
mapOf("lifecycleOwner" to this, "autocryptTransferView" to this)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -37,7 +33,6 @@ class AutocryptKeyTransferActivity : K9Activity() {
transferSendButton.setOnClickListener { presenter.onClickTransferSend() }
transferButtonShowCode.setOnClickListener { presenter.onClickShowTransferCode() }
presenter = AutocryptKeyTransferPresenter(this, applicationContext, this, viewModel, openPgpApiManager, transportProvider)
presenter.initFromIntent(accountUuid)
}

View file

@ -20,10 +20,11 @@ import timber.log.Timber
class AutocryptKeyTransferPresenter internal constructor(
lifecycleOwner: LifecycleOwner,
private val context: Context,
private val view: AutocryptKeyTransferActivity,
private val viewModel: AutocryptKeyTransferViewModel,
private val openPgpApiManager: OpenPgpApiManager,
private val transportProvider: TransportProvider
private val transportProvider: TransportProvider,
private val preferences: Preferences,
private val viewModel: AutocryptKeyTransferViewModel,
private val view: AutocryptKeyTransferActivity
) {
private lateinit var account: Account
@ -40,7 +41,7 @@ class AutocryptKeyTransferPresenter internal constructor(
return
}
account = Preferences.getPreferences(context).getAccount(accountUuid)
account = preferences.getAccount(accountUuid)
openPgpApiManager.setOpenPgpProvider(account.openPgpProvider, object : OpenPgpApiManagerCallback {
override fun onOpenPgpProviderStatusChanged() {

View file

@ -6,5 +6,15 @@ import org.koin.dsl.module.applicationContext
val endToEndUiModule = applicationContext {
factory { AutocryptSetupMessageLiveEvent() }
factory { AutocryptSetupTransferLiveEvent() }
factory { params ->
AutocryptKeyTransferPresenter(
params["lifecycleOwner"],
get(),
get(parameters = { params.values }),
get(),
get(),
get(),
params["autocryptTransferView"])
}
viewModel { AutocryptKeyTransferViewModel(get(), get()) }
}

View file

@ -1,6 +1,11 @@
package com.fsck.k9
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleOwner
import com.fsck.k9.ui.endtoend.AutocryptKeyTransferActivity
import com.fsck.k9.ui.endtoend.AutocryptKeyTransferViewModel
import com.fsck.k9.ui.endtoend.AutocryptSetupMessageLiveEvent
import com.nhaarman.mockito_kotlin.doReturn
import com.nhaarman.mockito_kotlin.mock
import org.junit.Test
import org.koin.Koin
@ -8,13 +13,18 @@ import org.koin.log.PrintLogger
import org.koin.test.dryRun
class DependencyInjectionTest : K9RobolectricTest() {
val lifecycleOwner = mock<LifecycleOwner> {
on { lifecycle } doReturn mock<Lifecycle>()
}
@Test
fun testDependencyTree() {
Koin.logger = PrintLogger()
dryRun {
mapOf(
"lifecycle" to mock<Lifecycle>()
"lifecycleOwner" to lifecycleOwner,
"autocryptTransferView" to mock<AutocryptKeyTransferActivity>()
)
}
}

View file

@ -2,9 +2,9 @@ package org.openintents.openpgp;
import android.app.PendingIntent;
import android.arch.lifecycle.Lifecycle;
import android.arch.lifecycle.Lifecycle.Event;
import android.arch.lifecycle.LifecycleObserver;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.OnLifecycleEvent;
import android.content.Context;
import android.content.Intent;
@ -32,10 +32,10 @@ public class OpenPgpApiManager implements LifecycleObserver {
private PendingIntent userInteractionPendingIntent;
private OpenPgpProviderState openPgpProviderState = OpenPgpProviderState.UNCONFIGURED;
public OpenPgpApiManager(Context context, Lifecycle lifecycle) {
public OpenPgpApiManager(Context context, LifecycleOwner lifecycleOwner) {
this.context = context;
lifecycle.addObserver(this);
lifecycleOwner.getLifecycle().addObserver(this);
}
@OnLifecycleEvent(Event.ON_CREATE)