-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
276 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
ferro-core/src/main/java/com/agna/ferro/core/PSSActivityDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
74
ferro-core/src/main/java/com/agna/ferro/core/PSSDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
ferro-core/src/main/java/com/agna/ferro/core/PSSFragmentDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
ferro-core/src/main/java/com/agna/ferro/core/PSSParentScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} |
Oops, something went wrong.