Search in sources :

Example 6 with BasePresenter

use of com.skocken.presentation.presenter.BasePresenter in project Presentation by StanKocken.

the class BaseActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    BasePresenter presenter = getPresenter();
    if (presenter != null) {
        presenter.onActivityResult(requestCode, resultCode, data);
    }
}
Also used : BasePresenter(com.skocken.presentation.presenter.BasePresenter)

Example 7 with BasePresenter

use of com.skocken.presentation.presenter.BasePresenter in project Presentation by StanKocken.

the class BaseActivity method initPresenter.

void initPresenter(Bundle savedInstanceState) {
    BasePresenter presenter = newPresenter();
    setPresenter(presenter);
    if (presenter != null) {
        // because the first onCreate won't be call otherwise (creation too late)
        presenter.onCreate(savedInstanceState);
    }
}
Also used : BasePresenter(com.skocken.presentation.presenter.BasePresenter)

Example 8 with BasePresenter

use of com.skocken.presentation.presenter.BasePresenter in project Presentation by StanKocken.

the class BaseAppCompatActivity method onBackPressed.

@Override
public void onBackPressed() {
    BasePresenter presenter = getPresenter();
    if (presenter != null && presenter.onBackPressed()) {
        return;
    }
    super.onBackPressed();
}
Also used : BasePresenter(com.skocken.presentation.presenter.BasePresenter)

Example 9 with BasePresenter

use of com.skocken.presentation.presenter.BasePresenter in project Presentation by StanKocken.

the class BaseActivityTest method testShouldWeakReferenceOnPresenter.

@Test
public void testShouldWeakReferenceOnPresenter() {
    BasePresenter basePresenter = new BasePresenter(null, null) {
    };
    final WeakReference<BasePresenter> weakReferencePresenter = new WeakReference<>(basePresenter);
    BaseActivity baseActivity = new TestBaseActivity() {

        @Override
        protected BasePresenter newPresenter() {
            return weakReferencePresenter.get();
        }
    };
    baseActivity.onCreate(null);
    assertEquals(basePresenter, baseActivity.getPresenter());
    basePresenter = null;
    for (int i = 0; i < 10 && weakReferencePresenter.get() != null; i++) {
        System.gc();
    }
    assertNull(basePresenter);
    assertNull(weakReferencePresenter.get());
    assertNull(baseActivity.getPresenter());
}
Also used : WeakReference(java.lang.ref.WeakReference) BasePresenter(com.skocken.presentation.presenter.BasePresenter) Test(org.junit.Test)

Example 10 with BasePresenter

use of com.skocken.presentation.presenter.BasePresenter in project Presentation by StanKocken.

the class BaseActivityTest method testShouldCallOnActivityResult.

@Test
public void testShouldCallOnActivityResult() {
    BaseActivity baseActivity = new TestBaseActivity();
    baseActivity.onCreate(null);
    BasePresenter presenter = baseActivity.getPresenter();
    int requestCode = 432;
    int resultCode = 542;
    Intent intent = Mockito.mock(Intent.class);
    verify(presenter, times(0)).onActivityResult(requestCode, resultCode, intent);
    baseActivity.onActivityResult(requestCode, resultCode, intent);
    verify(presenter, times(1)).onActivityResult(requestCode, resultCode, intent);
}
Also used : Intent(android.content.Intent) BasePresenter(com.skocken.presentation.presenter.BasePresenter) Test(org.junit.Test)

Aggregations

BasePresenter (com.skocken.presentation.presenter.BasePresenter)16 Test (org.junit.Test)10 Intent (android.content.Intent)2 Menu (android.view.Menu)2 MenuInflater (android.view.MenuInflater)2 MenuItem (android.view.MenuItem)2 WeakReference (java.lang.ref.WeakReference)2