33
This commit is contained in:
@@ -0,0 +1,418 @@
|
||||
package cn.shangyu.gdxzExpert.activity;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
import com.gyf.immersionbar.ImmersionBar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.shangyu.gdxzExpert.R;
|
||||
import cn.shangyu.gdxzExpert.adapter.PatientTeachAdapter;
|
||||
import cn.shangyu.gdxzExpert.base.BaseActivity;
|
||||
import cn.shangyu.gdxzExpert.bean.PatientTeachBean;
|
||||
import cn.shangyu.gdxzExpert.bean.PatientTeachBean.PatientTBean;
|
||||
import cn.shangyu.gdxzExpert.http.OnCallBackFromNet;
|
||||
import cn.shangyu.gdxzExpert.pulltorefreshview.PullToRefreshBase;
|
||||
import cn.shangyu.gdxzExpert.pulltorefreshview.PullToRefreshBase.Mode;
|
||||
import cn.shangyu.gdxzExpert.pulltorefreshview.PullToRefreshBase.OnRefreshListener2;
|
||||
import cn.shangyu.gdxzExpert.pulltorefreshview.PullToRefreshListView;
|
||||
import cn.shangyu.gdxzExpert.utils.CommonUtil;
|
||||
import cn.shangyu.gdxzExpert.utils.GsonTools;
|
||||
import cn.shangyu.gdxzExpert.utils.SharePrefUtil;
|
||||
import cn.shangyu.gdxzExpert.utils.StringUtil;
|
||||
import cn.shangyu.gdxzExpert.utils.ToastUtil;
|
||||
import cn.shangyu.gdxzExpert.utils.Url;
|
||||
import cn.shangyu.gdxzExpert.view.DrawableCenterButton;
|
||||
import cn.shangyu.gdxzExpert.view.DrawableCenterCheckBox;
|
||||
import cn.shangyu.gdxzExpert.widget.ECAlertDialog;
|
||||
import cn.shangyu.gdxzExpert.widget.LoadingPage.ResultState;
|
||||
|
||||
public class PatientTeachActivity extends BaseActivity implements
|
||||
OnCallBackFromNet, OnItemClickListener {
|
||||
|
||||
private PullToRefreshListView ptrLv;
|
||||
private LinearLayout ll_empty;
|
||||
private TextView tv_empty_msg;
|
||||
private int page = 1;
|
||||
private String searchStr;
|
||||
private PatientTeachActivity mActivity;
|
||||
private EditText mEt_search;
|
||||
private ImageView mIv_search;
|
||||
private ECAlertDialog buildAlert;
|
||||
private DrawableCenterButton ib_search;
|
||||
private DrawableCenterCheckBox cb_kp_jx;
|
||||
private String topic = "1";
|
||||
|
||||
@Override
|
||||
public void setTitle() {
|
||||
// TODO Auto-generated method stub
|
||||
top_title.setText("患教学堂");
|
||||
if(CommonUtil.BigModule())
|
||||
{
|
||||
top_title.setTextSize(23);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateSuccessedView() {
|
||||
// TODO Auto-generated method stub
|
||||
ImmersionBar.with(this).keyboardEnable(true).statusBarDarkFont(true).titleBar(mToolbar).init();
|
||||
View view;
|
||||
if(CommonUtil.BigModule())
|
||||
{
|
||||
view = View.inflate(ct, R.layout.activity_patient_teach_big, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
view = View.inflate(ct, R.layout.activity_patient_teach, null);
|
||||
}
|
||||
|
||||
mActivity = this;
|
||||
mEt_search = (EditText) view.findViewById(R.id.search);
|
||||
mIv_search = (ImageView) view.findViewById(R.id.iv_search);
|
||||
ib_search = view.findViewById(R.id.ib_search);
|
||||
cb_kp_jx = view.findViewById(R.id.cb_kp_jx);
|
||||
ib_search.setOnClickListener(this);
|
||||
cb_kp_jx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView,
|
||||
boolean isChecked) {
|
||||
// TODO Auto-generated method stub
|
||||
page = 1;
|
||||
if (isChecked) {
|
||||
topic = "2";
|
||||
cb_kp_jx.setText("最热");
|
||||
String result = SharePrefUtil.getString(mActivity,
|
||||
Url.getPolularScienceArticleListByKeywordsNew + "R",
|
||||
"");
|
||||
if (!StringUtil.isEmpty(result)) {
|
||||
processData(result);
|
||||
} else {
|
||||
getScienceList();
|
||||
}
|
||||
|
||||
} else {
|
||||
topic = "1";
|
||||
cb_kp_jx.setText("最新");
|
||||
String result = SharePrefUtil.getString(mActivity,
|
||||
Url.getPolularScienceArticleListByKeywordsNew + "X",
|
||||
"");
|
||||
if (!StringUtil.isEmpty(result)) {
|
||||
processData(result);
|
||||
} else {
|
||||
getScienceList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// 下拉刷新的listview控件
|
||||
ptrLv = (PullToRefreshListView) view.findViewById(R.id.lv_item_news);
|
||||
// 空布局,处理
|
||||
ll_empty = (LinearLayout) view.findViewById(R.id.ll_empty);
|
||||
tv_empty_msg = (TextView) view.findViewById(R.id.tv_empty_msg);
|
||||
// 设置空的提示信息,默认是“暂时没有数据”
|
||||
tv_empty_msg.setText("暂无患教学堂");
|
||||
ptrLv.setMode(Mode.BOTH);
|
||||
// 得到实际的ListView 设置点击
|
||||
ptrLv.getRefreshableView().setOnItemClickListener(this);
|
||||
|
||||
setLastUpdateTime();
|
||||
ptrLv.setOnRefreshListener(new OnRefreshListener2() {
|
||||
|
||||
@Override
|
||||
public void onPullDownToRefresh(PullToRefreshBase refreshView) {
|
||||
// 加载顶部新闻
|
||||
page = 1;
|
||||
getScienceList();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPullUpToRefresh(PullToRefreshBase refreshView) {
|
||||
page++;
|
||||
getScienceList();
|
||||
|
||||
// getNewsList(Url.getNewsList, false, false, page);
|
||||
}
|
||||
});
|
||||
initIntent();
|
||||
getScienceList();
|
||||
return view;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// TODO Auto-generated method stub
|
||||
super.onResume();
|
||||
|
||||
}
|
||||
|
||||
public void initIntent() {
|
||||
mIv_search.setOnClickListener(this);
|
||||
mEt_search.setOnEditorActionListener(new OnEditorActionListener() {
|
||||
|
||||
@Override
|
||||
public boolean onEditorAction(TextView v, int actionId,
|
||||
KeyEvent event) {
|
||||
// TODO Auto-generated method stub
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
|
||||
|
||||
searchStr = mEt_search.getText().toString().trim();
|
||||
page = 1;
|
||||
getScienceList();
|
||||
// search pressed and perform your functionality.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static final int GET_SEARCH_SCRENCE_RESULT = 101;
|
||||
|
||||
private void getScienceList() {
|
||||
// TODO Auto-generated method stub
|
||||
Log.i("TAG", "page = "+page+",topic = "+searchStr);
|
||||
Map<String, String> param = new HashMap<String, String>();
|
||||
param.put("page", String.valueOf(page));
|
||||
param.put("type", topic);
|
||||
param.put("keywords", "");
|
||||
// param.put("topic", mEt_search.getText().toString().trim());
|
||||
sendJsonPostParamtoNetSignMD5(Url.getPolularScienceArticleListByKeywordsNew, param,
|
||||
GET_SEARCH_SCRENCE_RESULT, mActivity);
|
||||
|
||||
}
|
||||
|
||||
private void setLastUpdateTime() {
|
||||
String text = CommonUtil.getStringDate();
|
||||
ptrLv.getLoadingLayoutProxy().setLastUpdatedLabel(text);
|
||||
}
|
||||
|
||||
private void onLoaded() {
|
||||
dismissLoadingProgress();
|
||||
ptrLv.onRefreshComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultState onLoad() {
|
||||
// TODO Auto-generated method stub
|
||||
return ResultState.STATE_SUCCESSED;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processClick(View v) {
|
||||
// TODO Auto-generated method stub
|
||||
switch (v.getId()) {
|
||||
case R.id.iv_search:
|
||||
searchStr = mEt_search.getText().toString().trim();
|
||||
page = 1;
|
||||
getScienceList();
|
||||
break;
|
||||
case R.id.ib_search://搜索
|
||||
Intent intent = new Intent(PatientTeachActivity.this,SearchPatientTeachActivity.class);
|
||||
startActivityForResult(intent, 80);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, final int position,
|
||||
long id) {
|
||||
// TODO Auto-generated method stub
|
||||
// sendKepu(position);
|
||||
PatientTBean datas1;
|
||||
int headerViewsCount = ptrLv.getRefreshableView().getHeaderViewsCount();
|
||||
if (headerViewsCount > 0 && position >= headerViewsCount) {
|
||||
datas1 = data.get(position - headerViewsCount);
|
||||
} else {
|
||||
datas1 = data.get(position);
|
||||
|
||||
}
|
||||
buildAlert = ECAlertDialog.buildAlert(PatientTeachActivity.this, datas1.getTopic(), "取消", "发送",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// TODO Auto-generated method stub
|
||||
buildAlert.dismiss();
|
||||
}
|
||||
}, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
sendKepu(position);
|
||||
buildAlert.dismiss();
|
||||
|
||||
}
|
||||
});
|
||||
buildAlert.setTitle("是否确定发送此患教科普");
|
||||
buildAlert.setTitleColor(PatientTeachActivity.this.getResources().getColor(
|
||||
R.color.black));
|
||||
buildAlert.setMessageColor("#666666");
|
||||
buildAlert.show();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void sendKepu(int position) {
|
||||
PatientTBean datas;
|
||||
int headerViewsCount = ptrLv.getRefreshableView().getHeaderViewsCount();
|
||||
if (headerViewsCount > 0 && position >= headerViewsCount) {
|
||||
datas = data.get(position - headerViewsCount);
|
||||
} else {
|
||||
datas = data.get(position);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Intent intent = new Intent();
|
||||
if (StringUtil.isEmpty(datas.getImgPath())) {
|
||||
|
||||
intent.putExtra("imagUrl",
|
||||
"http://doc.igandan.com/app/html/img/2016/20160714132557.png");
|
||||
} else {
|
||||
intent.putExtra("imagUrl", Url.urlHtml + datas.getImgPath());
|
||||
}
|
||||
// System.out.println("datas.getImgPath()== " + datas.getImgPath());
|
||||
|
||||
intent.putExtra("url", Url.urlHtml + datas.getPath());
|
||||
intent.putExtra("title", datas.getTopic());
|
||||
intent.putExtra("uuid",datas.getUuid());
|
||||
intent.putExtra("content", datas.getSummary());
|
||||
setResult(70, intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCallbackFromThread(String resultJson) {
|
||||
// TODO Auto-generated method stub
|
||||
processData(resultJson);
|
||||
|
||||
}
|
||||
|
||||
PatientTeachAdapter mAdapter;
|
||||
List<PatientTBean> data = new ArrayList<PatientTBean>();
|
||||
|
||||
public void processData(String result) {
|
||||
PatientTeachBean bean = null;
|
||||
try {
|
||||
bean = GsonTools.fromGsonToBean(result, PatientTeachBean.class);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (bean != null) {
|
||||
if (StringUtil.isOneToCode(bean.code)) {
|
||||
ToastUtil.showToast(bean.message);
|
||||
// 显示空布局
|
||||
ptrLv.setEmptyView(ll_empty);
|
||||
// 完成刷新
|
||||
onLoaded();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
ptrLv.setEmptyView(ll_empty);
|
||||
// 完成刷新
|
||||
onLoaded();
|
||||
return;
|
||||
}
|
||||
|
||||
// 判断是下拉刷新还是加载更多
|
||||
if (page == 1) {
|
||||
data.clear();
|
||||
if (bean.data == null || bean.data.isEmpty()) {
|
||||
// 显示空布局
|
||||
ptrLv.setEmptyView(ll_empty);
|
||||
// 完成刷新
|
||||
onLoaded();
|
||||
return;
|
||||
} else {
|
||||
data.addAll(bean.data);
|
||||
}
|
||||
} else {
|
||||
data.addAll(bean.data);
|
||||
}
|
||||
// 更新
|
||||
if (mAdapter == null) {
|
||||
mAdapter = new PatientTeachAdapter(data);
|
||||
ptrLv.getRefreshableView().setAdapter(mAdapter);
|
||||
} else {
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
// 完成刷新
|
||||
onLoaded();
|
||||
|
||||
if (page > 1) {
|
||||
// 是否有更多
|
||||
if (bean.data == null || bean.data.isEmpty()) {// 由于暂时虚构没数据,所以加载更多也没数据
|
||||
ToastUtil.showMessage("没有更多患教了");
|
||||
ptrLv.setMode(Mode.PULL_FROM_START);
|
||||
if (page > 1)
|
||||
page--;
|
||||
} else {
|
||||
ptrLv.setMode(Mode.BOTH);
|
||||
}
|
||||
} else if (page == 1) {
|
||||
// 得到总页码数
|
||||
int totalPage = bean.totalPage;
|
||||
if (totalPage <= 1 || totalPage < page) {
|
||||
ptrLv.setMode(Mode.PULL_FROM_START);
|
||||
} else {
|
||||
ptrLv.setMode(Mode.BOTH);
|
||||
}
|
||||
} else {
|
||||
ptrLv.setMode(Mode.BOTH);
|
||||
}
|
||||
|
||||
// 设置刷新的时间
|
||||
setLastUpdateTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCallBackFromThread(String resultJson, int resultCode) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (requestCode==80&&resultCode==80&&data!=null){
|
||||
Intent intent = new Intent();
|
||||
if (StringUtil.isEmpty(data.getStringExtra("imagUrl"))) {
|
||||
intent.putExtra("imagUrl",
|
||||
"http://doc.igandan.com/app/html/img/2016/20160714132557.png");
|
||||
} else {
|
||||
intent.putExtra("imagUrl",data.getStringExtra("imagUrl"));
|
||||
}
|
||||
System.out.println("datas.getImgPath()== " + data.getStringExtra("imagUrl"));
|
||||
|
||||
intent.putExtra("url", data.getStringExtra("url"));
|
||||
intent.putExtra("title", data.getStringExtra("title"));
|
||||
intent.putExtra("uuid", data.getStringExtra("uuid"));
|
||||
intent.putExtra("content",data.getStringExtra("content"));
|
||||
setResult(70, intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user