Skip to content

Commit

Permalink
add KeyHolder and set key for custom viewgroups
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhuinden committed Jan 13, 2017
1 parent 4831341 commit 7e2ecf5
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public class MainActivity extends AppCompatActivity implements StateChanger {
View view = LayoutInflater.from(this).inflate(newKey.layout(), root, false);
BackstackHolder backstackHolder = (BackstackHolder)view;
backstackHolder.setBackstack(backstack); // view currently doesn't implicitly receive the backstack
KeyHolder keyHolder = (KeyHolder)view;
keyHolder.setKey(newKey); // view currently doesn't implicitly receive the key
root.addView(view);
completionCallback.stateChangeComplete();
}
Expand All @@ -117,6 +119,6 @@ Scheduling a state change while a state change is already in progress throws an

## Demo limitations

In the demo, keys associated with the given custom views are currently not manually set for the custom views, therefore it is not accessible at the moment.
In the demo, keys associated with the given custom views are manually set for the custom views, therefore it is set via an interface, but is not accessible for any child views of the custom viewgroup.

In the demo, the backstack is manually set to the custom viewgroup using a `BackStackHolder` interface, instead of implicitly providing it via the Context.
In the demo, the backstack is also manually set to the custom viewgroup using a `BackStackHolder` interface, instead of implicitly providing it via the Context.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.zhuinden.simplestackdemoexample.demo.FirstKey;
import com.zhuinden.simplestackdemoexample.demo.Key;
import com.zhuinden.simplestackdemoexample.R;
import com.zhuinden.simplestackdemoexample.demo.KeyHolder;

import java.util.ArrayList;
import butterknife.BindView;
Expand Down Expand Up @@ -82,6 +83,8 @@ public void handleStateChange(StateChange stateChange, Callback completionCallba
View view = LayoutInflater.from(this).inflate(newKey.layout(), root, false);
BackstackHolder backstackHolder = (BackstackHolder)view;
backstackHolder.setBackstack(backstack);
KeyHolder keyHolder = (KeyHolder)view;
keyHolder.setKey(newKey);
root.addView(view);
completionCallback.stateChangeComplete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Created by Owner on 2017. 01. 12..
*/

public class FirstView extends RelativeLayout implements BackstackHolder {
public class FirstView extends RelativeLayout implements BackstackHolder, KeyHolder {
public FirstView(Context context) {
super(context);
}
Expand All @@ -33,6 +33,8 @@ public FirstView(Context context, AttributeSet attrs, int defStyleAttr, int defS

Backstack backstack;

FirstKey firstKey;

@OnClick(R.id.first_button)
public void clickButton(View view) {
backstack.goTo(new SecondKey());
Expand All @@ -48,4 +50,9 @@ protected void onFinishInflate() {
public void setBackstack(Backstack backstack) {
this.backstack = backstack;
}

@Override
public void setKey(Key key) {
this.firstKey = (FirstKey)key;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.zhuinden.simplestackdemoexample.demo;

/**
* Created by Owner on 2017. 01. 13..
*/

public interface KeyHolder {
void setKey(Key key);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
* Created by Owner on 2017. 01. 12..
*/

public class SecondView extends RelativeLayout implements BackstackHolder {

public class SecondView extends RelativeLayout implements BackstackHolder, KeyHolder {
public SecondView(Context context) {
super(context);
}
Expand All @@ -31,8 +30,15 @@ public SecondView(Context context, AttributeSet attrs, int defStyleAttr, int def

Backstack backstack;

SecondKey secondKey;

@Override
public void setBackstack(Backstack backstack) {
this.backstack = backstack;
}

@Override
public void setKey(Key key) {
this.secondKey = (SecondKey)key;
}
}

0 comments on commit 7e2ecf5

Please sign in to comment.