|
@@ -2,6 +2,7 @@ package com.dbs.mplus.knuh.adapter;
|
|
|
|
|
|
import android.content.Context;
|
|
|
import android.graphics.drawable.GradientDrawable;
|
|
|
+import android.telecom.Call;
|
|
|
import android.util.Log;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
@@ -9,29 +10,38 @@ import android.view.ViewGroup;
|
|
|
import android.widget.RelativeLayout;
|
|
|
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.httpTask.CallBack;
|
|
|
import com.dbs.mplus.knuh.model.ConsentFormListVO;
|
|
|
import com.dbs.mplus.knuh.util.ConsentConfig;
|
|
|
+import com.dbs.mplus.knuh.util.Util;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
+import org.ksoap2.serialization.SoapObject;
|
|
|
+
|
|
|
public class ConsentListAdapter extends RecyclerView.Adapter<ConsentListAdapter.ViewHolder> {
|
|
|
|
|
|
private static final String TAG = "ConsentListAdapter";
|
|
|
private AppCompatActivity mActivity;
|
|
|
private Context mContext;
|
|
|
+ private ConsentActivity instance;
|
|
|
public ArrayList<ConsentFormListVO> arrayList;
|
|
|
|
|
|
private String apiType = "";
|
|
|
|
|
|
- public ConsentListAdapter(AppCompatActivity mActivity, ArrayList<ConsentFormListVO> arrayList, String apiType) {
|
|
|
+ public ConsentListAdapter(AppCompatActivity mActivity, Context mContext, ArrayList<ConsentFormListVO> arrayList, String apiType) {
|
|
|
this.mActivity = mActivity;
|
|
|
- this.mContext = mActivity.getApplicationContext();
|
|
|
+ this.mContext = mContext;
|
|
|
+ this.instance = (ConsentActivity) mContext;
|
|
|
this.arrayList = arrayList;
|
|
|
this.apiType = apiType;
|
|
|
}
|
|
@@ -49,6 +59,8 @@ public class ConsentListAdapter extends RecyclerView.Adapter<ConsentListAdapter.
|
|
|
public TextView tvTemp;
|
|
|
public TextView tvSubText;
|
|
|
|
|
|
+ public int position = 0;
|
|
|
+
|
|
|
public ViewHolder(@NonNull View itemView) {
|
|
|
super(itemView);
|
|
|
}
|
|
@@ -97,17 +109,103 @@ public class ConsentListAdapter extends RecyclerView.Adapter<ConsentListAdapter.
|
|
|
|
|
|
holder.listLayer.setOnClickListener(onClickListener);
|
|
|
holder.tvSubText.setOnClickListener(onClickListener);
|
|
|
+
|
|
|
+ holder.position = position;
|
|
|
}
|
|
|
|
|
|
private View.OnClickListener onClickListener = new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
ViewHolder holder = (ViewHolder) v.getTag();
|
|
|
+ Log.e(TAG, "position -- > " + holder.getLayoutPosition());
|
|
|
+ final int position = holder.getLayoutPosition();
|
|
|
+ ConsentFormListVO consentFormListVO = arrayList.get(position);
|
|
|
+ String formCd = consentFormListVO.getFormCd();
|
|
|
+ Log.e(TAG, "formCd -- > " + formCd);
|
|
|
|
|
|
if (holder.listLayer == v) {
|
|
|
Log.e(TAG, "listLayer");
|
|
|
} else if (holder.tvSubText == v) {
|
|
|
- Log.e(TAG, "tvSubText");
|
|
|
+
|
|
|
+ String soapAction = "";
|
|
|
+ String alertMsg = "";
|
|
|
+ if (apiType.equals(ConsentConfig.GET_CONSENT_SEARCH)) {
|
|
|
+ soapAction = ConsentConfig.SET_USER_FORM_SET;
|
|
|
+ alertMsg = mContext.getString(R.string.addMaker);
|
|
|
+ } else {
|
|
|
+ soapAction = ConsentConfig.DEL_USER_FORM_SET;
|
|
|
+ alertMsg = mContext.getString(R.string.deleteMaker);
|
|
|
+ }
|
|
|
+
|
|
|
+ instance.csAlert.show();
|
|
|
+ instance.csAlert.setContent(alertMsg, "");
|
|
|
+ final String finalSoapAction = soapAction;
|
|
|
+ final String finalFormCd = formCd;
|
|
|
+ instance.csAlert.btnConfirm.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ CallBack callBack = new CallBack() {
|
|
|
+ @Override
|
|
|
+ public void result(final SoapObject result) {
|
|
|
+ Log.e(TAG, apiType + " result -- > " + result);
|
|
|
+ mActivity.runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (result == null || result.toString().indexOf("null") > 0 || result.getPropertyCount() == 0) {
|
|
|
+ stop();
|
|
|
+ } else {
|
|
|
+ String rts = result.getProperty("responseData").toString().trim();
|
|
|
+ int res = Integer.parseInt(rts);
|
|
|
+
|
|
|
+ if (res == 0) {
|
|
|
+ stop();
|
|
|
+ } else {
|
|
|
+ if (apiType.equals(ConsentConfig.GET_CONSENT_SET_LIST)) {
|
|
|
+ arrayList.remove(position);
|
|
|
+ notifyItemRemoved(position);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void stop() {
|
|
|
+ String message = "";
|
|
|
+ if (apiType.equals(ConsentConfig.GET_CONSENT_SEARCH)) {
|
|
|
+ message = String.format(mContext.getString(R.string.failMakerEvent), mContext.getString(R.string.add));
|
|
|
+ } else {
|
|
|
+ message= String.format(mContext.getString(R.string.failMakerEvent), mContext.getString(R.string.delete));
|
|
|
+ }
|
|
|
+ instance.showSingButtonDialog(message);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void error() {
|
|
|
+
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ HashMap<String, String> mData = new HashMap<String, String>();
|
|
|
+ mData.put("instCd", BuildConfig.INST_CD);
|
|
|
+ mData.put("userId", Util.getStringPreference(mContext, "userInfo", "userId"));
|
|
|
+ mData.put("formCd", finalFormCd);
|
|
|
+
|
|
|
+ Util.callHttp(mContext, ConsentConfig.HOST_HOSPITAL, finalSoapAction, mData, callBack);
|
|
|
+ instance.csAlert.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ instance.csAlert.btnCancel.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ instance.csAlert.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
}
|
|
|
|