201 lines
6.0 KiB
Java
201 lines
6.0 KiB
Java
|
package com.safemobile.adapters;
|
||
|
|
||
|
import java.text.SimpleDateFormat;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Calendar;
|
||
|
import java.util.Hashtable;
|
||
|
|
||
|
import android.app.Activity;
|
||
|
import android.content.Context;
|
||
|
import android.view.LayoutInflater;
|
||
|
import android.view.View;
|
||
|
import android.view.ViewGroup;
|
||
|
import android.widget.BaseAdapter;
|
||
|
import android.widget.ImageView;
|
||
|
import android.widget.LinearLayout;
|
||
|
import android.widget.TextView;
|
||
|
|
||
|
import com.safemobile.lib.Msg;
|
||
|
import com.safemobile.lib.R;
|
||
|
import com.safemobile.lib.SM;
|
||
|
|
||
|
public class ConversationGridViewAdapter extends BaseAdapter
|
||
|
{
|
||
|
private ArrayList<Msg> listMessages;
|
||
|
private Activity activity;
|
||
|
//public String time;
|
||
|
private ArrayList<Boolean> dispatcher_positions = new ArrayList<Boolean>();
|
||
|
private ArrayList<Boolean> ackPositions = new ArrayList<Boolean>();
|
||
|
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
||
|
|
||
|
|
||
|
public ConversationGridViewAdapter(Activity activity, ArrayList<Msg> listMessages, Context context, long sc_id, int unit_type, ArrayList<Boolean> dispatcher_positions, ArrayList<Boolean> ackPositions) {
|
||
|
this.activity = activity;
|
||
|
this.listMessages = listMessages;
|
||
|
this.dispatcher_positions = dispatcher_positions;
|
||
|
this.ackPositions = ackPositions;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public int getCount() {
|
||
|
return listMessages.size();
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public Msg getItem(int position) {
|
||
|
return listMessages.get(position);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public long getItemId(int position) {
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
public static class ViewHolder
|
||
|
{
|
||
|
public ImageView imgViewContact;
|
||
|
public TextView txtViewMsg;
|
||
|
public TextView txtViewDateTime;
|
||
|
public ImageView imgViewReceivedContact;
|
||
|
public TextView txtViewReceivedMsg;
|
||
|
public TextView txtViewReceivedDateTime;
|
||
|
public ImageView imageAck;
|
||
|
public TextView textViewNotACK;
|
||
|
public LinearLayout layoutSend;
|
||
|
public LinearLayout layoutReceived;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||
|
ViewHolder view;
|
||
|
LayoutInflater inflator = activity.getLayoutInflater();
|
||
|
|
||
|
if(convertView==null)
|
||
|
{
|
||
|
view = new ViewHolder();
|
||
|
convertView = inflator.inflate(R.layout.row_conversation, null);
|
||
|
|
||
|
view.imgViewContact = (ImageView) convertView.findViewById(R.id.imageViewSenderIco);
|
||
|
view.txtViewMsg = (TextView) convertView.findViewById(R.id.textViewSendMsg);
|
||
|
view.txtViewDateTime = (TextView) convertView.findViewById(R.id.textViewSendDate);
|
||
|
view.imgViewReceivedContact = (ImageView) convertView.findViewById(R.id.imageViewReceivedIco);
|
||
|
view.txtViewReceivedMsg = (TextView) convertView.findViewById(R.id.textViewReceivedMsg);
|
||
|
view.txtViewReceivedDateTime = (TextView) convertView.findViewById(R.id.textViewReceivedDate);
|
||
|
view.layoutSend = (LinearLayout) convertView.findViewById(R.id.layoutSend);
|
||
|
view.layoutReceived = (LinearLayout) convertView.findViewById(R.id.layoutReceived);
|
||
|
view.textViewNotACK = (TextView) convertView.findViewById(R.id.textViewNotACKSendMsg);
|
||
|
view.imageAck = (ImageView) convertView.findViewById(R.id.imageAck);
|
||
|
|
||
|
convertView.setTag(view);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
view = (ViewHolder) convertView.getTag();
|
||
|
}
|
||
|
try
|
||
|
{
|
||
|
hash.put(position, convertView);
|
||
|
|
||
|
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm MMM-dd");
|
||
|
Calendar calendar = Calendar.getInstance();
|
||
|
calendar.set(Calendar.HOUR_OF_DAY,0);
|
||
|
calendar.set(Calendar.MINUTE, 0);
|
||
|
calendar.set(Calendar.SECOND, 0);
|
||
|
calendar.set(Calendar.MILLISECOND, 0);
|
||
|
if(listMessages.get(position).received.after(calendar.getTime()))
|
||
|
sdf = new SimpleDateFormat("HH:mm:ss");
|
||
|
else
|
||
|
sdf = new SimpleDateFormat("HH:mm MMM-dd");
|
||
|
|
||
|
|
||
|
//view.imgViewContact.setImageResource(getIcon(listMessages.get(position).from.user_type));
|
||
|
view.imgViewContact.setImageResource(R.drawable.peoplegreen_large);
|
||
|
view.txtViewMsg.setText(listMessages.get(position).message);
|
||
|
view.txtViewDateTime.setText(sdf.format(listMessages.get(position).received));
|
||
|
//view.imgViewReceivedContact.setImageResource(getIcon(listMessages.get(position).from.user_type));
|
||
|
view.imgViewReceivedContact.setImageResource(listMessages.get(position).from.getLargeIcon());
|
||
|
view.txtViewReceivedMsg.setText(listMessages.get(position).message);
|
||
|
view.txtViewReceivedDateTime.setText(sdf.format(listMessages.get(position).received));
|
||
|
|
||
|
if(ackPositions.size() > 0)
|
||
|
switch(ackPositions.get(position) ? 1: 0) {
|
||
|
case 0:
|
||
|
// show not ack
|
||
|
view.textViewNotACK.setVisibility(View.VISIBLE);
|
||
|
view.imageAck.setVisibility(View.VISIBLE);
|
||
|
break;
|
||
|
case 1:
|
||
|
// show not ack
|
||
|
view.textViewNotACK.setVisibility(View.INVISIBLE);
|
||
|
view.imageAck.setVisibility(View.INVISIBLE);
|
||
|
}
|
||
|
|
||
|
switch(dispatcher_positions.get(position) ? 1 : 0) {
|
||
|
case 1:
|
||
|
view.layoutReceived.setVisibility(View.GONE);
|
||
|
view.layoutSend.setVisibility(View.VISIBLE);
|
||
|
break;
|
||
|
case 0:
|
||
|
view.layoutReceived.setVisibility(View.VISIBLE);
|
||
|
view.layoutSend.setVisibility(View.GONE);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
catch(Exception ex)
|
||
|
{
|
||
|
SM.Exception(ex.toString());
|
||
|
}
|
||
|
return convertView;
|
||
|
}
|
||
|
|
||
|
public void setACK(String seqID)
|
||
|
{
|
||
|
int position = -1, i=0;
|
||
|
|
||
|
for(Msg msg: listMessages)
|
||
|
{
|
||
|
if(msg.seqID.equals(seqID))
|
||
|
position = i;
|
||
|
|
||
|
i++;
|
||
|
}
|
||
|
|
||
|
if(position > -1 && position < ackPositions.size()) {
|
||
|
ackPositions.remove(position);
|
||
|
ackPositions.add(position, true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void changeView(String seqID)
|
||
|
{
|
||
|
int position = -1, i=0;
|
||
|
|
||
|
for(Msg msg: listMessages)
|
||
|
{
|
||
|
if(msg.seqID.equals(seqID))
|
||
|
position = i;
|
||
|
|
||
|
i++;
|
||
|
}
|
||
|
|
||
|
if(position != -1 && hash.size() > position)
|
||
|
{
|
||
|
SM.Debug("POSITON : " + position);
|
||
|
View con = hash.get(position);
|
||
|
ViewHolder view = (ViewHolder) con.getTag();
|
||
|
|
||
|
switch(ackPositions.get(position) ? 1 : 0)
|
||
|
{
|
||
|
case 1:
|
||
|
view.imageAck.setVisibility(View.INVISIBLE);
|
||
|
view.textViewNotACK.setVisibility(View.INVISIBLE);
|
||
|
break;
|
||
|
case 0:
|
||
|
view.imageAck.setVisibility(View.VISIBLE);
|
||
|
view.textViewNotACK.setVisibility(View.VISIBLE);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|