/
AttendeeListAdapter.java
142 lines (122 loc) · 5.64 KB
/
AttendeeListAdapter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package org.fossasia.fossasiaorgaandroidapp.Adapters;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.android.volley.VolleyError;
import com.google.gson.Gson;
import com.google.gson.internal.bind.ArrayTypeAdapter;
import org.fossasia.fossasiaorgaandroidapp.Api.ApiCall;
import org.fossasia.fossasiaorgaandroidapp.Api.LoginCall;
import org.fossasia.fossasiaorgaandroidapp.Interfaces.VolleyCallBack;
import org.fossasia.fossasiaorgaandroidapp.R;
import org.fossasia.fossasiaorgaandroidapp.Utils.Constants;
import org.fossasia.fossasiaorgaandroidapp.model.AttendeeDetails;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by rishabhkhanna on 27/04/17.
*/
public class AttendeeListAdapter extends RecyclerView.Adapter<AttendeeListAdapter.AttendeeListAdapterHolder> {
ArrayList<AttendeeDetails> attendeeDetailses;
Activity activity;
long id;
public static final String TAG = "AttendeeAdapter";
public AttendeeListAdapter(ArrayList<AttendeeDetails> attendeeDetailses, Activity activity, long id) {
this.attendeeDetailses = attendeeDetailses;
this.activity = activity;
this.id = id;
}
@Override
public AttendeeListAdapterHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater li = activity.getLayoutInflater();
View itemView = li.inflate(R.layout.attendee_layout,null);
AttendeeListAdapterHolder attendeeListAdapterHolder = new AttendeeListAdapterHolder(itemView);
return attendeeListAdapterHolder;
}
@Override
public void onBindViewHolder(final AttendeeListAdapterHolder holder, final int position) {
final AttendeeDetails thisAttendee = attendeeDetailses.get(position);
holder.tvLastName.setText(thisAttendee.getLastname());
holder.tvFirstName.setText(thisAttendee.getFirstname());
holder.tvEmail.setText(thisAttendee.getEmail());
if(thisAttendee.getCheckedIn()) {
holder.btnCheckedIn.setText("Checked In");
holder.btnCheckedIn.setBackgroundColor(ContextCompat.getColor(activity,android.R.color.holo_green_dark));
}else{
holder.btnCheckedIn.setText("Check In");
holder.btnCheckedIn.setBackgroundColor(ContextCompat.getColor(activity,android.R.color.holo_red_light));
}
holder.btnCheckedIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "onClick: alert builder click");
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
String alertTitle = "";
if(thisAttendee.getCheckedIn()){
alertTitle = Constants.AttendeeCheckingOut;
}else{
alertTitle = Constants.attendeeChechingIn;
}
builder.setTitle(alertTitle).setMessage(thisAttendee.getFirstname() + " "
+ thisAttendee.getLastname() + "\n"
+ "Ticket: " + thisAttendee.getTicket().getType() )
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Log.d(TAG, "onClick: inside ok");
changeCheckStatus(activity,thisAttendee,holder.btnCheckedIn,attendeeDetailses,position);
}
}).setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.create();
builder.show();
}
});
}
@Override
public int getItemCount() {
return attendeeDetailses.size();
}
public class AttendeeListAdapterHolder extends RecyclerView.ViewHolder{
TextView tvLastName;
TextView tvFirstName;
TextView tvEmail;
Button btnCheckedIn;
public AttendeeListAdapterHolder(View itemView) {
super(itemView);
tvLastName = (TextView) itemView.findViewById(R.id.tvLastName);
tvFirstName = (TextView) itemView.findViewById(R.id.tvFirstName);
tvEmail = (TextView) itemView.findViewById(R.id.tvEmail);
btnCheckedIn = (Button) itemView.findViewById(R.id.btnCheckedin);
}
}
public void changeCheckStatus(Activity activity, AttendeeDetails thisAttendee, final Button btnCheckedIn, final ArrayList<AttendeeDetails> attendeeDetailses, final int position){
ApiCall.PostApiCall(activity, Constants.eventDetails +id + Constants.attendeesToggle + thisAttendee.getId(), new VolleyCallBack() {
@Override
public void onSuccess(String result) {
Log.d(TAG, "onSuccess: " + result);
Gson gson = new Gson();
AttendeeDetails newattendeeDetailses = gson.fromJson(result,AttendeeDetails.class);
attendeeDetailses.set(position , newattendeeDetailses);
notifyDataSetChanged();
}
@Override
public void onError(VolleyError error) {
}
});
}
}