377 lines
14 KiB
Java
377 lines
14 KiB
Java
package cn.shangyu.gdxzExpert.activity;
|
|
|
|
import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.os.Handler;
|
|
import android.os.Message;
|
|
import android.view.View;
|
|
import android.widget.AdapterView;
|
|
import android.widget.EditText;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.Nullable;
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
import androidx.appcompat.widget.Toolbar;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.gyf.immersionbar.ImmersionBar;
|
|
import com.lidroid.xutils.util.LogUtils;
|
|
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
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.VideoTeachAdapter;
|
|
import cn.shangyu.gdxzExpert.bean.TimestampBean;
|
|
import cn.shangyu.gdxzExpert.bean.VideoMoreBean;
|
|
import cn.shangyu.gdxzExpert.big.adapter.BigVideoTeachAdapter;
|
|
import cn.shangyu.gdxzExpert.http.HttpHelper;
|
|
import cn.shangyu.gdxzExpert.pulltorefreshview.PullToRefreshBase;
|
|
import cn.shangyu.gdxzExpert.pulltorefreshview.PullToRefreshListView;
|
|
import cn.shangyu.gdxzExpert.utils.CommonUtil;
|
|
import cn.shangyu.gdxzExpert.utils.GsonTools;
|
|
import cn.shangyu.gdxzExpert.utils.LogUtil;
|
|
import cn.shangyu.gdxzExpert.utils.SharePrefUtil;
|
|
import cn.shangyu.gdxzExpert.utils.SignUtil;
|
|
import cn.shangyu.gdxzExpert.utils.StreamTool;
|
|
import cn.shangyu.gdxzExpert.utils.StringUtil;
|
|
import cn.shangyu.gdxzExpert.utils.ToastUtil;
|
|
import cn.shangyu.gdxzExpert.utils.UpdateVersionUtils;
|
|
import cn.shangyu.gdxzExpert.utils.Url;
|
|
import cn.shangyu.gdxzExpert.widget.ECAlertDialog;
|
|
|
|
/**
|
|
* Created by WANGChengXin on 2019/10/28.
|
|
* 搜索患教视频
|
|
*/
|
|
|
|
public class SearchVideoTeachActivity extends AppCompatActivity implements View.OnClickListener,AdapterView.OnItemClickListener{
|
|
|
|
private TextView tv_public_ser;
|
|
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 ECAlertDialog buildAlert;
|
|
private ImageView top_back;
|
|
public static final int GET_SEARCH_SCRENCE_RESULT = 101;
|
|
private List<VideoMoreBean.VideoMore> data = new ArrayList<>();
|
|
Handler mHandler = new Handler() {
|
|
public void handleMessage(Message msg) {
|
|
if (msg != null) {
|
|
String resultData = (String) msg.obj;
|
|
int i = msg.what;
|
|
if (GET_SEARCH_SCRENCE_RESULT == i)
|
|
processData(resultData);
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
private String sort = "2";
|
|
private VideoTeachAdapter mAdapter;
|
|
private String typeUuid;
|
|
|
|
@Override
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
if(CommonUtil.BigModule())
|
|
{
|
|
setContentView(R.layout.activity_search_patientteach_big);
|
|
}
|
|
else
|
|
{
|
|
setContentView(R.layout.activity_search_patientteach);
|
|
}
|
|
|
|
Toolbar mToolbar=findViewById(R.id.toolbar);
|
|
ImmersionBar.with(this).keyboardEnable(true).statusBarDarkFont(true).titleBar(mToolbar).init();
|
|
tv_public_ser = findViewById(R.id.tv_public_ser);
|
|
top_back = findViewById(R.id.top_back);
|
|
top_back.setOnClickListener(this);
|
|
tv_public_ser.setOnClickListener(this);
|
|
mEt_search =findViewById(R.id.tv_top_search);
|
|
// 下拉刷新的listview控件
|
|
ptrLv = (PullToRefreshListView)findViewById(R.id.lv_item_news);
|
|
// 空布局,处理
|
|
ll_empty = (LinearLayout) findViewById(R.id.ll_empty);
|
|
tv_empty_msg = (TextView) findViewById(R.id.tv_empty_msg);
|
|
// 设置空的提示信息,默认是“暂时没有数据”
|
|
tv_empty_msg.setText("暂无视频科普");
|
|
ptrLv.setMode(PullToRefreshBase.Mode.BOTH);
|
|
// 得到实际的ListView 设置点击
|
|
ptrLv.getRefreshableView().setOnItemClickListener(this);
|
|
|
|
setLastUpdateTime();
|
|
|
|
ptrLv.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2() {
|
|
|
|
@Override
|
|
public void onPullDownToRefresh(PullToRefreshBase refreshView) {
|
|
// 加载顶部新闻
|
|
page = 1;
|
|
getVideoList();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onPullUpToRefresh(PullToRefreshBase refreshView) {
|
|
page++;
|
|
getVideoList();
|
|
|
|
// getNewsList(Url.getNewsList, false, false, page);
|
|
}
|
|
});
|
|
|
|
typeUuid = getIntent().getStringExtra("typeUuid");
|
|
sort = getIntent().getStringExtra("sort");
|
|
getVideoList();
|
|
}
|
|
|
|
private void getVideoList() {
|
|
final Map<String, String> param = new HashMap<String, String>();
|
|
param.put("page", String.valueOf(page));
|
|
param.put("name", mEt_search.getText().toString().trim());
|
|
param.put("typeUuid",typeUuid);
|
|
param.put("sort",sort);
|
|
LogUtil.i("page = "+page);
|
|
LogUtil.i("name = "+mEt_search.getText().toString().trim());
|
|
LogUtil.i("typeUuid = "+typeUuid);
|
|
LogUtil.i("sort = "+sort);
|
|
param.put("user_uuid", SharePrefUtil.getString(this, "uuid", ""));
|
|
param.put("client_type", "A");
|
|
param.put("version", UpdateVersionUtils.getVersionName());
|
|
LogUtils.e("user_uuid+version = "+SharePrefUtil.getString(this, "uuid", "")+","+UpdateVersionUtils.getVersionName());
|
|
new Thread(new Runnable() {
|
|
private HttpHelper.HttpResult httpResult;
|
|
private String result1;
|
|
|
|
@Override
|
|
public void run() {
|
|
// TODO Auto-generated method stub
|
|
try {
|
|
httpResult = HttpHelper.post(Url.getTimestamp, null);
|
|
if (httpResult != null) {
|
|
result1 = httpResult.getString();
|
|
// LogUtils.e(result);
|
|
TimestampBean bean = GsonTools.fromGsonToBean(result1, TimestampBean.class);
|
|
param.put("timestamp", bean.getTimestamp());
|
|
LogUtils.e("timestamp = "+ bean.getTimestamp());
|
|
|
|
String encoding = "UTF-8";
|
|
Gson gson = new Gson();
|
|
String params = gson.toJson(param);
|
|
LogUtil.i("params = "+params.toString());
|
|
byte[] data;
|
|
String sign = SignUtil.getSign(param);
|
|
data = params.getBytes(encoding);
|
|
URL url = new URL(Url.patientVideoByName);
|
|
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
conn.setRequestMethod("POST");
|
|
conn.setDoOutput(true);
|
|
conn.setRequestProperty("Content-Type","application/json");
|
|
conn.setRequestProperty("sign",sign);
|
|
conn.setRequestProperty("Content-Length",String.valueOf(data.length));
|
|
conn.setConnectTimeout(5 * 1000);
|
|
OutputStream outStream = conn.getOutputStream();
|
|
outStream.write(data);
|
|
outStream.flush();
|
|
outStream.close();
|
|
if (conn.getResponseCode() == 200) {
|
|
InputStream inStream = conn.getInputStream();
|
|
String result = new String(StreamTool.readInputStream(inStream), "UTF-8");
|
|
Message message = new Message();
|
|
message.what = GET_SEARCH_SCRENCE_RESULT;
|
|
message.obj = new String(result);
|
|
mHandler.sendMessage(message);
|
|
} else {
|
|
mHandler.sendEmptyMessage(010);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
// ToastUtil.showMessage("提交失败,请重试");
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
}).start();
|
|
}
|
|
|
|
private void setLastUpdateTime() {
|
|
String text = CommonUtil.getStringDate();
|
|
ptrLv.getLoadingLayoutProxy().setLastUpdatedLabel(text);
|
|
}
|
|
private void processData(String resultData) {
|
|
LogUtil.i("resultData = "+resultData);
|
|
VideoMoreBean bean = null;
|
|
try {
|
|
bean = GsonTools.fromGsonToBean(resultData, VideoMoreBean.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.list.size()==0) {
|
|
// 显示空布局
|
|
ptrLv.setEmptyView(ll_empty);
|
|
// 完成刷新
|
|
onLoaded();
|
|
return;
|
|
} else {
|
|
data.addAll(bean.data.list);
|
|
}
|
|
} else {
|
|
data.addAll(bean.data.list);
|
|
}
|
|
// 更新
|
|
if (mAdapter == null) {
|
|
if(CommonUtil.BigModule())
|
|
{
|
|
mAdapter = new BigVideoTeachAdapter(data);
|
|
}
|
|
else
|
|
{
|
|
mAdapter = new VideoTeachAdapter(data);
|
|
}
|
|
|
|
ptrLv.getRefreshableView().setAdapter(mAdapter);
|
|
} else {
|
|
mAdapter.notifyDataSetChanged();
|
|
}
|
|
// 完成刷新
|
|
onLoaded();
|
|
|
|
if (page > 1) {
|
|
// 是否有更多
|
|
if (bean.data == null || bean.data.list.size()==0) {// 由于暂时虚构没数据,所以加载更多也没数据
|
|
ToastUtil.showMessage("没有更多患教了");
|
|
ptrLv.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
|
|
if (page > 1)
|
|
page--;
|
|
} else {
|
|
ptrLv.setMode(PullToRefreshBase.Mode.BOTH);
|
|
}
|
|
} else if (page == 1) {
|
|
// 得到总页码数
|
|
int totalPage = bean.data.totalPage;
|
|
if (totalPage <= 1 || totalPage < page) {
|
|
ptrLv.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
|
|
} else {
|
|
ptrLv.setMode(PullToRefreshBase.Mode.BOTH);
|
|
}
|
|
} else {
|
|
ptrLv.setMode(PullToRefreshBase.Mode.BOTH);
|
|
}
|
|
|
|
// 设置刷新的时间
|
|
setLastUpdateTime();
|
|
}
|
|
|
|
private void onLoaded() {
|
|
ptrLv.onRefreshComplete();
|
|
}
|
|
@Override
|
|
public void onClick(View v) {
|
|
switch (v.getId()){
|
|
case R.id.top_back:
|
|
finish();
|
|
break;
|
|
case R.id.tv_public_ser:
|
|
page = 1;
|
|
getVideoList();
|
|
break;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
|
|
VideoMoreBean.VideoMore datas1;
|
|
int headerViewsCount = ptrLv.getRefreshableView().getHeaderViewsCount();
|
|
if (headerViewsCount > 0 && position >= headerViewsCount) {
|
|
datas1 = data.get(position - headerViewsCount);
|
|
} else {
|
|
datas1 = data.get(position);
|
|
|
|
}
|
|
buildAlert = ECAlertDialog.buildAlert(SearchVideoTeachActivity.this, datas1.getName(), "取消", "发送",
|
|
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(SearchVideoTeachActivity.this.getResources().getColor(
|
|
R.color.black));
|
|
buildAlert.setMessageColor("#666666");
|
|
buildAlert.show();
|
|
}
|
|
private void sendKepu(int position) {
|
|
VideoMoreBean.VideoMore 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.getName());
|
|
intent.putExtra("uuid",datas.getUuid());
|
|
intent.putExtra("content","肝胆相照®肝胆病在线公共服务平台");
|
|
setResult(80, intent);
|
|
finish();
|
|
}
|
|
|
|
}
|