123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- package com.dbs.mplus.knuh.fragment;
- import androidx.annotation.NonNull;
- import androidx.annotation.Nullable;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.core.content.ContextCompat;
- import androidx.fragment.app.Fragment;
- import androidx.recyclerview.widget.LinearLayoutManager;
- import androidx.recyclerview.widget.RecyclerView;
- import android.content.Context;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.KeyEvent;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.inputmethod.EditorInfo;
- import android.widget.AdapterView;
- import android.widget.EditText;
- import android.widget.LinearLayout;
- import android.widget.Spinner;
- import android.widget.TextView;
- import com.dbs.mplus.knuh.BuildConfig;
- import com.dbs.mplus.knuh.R;
- import com.dbs.mplus.knuh.activity.ConsentActivity;
- import com.dbs.mplus.knuh.adapter.CategoryAdapter;
- import com.dbs.mplus.knuh.adapter.ConsentListAdapter;
- import com.dbs.mplus.knuh.customView.CustomAlertDialog;
- import com.dbs.mplus.knuh.customView.LoadingProgress;
- import com.dbs.mplus.knuh.httpTask.CallBack;
- import com.dbs.mplus.knuh.httpTask.SoapParser;
- import com.dbs.mplus.knuh.model.CategoryVO;
- import com.dbs.mplus.knuh.model.ConsentFormListVO;
- import com.dbs.mplus.knuh.util.ConsentConfig;
- import com.dbs.mplus.knuh.util.Util;
- import org.ksoap2.serialization.SoapObject;
- import java.util.ArrayList;
- import java.util.HashMap;
- public class SearchFragment extends Fragment {
- private static final String TAG = "SearchFragment";
- private AppCompatActivity mActivity;
- private Context mContext;
- private ConsentActivity instance;
- private CategoryAdapter categoryAdapter;
- private ConsentListAdapter consentListAdapter;
- private LinearLayoutManager linearLayoutManager;
- private LinearLayout searchClickLayout;
- private RecyclerView searchRecyclerView;
- private Spinner searchDeptSpinner;
- private TextView tvHospitalName;
- private EditText etPatientId;
- private TextView tvEmptySearchConsent;
- private String categoryId = "";
- public SearchFragment() {
- }
- public SearchFragment(AppCompatActivity mActivity, Context mContext) {
- this.mActivity = mActivity;
- this.mContext = mContext;
- this.instance = (ConsentActivity) mContext;
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
- @Nullable
- @Override
- public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
- View view = (View) inflater.inflate(R.layout.activity_search_fragment, container, false);
- searchDeptSpinner = (Spinner) view.findViewById(R.id.searchDeptSpinner);
- tvHospitalName = (TextView) view.findViewById(R.id.tvHospitalName);
- etPatientId = (EditText) view.findViewById(R.id.etPatientId);
- searchClickLayout = (LinearLayout) view.findViewById(R.id.searchClickLayout);
- searchRecyclerView = (RecyclerView) view.findViewById(R.id.searchRecyclerView);
- tvEmptySearchConsent = (TextView) view.findViewById(R.id.tvEmptySearchConsent);
- getCategoryList(BuildConfig.INST_CD);
- setEvent();
- return view;
- }
- private void setEvent() {
- searchClickLayout.setOnClickListener(onClickListener);
- etPatientId.setOnEditorActionListener(onEditorActionListener);
- }
- private View.OnClickListener onClickListener = new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if (v == searchClickLayout) {
- getConsentList(categoryId);
- }
- }
- };
- public EditText.OnEditorActionListener onEditorActionListener = new EditText.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT) {
- if (v == etPatientId) {
- getConsentList(categoryId);
- }
- }
- return false;
- }
- };
- /** Spinner List API **/
- /**
- * 동의서 검색 조건에 필요한 카테고리 데이터를 가져온다
- * @author jksong
- * @since 2020-01-28 오후 5:05
- **/
- private void getCategoryList(final String instCd) {
- instance.showProgress();
- CallBack callBack = new CallBack() {
- @Override
- public void result(SoapObject result) {
- if (result == null || result.toString().indexOf("null") > 0) {
- stop();
- } else {
- ArrayList<CategoryVO> categoryArray = SoapParser.getHospitalList(result);
- setSpinnerAdapter(categoryArray);
- }
- }
- @Override
- public void stop() {
- }
- @Override
- public void error() {
- }
- };
- if (instCd.equals("031")) {
- tvHospitalName.setText(getText(R.string.knuh));
- } else {
- tvHospitalName.setText(getText(R.string.chilgok));
- }
- HashMap<String, String> mData = new HashMap<String, String>();
- mData.put("instCd", instCd);
- if (Util.checkNetwork(mContext) == true) {
- Util.callHttp(mContext, ConsentConfig.HOST_CONSENT, ConsentConfig.GET_CONSENT_CATEGORYY, mData, callBack);
- } else {
- instance.dismissProgress();
- Util.networkErrorAlert(mActivity);
- }
- }
- private void setSpinnerAdapter(final ArrayList arrayList) {
- mActivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- categoryAdapter = new CategoryAdapter(mActivity, arrayList);
- searchDeptSpinner.setAdapter(categoryAdapter);
- searchDeptSpinner.setOnItemSelectedListener(onItemSelectedListener);
- }
- });
- }
- private Spinner.OnItemSelectedListener onItemSelectedListener = new Spinner.OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- CategoryVO categoryVO = (CategoryVO) parent.getAdapter().getItem(position);
- categoryId = categoryVO.getCategoryId();
- }
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- }
- };
- /**
- * 동의서 찾기 리스트
- * @author jksong
- * @since 2020-01-28 오후 5:03
- **/
- private void getConsentList(String categoryId) {
- CallBack callBack = new CallBack() {
- @Override
- public void result(final SoapObject result) {
- mActivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- instance.dismissProgress();
- if (result == null || result.toString().indexOf("null") > 0 || result.getPropertyCount() == 0) {
- tvEmptySearchConsent.setVisibility(View.VISIBLE);
- if (consentListAdapter != null) {
- consentListAdapter.arrayList.clear();
- consentListAdapter.notifyDataSetChanged();
- }
- } else {
- tvEmptySearchConsent.setVisibility(View.GONE);
- ArrayList<ConsentFormListVO> arrayList = SoapParser.getConsentList(result);
- setConsentAdapter(arrayList);
- }
- }
- });
- }
- @Override
- public void stop() {
- }
- @Override
- public void error() {
- }
- };
- if ((categoryId.equals("EMA_031") || categoryId.equals("EMA_032")) && etPatientId.getText().toString().trim().equals("")) {
- // categoryNotSelected
- instance.showSingButtonDialog(mContext.getString(R.string.categoryNotSelected));
- } else {
- instance.showProgress();
- HashMap<String, String> mData = new HashMap<String, String>();
- mData.put("instCd", BuildConfig.INST_CD);
- mData.put("keyWord", etPatientId.getText().toString().trim());
- mData.put("categoryId", categoryId);
- if (Util.checkNetwork(mContext) == true) {
- Util.callHttp(mContext, ConsentConfig.HOST_CONSENT, ConsentConfig.GET_CONSENT_SEARCH, mData, callBack);
- } else {
- instance.dismissProgress();
- Util.networkErrorAlert(mActivity);
- }
- }
- }
- private void setConsentAdapter(final ArrayList<ConsentFormListVO> arrayList) {
- if (consentListAdapter == null) {
- linearLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
- searchRecyclerView.setLayoutManager(linearLayoutManager);
- consentListAdapter = new ConsentListAdapter(mActivity, mContext, arrayList, ConsentConfig.GET_CONSENT_SEARCH);
- searchRecyclerView.setAdapter(consentListAdapter);
- } else {
- consentListAdapter.arrayList = arrayList;
- consentListAdapter.notifyDataSetChanged();
- }
- }
- }
|