forked from sdwfqin/AndroidQuick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeatherMvvmActivity.java
51 lines (39 loc) · 1.42 KB
/
WeatherMvvmActivity.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
package com.sdwfqin.quickseed.ui.mvvm;
import androidx.lifecycle.ViewModelProvider;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.LogUtils;
import com.sdwfqin.quickseed.constants.ArouterConstants;
import com.sdwfqin.quickseed.databinding.ActivityWeatherMvvmBinding;
import io.github.sdwfqin.samplecommonlibrary.base.SampleBaseMvvmActivity;
/**
* 获取天气信息 mvvm
* <p>
*
* @author 张钦
* @date 2020/4/14
*/
@Route(path = ArouterConstants.COMPONENTS_MVVM)
public class WeatherMvvmActivity extends SampleBaseMvvmActivity<ActivityWeatherMvvmBinding, WeatherViewModel> {
@Override
protected ActivityWeatherMvvmBinding getViewBinding() {
return ActivityWeatherMvvmBinding.inflate(getLayoutInflater());
}
@Override
protected WeatherViewModel getViewModel() {
return new ViewModelProvider(this).get(WeatherViewModel.class);
}
@Override
protected void initEventAndData() {
mTopBar.setTitle("MVVM DEMO");
mTopBar.addLeftBackImageButton().setOnClickListener(v -> finish());
mBinding.setViewModel(mVm);
mBinding.setHandlers(new WeatherMvvmHandlers());
mBinding.setLifecycleOwner(this);
mVm.birthDate.observe(this, LogUtils::e);
mVm.loadWeather();
}
@Override
protected void commonNetworkErrorListener(Throwable throwable) {
showMsg(throwable.getMessage());
}
}