Skip to content

Commit

Permalink
Merge branch 'dev/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksTuev committed Feb 22, 2017
2 parents 16880d6 + ada11a8 commit f6ef29b
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 87 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {

//tasks.findByPath(':ferro-core:javadoc').enabled = false
//tasks.findByPath(':ferro-mvp:javadoc').enabled = false
tasks.findByPath(':ferro-mvp-rx:javadoc').enabled = false
//tasks.findByPath(':ferro-mvp-rx:javadoc').enabled = false
//tasks.findByPath(':ferro-rx:javadoc').enabled = false


Expand Down
4 changes: 2 additions & 2 deletions ferro-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'com.android.library'
siteUrl = 'https://github.com/MaksTuev/ferro'
gitUrl = 'https://github.com/MaksTuev/ferro.git'
libraryVersion = '1.0.2'
libraryVersion = '1.1.0'
developerId = 'makstuev'
developerName = 'Maks Tuev'
Expand All @@ -32,7 +32,7 @@ android {
minSdkVersion 11
targetSdkVersion 23
versionCode 3
versionName "1.0.2"
versionName "1.1.0"
}
buildTypes {
release {
Expand Down
35 changes: 17 additions & 18 deletions ferro-core/src/main/java/com/agna/ferro/core/PSSActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,41 @@
* The name from {@link HasName#getName()} used for distinguish one PersistentScreenScope from
* another inside one Activity. You can use this name for logging, analytics etc.
*/
public abstract class PSSActivity extends AppCompatActivity implements HasName {
public abstract class PSSActivity extends AppCompatActivity implements PSSParentScreen {

private PersistentScreenScope screenScope;
private PSSDelegate delegate = new PSSActivityDelegate(this, this);

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initPersistentScreenScope();
delegate.init();
}

@Override
protected void onDestroy() {
super.onDestroy();
delegate.onDestroy();
}

@Override
protected void onResume() {
super.onResume();
delegate.checkUniqueScreenName();
}

/**
* @return true if screen was recreated after changing configuration
*/
public boolean isScreenRecreated() {
return screenScope.isScreenRecreated();
return delegate.isScreenRecreated();
}

/**
* @return {@link PersistentScreenScope} of this screen
*/
@Override
public PersistentScreenScope getPersistentScreenScope() {
return screenScope;
}

private void initPersistentScreenScope() {
screenScope = PersistentScreenScope.find(this);
if (screenScope == null) {
screenScope = createPersistentScreenScope();
screenScope.attach(this);
}
screenScope.updateParent(this);
}

protected PersistentScreenScope createPersistentScreenScope() {
return new PersistentScreenScope();
return delegate.getScreenScope();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.agna.ferro.core;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

/**
* delegate for managing of {@link PersistentScreenScope} on activity
*/
public class PSSActivityDelegate extends PSSDelegate {

private final FragmentActivity parentActivity;

public PSSActivityDelegate(HasName screenNameProvider, FragmentActivity parentActivity) {
super(screenNameProvider);
this.parentActivity = parentActivity;
}

@Override
protected FragmentActivity getParentActivity() {
return parentActivity;
}

@Override
protected Fragment getParentFragment() {
return null;
}
}
74 changes: 74 additions & 0 deletions ferro-core/src/main/java/com/agna/ferro/core/PSSDelegate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.agna.ferro.core;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;

/**
* base delegate for managing {@link PersistentScreenScope}
*/
public abstract class PSSDelegate {

private PersistentScreenScope screenScope;
private HasName screenNameProvider;

public PSSDelegate(HasName screenNameProvider) {
this.screenNameProvider = screenNameProvider;
}

protected abstract FragmentActivity getParentActivity();

protected abstract Fragment getParentFragment();

protected PersistentScreenScope createPersistentScreenScope() {
return new PersistentScreenScope();
}

public PersistentScreenScope getScreenScope() {
return screenScope;
}

public boolean isScreenRecreated() {
return screenScope.isScreenRecreated();
}

public void init() {
screenScope = PersistentScreenScope.find(getFragmentManager(), screenNameProvider.getName());
if (screenScope == null) {
screenScope = createPersistentScreenScope();
screenScope.attach(getFragmentManager(), screenNameProvider.getName());
}
screenScope.setParentActivity(getParentActivity());
screenScope.setParentPSSFragment(getParentFragment());
}

private FragmentManager getFragmentManager() {
return getParentActivity().getSupportFragmentManager();
}

public void onDestroy() {
if (screenScope != null) {
screenScope.clearParentActivity();
screenScope.clearParentPSSFragment();
}
}

public void checkUniqueScreenName() {
checkUniqueScreenName(getParentActivity());
for(Fragment fragment : getFragmentManager().getFragments()){
checkUniqueScreenName(fragment);
}
}

private void checkUniqueScreenName(Object anotherScreen) {
if (screenNameProvider != anotherScreen) {
if(HasName.class.isInstance(anotherScreen)){
String anotherName = ((PSSParentScreen)anotherScreen).getName();
if(anotherName.equals(screenNameProvider.getName())){
throw new IllegalStateException("two screens has same name: "+ anotherScreen
+ ", " + screenNameProvider);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.agna.ferro.core;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;

/**
* delegate for managing of {@link PersistentScreenScope} on fragment
*/
public class PSSFragmentDelegate extends PSSDelegate {

private final Fragment parentFragment;

public PSSFragmentDelegate(HasName screenNameProvider, Fragment parentFragment) {
super(screenNameProvider);
this.parentFragment = parentFragment;
}

@Override
protected FragmentActivity getParentActivity() {
return parentFragment.getActivity();
}

@Override
protected Fragment getParentFragment() {
return parentFragment;
}
}
42 changes: 21 additions & 21 deletions ferro-core/src/main/java/com/agna/ferro/core/PSSFragmentV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,55 @@
/**
* This fragment provide access to own {@link PersistentScreenScope}
* PSS - PersistentScreenScope
*
* <p>
* The name from {@link HasName#getName()} used for distinguish one PersistentScreenScope from
* another inside one Activity. You can use this name for logging, analytics etc.
*/
public abstract class PSSFragmentV4 extends Fragment implements HasName {
public abstract class PSSFragmentV4 extends Fragment implements PSSParentScreen {

private PersistentScreenScope screenScope;
private PSSDelegate delegate = new PSSFragmentDelegate(this, this);

@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
initPersistentScreenScope();
delegate.init();
}

@Override
public void onDestroy() {
super.onDestroy();
delegate.onDestroy();
}

@Override
public void onResume() {
super.onResume();
delegate.checkUniqueScreenName();
}

/**
* @return true if screen was recreated after changing configuration
*/
public boolean isScreenRecreated() {
return screenScope.isScreenRecreated();
return delegate.isScreenRecreated();
}

/**
* @return {@link PersistentScreenScope} of this screen
*/
@Override
public PersistentScreenScope getPersistentScreenScope() {
return screenScope;
return delegate.getScreenScope();
}

/**
* Clear all objects from own {@link PersistentScreenScope}
*/
@Deprecated
public void clearPersistentScreenScope() {
PersistentScreenScope screenScope = delegate.getScreenScope();
if (screenScope != null) {
screenScope.clear();
}
}

private void initPersistentScreenScope() {
screenScope = PersistentScreenScope.find(this);
if (screenScope == null) {
screenScope = createPersistentScreenScope();
screenScope.attach(this);
}
screenScope.updateParent(getActivity());
}


protected PersistentScreenScope createPersistentScreenScope() {
return new PersistentScreenScope();
}

}
13 changes: 13 additions & 0 deletions ferro-core/src/main/java/com/agna/ferro/core/PSSParentScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.agna.ferro.core;

/**
* interface for screen, which is parent of {@link PersistentScreenScope}
*/
public interface PSSParentScreen extends HasName {

/**
* @return {@link PersistentScreenScope} of this screen
*/
PersistentScreenScope getPersistentScreenScope();

}
Loading

0 comments on commit f6ef29b

Please sign in to comment.