Skip to content

Commit

Permalink
Merge branch 'release/1.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
senneco committed Nov 29, 2016
2 parents 0ef99bb + 0f293b7 commit bbfa096
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 60 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,29 @@ Base modules integration:
```groovy
dependencies {
...
compile 'com.arello-mobile:moxy:1.3.1'
provided 'com.arello-mobile:moxy-compiler:1.3.1'
compile 'com.arello-mobile:moxy:1.3.2'
provided 'com.arello-mobile:moxy-compiler:1.3.2'
}
```
If you want to see generated code, use `apt` instead of `provided` dependency type:
```groovy
dependencies {
...
apt 'com.arello-mobile:moxy-compiler:1.3.1'
apt 'com.arello-mobile:moxy-compiler:1.3.2'
}
```
For additional base view classes `MvpActivity` and `MvpFragment` add this:
```groovy
dependencies {
...
compile 'com.arello-mobile:moxy-android:1.3.1'
compile 'com.arello-mobile:moxy-android:1.3.2'
}
```
If you planing to use AppCompat, then you can use `MvpAppCompatActivity` and `MvpAppCompatFragment`. Then add this:
```groovy
dependencies {
...
compile 'com.arello-mobile:moxy-app-compat:1.3.1'
compile 'com.arello-mobile:moxy-app-compat:1.3.2'
compile 'com.android.support:appcompat-v7:$support_version'
}
```
Expand All @@ -107,7 +107,7 @@ If you are using kotlin, use `kapt` instead of `provided`/`apt` dependency type
```groovy
dependencies {
...
kapt 'com.arello-mobile:moxy-compiler:1.3.1'
kapt 'com.arello-mobile:moxy-compiler:1.3.2'
}
kapt {
generateStubs = true
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ allprojects {
}

ext {
targetVersionCode = 30
targetVersionName = "1.3.1"
targetVersionCode = 31
targetVersionName = "1.3.2"
}

task clean(type: Delete) {
Expand Down
21 changes: 11 additions & 10 deletions moxy-android/src/main/java/com/arellomobile/mvp/MvpFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import android.app.Fragment;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.util.Log;

/**
* Date: 19-Dec-15
Expand All @@ -27,16 +25,11 @@ public void onCreate(Bundle savedInstanceState) {
getMvpDelegate().onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mIsStateSaved = false;

return super.onCreateView(inflater, container, savedInstanceState);
}

public void onResume() {
super.onResume();

mIsStateSaved = false;

getMvpDelegate().onAttach();
}

Expand All @@ -56,6 +49,14 @@ public void onStop() {
getMvpDelegate().onDetach();
}

@Override
public void onDestroyView() {
super.onDestroyView();

getMvpDelegate().onDetach();
getMvpDelegate().onDestroyView();
}

@Override
public void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package android.app;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* Created by senneco on 11.10.2016
*/

public class Fragment {

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
throw new RuntimeException("Stub!");
}

public void onCreate(Bundle savedInstanceState) {
throw new RuntimeException("Stub!");
}
Expand All @@ -31,6 +24,10 @@ public void onStop() {
throw new RuntimeException("Stub!");
}

public void onDestroyView() {
throw new RuntimeException("Stub!");
}

public void onDestroy() {
throw new RuntimeException("Stub!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* Date: 19-Dec-15
Expand All @@ -26,16 +23,11 @@ public void onCreate(Bundle savedInstanceState) {
getMvpDelegate().onCreate(savedInstanceState);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mIsStateSaved = false;

return super.onCreateView(inflater, container, savedInstanceState);
}

public void onResume() {
super.onResume();

mIsStateSaved = false;

getMvpDelegate().onAttach();
}

Expand All @@ -55,6 +47,14 @@ public void onStop() {
getMvpDelegate().onDetach();
}

@Override
public void onDestroyView() {
super.onDestroyView();

getMvpDelegate().onDetach();
getMvpDelegate().onDestroyView();
}

@Override
public void onDestroy() {
super.onDestroy();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package android.support.v4.app;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
* Date: 30-Sen-16
Expand All @@ -12,10 +9,6 @@
* @author Yuri Shmakov
*/
public class Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
throw new RuntimeException("Stub!");
}

public void onCreate(Bundle savedInstanceState) {
throw new RuntimeException("Stub!");
}
Expand All @@ -32,6 +25,10 @@ public void onStop() {
throw new RuntimeException("Stub!");
}

public void onDestroyView() {
throw new RuntimeException("Stub!");
}

public void onDestroy() {
throw new RuntimeException("Stub!");
}
Expand Down
13 changes: 13 additions & 0 deletions moxy/src/main/java/com/arellomobile/mvp/MvpDelegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ public void onDetach() {
}
}

/**
* <p>View was being destroyed, but logical unit still alive</p>
*/
public void onDestroyView() {
for (MvpPresenter<? super Delegated> presenter : mPresenters) {
presenter.destroyView(mDelegated);
}

for (MvpDelegate<?> childDelegate : mChildDelegates) {
childDelegate.onDestroyView();
}
}

/**
* <p>Destroy presenters.</p>
*/
Expand Down
6 changes: 6 additions & 0 deletions moxy/src/main/java/com/arellomobile/mvp/MvpPresenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public void detachView(View view) {
}
}

public void destroyView(View view) {
if (mViewState != null) {
mViewState.destroyView(view);
}
}

/**
* @return views attached to view state, or attached to presenter(if view state not exists)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public void detachView(View view) {
mInRestoreState.remove(view);
}

public void destroyView(View view) {
mViewStates.remove(view);
}

/**
* @param view target view
* @return commands that was applied already
Expand Down
6 changes: 3 additions & 3 deletions sample-github/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dependencies {
testCompile "org.hamcrest:hamcrest-all:1.3"
testCompile "org.robolectric:robolectric:3.1-rc1"

compile 'com.arello-mobile:moxy:1.3.1'
compile 'com.arello-mobile:moxy-app-compat:1.3.1'
apt 'com.arello-mobile:moxy-compiler:1.3.1'
compile 'com.arello-mobile:moxy:1.3.2'
compile 'com.arello-mobile:moxy-app-compat:1.3.2'
apt 'com.arello-mobile:moxy-compiler:1.3.2'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.arellomobile.mvp.sample.github.mvp.presenters;

import java.util.List;

import android.util.Log;

import com.arellomobile.mvp.InjectViewState;
import com.arellomobile.mvp.MvpPresenter;
import com.arellomobile.mvp.sample.github.mvp.models.Repository;
import com.arellomobile.mvp.sample.github.mvp.views.RepositoryView;

/**
* Date: 27.01.2016
* Time: 21:12
*
* @author Yuri Shmakov
*/
@InjectViewState
public class RepositoryWidgetPresenter extends MvpPresenter<RepositoryView> {
private boolean mIsInitialized = false;
private Repository mRepository;
private List<Integer> mInProgress;
private List<Integer> mLikedIds;

public RepositoryWidgetPresenter() {
super();

Log.i("***-***", "Create new presenter");
}

public void setRepository(Repository repository) {
if (mIsInitialized) {
return;
}
mIsInitialized = true;

mRepository = repository;

getViewState().showRepository(repository);

updateLikes(mInProgress, mLikedIds);
}

public void updateLikes(List<Integer> inProgress, List<Integer> likedIds) {
mInProgress = inProgress;
mLikedIds = likedIds;

if (mRepository == null || mInProgress == null || mLikedIds == null) {
return;
}

boolean isInProgress = inProgress.contains(mRepository.getId());
boolean isLiked = likedIds.contains(mRepository.getId());

getViewState().updateLike(isInProgress, isLiked);
}

@Override
public void onDestroy() {
super.onDestroy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ void bind(int position, Repository repository) {
if (getMvpDelegate() != null) {
getMvpDelegate().onSaveInstanceState(getMvpDelegate().getChildrenSaveState());
getMvpDelegate().onDetach();
getMvpDelegate().onDestroyView();
mMvpDelegate = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.arellomobile.mvp.presenter.InjectPresenter;
import com.arellomobile.mvp.presenter.ProvidePresenter;
import com.arellomobile.mvp.sample.github.mvp.models.Repository;
import com.arellomobile.mvp.sample.github.mvp.presenters.RepositoryPresenter;
import com.arellomobile.mvp.sample.github.mvp.presenters.RepositoryWidgetPresenter;
import com.arellomobile.mvp.sample.github.mvp.views.RepositoryView;

/**
Expand All @@ -28,7 +28,7 @@ public class RepositoryWidget extends TextView implements RepositoryView {
private Repository mRepository;

@InjectPresenter
RepositoryPresenter mRepositoryPresenter;
RepositoryWidgetPresenter mRepositoryPresenter;

public RepositoryWidget(Context context) {
super(context);
Expand All @@ -48,8 +48,8 @@ public RepositoryWidget(Context context, AttributeSet attrs, int defStyleAttr, i
}

@ProvidePresenter
RepositoryPresenter provideRepositoryPresenter() {
return new RepositoryPresenter();
RepositoryWidgetPresenter provideRepositoryPresenter() {
return new RepositoryWidgetPresenter();
}

public void setRepository(MvpDelegate parentDelegate, Repository repository) {
Expand All @@ -62,14 +62,6 @@ public void setRepository(MvpDelegate parentDelegate, Repository repository) {
mRepositoryPresenter.setRepository(mRepository);
}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();

getMvpDelegate().onSaveInstanceState();
getMvpDelegate().onDetach();
}

public MvpDelegate getMvpDelegate() {
if (mMvpDelegate == null) {
mMvpDelegate = new MvpDelegate<>(this);
Expand Down
6 changes: 3 additions & 3 deletions sample-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ android {
dependencies {
compile 'com.android.support:appcompat-v7:25.0.0'

compile 'com.arello-mobile:moxy:1.3.1'
compile 'com.arello-mobile:moxy-app-compat:1.3.1'
kapt 'com.arello-mobile:moxy-compiler:1.3.1'
compile 'com.arello-mobile:moxy:1.3.2'
compile 'com.arello-mobile:moxy-app-compat:1.3.2'
kapt 'com.arello-mobile:moxy-compiler:1.3.2'

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

0 comments on commit bbfa096

Please sign in to comment.