-
-
Notifications
You must be signed in to change notification settings - Fork 195
/
BaseActivity.java
77 lines (67 loc) · 1.89 KB
/
BaseActivity.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
71
72
73
74
75
76
77
package com.hjq.easy.demo;
import android.app.ProgressDialog;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import com.hjq.http.config.IRequestApi;
import com.hjq.http.listener.OnHttpListener;
import com.hjq.toast.Toaster;
/**
* author : Android 轮子哥
* github : https://github.com/getActivity/EasyHttp
* time : 2019/05/19
* desc : 基类封装
*/
public class BaseActivity extends AppCompatActivity implements OnHttpListener<Object> {
/** 加载对话框 */
private ProgressDialog mDialog;
/** 对话框数量 */
private int mDialogTotal;
/**
* 当前加载对话框是否在显示中
*/
public boolean isShowDialog() {
return mDialog != null && mDialog.isShowing();
}
/**
* 显示加载对话框
*/
public void showDialog() {
if (mDialog == null) {
mDialog = new ProgressDialog(this);
mDialog.setMessage(getResources().getString(R.string.dialog_loading_hint));
mDialog.setCancelable(false);
mDialog.setCanceledOnTouchOutside(false);
}
if (!mDialog.isShowing()) {
mDialog.show();
}
mDialogTotal++;
}
/**
* 隐藏加载对话框
*/
public void hideDialog() {
if (mDialogTotal == 1) {
if (mDialog != null && mDialog.isShowing()) {
mDialog.dismiss();
}
}
if (mDialogTotal > 0) {
mDialogTotal--;
}
}
@Override
public void onHttpStart(@NonNull IRequestApi api) {
showDialog();
}
@Override
public void onHttpSuccess(@NonNull Object result) {}
@Override
public void onHttpFail(@NonNull Throwable throwable) {
Toaster.show(throwable.getMessage());
}
@Override
public void onHttpEnd(@NonNull IRequestApi api) {
hideDialog();
}
}