Skip to content

Commit 9229ad8

Browse files
committed
Add some new apis
1 parent 3f940ee commit 9229ad8

File tree

12 files changed

+380
-83
lines changed

12 files changed

+380
-83
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,15 @@ Fragment
129129

130130
//Navigate from a fragment to a fragment
131131
GoRouter.getInstance().build("routeKey1")
132-
.setFragmentContainer(fragment's containerId)
132+
.setFragmentContainerId(fragment's containerId)
133133
.go()
134134
135135
136136
//With data
137137
Bundle data = new Bundle()
138138
data.putInt(key , value);
139139
GoRouter.getInstance().build("routeKey1" , data)
140-
.setFragmentContainer(fragment's containerId)
140+
.setFragmentContainerId(fragment's containerId)
141141
.go();
142142

143143
//Here you will navigation to RouteFragment

README_CN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ Fragment篇
123123

124124
//从某个fragment导航到某个fragment
125125
GoRouter.getInstance().build("routeKey1")
126-
.setFragmentContainer(fragment's containerId)
126+
.setFragmentContainerId(fragment's containerId)
127127
.go()
128128
129129
130130
//携带数据
131131
Bundle data = new Bundle()
132132
data.putInt(key , value);
133133
GoRouter.getInstance().build("routeKey1" , data)
134-
.setFragmentContainer(fragment's containerId)
134+
.setFragmentContainerId(fragment's containerId)
135135
.go();
136136

137137
//至此,你已导航到指定的fragment

app/src/main/java/cn/gorouter/MainActivity.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class MainActivity : AppCompatActivity(){
2626

2727
var data = Bundle()
2828
data.putInt("containerId" , R.id.flContainer)
29-
GoRouter.getInstance().build("app/TestFragment" , data)
30-
.setFragmentContainer(R.id.flContainer)
29+
GoRouter.getInstance().build("app/TestFragment")
30+
.withExtra(data)
31+
.withContainer(R.id.flContainer)
3132
.go()
3233

3334
}

app/src/main/java/cn/gorouter/TestFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void onClick(View v) {
4949
.go();
5050

5151
// GoRouter.getInstance().build("app/TestFragment2")
52-
// .setFragmentContainer(resId)
52+
// .setFragmentContainerId(resId)
5353
// .go();
5454

5555

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package cn.gorouter.api.card;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.view.View;
6+
7+
import cn.gorouter.api.exception.DataEmptyException;
8+
9+
/**
10+
* @author logcat
11+
*/
12+
public class GoBoard {
13+
private int flag;
14+
private String routeKey;
15+
private int fragmentContainerId;
16+
private Bundle data;
17+
18+
public Bundle getData() {
19+
return data;
20+
}
21+
22+
public void setData(Bundle data) {
23+
this.data = data;
24+
}
25+
26+
public int getFragmentContainerId() {
27+
return fragmentContainerId;
28+
}
29+
30+
public void setFragmentContainerId(int fragmentContainerId) {
31+
this.fragmentContainerId = fragmentContainerId;
32+
}
33+
34+
public int getFlag() {
35+
return flag;
36+
}
37+
38+
public void setFlag(int flag) {
39+
this.flag = flag;
40+
}
41+
42+
public String getRouteKey() {
43+
return routeKey;
44+
}
45+
46+
public void setRouteKey(String routeKey) {
47+
this.routeKey = routeKey;
48+
}
49+
50+
public void putInt(String key , int intValue){
51+
try {
52+
checkDataNotNull();
53+
} catch (DataEmptyException e) {
54+
e.printStackTrace();
55+
data = new Bundle();
56+
}
57+
58+
data.putInt(key , intValue);
59+
}
60+
61+
public void putFloat(String key , float floatValue){
62+
try {
63+
checkDataNotNull();
64+
} catch (DataEmptyException e) {
65+
e.printStackTrace();
66+
data = new Bundle();
67+
}
68+
data.putFloat(key , floatValue);
69+
}
70+
71+
72+
public void putLong(String key , long longValue){
73+
try {
74+
checkDataNotNull();
75+
} catch (DataEmptyException e) {
76+
e.printStackTrace();
77+
data = new Bundle();
78+
}
79+
80+
data.putLong(key , longValue);
81+
}
82+
83+
84+
public void putShort(String key , short shortValue){
85+
try {
86+
checkDataNotNull();
87+
} catch (DataEmptyException e) {
88+
e.printStackTrace();
89+
data = new Bundle();
90+
}
91+
data.putShort(key , shortValue);
92+
}
93+
94+
public void putDouble(String key , double doubleValue){
95+
try {
96+
checkDataNotNull();
97+
} catch (DataEmptyException e) {
98+
e.printStackTrace();
99+
data = new Bundle();
100+
}
101+
data.putDouble(key , doubleValue);
102+
}
103+
104+
public void putString(String key , String value){
105+
try {
106+
checkDataNotNull();
107+
} catch (DataEmptyException e) {
108+
e.printStackTrace();
109+
data = new Bundle();
110+
}
111+
data.putString(key , value);
112+
}
113+
114+
115+
public void putCharSequence(String key , CharSequence charSequenceValue){
116+
try {
117+
checkDataNotNull();
118+
} catch (DataEmptyException e) {
119+
e.printStackTrace();
120+
data = new Bundle();
121+
}
122+
123+
data.putCharSequence(key , charSequenceValue);
124+
}
125+
126+
127+
public void release(){
128+
this.data = null;
129+
this.routeKey = null;
130+
this.flag = Intent.FLAG_ACTIVITY_NEW_TASK;
131+
this.fragmentContainerId = View.NO_ID;
132+
}
133+
134+
private void checkDataNotNull() throws DataEmptyException {
135+
if(this.data == null){
136+
throw new DataEmptyException("Data is empty!!!");
137+
}
138+
}
139+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package cn.gorouter.api.exception;
2+
3+
import androidx.annotation.Nullable;
4+
5+
/**
6+
* @author logcat
7+
* @date 2020/09/22
8+
*/
9+
public class DataEmptyException extends Exception {
10+
public DataEmptyException(String message) {
11+
super(message);
12+
}
13+
}

0 commit comments

Comments
 (0)