255 lines
7.7 KiB
Java
255 lines
7.7 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.Recording;
|
|
import com.safemobile.lib.Contact;
|
|
import com.safemobile.lib.SM;
|
|
|
|
public class RecordingsGridViewAdapter extends BaseAdapter
|
|
{
|
|
private ArrayList<Recording> 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 RecordingsGridViewAdapter(Activity activity, Context context, ArrayList<Recording> listRecordings, ArrayList<Boolean> recordingExists)
|
|
{
|
|
super();
|
|
this.activity = activity;
|
|
this.context = context;
|
|
this.listRecordings = listRecordings;
|
|
this.recordingExists = recordingExists;
|
|
|
|
playingPositions = new ArrayList<Boolean>();
|
|
for(int i=0; i<recordingExists.size(); i++) {
|
|
playingPositions.add(false);
|
|
|
|
listRecordings.get(i).date = listRecordings.get(i).startGMT;
|
|
listRecordings.get(i).duration = listRecordings.get(i).endGMT - listRecordings.get(i).startGMT;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int getCount() {
|
|
return listRecordings.size();
|
|
}
|
|
|
|
@Override
|
|
public Recording getItem(int position) {
|
|
return listRecordings.get(position);
|
|
}
|
|
|
|
@Override
|
|
public long getItemId(int position) {
|
|
return 0;
|
|
}
|
|
|
|
/** 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);
|
|
view.imageViewRecycle.setVisibility(View.GONE);
|
|
convertView.setTag(view);
|
|
}
|
|
else
|
|
{
|
|
view = (ViewHolder) convertView.getTag();
|
|
}
|
|
|
|
hash.put(position, convertView);
|
|
|
|
|
|
|
|
/* if recording doesn't exists change background */
|
|
if(!recordingExists.get(position))
|
|
view.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
|
else
|
|
{
|
|
/* if recording is not playing let background to white */
|
|
if(!playingPositions.get(position))
|
|
view.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
|
else
|
|
view.layoutRecording.setBackgroundColor(0xFF457c98);
|
|
}
|
|
|
|
/* change icon according to call type [outgoing or incoming] */
|
|
SM.Exception("REC TYPE : " + listRecordings.get(position).type);
|
|
switch(listRecordings.get(position).type)
|
|
{
|
|
case AppParams.AllCall:
|
|
if(listRecordings.get(position).destinationRadioID == 0)
|
|
view.imageViewPlay.setImageResource(R.drawable.call_received_all);
|
|
else
|
|
view.imageViewPlay.setImageResource(R.drawable.call_made_all);
|
|
break;
|
|
case AppParams.PrivateCall:
|
|
if(listRecordings.get(position).destinationRadioID == 0)
|
|
view.imageViewPlay.setImageResource(R.drawable.call_received);
|
|
else
|
|
view.imageViewPlay.setImageResource(R.drawable.call_made);
|
|
break;
|
|
case AppParams.GroupCall:
|
|
if(listRecordings.get(position).destinationRadioID == 0)
|
|
view.imageViewPlay.setImageResource(R.drawable.call_received_group);
|
|
else
|
|
view.imageViewPlay.setImageResource(R.drawable.call_made_group);
|
|
break;
|
|
}
|
|
/*
|
|
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.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);
|
|
}
|
|
});
|
|
|
|
// set recording image
|
|
if(getItem(position).NameForDisplay.equals(AppParams.USERNAME))
|
|
view.imageViewPlay.setImageDrawable(context.getResources().getDrawable(R.drawable.call_made_group));
|
|
else
|
|
view.imageViewPlay.setImageDrawable(context.getResources().getDrawable(R.drawable.call_received_group));
|
|
|
|
view.textViewSender.setText(getItem(position).NameForDisplay);
|
|
view.textViewDuration.setText("[" + getItem(position).duration + " sec]");
|
|
|
|
/* Add call Date */
|
|
Date date = new Date();
|
|
date.setTime(listRecordings.get(position).date * 1000);
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
|
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(date.after(calendar.getTime()))
|
|
sdf = new SimpleDateFormat("HH:mm:ss");
|
|
else
|
|
sdf = new SimpleDateFormat("MMM-dd HH:mm");
|
|
|
|
// 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);
|
|
|
|
RecordingsGridViewAdapter.ViewHolder viewHolder = (RecordingsGridViewAdapter.ViewHolder) getView(position).getTag();
|
|
if(!playing)
|
|
viewHolder.layoutRecording.setBackgroundColor(0xFFFFFFFF);
|
|
else
|
|
viewHolder.layoutRecording.setBackgroundColor(0xFF457c98);
|
|
|
|
// update hash
|
|
hash.get(position).setTag(viewHolder);
|
|
|
|
}
|
|
}
|