Skip to content

Commit

Permalink
release 0.1.1 - adding javadocs + major refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejchm committed Jun 23, 2016
1 parent 272e8f4 commit dcee350
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 38 deletions.
2 changes: 1 addition & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ android {
minSdkVersion 10
targetSdkVersion 24
versionCode 1
versionName "1.0"
versionName "0.1.1"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.appflate.droidmvp.base;
package io.appflate.droidmvp;

import android.os.Bundle;
import android.support.annotation.NonNull;
Expand All @@ -26,8 +26,8 @@ public abstract class DroidMVPActivity<M extends Serializable, V extends DroidMV
extends AppCompatActivity implements DroidMVPView {

private DroidMVPViewDelegate<M, V, P> mvpDelegate = new DroidMVPViewDelegate<M, V, P>() {
@NonNull @Override protected P createPresenter(M presentationModel) {
return DroidMVPActivity.this.createPresenter(presentationModel);
@NonNull @Override protected P createPresenter() {
return DroidMVPActivity.this.createPresenter();
}

@NonNull @Override protected M createPresentationModel() {
Expand Down Expand Up @@ -61,9 +61,30 @@ public abstract class DroidMVPActivity<M extends Serializable, V extends DroidMV
mvpDelegate.onStart((V) this);
}

/**
* Used for performing field injection trough various dependency injection frameworks like
* Dagger. The injection is performed just before the #createPresenter() or
* #createPresentationModel() methods are called, so you can
* have your presenter and/or Presentation Model being injected by Dagger.
*/
protected abstract void performFieldInjection();

@NonNull protected abstract P createPresenter(M presentationModel);
/**
* Used for creating the presenter instance, called in #onCreate(Bundle) method.
* @return an instance of your Presenter.
*/
@NonNull protected abstract P createPresenter();

/**
* Used to create the Presentation Model that will be attached to your presenter in #onAttach()
* method of your presenter.
*
* NOTE: this will be called only if there is no Presentation Model persisted in your
* savedInstanceState!
*
* You can retrieve the arguments from your Intent's extra and pass it
* to your Presentation's model constructor.
* @return Presentation Model instance used by your Presenter.
*/
@NonNull protected abstract M createPresentationModel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.appflate.droidmvp.base;
package io.appflate.droidmvp;

import android.os.Bundle;
import android.support.annotation.NonNull;
Expand All @@ -26,8 +26,8 @@ public abstract class DroidMVPFragment<M extends Serializable, V extends DroidMV
extends Fragment implements DroidMVPView {

private DroidMVPViewDelegate<M, V, P> mvpDelegate = new DroidMVPViewDelegate<M, V, P>() {
@NonNull @Override protected P createPresenter(M presentationModel) {
return DroidMVPFragment.this.createPresenter(presentationModel);
@NonNull @Override protected P createPresenter() {
return DroidMVPFragment.this.createPresenter();
}

@NonNull @Override protected M createPresentationModel() {
Expand Down Expand Up @@ -61,9 +61,31 @@ public abstract class DroidMVPFragment<M extends Serializable, V extends DroidMV
mvpDelegate.onDestroy();
}

/**
* Used for performing field injection trough various dependency injection frameworks like
* Dagger. The injection is performed just before the #createPresenter() or
* #createPresentationModel() methods are called, so you can
* have your presenter and/or Presentation Model being injected by Dagger.
*/
protected abstract void performFieldInection();

@NonNull protected abstract P createPresenter(M presentationModel);
/**
* Used for creating the presenter instance, called in #onCreate(Bundle) method.
*
* @return an instance of your Presenter.
*/
@NonNull protected abstract P createPresenter();

/**
* Used to create the Presentation Model that will be attached to your presenter in #onAttach()
* method of your presenter.
*
* NOTE: this will be called only if there is no Presentation Model persisted in your
* savedInstanceState!
*
* You can retrieve the arguments from #getArguments() method of your
* fragment and pass it to your Presentation's model constructor.
* @return Presentation Model instance used by your Presenter.
*/
@NonNull protected abstract M createPresentationModel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.appflate.droidmvp.base;
package io.appflate.droidmvp;

import java.io.Serializable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.appflate.droidmvp.base;
package io.appflate.droidmvp;

/**
* Base interface that any class that wants to act as a View in the MVP (Model-View-Presenter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.appflate.droidmvp.base;
package io.appflate.droidmvp;

import android.os.Bundle;
import android.support.annotation.NonNull;
Expand All @@ -23,7 +23,10 @@
import java.io.Serializable;

/**
* Created by andrzejchm on 16/05/16.
* Class that makes it possible to write your own custom MVP Views that will fit in the DroidMVP structure.
* It is tightly coupled with the common android component's lifecycle, like onCreate, onStart, onStop,
* onSaveInstanceState and onDestroy to properly recover the model on configuration changes and making sure
* your presenters won't leak your views when those are supposed to be destroyed.
*/
public abstract class DroidMVPViewDelegate<M extends Serializable, V extends DroidMVPView, P extends DroidMVPPresenter<V, M>> {

Expand All @@ -32,41 +35,65 @@ public abstract class DroidMVPViewDelegate<M extends Serializable, V extends Dro

private String presentationModelKey;

/**
* Commonly called from fragment's/activity's onCreate. Presentation Model is either created or restored
* here.
* @param mvpView the MVP view that is being created.
* @param savedInstanceState instanceState provided by android framework in which we store the
* Presentation Model
*/
public void onCreate(DroidMVPView mvpView, @Nullable Bundle savedInstanceState) {
presentationModelKey = mvpView.getClass().getCanonicalName() + "$PresentationModel";
presentationModel = restorePresentationModel(getClass(), savedInstanceState);
if (presentationModel == null) {
presentationModel = createPresentationModel();
}
this.presenter = createPresenter(presentationModel);
this.presenter = createPresenter();
}

@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") protected void onStop() {
/**
* Commonly called from fragment's/activity's onStart. Used for attaching the view to presenter,
* so the presenter can start to update the view's state
*/
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public void onStart(V mvpView) {
checkPresenter();
checkPresentationModel();
presenter.attachView(mvpView, presentationModel);
}

/**
* Commonly called from fragment's/activity's onStop. Used for detaching the view from presenter, so no
* memory leaks happen.
*/
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") public void onStop() {
checkPresenter();
presenter.detachView();
}

@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") protected void onDestroy() {
/**
* Commonly called from fragment's/activity's onDestroy. Used to notify the presenter that the view
* will no longer be attached to the presenter, so all the long running tasks have to be terminated
* and the context should be cleared.
*/
@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR") public void onDestroy() {
checkPresenter();
presenter.onDestroy();
}

protected void onSaveInstanceState(Bundle outState) {
/**
* Used by the delegate to persist current Presentation Model due to configuration change.
* @param outState
*/
public void onSaveInstanceState(Bundle outState) {
outState.putSerializable(presentationModelKey, presentationModel);
}

@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
protected void onStart(V mvpView) {
checkPresenter();
checkPresentationModel();
presenter.attachView(mvpView, presentationModel);
}

public P getPresenter() {
return presenter;
}

@NonNull protected abstract P createPresenter(M presentationModel);
@NonNull protected abstract P createPresenter();

@NonNull protected abstract M createPresentationModel();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
package io.appflate.droidmvp.base;
/*
* Copyright (C) 2016 Appflate.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.appflate.droidmvp;

import java.io.Serializable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package io.appflate.droidvmp.androidsample.ui.base;

import android.support.annotation.NonNull;
import io.appflate.droidmvp.base.DroidMVPActivity;
import io.appflate.droidmvp.base.DroidMVPPresenter;
import io.appflate.droidmvp.base.DroidMVPView;
import io.appflate.droidmvp.DroidMVPActivity;
import io.appflate.droidmvp.DroidMVPPresenter;
import io.appflate.droidmvp.DroidMVPView;
import java.io.Serializable;
import javax.inject.Inject;

Expand All @@ -30,7 +30,7 @@ public abstract class BaseActivity<M extends Serializable, V extends DroidMVPVie
extends DroidMVPActivity<M, V, P> {
@Inject protected P presenter;

@NonNull @Override protected P createPresenter(M presentationModel) {
@NonNull @Override protected P createPresenter() {
//this field will be populated by field injeciton from dagger
// your presenter should not accept the presentationModel as its constructor's paramteter.
// Instead, it will be provided to your presenter in #attachView method.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.appflate.droidvmp.androidsample.ui.base;

import android.support.annotation.NonNull;
import io.appflate.droidmvp.base.DroidMVPFragment;
import io.appflate.droidmvp.base.DroidMVPPresenter;
import io.appflate.droidmvp.base.DroidMVPView;
import io.appflate.droidmvp.DroidMVPFragment;
import io.appflate.droidmvp.DroidMVPPresenter;
import io.appflate.droidmvp.DroidMVPView;
import java.io.Serializable;
import javax.inject.Inject;

Expand All @@ -14,7 +14,7 @@ public abstract class BaseFragment<M extends Serializable, V extends DroidMVPVie
extends DroidMVPFragment<M, V, P> {
@Inject protected P presenter;

@NonNull @Override protected P createPresenter(M presentationModel) {
@NonNull @Override protected P createPresenter() {
//this field will be populated by field injeciton from dagger
// your presenter should not accept the presentationModel as its constructor's paramteter.
// Instead, it will be provided by #attachView method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.appflate.droidvmp.androidsample.ui.mvpviews;

import io.appflate.droidmvp.base.DroidMVPView;
import io.appflate.droidmvp.DroidMVPView;

/**
* Created by andrzejchm on 21/06/16.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.appflate.droidvmp.androidsample.ui.mvpviews;

import io.appflate.droidmvp.base.DroidMVPView;
import io.appflate.droidmvp.DroidMVPView;
import io.appflate.droidvmp.androidsample.model.Repository;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.appflate.droidvmp.androidsample.ui.presenters;

import io.appflate.droidmvp.base.SimpleDroidMVPPresenter;
import io.appflate.droidmvp.SimpleDroidMVPPresenter;
import io.appflate.droidvmp.androidsample.domain.GithubApi;
import io.appflate.droidvmp.androidsample.model.User;
import io.appflate.droidvmp.androidsample.model.presentation.MainPresentationModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package io.appflate.droidvmp.androidsample.ui.presenters;

import io.appflate.droidmvp.base.SimpleDroidMVPPresenter;
import io.appflate.droidmvp.SimpleDroidMVPPresenter;
import io.appflate.droidvmp.androidsample.domain.GithubApi;
import io.appflate.droidvmp.androidsample.model.Repository;
import io.appflate.droidvmp.androidsample.model.presentation.RepositoriesPresentationModel;
Expand Down

0 comments on commit dcee350

Please sign in to comment.