Commit c2a1fef9 by amateur

1

1 parent ee9add31
package com.polysoft.nafmii.bean;
import com.alibaba.fastjson.annotation.JSONField;
public class AdvertisementBean {
@JSONField(name = "picUrl")
String picUrl;
@JSONField(name = "linkUrl")
String linkUrl;
@JSONField(name = "linkType")
String linkType;
@JSONField(name = "isShare")
int isShare;
@JSONField(name = "isLogin")
int isLogin;
public String getPicUrl() {
return picUrl;
}
public String getLinkUrl() {
return linkUrl;
}
public String getLinkType() {
return linkType;
}
public int getIsShare() {
return isShare;
}
public int getIsLogin() {
return isLogin;
}
public void setPicUrl(String picUrl) {
this.picUrl = picUrl;
}
public void setLinkUrl(String linkUrl) {
this.linkUrl = linkUrl;
}
public void setLinkType(String linkType) {
this.linkType = linkType;
}
public void setIsShare(int isShare) {
this.isShare = isShare;
}
public void setIsLogin(int isLogin) {
this.isLogin = isLogin;
}
}
...@@ -45,8 +45,8 @@ public abstract class RequestBack<T> { ...@@ -45,8 +45,8 @@ public abstract class RequestBack<T> {
} }
JSONObject res = JSON.parseObject(string); JSONObject res = JSON.parseObject(string);
int status = res.getInteger("status"); String status = res.getString("status");
if (status == 200) { if ("0".equals(status)) {
String json = res.getString("data"); String json = res.getString("data");
Log.d("onParseResponse", "onParseResponse: " + json); Log.d("onParseResponse", "onParseResponse: " + json);
Type type = this.getClass().getGenericSuperclass(); Type type = this.getClass().getGenericSuperclass();
......
...@@ -13,12 +13,16 @@ import androidx.lifecycle.ViewModel; ...@@ -13,12 +13,16 @@ import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner; import androidx.lifecycle.ViewModelStoreOwner;
import com.polysoft.nafmii.bean.AdvertisementBean;
import com.polysoft.nafmii.constants.ServerApi;
import com.polysoft.nafmii.enums.StateEnum;
import com.polysoft.nafmii.net.RequestBack;
import com.polysoft.nafmii.utils.TimerUtils; import com.polysoft.nafmii.utils.TimerUtils;
import com.whaty.nafmii.BuildConfig; import com.whaty.nafmii.BuildConfig;
public class AdvertisementViewModel extends ViewModel { public class AdvertisementViewModel extends ViewModel {
private MutableLiveData<LiveData> data = new MutableLiveData<>(); private MutableLiveData<LiveData> dataModel = new MutableLiveData<>();
private final LifecycleOwner owner; private final LifecycleOwner owner;
public static AdvertisementViewModel newInstance(FragmentActivity owner) { public static AdvertisementViewModel newInstance(FragmentActivity owner) {
...@@ -35,27 +39,40 @@ public class AdvertisementViewModel extends ViewModel { ...@@ -35,27 +39,40 @@ public class AdvertisementViewModel extends ViewModel {
AdvertisementViewModel(LifecycleOwner owner) { AdvertisementViewModel(LifecycleOwner owner) {
this.owner = owner; this.owner = owner;
System.out.println("=====================>>>>>AdvertisementViewModel"); this.fetchData();
TimerUtils.setTimeOut(msg -> {
this.data.setValue(new LiveData());
return false;
}, 1000);
} }
public void observe(Observer<LiveData> observer) { public void observe(Observer<LiveData> observer) {
this.data.observe(this.owner, observer); this.dataModel.observe(this.owner, observer);
}
private void fetchData() {
ServerApi.postAdvertisement(new RequestBack<AdvertisementBean>() {
@Override
protected void onResponse(StateEnum state, AdvertisementBean data, String message) {
if (state.state == StateEnum.OK.state) {
dataModel.setValue(new LiveData(data));
} else {
dataModel.setValue(new LiveData(null));
}
}
});
} }
public static class LiveData { public static class LiveData {
public String json; public final AdvertisementBean data;
LiveData(AdvertisementBean data) {
this.data = data;
}
public boolean empty() { public boolean empty() {
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
return true; return false;
} }
return TextUtils.isEmpty(json); return null == this.data || TextUtils.isEmpty(this.data.getPicUrl());
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!