Skip to content

Commit 62b9516

Browse files
committed
added view to listener
1 parent 938c48f commit 62b9516

File tree

5 files changed

+58
-41
lines changed

5 files changed

+58
-41
lines changed

app/src/main/java/com/hololo/tutorial/sample/MainActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public class MainActivity extends TutorialActivity {
1414

1515
private View currentFragmentView;
16-
private int currentPosition;
16+
private String currentFragmentTag;
1717

1818
@Override
1919
protected void onCreate(Bundle savedInstanceState) {
@@ -39,8 +39,8 @@ public void currentFragmentPosition(int position) {
3939
}
4040

4141
@Override
42-
public void currentFragmentView(View view, int position) {
42+
public void currentFragmentView(View view, String tag) {
4343
currentFragmentView = view;
44-
currentPosition = position;
44+
currentFragmentTag = tag;
4545
}
4646
}

library/src/main/java/com/hololo/tutorial/library/CurrentFragmentListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
public interface CurrentFragmentListener {
66
void currentFragmentPosition(int position);
77

8-
void currentFragmentView(View view, int position);
8+
void currentFragmentView(View view, String position);
99
}

library/src/main/java/com/hololo/tutorial/library/PermissionStep.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public Builder setView(int view) {
5959
step.setViewType(view);
6060
return this;
6161
}
62+
63+
public Builder setTag(String tag) {
64+
step.setTag(tag);
65+
return this;
66+
}
6267
}
6368

6469
}

library/src/main/java/com/hololo/tutorial/library/Step.java

Lines changed: 48 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,37 @@
55

66
public class Step implements Parcelable {
77

8+
public static final Creator<Step> CREATOR = new Creator<Step>() {
9+
@Override
10+
public Step createFromParcel(Parcel source) {
11+
return new Step(source);
12+
}
13+
14+
@Override
15+
public Step[] newArray(int size) {
16+
return new Step[size];
17+
}
18+
};
819
private String title;
920
private String content;
1021
private String summary;
22+
private String tag;
1123
private int drawable;
1224
private int backgroundColor;
1325
private int viewType;
1426

1527
public Step() {
1628
}
1729

30+
protected Step(Parcel in) {
31+
this.title = in.readString();
32+
this.content = in.readString();
33+
this.summary = in.readString();
34+
this.drawable = in.readInt();
35+
this.backgroundColor = in.readInt();
36+
this.viewType = in.readInt();
37+
}
38+
1839
public int getViewType() {
1940
return viewType;
2041
}
@@ -63,6 +84,29 @@ public void setSummary(String summary) {
6384
this.summary = summary;
6485
}
6586

87+
public String getTag() {
88+
return tag;
89+
}
90+
91+
public void setTag(String tag) {
92+
this.tag = tag;
93+
}
94+
95+
@Override
96+
public int describeContents() {
97+
return 0;
98+
}
99+
100+
@Override
101+
public void writeToParcel(Parcel dest, int flags) {
102+
dest.writeString(this.title);
103+
dest.writeString(this.content);
104+
dest.writeString(this.summary);
105+
dest.writeInt(this.drawable);
106+
dest.writeInt(this.backgroundColor);
107+
dest.writeInt(this.viewType);
108+
}
109+
66110
public static class Builder {
67111

68112
private Step step;
@@ -104,42 +148,10 @@ public Builder setView(int view) {
104148
step.viewType = view;
105149
return this;
106150
}
107-
}
108-
109-
110-
@Override
111-
public int describeContents() {
112-
return 0;
113-
}
114-
115-
@Override
116-
public void writeToParcel(Parcel dest, int flags) {
117-
dest.writeString(this.title);
118-
dest.writeString(this.content);
119-
dest.writeString(this.summary);
120-
dest.writeInt(this.drawable);
121-
dest.writeInt(this.backgroundColor);
122-
dest.writeInt(this.viewType);
123-
}
124-
125-
protected Step(Parcel in) {
126-
this.title = in.readString();
127-
this.content = in.readString();
128-
this.summary = in.readString();
129-
this.drawable = in.readInt();
130-
this.backgroundColor = in.readInt();
131-
this.viewType = in.readInt();
132-
}
133151

134-
public static final Creator<Step> CREATOR = new Creator<Step>() {
135-
@Override
136-
public Step createFromParcel(Parcel source) {
137-
return new Step(source);
138-
}
139-
140-
@Override
141-
public Step[] newArray(int size) {
142-
return new Step[size];
152+
public Builder setTag(String tag) {
153+
step.tag = tag;
154+
return this;
143155
}
144-
};
156+
}
145157
}

library/src/main/java/com/hololo/tutorial/library/StepFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
4141
int layout = step.getViewType() > 0 ? step.getViewType() : R.layout.fragment_step;
4242

4343
View view = inflater.inflate(layout, container, false);
44-
currentFragmentListener.currentFragmentView(view, position);
44+
currentFragmentListener.currentFragmentView(view, step.getTag());
4545
initViews(view);
4646
initData();
4747

0 commit comments

Comments
 (0)