SearchFragment.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. package com.dbs.mplus.knuh.fragment;
  2. import androidx.annotation.NonNull;
  3. import androidx.annotation.Nullable;
  4. import androidx.appcompat.app.AppCompatActivity;
  5. import androidx.core.content.ContextCompat;
  6. import androidx.fragment.app.Fragment;
  7. import androidx.recyclerview.widget.LinearLayoutManager;
  8. import androidx.recyclerview.widget.RecyclerView;
  9. import android.content.Context;
  10. import android.os.Bundle;
  11. import android.util.Log;
  12. import android.view.KeyEvent;
  13. import android.view.LayoutInflater;
  14. import android.view.View;
  15. import android.view.ViewGroup;
  16. import android.view.inputmethod.EditorInfo;
  17. import android.widget.AdapterView;
  18. import android.widget.EditText;
  19. import android.widget.LinearLayout;
  20. import android.widget.Spinner;
  21. import android.widget.TextView;
  22. import com.dbs.mplus.knuh.BuildConfig;
  23. import com.dbs.mplus.knuh.R;
  24. import com.dbs.mplus.knuh.activity.ConsentActivity;
  25. import com.dbs.mplus.knuh.adapter.CategoryAdapter;
  26. import com.dbs.mplus.knuh.adapter.ConsentListAdapter;
  27. import com.dbs.mplus.knuh.customView.CustomAlertDialog;
  28. import com.dbs.mplus.knuh.customView.LoadingProgress;
  29. import com.dbs.mplus.knuh.httpTask.CallBack;
  30. import com.dbs.mplus.knuh.httpTask.SoapParser;
  31. import com.dbs.mplus.knuh.model.CategoryVO;
  32. import com.dbs.mplus.knuh.model.ConsentFormListVO;
  33. import com.dbs.mplus.knuh.util.ConsentConfig;
  34. import com.dbs.mplus.knuh.util.Util;
  35. import org.ksoap2.serialization.SoapObject;
  36. import java.util.ArrayList;
  37. import java.util.HashMap;
  38. public class SearchFragment extends Fragment {
  39. private static final String TAG = "SearchFragment";
  40. private AppCompatActivity mActivity;
  41. private Context mContext;
  42. private ConsentActivity instance;
  43. private CategoryAdapter categoryAdapter;
  44. private ConsentListAdapter consentListAdapter;
  45. private LinearLayoutManager linearLayoutManager;
  46. private LinearLayout searchClickLayout;
  47. private RecyclerView searchRecyclerView;
  48. private Spinner searchDeptSpinner;
  49. private TextView tvHospitalName;
  50. private EditText etPatientId;
  51. private TextView tvEmptySearchConsent;
  52. private String categoryId = "";
  53. public SearchFragment() {
  54. }
  55. public SearchFragment(AppCompatActivity mActivity, Context mContext) {
  56. this.mActivity = mActivity;
  57. this.mContext = mContext;
  58. this.instance = (ConsentActivity) mContext;
  59. }
  60. @Override
  61. public void onCreate(Bundle savedInstanceState) {
  62. super.onCreate(savedInstanceState);
  63. }
  64. @Nullable
  65. @Override
  66. public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  67. View view = (View) inflater.inflate(R.layout.activity_search_fragment, container, false);
  68. searchDeptSpinner = (Spinner) view.findViewById(R.id.searchDeptSpinner);
  69. tvHospitalName = (TextView) view.findViewById(R.id.tvHospitalName);
  70. etPatientId = (EditText) view.findViewById(R.id.etPatientId);
  71. searchClickLayout = (LinearLayout) view.findViewById(R.id.searchClickLayout);
  72. searchRecyclerView = (RecyclerView) view.findViewById(R.id.searchRecyclerView);
  73. tvEmptySearchConsent = (TextView) view.findViewById(R.id.tvEmptySearchConsent);
  74. getCategoryList(BuildConfig.INST_CD);
  75. setEvent();
  76. return view;
  77. }
  78. private void setEvent() {
  79. searchClickLayout.setOnClickListener(onClickListener);
  80. etPatientId.setOnEditorActionListener(onEditorActionListener);
  81. }
  82. private View.OnClickListener onClickListener = new View.OnClickListener() {
  83. @Override
  84. public void onClick(View v) {
  85. if (v == searchClickLayout) {
  86. getConsentList(categoryId);
  87. }
  88. }
  89. };
  90. public EditText.OnEditorActionListener onEditorActionListener = new EditText.OnEditorActionListener() {
  91. @Override
  92. public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
  93. if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT) {
  94. if (v == etPatientId) {
  95. getConsentList(categoryId);
  96. }
  97. }
  98. return false;
  99. }
  100. };
  101. /** Spinner List API **/
  102. /**
  103. * 동의서 검색 조건에 필요한 카테고리 데이터를 가져온다
  104. * @author jksong
  105. * @since 2020-01-28 오후 5:05
  106. **/
  107. private void getCategoryList(final String instCd) {
  108. instance.showProgress();
  109. CallBack callBack = new CallBack() {
  110. @Override
  111. public void result(SoapObject result) {
  112. if (result == null || result.toString().indexOf("null") > 0) {
  113. stop();
  114. } else {
  115. ArrayList<CategoryVO> categoryArray = SoapParser.getHospitalList(result);
  116. setSpinnerAdapter(categoryArray);
  117. }
  118. }
  119. @Override
  120. public void stop() {
  121. }
  122. @Override
  123. public void error() {
  124. }
  125. };
  126. if (instCd.equals("031")) {
  127. tvHospitalName.setText(getText(R.string.knuh));
  128. } else {
  129. tvHospitalName.setText(getText(R.string.chilgok));
  130. }
  131. HashMap<String, String> mData = new HashMap<String, String>();
  132. mData.put("instCd", instCd);
  133. if (Util.checkNetwork(mContext) == true) {
  134. Util.callHttp(mContext, ConsentConfig.HOST_CONSENT, ConsentConfig.GET_CONSENT_CATEGORYY, mData, callBack);
  135. } else {
  136. instance.dismissProgress();
  137. Util.networkErrorAlert(mActivity);
  138. }
  139. }
  140. private void setSpinnerAdapter(final ArrayList arrayList) {
  141. mActivity.runOnUiThread(new Runnable() {
  142. @Override
  143. public void run() {
  144. categoryAdapter = new CategoryAdapter(mActivity, arrayList);
  145. searchDeptSpinner.setAdapter(categoryAdapter);
  146. searchDeptSpinner.setOnItemSelectedListener(onItemSelectedListener);
  147. }
  148. });
  149. }
  150. private Spinner.OnItemSelectedListener onItemSelectedListener = new Spinner.OnItemSelectedListener() {
  151. @Override
  152. public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  153. CategoryVO categoryVO = (CategoryVO) parent.getAdapter().getItem(position);
  154. categoryId = categoryVO.getCategoryId();
  155. }
  156. @Override
  157. public void onNothingSelected(AdapterView<?> parent) {
  158. }
  159. };
  160. /**
  161. * 동의서 찾기 리스트
  162. * @author jksong
  163. * @since 2020-01-28 오후 5:03
  164. **/
  165. private void getConsentList(String categoryId) {
  166. CallBack callBack = new CallBack() {
  167. @Override
  168. public void result(final SoapObject result) {
  169. mActivity.runOnUiThread(new Runnable() {
  170. @Override
  171. public void run() {
  172. instance.dismissProgress();
  173. if (result == null || result.toString().indexOf("null") > 0 || result.getPropertyCount() == 0) {
  174. tvEmptySearchConsent.setVisibility(View.VISIBLE);
  175. if (consentListAdapter != null) {
  176. consentListAdapter.arrayList.clear();
  177. consentListAdapter.notifyDataSetChanged();
  178. }
  179. } else {
  180. tvEmptySearchConsent.setVisibility(View.GONE);
  181. ArrayList<ConsentFormListVO> arrayList = SoapParser.getConsentList(result);
  182. setConsentAdapter(arrayList);
  183. }
  184. }
  185. });
  186. }
  187. @Override
  188. public void stop() {
  189. }
  190. @Override
  191. public void error() {
  192. }
  193. };
  194. if ((categoryId.equals("EMA_031") || categoryId.equals("EMA_032")) && etPatientId.getText().toString().trim().equals("")) {
  195. // categoryNotSelected
  196. instance.showSingButtonDialog(mContext.getString(R.string.categoryNotSelected));
  197. } else {
  198. instance.showProgress();
  199. HashMap<String, String> mData = new HashMap<String, String>();
  200. mData.put("instCd", BuildConfig.INST_CD);
  201. mData.put("keyWord", etPatientId.getText().toString().trim());
  202. mData.put("categoryId", categoryId);
  203. if (Util.checkNetwork(mContext) == true) {
  204. Util.callHttp(mContext, ConsentConfig.HOST_CONSENT, ConsentConfig.GET_CONSENT_SEARCH, mData, callBack);
  205. } else {
  206. instance.dismissProgress();
  207. Util.networkErrorAlert(mActivity);
  208. }
  209. }
  210. }
  211. private void setConsentAdapter(final ArrayList<ConsentFormListVO> arrayList) {
  212. if (consentListAdapter == null) {
  213. linearLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
  214. searchRecyclerView.setLayoutManager(linearLayoutManager);
  215. consentListAdapter = new ConsentListAdapter(mActivity, mContext, arrayList, ConsentConfig.GET_CONSENT_SEARCH);
  216. searchRecyclerView.setAdapter(consentListAdapter);
  217. } else {
  218. consentListAdapter.arrayList = arrayList;
  219. consentListAdapter.notifyDataSetChanged();
  220. }
  221. }
  222. }