-
Notifications
You must be signed in to change notification settings - Fork 503
/
NormalFragment.java
70 lines (62 loc) · 2.4 KB
/
NormalFragment.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package sample.kingja.loadsir.target;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.kingja.loadsir.callback.Callback;
import com.kingja.loadsir.core.LoadService;
import com.kingja.loadsir.core.LoadSir;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import butterknife.ButterKnife;
import sample.kingja.loadsir.PostUtil;
import sample.kingja.loadsir.R;
import sample.kingja.loadsir.callback.CustomCallback;
import sample.kingja.loadsir.callback.ErrorCallback;
import sample.kingja.loadsir.callback.LoadingCallback;
/**
* Description:TODO
* Create Time:2017/9/5 13:28
* Author:KingJA
* Email:kingjavip@gmail.com
*/
public class NormalFragment extends Fragment {
private LoadService loadService;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
LoadSir loadSir = new LoadSir.Builder()
.addCallback(new CustomCallback())
.addCallback(new LoadingCallback())
.addCallback(new ErrorCallback())
.setDefaultCallback(LoadingCallback.class)
.build();
View rootView = inflater.inflate(R.layout.fragment_a_content, container, false);
ButterKnife.bind(this, rootView);
loadService = loadSir.register(rootView, new Callback.OnReloadListener() {
@Override
public void onReload(View v) {
// Your can change the status out of Main thread.
new Thread(new Runnable() {
@Override
public void run() {
loadService.showCallback(LoadingCallback.class);
//do retry logic...
SystemClock.sleep(500);
//callback
loadService.showCallback(CustomCallback.class);
}
}).start();
}
});
return loadService.getLoadLayout();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
PostUtil.postCallbackDelayed(loadService, ErrorCallback.class);
}
}