125 lines
3.6 KiB
Java
125 lines
3.6 KiB
Java
|
|
package beyondsoft.bewomitarbeiterapp;
|
||
|
|
|
||
|
|
import android.app.Activity;
|
||
|
|
import android.text.Html;
|
||
|
|
import android.util.Log;
|
||
|
|
import android.view.LayoutInflater;
|
||
|
|
import android.view.View;
|
||
|
|
import android.view.ViewGroup;
|
||
|
|
import android.widget.ArrayAdapter;
|
||
|
|
import android.widget.TextView;
|
||
|
|
|
||
|
|
import java.text.SimpleDateFormat;
|
||
|
|
import java.util.Calendar;
|
||
|
|
import java.util.Date;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Created by bib on 20.05.2016.
|
||
|
|
*/
|
||
|
|
public class MessageAdapter extends ArrayAdapter<ChatMessageFormat> {
|
||
|
|
|
||
|
|
private Activity activity;
|
||
|
|
private List<ChatMessageFormat> messages;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
public MessageAdapter(Activity context, int resource, List<ChatMessageFormat> objects) {
|
||
|
|
super(context, resource, objects);
|
||
|
|
this.activity = context;
|
||
|
|
this.messages = objects;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||
|
|
ViewHolder holder;
|
||
|
|
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
|
||
|
|
|
||
|
|
int layoutResource = 0; // determined by view type
|
||
|
|
ChatMessageFormat chatMessage = getItem(position);
|
||
|
|
int viewType = getItemViewType(position);
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
//Splitt message um zu wissen ob from server oder nicht
|
||
|
|
String line = chatMessage.getMessage();
|
||
|
|
|
||
|
|
String[] splitt = line.split(":");
|
||
|
|
|
||
|
|
//Server nachricht kenntlich machen
|
||
|
|
if (chatMessage.getIsME()) {
|
||
|
|
layoutResource = R.layout.item_chat_right;
|
||
|
|
} else if(splitt[0].equals("Server")) {
|
||
|
|
layoutResource = R.layout.item_chat_sever_right;
|
||
|
|
}else {
|
||
|
|
layoutResource = R.layout.item_chat_left;
|
||
|
|
}
|
||
|
|
|
||
|
|
/* Original
|
||
|
|
if (chatMessage.getIsME()) {
|
||
|
|
layoutResource = R.layout.item_chat_left;
|
||
|
|
} else {
|
||
|
|
layoutResource = R.layout.item_chat_right;
|
||
|
|
}
|
||
|
|
*/
|
||
|
|
/* if (convertView != null) {
|
||
|
|
holder = (ViewHolder) convertView.getTag();
|
||
|
|
Log.v("Status","Bin ich hier ?? ");
|
||
|
|
} else {*/
|
||
|
|
convertView = inflater.inflate(layoutResource, parent, false);
|
||
|
|
holder = new ViewHolder(convertView);
|
||
|
|
convertView.setTag(holder);
|
||
|
|
//}
|
||
|
|
|
||
|
|
//set message content
|
||
|
|
holder.msg.setText(chatMessage.getMessage());
|
||
|
|
|
||
|
|
|
||
|
|
//TODO eine weitere option für Chatmessage hinzufügen zum abfragen wegen send Message
|
||
|
|
|
||
|
|
if(holder.send_tick != null)
|
||
|
|
holder.send_tick.setText(Html.fromHtml("✓")+""+Html.fromHtml("✓"));
|
||
|
|
|
||
|
|
|
||
|
|
if(chatMessage.getIsME()){
|
||
|
|
holder.dateIn.setText(chatMessage.getDatum());
|
||
|
|
}else {
|
||
|
|
holder.dateOut.setText(chatMessage.getDatum());
|
||
|
|
}
|
||
|
|
|
||
|
|
return convertView;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public int getViewTypeCount() {
|
||
|
|
// return the total number of view types. this value should never change
|
||
|
|
// at runtime
|
||
|
|
return 2;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public int getItemViewType(int position) {
|
||
|
|
// return a value between 0 and (getViewTypeCount - 1)
|
||
|
|
return position % 2;
|
||
|
|
}
|
||
|
|
|
||
|
|
private class ViewHolder {
|
||
|
|
private TextView msg;
|
||
|
|
private TextView dateOut;
|
||
|
|
private TextView dateIn;
|
||
|
|
|
||
|
|
private TextView send_tick;
|
||
|
|
|
||
|
|
|
||
|
|
public ViewHolder(View v) {
|
||
|
|
msg = (TextView) v.findViewById(R.id.txt_msg);
|
||
|
|
dateOut = (TextView)v.findViewById(R.id.DateOUT);
|
||
|
|
dateIn = (TextView)v.findViewById(R.id.DateIN);
|
||
|
|
send_tick = (TextView)v.findViewById(R.id.txt_msg_tick);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|