-
Notifications
You must be signed in to change notification settings - Fork 1
/
BetterGetActivity.java
72 lines (58 loc) · 2.38 KB
/
BetterGetActivity.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
package com.dwgg.retrofitandrxjava;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.view.View;
import com.dwgg.retrofitandrxjava.api.GitHubService;
import com.dwgg.retrofitandrxjava.api.MySubscriber;
import com.dwgg.retrofitandrxjava.api.entity.GitHubUser;
import com.dwgg.retrofitandrxjava.api.utils.ServiceGenerator;
import com.dwgg.retrofitandrxjava.databinding.ActivityGetBinding;
import com.dwgg.retrofitandrxjava.listener.ClickListener;
import com.dwgg.retrofitandrxjava.utils.RxUtils;
import com.dwgg.retrofitandrxjava.utils.Tools;
import com.dwgg.retrofitandrxjava.utils.ViewUtil;
import com.dwgg.retrofitandrxjava.vmdata.GetVM;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;
import rx.schedulers.Schedulers;
import timber.log.Timber;
public class BetterGetActivity extends RxAppCompatActivity implements ClickListener, RxUtils.ILoading {
private ActivityGetBinding binding;
private GetVM vmData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
vmData = new GetVM();
binding = DataBindingUtil.setContentView(this, R.layout.activity_get);
binding.setListener(this);
binding.setData(vmData);
if (BuildConfig.DEBUG) {
binding.username.setText("JakeWharton");
}
}
@Override
public void onClick(View view) {
vmData.clear();
ServiceGenerator.createService(GitHubService.class)
.getUser(ViewUtil.getEditText(binding.username))
.compose(this.<GitHubUser>bindToLifecycle())
.compose(RxUtils.<GitHubUser>validateGitHubResponse(this))
.subscribeOn(Schedulers.io())
.compose(RxUtils.<GitHubUser>showLoading(this))
.subscribe(new MySubscriber<GitHubUser>() {
@Override
public void onNext(GitHubUser gitHubUser) {
vmData.setText(gitHubUser.toString());
}
});
}
@Override
public void showLoading(String tip) {
Timber.d("thread of showLoading = %s", Thread.currentThread().getName());
Tools.toast(this, tip);
}
@Override
public void hideLoading() {
Timber.d("thread of hideLoading = %s", Thread.currentThread().getName());
Tools.toast(this, "over.");
}
}