329 lines
10 KiB
Java
329 lines
10 KiB
Java
package com.safemobile.adapters;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.Hashtable;
|
|
import java.util.Locale;
|
|
import java.util.TimeZone;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.View.OnClickListener;
|
|
import android.view.ViewGroup;
|
|
import android.widget.BaseAdapter;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.TextView;
|
|
|
|
import com.safemobile.activities.AbstractRecordingsActivity;
|
|
import com.safemobile.lib.AppParams;
|
|
import com.safemobile.lib.R;
|
|
import com.safemobile.lib.Contact;
|
|
import com.safemobile.lib.SM;
|
|
import com.safemobile.libpad.PadRecording;
|
|
|
|
public class PadRecordingsGridViewAdapter extends BaseAdapter
|
|
{
|
|
private ArrayList<PadRecording> listRecordings;
|
|
private ArrayList<Boolean> recordingExists;
|
|
private ArrayList<Boolean> playingPositions;
|
|
private Activity activity;
|
|
private Context context;
|
|
private int removePosition = -1;
|
|
//public String time;
|
|
//private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D2E4FC") };
|
|
private Hashtable<Integer, View> hash = new Hashtable<Integer, View>();
|
|
|
|
public PadRecordingsGridViewAdapter(Activity activity, Context context, ArrayList<PadRecording> listRecordings)
|
|
{
|
|
super();
|
|
this.activity = activity;
|
|
this.context = context;
|
|
this.listRecordings = listRecordings;
|
|
|
|
this.recordingExists = new ArrayList<Boolean>();
|
|
for(int i=0; i<listRecordings.size(); i++)
|
|
recordingExists.add(true);
|
|
|
|
playingPositions = new ArrayList<Boolean>();
|
|
for(int i=0; i<listRecordings.size(); i++)
|
|
playingPositions.add(false);
|
|
}
|
|
|
|
@Override
|
|
public int getCount() {
|
|
return listRecordings.size();
|
|
}
|
|
|
|
@Override
|
|
public PadRecording getItem(int position) {
|
|
return listRecordings.get(position);
|
|
}
|
|
|
|
@Override
|
|
public long getItemId(int position) {
|
|
return 0;
|
|
}
|
|
|
|
public ArrayList<PadRecording> getRecordings() {
|
|
return listRecordings;
|
|
}
|
|
|
|
/** Define Row Template */
|
|
public static class ViewHolder
|
|
{
|
|
public LinearLayout layoutRecording;
|
|
public ImageView imageViewPlay, imageViewRecycle;
|
|
public TextView textViewSender, textViewDuration, textViewDate;
|
|
}
|
|
|
|
@Override
|
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
|
final ViewHolder view;
|
|
LayoutInflater inflator = activity.getLayoutInflater();
|
|
if(convertView==null)
|
|
{
|
|
view = new ViewHolder();
|
|
convertView = inflator.inflate(R.layout.row_recordings, null);
|
|
view.layoutRecording = (LinearLayout) convertView.findViewById(R.id.layoutRecording);
|
|
view.imageViewPlay = (ImageView) convertView.findViewById(R.id.imageViewPlay);
|
|
view.textViewSender = (TextView) convertView.findViewById(R.id.textViewSender);
|
|
view.textViewDuration = (TextView) convertView.findViewById(R.id.textViewDuration);
|
|
view.textViewDate = (TextView) convertView.findViewById(R.id.textViewDate);
|
|
view.imageViewRecycle = (ImageView) convertView.findViewById(R.id.imageViewRecycle);
|
|
|
|
convertView.setTag(view);
|
|
}
|
|
else
|
|
{
|
|
view = (ViewHolder) convertView.getTag();
|
|
}
|
|
|
|
hash.put(position, convertView);
|
|
|
|
try {
|
|
//SM.Debug("SIZE EXISTS : " + recordingExists.size() + " | " + playingPositions.size());
|
|
/* if recording doesn't exists change background */
|
|
/*
|
|
if(recordingExists.size()> position && !recordingExists.get(position))
|
|
view.layoutRecording.setBackgroundColor(0xFFDDDDDD);
|
|
else
|
|
*/
|
|
|
|
if(playingPositions.size() > position)
|
|
{
|
|
/* if recording is not playing let background to white */
|
|
|
|
if(!playingPositions.get(position))
|
|
view.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
|
else
|
|
view.layoutRecording.setBackgroundColor(0xFF457c98);
|
|
|
|
}
|
|
else
|
|
view.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
|
|
|
/* change icon according to call type [outgoing or incoming] */
|
|
if(listRecordings.size() > position)
|
|
switch(listRecordings.get(position).callType)
|
|
{
|
|
case AppParams.MotoAllCall:
|
|
if(!listRecordings.get(position).isOutgoing)
|
|
view.imageViewPlay.setImageResource(R.drawable.call_received_all);
|
|
else
|
|
view.imageViewPlay.setImageResource(R.drawable.call_made_all);
|
|
break;
|
|
case AppParams.MotoPrivate:
|
|
if(!listRecordings.get(position).isOutgoing)
|
|
view.imageViewPlay.setImageResource(R.drawable.call_received);
|
|
else
|
|
view.imageViewPlay.setImageResource(R.drawable.call_made);
|
|
break;
|
|
case AppParams.MotoGroup:
|
|
if(!listRecordings.get(position).isOutgoing)
|
|
view.imageViewPlay.setImageResource(R.drawable.call_received_group);
|
|
else
|
|
view.imageViewPlay.setImageResource(R.drawable.call_made_group);
|
|
break;
|
|
}
|
|
}
|
|
catch(IndexOutOfBoundsException ex) {
|
|
SM.Exception("IndexOutOfBounds Exception [PadRecordingsGridViewAdapter]" + ex.toString());
|
|
}
|
|
/*
|
|
try
|
|
{
|
|
if(receivedPositions.get(position))
|
|
{
|
|
if(playingPositions.get(position))
|
|
view.imageViewPlay.setImageResource(R.drawable.play_received);
|
|
else
|
|
view.imageViewPlay.setImageResource(R.drawable.call_received);
|
|
|
|
}
|
|
else
|
|
{
|
|
if(playingPositions.get(position))
|
|
view.imageViewPlay.setImageResource(R.drawable.play_made);
|
|
else
|
|
view.imageViewPlay.setImageResource(R.drawable.call_made);
|
|
}
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
SM.Exception("EXCeptioN", ex.toString());
|
|
view.imageViewPlay.setImageResource(R.drawable.play);
|
|
}*/
|
|
|
|
/* intercept Recycle click */
|
|
view.imageViewRecycle.setVisibility(View.GONE);
|
|
view.imageViewRecycle.setOnClickListener(new OnClickListener() {
|
|
@Override
|
|
public void onClick(View v) {
|
|
// save the position of the marked record
|
|
removePosition = position;
|
|
|
|
// change the background for marked record
|
|
View view = (View) hash.get(position);
|
|
ViewHolder viewHolder = (ViewHolder) view.getTag();
|
|
viewHolder.layoutRecording.setBackgroundColor(0xFF457c98);
|
|
((AbstractRecordingsActivity) activity).deleteSelected(position);
|
|
}
|
|
});
|
|
|
|
String sender = "", name="", initName="";
|
|
|
|
for(Contact cont: AppParams.listContacts)
|
|
{
|
|
if(cont.id == getItem(position).radioID)
|
|
{
|
|
// get name only if callType equals with the one from the ConfigFile
|
|
if( (getItem(position).callType == AppParams.MotoPrivate && cont.contactType == Contact.PRIVATE)
|
|
|| (getItem(position).callType == AppParams.MotoGroup && cont.contactType == Contact.GROUP)
|
|
|| (getItem(position).callType == AppParams.MotoAllCall))
|
|
// || getItem(position).type == AppParams.AllCall && cont.callType.equals("All Call"))
|
|
name = cont.name;
|
|
}
|
|
if (cont.id == getItem(position).initRadioID) {
|
|
// get name only if callType equals with the one from the ConfigFile
|
|
if( (getItem(position).callType == AppParams.MotoPrivate && cont.contactType == Contact.PRIVATE)
|
|
|| (getItem(position).callType == AppParams.MotoGroup && cont.contactType == Contact.GROUP)
|
|
|| (getItem(position).callType == AppParams.MotoAllCall))
|
|
// || getItem(position).type == AppParams.AllCall && cont.callType.equals("All Call"))
|
|
initName = cont.name;
|
|
}
|
|
|
|
// if call type is Group I should find a private
|
|
if(getItem(position).callType == AppParams.MotoGroup && (cont.id == getItem(position).initRadioID && cont.contactType == Contact.PRIVATE))
|
|
initName = cont.name;
|
|
|
|
}
|
|
|
|
// // set name to All Call if call was made from tabled
|
|
if(getItem(position).callType == AppParams.MotoAllCall && getItem(position).isOutgoing)
|
|
sender += context.getResources().getString(R.string.AllCall);
|
|
else if(getItem(position).callType == AppParams.MotoAllCall) {
|
|
name = context.getResources().getString(R.string.AllCall);
|
|
if(initName.length() > 0)
|
|
sender = name + " [" + initName + "]";
|
|
else
|
|
sender = name + " [" + getItem(position).initRadioID + "]";
|
|
}
|
|
// add the name/id of the contact that initiated the AllCall
|
|
else if(name.length() < 1)
|
|
sender += getItem(position).radioID;
|
|
else
|
|
sender += name;
|
|
|
|
// add caller name for group call
|
|
if(listRecordings.get(position).callType == AppParams.MotoGroup)
|
|
{
|
|
if(!getItem(position).isOutgoing) {
|
|
if(initName.length() > 0)
|
|
sender = name + " [" + initName + "]";
|
|
else
|
|
sender = name + " [" + getItem(position).initRadioID + "]";
|
|
}
|
|
else
|
|
sender = name;
|
|
}
|
|
// for private call that was received I have to get the id from the initRadioID
|
|
else if(listRecordings.get(position).callType == AppParams.MotoPrivate)
|
|
{
|
|
if(!getItem(position).isOutgoing && initName.length()>0)
|
|
sender = initName;
|
|
else if (!getItem(position).isOutgoing)
|
|
sender += getItem(position).initRadioID + "";
|
|
}
|
|
|
|
view.textViewSender.setText(sender);
|
|
view.textViewDuration.setText("[" + listRecordings.get(position).duration + " sec]");
|
|
|
|
/* Add call Date */
|
|
Date date = new Date(getItem(position).timeGMT * 1000);
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
|
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
|
|
calendar.set(Calendar.HOUR_OF_DAY,0);
|
|
calendar.set(Calendar.MINUTE, 0);
|
|
calendar.set(Calendar.SECOND, 0);
|
|
calendar.set(Calendar.MILLISECOND, 0);
|
|
|
|
if(date.after(calendar.getTime()))
|
|
sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault());
|
|
else
|
|
sdf = new SimpleDateFormat("MMM-dd HH:mm", Locale.getDefault());
|
|
|
|
// set gmt time
|
|
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
|
|
|
view.textViewDate.setText(sdf.format(date));
|
|
|
|
return convertView;
|
|
}
|
|
|
|
|
|
/** Reset row background when recycle was canceled */
|
|
public void cancelDelete()
|
|
{
|
|
View view = (View) hash.get(removePosition);
|
|
if(recordingExists.get(removePosition))
|
|
view.setBackgroundColor(0xFFFFFFFF);
|
|
else
|
|
view.setBackgroundColor(0xFFDDDDDD);
|
|
|
|
removePosition = -1;
|
|
}
|
|
|
|
|
|
/** Get the View for one row in the GridView */
|
|
public View getView(int position)
|
|
{
|
|
return (View) hash.get(position);
|
|
}
|
|
|
|
|
|
/** Change playing recording background */
|
|
public void changePlaying(int position, boolean playing)
|
|
{
|
|
// change value in the vector
|
|
playingPositions.set(position, playing);
|
|
|
|
// make changes in the UI //
|
|
try {
|
|
PadRecordingsGridViewAdapter.ViewHolder viewHolder = (PadRecordingsGridViewAdapter.ViewHolder) getView(position).getTag();
|
|
if(!playing)
|
|
viewHolder.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
|
else
|
|
viewHolder.layoutRecording.setBackgroundColor(0xFF457c98);
|
|
}
|
|
catch (NullPointerException ex) {
|
|
|
|
}
|
|
}
|
|
}
|