Skip to content

Commit

Permalink
Merge branch 'v1.2.0-alpha'
Browse files Browse the repository at this point in the history
Conflicts:
	sample-recyclerview/src/main/java/com/mateuszkoslacz/moviper/recyclerviewsample/viper/view/adapter/ProductAdapter.java
  • Loading branch information
mkoslacz committed Dec 20, 2016
2 parents 3878cb3 + 47c3cfb commit 2127c97
Show file tree
Hide file tree
Showing 173 changed files with 1,232 additions and 2,394 deletions.
8 changes: 4 additions & 4 deletions moviper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
}

compileSdkVersion 25
buildToolsVersion '25'
buildToolsVersion '25.0.2'

defaultConfig {
minSdkVersion 16
Expand All @@ -35,15 +35,15 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.2.9'
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:recyclerview-v7:25.0.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:recyclerview-v7:25.1.0'
compile 'com.hannesdorfmann.mosby:mvp:2.0.1'
compile 'com.hannesdorfmann.mosby:viewstate:2.0.1'

// TODO: probably should split to two flavours to
// avoid including rxJava in projects that don't
// use rx
compile 'io.reactivex:rxjava:1.2.2'
compile 'io.reactivex:rxjava:1.2.3'

}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mateuszkoslacz.moviper.annotation;

import com.mateuszkoslacz.moviper.iface.presenter.ViperPresenter;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -8,7 +10,7 @@
/**
* Created by mateuszkoslacz on 25.10.2016. <p>
*
* Annotates {@link com.mateuszkoslacz.moviper.iface.presenter.MoviperPresenter} method that is
* Annotates {@link ViperPresenter} method that is
* called from the outside of its VIPER screen using the {@link com.mateuszkoslacz.moviper.presenterbus.Moviper}
* presenters bundle access mechanism.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package com.mateuszkoslacz.moviper.base.exception;

import com.mateuszkoslacz.moviper.iface.presenter.MoviperPresenter;
import com.mateuszkoslacz.moviper.iface.presenter.ViperPresenter;

/**
* Created by mateuszkoslacz on 24.10.2016.
*/

public class PresenterAlreadyRegisteredException extends RuntimeException {

public PresenterAlreadyRegisteredException(MoviperPresenter presenter) {
super(String.format("Presenter %1$s named %1$s is already registered! You enabled presenter instances" +
"access and tried to register two or more presenters of the same class and name." +
"Override getName() method in your %1$s presenter in way that will provide unique name" +
"for each instance or disable presenter instances access using " +
"Moviper.getInstance().setConfig(new Config.Builder()...) and setting " +
"withInstancePresentersEnabled(true) in config builder.",
presenter.getClass().getName(), presenter.getName()));
public PresenterAlreadyRegisteredException(ViperPresenter presenter) {
super(String.format(
"Presenter %1$s named %2$s is already registered! You enabled presenter " +
"instances access and tried to register two or more presenters of the " +
"same class and name. Override getName() method in your %1$s presenter " +
"in way that will provide unique name for each instance or disable " +
"presenter instances access using " +
"Moviper.getInstance().setConfig(new Config.Builder()...) and setting " +
"withInstancePresentersEnabled(true) in config builder.",
presenter.getClass().getName(),
presenter.getName()));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.mateuszkoslacz.moviper.base.exception;

import com.mateuszkoslacz.moviper.iface.presenter.MoviperPresenter;

/**
* Created by mateuszkoslacz on 24.10.2016.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.mateuszkoslacz.moviper.base.exception;

import com.mateuszkoslacz.moviper.iface.presenter.MoviperPresenter;

/**
* Created by mateuszkoslacz on 24.10.2016.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import android.support.annotation.Nullable;

import com.mateuszkoslacz.moviper.iface.interactor.MoviperInteractor;
import com.mateuszkoslacz.moviper.iface.presenter.interactor.MoviperPresenterForInteractor;
import com.mateuszkoslacz.moviper.iface.interactor.ViperInteractor;
import com.mateuszkoslacz.moviper.iface.presenter.interactor.ViperPresenterForInteractor;
import com.mateuszkoslacz.moviper.util.WeakReferenceUtils;

import java.lang.ref.WeakReference;
Expand All @@ -14,10 +14,10 @@
* <p>
* Adapted and modified by mateuszkoslacz on 08.08.2016.
* <p>
* Base Interactor class. (see {@link MoviperInteractor})
* Base Interactor class. (see {@link ViperInteractor})
*/
public abstract class BaseInteractor<PresenterType extends MoviperPresenterForInteractor>
implements MoviperInteractor<PresenterType> {
public abstract class BaseInteractor<PresenterType extends ViperPresenterForInteractor>
implements ViperInteractor<PresenterType> {

@Nullable
private WeakReference<PresenterType> presenter;
Expand All @@ -34,24 +34,13 @@ public boolean isPresenterAttached() {
}

@Override
public void attachPresenter(PresenterType presenter) {
public void attach(PresenterType presenter) {
this.presenter = new WeakReference<>(presenter);
}

@Override
public void detachPresenter() {
public void detach(boolean retainInstance) {
WeakReferenceUtils.detach(presenter);
}

@Override
public void onPresenterDetached(boolean retainInstance) {
onPresenterDetached();
// stub
}

@Override
@Deprecated
public void onPresenterDetached() {
// stub
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package com.mateuszkoslacz.moviper.base.interactor;


import com.mateuszkoslacz.moviper.iface.interactor.MoviperInteractor;
import com.mateuszkoslacz.moviper.iface.interactor.MoviperRxInteractor;
import com.mateuszkoslacz.moviper.iface.interactor.ViperInteractor;
import com.mateuszkoslacz.moviper.iface.interactor.ViperRxInteractor;

/**
* Created by lucas.urbas on 29/08/15.
* <p>
* Adapted and modified by mateuszkoslacz on 21.10.2016.
* <p>
* Base Interactor class. (see {@link MoviperInteractor})
* Base Interactor class. (see {@link ViperInteractor})
*/
public abstract class BaseRxInteractor implements MoviperRxInteractor {
public abstract class BaseRxInteractor implements ViperRxInteractor {

@Override
public void onPresenterDetached(boolean retainInstance) {
onPresenterDetached();
// stub
public void attach() {

}

@Override
@Deprecated
public void onPresenterDetached(){
// stub
public void detach(boolean retainInstance) {

}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.mateuszkoslacz.moviper.base.presenter;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;

import com.hannesdorfmann.mosby.mvp.MvpBasePresenter;
import com.hannesdorfmann.mosby.mvp.MvpView;
import com.mateuszkoslacz.moviper.iface.interactor.MoviperInteractor;
import com.mateuszkoslacz.moviper.iface.presenter.MoviperPresenter;
import com.mateuszkoslacz.moviper.iface.presenter.interactor.MoviperPresenterForInteractor;
import com.mateuszkoslacz.moviper.iface.presenter.routing.MoviperActivityPresenterForRouting;
import com.mateuszkoslacz.moviper.iface.routing.MoviperRouting;
import com.mateuszkoslacz.moviper.iface.interactor.ViperInteractor;
import com.mateuszkoslacz.moviper.iface.presenter.ViperPresenter;
import com.mateuszkoslacz.moviper.iface.presenter.interactor.ViperPresenterForInteractor;
import com.mateuszkoslacz.moviper.iface.presenter.routing.ViperPresenterForRouting;
import com.mateuszkoslacz.moviper.iface.routing.ViperRouting;
import com.mateuszkoslacz.moviper.iface.view.ViperView;

/**
* Created by mateuszkoslacz on 08.08.2016.
Expand All @@ -27,50 +27,56 @@
* {@link com.hannesdorfmann.mosby.mvp.viewstate.lce.MvpLceViewStateActivity})
*/
//TODO migrate to MvpNullObjectPresenter base class?
public abstract class ViperActivityBasePresenter
public abstract class BasePresenter
<ViewType extends MvpView, // I prefer readability rather than conventions
InteractorType extends MoviperInteractor,
RoutingType extends MoviperRouting>
extends WipeBasePresenter<ViewType, InteractorType>
implements MoviperPresenter<ViewType>,
MoviperPresenterForInteractor<InteractorType>,
MoviperActivityPresenterForRouting<RoutingType> {
InteractorType extends ViperInteractor,
RoutingType extends ViperRouting>
extends CommonBasePresenter<ViewType>
implements ViperPresenter<ViewType>,
ViperPresenterForInteractor<InteractorType>,
ViperPresenterForRouting<RoutingType> {

@NonNull
private RoutingType routing;

public ViperActivityBasePresenter(@NonNull Activity activity) {
super();
this.routing = createRouting(activity);
}
@NonNull
private InteractorType interactor;

public ViperActivityBasePresenter(@NonNull Activity activity, Bundle args) {
super(args);
this.routing = createRouting(activity);
public BasePresenter() {
this(null);
}

@Override
@Deprecated
public boolean isRoutingAttached() {
return routing != null;
public BasePresenter(Bundle args) {
super(args);
this.routing = createRouting();
this.interactor = createInteractor();
}

@Override
public void attachView(ViewType view) {
super.attachView(view);
//noinspection unchecked
routing.attachPresenter(this);
routing.attach((ViperView) view, this);
//noinspection unchecked
interactor.attach(this);
}

@Override
public void detachView(boolean retainInstance) {
super.detachView(retainInstance);
routing.detachPresenter();
routing.detach(retainInstance);
interactor.detach(retainInstance);
}

@NonNull
@Override
public RoutingType getRouting() {
return routing;
}

@NonNull
@Override
public InteractorType getInteractor() {
return interactor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.mateuszkoslacz.moviper.base.presenter;

import android.os.Bundle;
import android.support.annotation.NonNull;

import com.hannesdorfmann.mosby.mvp.MvpBasePresenter;
import com.hannesdorfmann.mosby.mvp.MvpView;
import com.mateuszkoslacz.moviper.iface.interactor.ViperRxInteractor;
import com.mateuszkoslacz.moviper.iface.presenter.ViperPresenter;
import com.mateuszkoslacz.moviper.iface.presenter.interactor.ViperPresenterForInteractor;
import com.mateuszkoslacz.moviper.iface.presenter.routing.ViperPresenterForRouting;
import com.mateuszkoslacz.moviper.iface.routing.ViperRxRouting;
import com.mateuszkoslacz.moviper.iface.view.ViperView;
import com.mateuszkoslacz.moviper.presenterbus.Moviper;

import rx.Subscription;
import rx.subscriptions.CompositeSubscription;

/**
* Created by mateuszkoslacz on 08.08.2016.
* <p>
* Viper - View, Interactor, Presenter, Entities, Routing
* <p>
* This is a Activity version of base presenter class for mentioned set of concepts.
* (see {@link MvpBasePresenter})
* <p>
* You can use any Mosby Activity View with this class
* ({@link com.hannesdorfmann.mosby.mvp.MvpActivity},
* {@link com.hannesdorfmann.mosby.mvp.lce.MvpLceActivity},
* {@link com.hannesdorfmann.mosby.mvp.viewstate.MvpViewStateActivity},
* {@link com.hannesdorfmann.mosby.mvp.viewstate.lce.MvpLceViewStateActivity})
*/
//TODO migrate to MvpNullObjectPresenter base class?
public abstract class BaseRxPresenter
<ViewType extends MvpView, // I prefer readability rather than conventions
InteractorType extends ViperRxInteractor,
RoutingType extends ViperRxRouting>
extends CommonBasePresenter<ViewType>
implements ViperPresenter<ViewType>,
ViperPresenterForInteractor<InteractorType>,
ViperPresenterForRouting<RoutingType> {

@NonNull
private RoutingType routing;

@NonNull
private InteractorType interactor;


private CompositeSubscription compositeSubscription;

public BaseRxPresenter() {
this(null);
}

public BaseRxPresenter(Bundle args) {
super(args);
this.compositeSubscription = new CompositeSubscription();
this.routing = createRouting();
this.interactor = createInteractor();
}

@Override
public void attachView(ViewType view) {
super.attachView(view);
Moviper.getInstance().register(this);
routing.attach((ViperView) view);
interactor.attach();
}

@Override
public void detachView(boolean retainInstance) {
super.detachView(retainInstance);
if (!retainInstance) unsubscribe();
Moviper.getInstance().unregister(this);
routing.detach(retainInstance);
interactor.detach(retainInstance);
}

@NonNull
@Override
public RoutingType getRouting() {
return routing;
}

@NonNull
@Override
public InteractorType getInteractor() {
return interactor;
}

protected void addSubscription(Subscription subscription) {
if (compositeSubscription != null) compositeSubscription.add(subscription);
}

private void unsubscribe() {
if (compositeSubscription != null) compositeSubscription.clear();
}
}
Loading

0 comments on commit 2127c97

Please sign in to comment.