Thursday, 5 October 2017

getIs_favourite

 if(!listResponse.getIs_favourite())
holder.img_heart.setImageResource(R.mipmap.heart);
  else      holder.img_heart.setImageResource(R.mipmap.heart_fill);



if(!data.getIs_favourite()) {
    img_heart.setImageResource(R.mipmap.heart);
    img_heart.setTag(R.mipmap.heart);
}else{
    img_heart.setImageResource(R.mipmap.heart_fill);
    img_heart.setTag(R.mipmap.heart_fill);

}

Wednesday, 4 October 2017

Save data on Button Click in Preference


    Button btnPunchin,btnPunchout,detail;
    static boolean isPunchedIn;
    SharedPreferences prefs;
    SharedPreferences.Editor edit;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
       View view=  inflater.inflate(R.layout.fragment_attendance, container, false);

        prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
        btnPunchin= (Button) view.findViewById(R.id.punchin);
        btnPunchout= (Button) view.findViewById(R.id.punchout);
        detail= (Button) view.findViewById(R.id.detail);

        if(prefs.getBoolean("isPunchedIn",false)==true){
            btnPunchin.setVisibility(View.GONE);
        }else {
            btnPunchout.setVisibility(View.GONE);
        }

        btnPunchin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btnPunchin.setVisibility(View.GONE);
                btnPunchout.setVisibility(View.VISIBLE);
                isPunchedIn = true;
                edit = prefs.edit();
                edit.putBoolean("isPunchedIn", isPunchedIn);
                edit.commit();
            }
        });
        btnPunchout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btnPunchin.setVisibility(View.VISIBLE);
                btnPunchout.setVisibility(View.GONE);
                isPunchedIn = false;
                edit = prefs.edit();
                edit.putBoolean("isPunchedIn", isPunchedIn);
                edit.commit();
            }
        });
        detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), AttendanceDetail.class);

                startActivity(intent);
            }
        });

        return view;


    }

Pass Array In Json Object in body

private void update() {
try {
    final ProgressDialog pd = new ProgressDialog(OrdersDetails.this);
    pd.setMessage("Loading...");
    pd.show();
    JSONObject jsonObject = new JSONObject();
    JSONArray array = new JSONArray();
    List<CommanData> data = new ArrayList<>();
    data = adb.getDataList();
    for (CommanData commanData : data) {
        JSONObject object = new JSONObject();
        object.put("id", commanData.getId());
        object.put("item_id", commanData.getItem_id());
        object.put("weight", commanData.getWeight());
        object.put("item_type", commanData.getItem_type());
        if (commanData.getQuantity() != null && !commanData.getQuantity().isEmpty())
            object.put("quantity", commanData.getQuantity());
        else            object.put("quantity", "1");
        array.put(object);
    }

    if (addon != null) {
        List<CommanData> data1 = addon.getDataList();
        for (CommanData commanData1 : data1) {
            JSONObject object = new JSONObject();
            object.put("id", commanData1.getId());
            object.put("item_id", commanData1.getItem_id());
            object.put("weight", commanData1.getWeight());
            object.put("item_type", commanData1.getItem_type());
            if (commanData1.getQuantity() != null && !commanData1.getQuantity().isEmpty())
                object.put("quantity", commanData1.getQuantity());
            else                object.put("quantity", "1");
            array.put(object);
        }
    }
    List<CommanData> data2 = new ArrayList<>();
    if (dryclean != null) {
        data2 = dryclean.getDataList();
        for (CommanData commanData2 : data2) {
            JSONObject object = new JSONObject();
            object.put("id", commanData2.getId());
            object.put("item_id", commanData2.getItem_id());
            object.put("weight", commanData2.getWeight());
            object.put("item_type", commanData2.getItem_type());
            if (commanData2.getQuantity() != null && !commanData2.getQuantity().isEmpty())
                object.put("quantity", commanData2.getQuantity());
            else                object.put("quantity", "1");
            array.put(object);
        }
    }


    jsonObject.put("id", itemId);
    jsonObject.put("order_details", array);
  JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
                UPDATE, jsonObject, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    String status = response.getString("status");
                    String message = response.getString("message");
                   

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                pd.dismiss();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(OrdersDetails.this,
                        error.getMessage(), Toast.LENGTH_SHORT).show();
                pd.dismiss();
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> params = new HashMap<String, String>();
                params.put("Csrf-Token", "default11");
                params.put("Auth-Token", preferences.getString("auth_token", ""));
                return params;
            }
        };

        RequestQueue requestQueue = Volley.newRequestQueue(OrdersDetails.this);
        requestQueue.add(jsonObjReq);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

Monday, 2 October 2017

Interface in android

public interface AgentClickInterface {

    void onAgentClick(String agent_id);
}


In Adpter


private AgentClickInterface agentClickInterface;


public AgentAdpter(Activity mContext, ArrayList property_agents,AgentClickInterface agentInterface) {
    this.agentses = property_agents;
    this.mContext = mContext;
    this.agentClickInterface = agentInterface;
}


@Overridepublic void onBindViewHolder(AgentAdpter.ItemViewHolder holder, final int position) {
    final Property_agents property_agents = agentses.get(position);
    holder.txt_agent_name.setText(property_agents.getAgent_name());
    holder.txt_agent_contactno.setText(property_agents.getAgent_phone());
    holder.txt_agent_email.setText(property_agents.getAgent_email());
    holder.txt_agnent_viewprofile.setTag(property_agents.getAgent_id());

    Picasso.with(context).load(property_agents.getAgent_image()).resize(120, 60).into(holder.img_agent);

    holder.txt_agnent_viewprofile.setOnClickListener(new View.OnClickListener() {
        @Override        public void onClick(View v) {
            agentClickInterface.onAgentClick(property_agents.getAgent_id());
        }
    });

}

Main Class

public class DescriptionFragment extends Fragment implements AgentClickInterface, ViewPager.OnPageChangeListener {



@Overridepublic void onAgentClick(String agent_id) {
    this.agent_id = agent_id;
    Intent intent = new Intent(getActivity(), AgentDetails.class);
    intent.putExtra("agent_id", agent_id);
    startActivity(intent);
}