From af739477dc1613de5d0b797a014f073242e548aa Mon Sep 17 00:00:00 2001 From: pika Date: Wed, 17 Jul 2019 19:12:25 +0800 Subject: [PATCH] add huati --- .../linwancunyi/ui/back/patient_list.java | 10 ---- .../ui/patient/PatientArticle.java | 39 +++++++++++++- .../ui/patient/PatientArticle_content.java | 47 ++--------------- .../linwancunyi/ui/patient/PatientMain.java | 46 ++++++++++++++++- .../res/layout/fragment_patient_article.xml | 51 ++----------------- 5 files changed, 90 insertions(+), 103 deletions(-) diff --git a/app/src/main/java/com/linwankaifa/linwancunyi/ui/back/patient_list.java b/app/src/main/java/com/linwankaifa/linwancunyi/ui/back/patient_list.java index bbccd18..62219c9 100644 --- a/app/src/main/java/com/linwankaifa/linwancunyi/ui/back/patient_list.java +++ b/app/src/main/java/com/linwankaifa/linwancunyi/ui/back/patient_list.java @@ -6,32 +6,22 @@ import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.AdapterView; -import android.widget.Button; -import android.widget.EditText; import android.widget.ListView; import android.widget.Toast; import com.linwankaifa.linwancunyi.R; -import com.linwankaifa.linwancunyi.bean.ChatrecordBean; import com.linwankaifa.linwancunyi.bean.PatientBean; import com.linwankaifa.linwancunyi.helper.Data_whole; -import com.linwankaifa.linwancunyi.ui.patient.PatientFindHospital; -import com.linwankaifa.linwancunyi.ui.patient.PatientFindHospitalResult; import com.linwankaifa.linwancunyi.util.JsonTransformation; -import com.linwankaifa.linwancunyi.util.MsgActivity; -import com.linwankaifa.linwancunyi.util.MsgAdapter; import com.linwankaifa.linwancunyi.util.patientAdapter; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import okhttp3.Call; import okhttp3.Callback; -import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; -import okhttp3.RequestBody; import okhttp3.Response; public class patient_list extends AppCompatActivity { diff --git a/app/src/main/java/com/linwankaifa/linwancunyi/ui/patient/PatientArticle.java b/app/src/main/java/com/linwankaifa/linwancunyi/ui/patient/PatientArticle.java index 0cc6aa5..887bb66 100644 --- a/app/src/main/java/com/linwankaifa/linwancunyi/ui/patient/PatientArticle.java +++ b/app/src/main/java/com/linwankaifa/linwancunyi/ui/patient/PatientArticle.java @@ -1,6 +1,7 @@ package com.linwankaifa.linwancunyi.ui.patient; import android.content.Context; +import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -8,8 +9,19 @@ import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ListView; import com.linwankaifa.linwancunyi.R; +import com.linwankaifa.linwancunyi.bean.DoctorBean; +import com.linwankaifa.linwancunyi.bean.HospitalBean; +import com.linwankaifa.linwancunyi.bean.HuatiBean; +import com.linwankaifa.linwancunyi.helper.Data_whole; +import com.linwankaifa.linwancunyi.util.ChatDoctorAdapter; +import com.linwankaifa.linwancunyi.util.huatiAdapter; + +import java.util.ArrayList; +import java.util.List; /** * A simple {@link Fragment} subclass. @@ -30,11 +42,17 @@ public class PatientArticle extends Fragment{ private String mParam2; private OnFragmentInteractionListener mListener; - + View view2; + private ListView articleListView; + private huatiAdapter adapter; + private List articleList = new ArrayList(); public PatientArticle() { // Required empty public constructor } - + public void setarticleList(List article) + { + articleList = article; + } /** * Use this factory method to create a new instance of * this fragment using the provided parameters. @@ -69,6 +87,23 @@ public class PatientArticle extends Fragment{ return inflater.inflate(R.layout.fragment_patient_article, container, false); } + private void initlist(View view) { + + articleListView=(ListView)view.findViewById(R.id.article_list_view); + + adapter=new huatiAdapter(getActivity(),R.layout.item_huati,articleList); + + articleListView.setAdapter(adapter); + articleListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + HuatiBean huati = articleList.get(i); + Data_whole.setHuatiBean(huati); + Intent intent = new Intent(getActivity(), PatientArticle_content.class); + startActivity(intent); + } + }); + } // TODO: Rename method, update argument and hook method into UI event public void onButtonPressed(Uri uri) { if (mListener != null) { diff --git a/app/src/main/java/com/linwankaifa/linwancunyi/ui/patient/PatientArticle_content.java b/app/src/main/java/com/linwankaifa/linwancunyi/ui/patient/PatientArticle_content.java index 9384f53..186ac97 100644 --- a/app/src/main/java/com/linwankaifa/linwancunyi/ui/patient/PatientArticle_content.java +++ b/app/src/main/java/com/linwankaifa/linwancunyi/ui/patient/PatientArticle_content.java @@ -33,49 +33,8 @@ public class PatientArticle_content extends AppCompatActivity { setContentView(R.layout.activity_patien_article_content); articlebrief = (TextView) findViewById(R.id.articlebrief); articlecontent = (TextView) findViewById(R.id.articlecontent); - OkHttpClient client = new OkHttpClient(); - RequestBody requestBody = null; - final HuatiBean huati = new HuatiBean(); - huati.setBriefintroduction("美容是什么?"); - requestBody = RequestBody.create(MediaType.parse("text; charset=utf-8"), - JsonTransformation.objectToJson(huati)); - Log.e("dynamic", JsonTransformation.objectToJson(huati)); - - String url = "http://49.234.4.35:8080/"; - url += "patient/getarticleInfo"; - Log.e("dynamic", url); - Request request = new Request.Builder() - .url(url) - .post(requestBody) - .build(); - okhttp3.Call call = client.newCall(request); - call.enqueue(new Callback() { - @Override - public void onFailure(Call call, IOException e) { - Toast toast = Toast.makeText(getApplicationContext(), "医生话题信息获取失败", Toast.LENGTH_SHORT); - toast.show(); - } - - @Override - public void onResponse(Call call, Response response) throws IOException { - // 判断是否成功 - final String isSuccess = response.body().string(); - runOnUiThread(new Runnable() { - @Override - public void run() { - if(isSuccess.equals("404")) - { - Toast.makeText(getApplicationContext(), "该医生话题不存在", Toast.LENGTH_SHORT).show(); - } - else - { - HuatiBean huati = JsonTransformation.jsonToObject(isSuccess, HuatiBean.class); - articlebrief.setText(huati.getBriefintroduction()); - articlecontent.setText(huati.getFabucontent()); - } - } - }); - } - }); + HuatiBean huati=new HuatiBean(); + articlebrief.setText(huati.getBriefintroduction()); + articlecontent.setText(huati.getFabucontent()); } } diff --git a/app/src/main/java/com/linwankaifa/linwancunyi/ui/patient/PatientMain.java b/app/src/main/java/com/linwankaifa/linwancunyi/ui/patient/PatientMain.java index ad92929..771d14b 100644 --- a/app/src/main/java/com/linwankaifa/linwancunyi/ui/patient/PatientMain.java +++ b/app/src/main/java/com/linwankaifa/linwancunyi/ui/patient/PatientMain.java @@ -14,6 +14,7 @@ import android.widget.Toast; import com.linwankaifa.linwancunyi.R; import com.linwankaifa.linwancunyi.bean.DoctorBean; +import com.linwankaifa.linwancunyi.bean.HuatiBean; import com.linwankaifa.linwancunyi.controller.Adapter.FragmentAdapter; import com.linwankaifa.linwancunyi.helper.BottomNavigationViewHelper; import com.linwankaifa.linwancunyi.helper.Data_whole; @@ -45,7 +46,7 @@ public class PatientMain extends FragmentActivity private MenuItem menuItem; private BottomNavigationView bottomNavigationView; private List doctors = new ArrayList(); - + private List huati = new ArrayList(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -121,6 +122,8 @@ public class PatientMain extends FragmentActivity getDoctors(); patientConsult.setdoctorList(doctors); + getArticle(); + patientArticle.setarticleList(huati); } private void setupViewPager(ViewPager viewPager) { @@ -222,4 +225,45 @@ public class PatientMain extends FragmentActivity } }); } + + public void getArticle() + { + OkHttpClient client = new OkHttpClient(); + RequestBody requestBody = RequestBody.create(MediaType.parse("text; charset=utf-8"), + JsonTransformation.objectToJson(Data_whole.getHuatiBean())); + + String url = "http://49.234.4.35:8080/patient/getarticleinfoList"; + + Request request = new Request.Builder() + .url(url) + .get() + .build(); + okhttp3.Call call = client.newCall(request); + call.enqueue(new Callback() { + @Override + public void onFailure(Call call, IOException e) { + // 如果失败,就显示失败信息 + Toast toast = makeText(getApplicationContext(), "请求失败", Toast.LENGTH_SHORT); + toast.show(); + } + + @Override + public void onResponse(Call call, Response response) throws IOException { + // 判断请求是否成功 + final String isSuccess = response.body().string(); + runOnUiThread(new Runnable() { + @Override + public void run() { + if (isSuccess.equals("404")) + makeText(getApplicationContext(), "错误请求404", Toast.LENGTH_SHORT).show(); + else { + List articleList = JsonTransformation.jsonToList(isSuccess, HuatiBean.class); + for(HuatiBean article:articleList) + huati.add(article); + } + } + }); + } + }); + } } diff --git a/app/src/main/res/layout/fragment_patient_article.xml b/app/src/main/res/layout/fragment_patient_article.xml index ddd0656..4f63ca1 100644 --- a/app/src/main/res/layout/fragment_patient_article.xml +++ b/app/src/main/res/layout/fragment_patient_article.xml @@ -6,52 +6,11 @@ android:layout_height="match_parent" tools:context="com.linwankaifa.linwancunyi.ui.patient.PatientArticle"> - - - - - - - - - - - - - - - - - + android:layout_height="match_parent" + android:layout_weight="1"> - - + -- Gitee