Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package id.co.acc.www.amos.adapter;
- import android.app.Dialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.support.v7.widget.RecyclerView;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import com.google.gson.Gson;
- import com.raizlabs.android.dbflow.sql.language.SQLite;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.List;
- import id.co.acc.www.amos.R;
- import id.co.acc.www.amos.activity.CustomerDetailActivity;
- import id.co.acc.www.amos.activity.HomeActivity;
- import id.co.acc.www.amos.model.TGprs.DataObject;
- import id.co.acc.www.amos.model.TGprs.DataObject_Table;
- import id.co.acc.www.amos.util.GlobalParam;
- import id.co.acc.www.amos.util.ItemAnimation;
- import id.co.acc.www.amos.util.SharedPreferenceUtils;
- import id.co.acc.www.amos.util.StringConverter;
- import id.co.acc.www.amos.util.UpdateSurveyUtil;
- public class CustomerListAdapter extends RecyclerView.Adapter<CustomerListAdapter.ViewHolder> {
- private Context context;
- private List<DataObject> tgprs;
- private String activePage;
- public CustomerListAdapter(Context context, List<DataObject> tgprs, String activePage) {
- this.context = context;
- this.tgprs = tgprs;
- this.activePage = activePage;
- }
- @Override
- public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- if(activePage.equalsIgnoreCase(context.getString(R.string.pendingSurvey))){
- View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.lst_customer, parent, false);
- LinearLayout a = v.findViewById(R.id.lytCustomerList);
- a.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));
- ViewHolder holder = new ViewHolder(v);
- return holder;
- }else{
- View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.lst_customer, parent, false);
- ViewHolder holder = new ViewHolder(v);
- return holder;
- }
- }
- @Override
- public void onBindViewHolder(ViewHolder holder, final int position) {
- final DataObject value = tgprs.get(position);
- String namepass[] = value.getMessage().split(";");
- String address = namepass[10];
- String dokumen="";
- String grading = namepass[0];
- try
- {
- if(!namepass[34].equals(" "))
- dokumen = namepass[34];
- }
- catch (Exception e)
- {
- }
- holder.txtCustomerNameList.setText(value.getCustName());
- // holder.txtLogDateCorrection.setText(value.getLogDate());
- holder.txtAddressList.setText(address);
- holder.txtOrderNoList.setText(value.getOrderNo()+" ("+grading+")");
- if(!dokumen.isEmpty())
- {
- holder.txtDoc.setVisibility(View.VISIBLE);
- }
- else
- holder.txtDoc.setVisibility(View.GONE);
- String lockStatus = GlobalParam.getValue("LockSurvey");
- Date date=new Date();
- DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
- DateFormat timeFormat = new SimpleDateFormat("HH:mm");
- final String dateOpen=dateFormat.format(date);
- final String timeOpen=timeFormat.format(date);
- if(lockStatus.equalsIgnoreCase("no"))
- {
- if(activePage.equalsIgnoreCase(context.getString(R.string.new_survey)))
- {
- if(SQLite.select().from(DataObject.class)
- .where(DataObject_Table.processFlag.eq("1")).queryList().size()==0)
- {
- if(position>0)
- {
- /*holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));*/
- holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
- }
- else
- {
- holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
- }
- holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- updateOpenDate(dateOpen, timeOpen, value);
- goToCustomerDetail(value, position);
- }
- });
- holder.lytCustomerList.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- //show pop up
- /*DialogAdapter.showDialogOneBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
- , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- }
- });*/
- DialogAdapter.showDialogTwoBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
- , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
- value.delete();
- Intent intention = new Intent(context, HomeActivity.class);
- context.startActivity(intention);
- }
- }, context.getString(R.string.no), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- }
- }
- );
- return true;
- }
- });
- }
- else
- {
- /*holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));*/
- holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
- holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- updateOpenDate(dateOpen, timeOpen, value);
- goToCustomerDetail(value, position);
- }
- });
- holder.lytCustomerList.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- //show pop up
- DialogAdapter.showDialogTwoBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
- , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
- value.delete();
- Intent intention = new Intent(context, HomeActivity.class);
- context.startActivity(intention);
- }
- }, context.getString(R.string.no), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- }
- }
- );
- return true;
- }
- });
- }
- }
- else if(activePage.equalsIgnoreCase(context.getString(R.string.active_survey)))
- {
- if(position>0)
- {
- /*holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));*/
- holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
- }
- holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- goToCustomerDetail(value, position);
- }
- });
- holder.lytCustomerList.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- //show pop up
- DialogAdapter.showDialogTwoBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
- , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
- value.delete();
- Intent intention = new Intent(context, HomeActivity.class);
- context.startActivity(intention);
- }
- }, context.getString(R.string.no), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- }
- }
- );
- return true;
- }
- });
- }else if(activePage.equalsIgnoreCase(context.getString(R.string.pendingSurvey))){
- holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- DialogAdapter.showDialogOneBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
- , "Maaf anda tidak bisa mengedit data ini lagi", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
- value.delete();
- Intent intention = new Intent(context, HomeActivity.class);
- context.startActivity(intention);
- }
- });
- }
- });
- }
- }
- else
- {
- if(activePage.equals(context.getString(R.string.new_survey)))
- {
- if(SQLite.select().from(DataObject.class)
- .where(DataObject_Table.processFlag.eq("1")).queryList().size()==0) {
- holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- updateOpenDate(dateOpen, timeOpen, value);
- goToCustomerDetail(value, position);
- }
- });
- holder.lytCustomerList.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- //show pop up
- DialogAdapter.showDialogTwoBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
- , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
- value.delete();
- Intent intention = new Intent(context, HomeActivity.class);
- context.startActivity(intention);
- }
- }, context.getString(R.string.no), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- }
- }
- );
- return true;
- }
- });
- }
- else
- {
- /*holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));*/
- holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
- holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- updateOpenDate(dateOpen, timeOpen, value);
- goToCustomerDetail(value, position);
- }
- });
- holder.lytCustomerList.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- //show pop up
- DialogAdapter.showDialogTwoBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
- , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
- value.delete();
- Intent intention = new Intent(context, HomeActivity.class);
- context.startActivity(intention);
- }
- }, context.getString(R.string.no), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- }
- }
- );
- return true;
- }
- });
- }
- }
- else if(activePage.equalsIgnoreCase(context.getString(R.string.active_survey)))
- {
- if(position>0)
- {
- /*holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));*/
- holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
- }
- holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- goToCustomerDetail(value, position);
- }
- });
- holder.lytCustomerList.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- //show pop up
- DialogAdapter.showDialogTwoBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
- , "Ingin Menghapus", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- new UpdateSurveyUtil().deleteSurveyMsisdn(value.getOrderNo(), context);
- value.delete();
- Intent intention = new Intent(context, HomeActivity.class);
- context.startActivity(intention);
- }
- }, context.getString(R.string.no), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- }
- }
- );
- return true;
- }
- });
- }
- else if(activePage.equalsIgnoreCase(context.getString(R.string.pendingSurvey)))
- {
- /*holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_grey));*/
- holder.lytCustomerList.setBackground(context.getDrawable(R.drawable.rounded_btn_blue));
- holder.lytCustomerList.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- DialogAdapter.showDialogOneBtn(StringConverter.getActivity(context), context.getString(R.string.title_informasi_dialog)
- , "Maaf anda tidak bisa mengedit data ini lagi", context.getString(R.string.yes), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- }
- });
- }
- });
- }
- }
- setAnimation(holder.itemView, position);
- }
- private int lastPosition = -1;
- private boolean on_attach = true;
- private void setAnimation(View view, int position) {
- if (position > lastPosition) {
- ItemAnimation.animate(view, on_attach ? position : -1, ItemAnimation.FADE_IN);
- lastPosition = position;
- }
- }
- private void updateOpenDate(String dateOpen, String timeOpen, DataObject value)
- {
- DataObject dataObject = SQLite.select().from(DataObject.class).where(DataObject_Table.orderNo.eq(value.getOrderNo())).querySingle();
- if(dataObject.getOpenDate()==null || dataObject.getOpenTime()==null)
- {
- // dataObject.setOpenDate(dateOpen);
- // dataObject.setOpenTime(timeOpen);
- // dataObject.save();
- SQLite.update(DataObject.class).set(
- DataObject_Table.openDate.eq(dateOpen),
- DataObject_Table.openTime.eq(timeOpen)
- ).where(DataObject_Table.orderNo.eq(value.getOrderNo())).execute();
- }
- }
- private void goToCustomerDetail(DataObject value, int position)
- {
- Intent intent = new Intent(context, CustomerDetailActivity.class);
- Gson gson = new Gson();
- // intent.putExtra("customerSelected", gson.toJson(value));
- SharedPreferenceUtils.setSetting(context, "customerSelected", gson.toJson(value));
- // intent.putExtra("activePage", activePage);
- SharedPreferenceUtils.setSetting(context, "activePage", activePage);
- SharedPreferenceUtils.setSetting(context, "customerPosition", position+"");
- context.startActivity(intent);
- }
- @Override
- public int getItemCount() {
- return tgprs.size();
- }
- public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
- TextView txtCustomerNameList, txtAddressList, txtDoc, txtOrderNoList;
- LinearLayout lytCustomerList;
- public ViewHolder(View itemView) {
- super(itemView);
- txtCustomerNameList = (TextView) itemView.findViewById(R.id.txtCustomerNameList);
- txtAddressList = (TextView) itemView.findViewById(R.id.txtAddressList);
- txtOrderNoList = (TextView) itemView.findViewById(R.id.txtOrderNoList);
- lytCustomerList = (LinearLayout) itemView.findViewById(R.id.lytCustomerList);
- txtDoc= (TextView) itemView.findViewById(R.id.txtDoc);
- itemView.setOnClickListener(this);
- }
- @Override
- public void onClick(View v) {
- }
- public void deleteConfirm(){
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement