From b072355b4fa2bdd8b168f128701f825f29ba7d5c Mon Sep 17 00:00:00 2001 From: Bogdan Date: Fri, 18 Mar 2022 08:40:05 +0200 Subject: [PATCH] #SD-185 - Make the UI compatible with SMS parsing changes --- .../adapters/ConversationGridViewAdapter.java | 318 ++-- .../adapters/MessagesGridViewAdapter.java | 91 +- .../PadConversationGridViewAdapter.java | 215 --- .../src/main/res/layout/row_conversation.xml | 275 ++-- .../safemobile/dispatch/MessagesActivity.java | 1282 +++++++---------- .../dispatch/TabLayoutActivity.java | 54 +- .../src/main/res/layout-large/tabtext.xml | 471 +++--- safeDispatch/src/main/res/layout/tabtext.xml | 465 +++--- 8 files changed, 1418 insertions(+), 1753 deletions(-) delete mode 100644 libSafeMobile/src/main/java/com/safemobile/adapters/PadConversationGridViewAdapter.java diff --git a/libSafeMobile/src/main/java/com/safemobile/adapters/ConversationGridViewAdapter.java b/libSafeMobile/src/main/java/com/safemobile/adapters/ConversationGridViewAdapter.java index e9ef9dd..36de8e2 100644 --- a/libSafeMobile/src/main/java/com/safemobile/adapters/ConversationGridViewAdapter.java +++ b/libSafeMobile/src/main/java/com/safemobile/adapters/ConversationGridViewAdapter.java @@ -6,7 +6,6 @@ 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; @@ -19,23 +18,21 @@ import com.safemobile.lib.Msg; import com.safemobile.lib.R; import com.safemobile.lib.SM; -public class ConversationGridViewAdapter extends BaseAdapter -{ - private ArrayList listMessages; - private Activity activity; - //public String time; - private ArrayList dispatcher_positions = new ArrayList(); - private ArrayList ackPositions = new ArrayList(); - private Hashtable hash = new Hashtable(); - - - public ConversationGridViewAdapter(Activity activity, ArrayList listMessages, Context context, long sc_id, int unit_type, ArrayList dispatcher_positions, ArrayList ackPositions) { +public class ConversationGridViewAdapter extends BaseAdapter { + private final ArrayList listMessages; + private final Activity activity; + private final ArrayList dispatcherPositions; + private final ArrayList ackPositions; + private final Hashtable hash = new Hashtable<>(); + + + public ConversationGridViewAdapter(Activity activity, ArrayList listMessages, ArrayList dispatcherPositions, ArrayList ackPositions) { this.activity = activity; this.listMessages = listMessages; - this.dispatcher_positions = dispatcher_positions; - this.ackPositions = ackPositions; + this.dispatcherPositions = dispatcherPositions; + this.ackPositions = ackPositions; } - + @Override public int getCount() { return listMessages.size(); @@ -51,149 +48,230 @@ public class ConversationGridViewAdapter extends BaseAdapter 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; + public static class ViewHolder { + private ImageView imgViewContact; + private TextView txtViewMsg; + private TextView txtViewDateTime; + private ImageView imgViewReceivedContact; + private TextView txtViewReceivedMsg; + private TextView txtViewReceivedDateTime; + private ImageView imageAck; + private TextView textViewNotACK; + private LinearLayout layoutSend; + private LinearLayout layoutReceived; + + public ImageView getImgViewContact() { + return imgViewContact; + } + + public void setImgViewContact(ImageView imgViewContact) { + this.imgViewContact = imgViewContact; + } + + public TextView getTxtViewMsg() { + return txtViewMsg; + } + + public void setTxtViewMsg(TextView txtViewMsg) { + this.txtViewMsg = txtViewMsg; + } + + public TextView getTxtViewDateTime() { + return txtViewDateTime; + } + + public void setTxtViewDateTime(TextView txtViewDateTime) { + this.txtViewDateTime = txtViewDateTime; + } + + public ImageView getImgViewReceivedContact() { + return imgViewReceivedContact; + } + + public void setImgViewReceivedContact(ImageView imgViewReceivedContact) { + this.imgViewReceivedContact = imgViewReceivedContact; + } + + public TextView getTxtViewReceivedMsg() { + return txtViewReceivedMsg; + } + + public void setTxtViewReceivedMsg(TextView txtViewReceivedMsg) { + this.txtViewReceivedMsg = txtViewReceivedMsg; + } + + public TextView getTxtViewReceivedDateTime() { + return txtViewReceivedDateTime; + } + + public void setTxtViewReceivedDateTime(TextView txtViewReceivedDateTime) { + this.txtViewReceivedDateTime = txtViewReceivedDateTime; + } + + public ImageView getImageAck() { + return imageAck; + } + + public void setImageAck(ImageView imageAck) { + this.imageAck = imageAck; + } + + public TextView getTextViewNotACK() { + return textViewNotACK; + } + + public void setTextViewNotACK(TextView textViewNotACK) { + this.textViewNotACK = textViewNotACK; + } + + public LinearLayout getLayoutSend() { + return layoutSend; + } + + public void setLayoutSend(LinearLayout layoutSend) { + this.layoutSend = layoutSend; + } + + public LinearLayout getLayoutReceived() { + return layoutReceived; + } + + public void setLayoutReceived(LinearLayout layoutReceived) { + this.layoutReceived = layoutReceived; + } } - + @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder view; - LayoutInflater inflator = activity.getLayoutInflater(); - - if(convertView==null) - { + LayoutInflater inflater = 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 = inflater.inflate(R.layout.row_conversation, null); + + view.setImgViewContact(convertView.findViewById(R.id.imageViewSenderIco)); + view.setTxtViewMsg(convertView.findViewById(R.id.textViewSendMsg)); + view.setTxtViewDateTime(convertView.findViewById(R.id.textViewSendDate)); + view.setImgViewReceivedContact(convertView.findViewById(R.id.imageViewReceivedIco)); + view.setTxtViewReceivedMsg(convertView.findViewById(R.id.textViewReceivedMsg)); + view.setTxtViewReceivedDateTime(convertView.findViewById(R.id.textViewReceivedDate)); + view.setLayoutSend(convertView.findViewById(R.id.layoutSend)); + view.setLayoutReceived(convertView.findViewById(R.id.layoutReceived)); + view.setTextViewNotACK(convertView.findViewById(R.id.textViewNotACK)); + view.setImageAck(convertView.findViewById(R.id.imageAck)); + convertView.setTag(view); - } - else - { + } else { view = (ViewHolder) convertView.getTag(); } - try - { + 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.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())) + 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); + + + view.getImgViewContact().setImageResource(R.drawable.peoplegreen_large); + view.getTxtViewMsg().setText(listMessages.get(position).message); + view.getTxtViewDateTime().setText(sdf.format(listMessages.get(position).received)); + view.getImgViewReceivedContact().setImageResource(listMessages.get(position).from.getLargeIcon()); + view.getTxtViewReceivedMsg().setText(listMessages.get(position).message); + view.getTxtViewReceivedDateTime().setText(sdf.format(listMessages.get(position).received)); + + if (!ackPositions.isEmpty()) + switch (Boolean.TRUE.equals(ackPositions.get(position)) ? 1 : 0) { + case 0: + // show not ack + view.getTextViewNotACK().setVisibility(View.VISIBLE); + view.getImageAck().setVisibility(View.VISIBLE); + break; + case 1: + // show not ack + view.getTextViewNotACK().setVisibility(View.INVISIBLE); + view.getImageAck().setVisibility(View.INVISIBLE); + break; + default: + throw new IllegalStateException("Unexpected value: " + (Boolean.TRUE.equals(ackPositions.get(position)) ? 1 : 0)); } - - 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) - { + + switch (Boolean.TRUE.equals(dispatcherPositions.get(position)) ? 1 : 0) { + case 1: + view.getLayoutReceived().setVisibility(View.GONE); + view.getLayoutSend().setVisibility(View.VISIBLE); + break; + case 0: + view.getLayoutReceived().setVisibility(View.VISIBLE); + view.getLayoutSend().setVisibility(View.GONE); + break; + default: + throw new IllegalStateException("Unexpected value: " + (Boolean.TRUE.equals(dispatcherPositions.get(position)) ? 1 : 0)); + } + } 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)) + + public void setACK(String seqID) { + int position = -1; + int i = 0; + + for (Msg msg : listMessages) { + if (msg.seqID.equals(seqID)) position = i; - + i++; } - - if(position > -1 && position < ackPositions.size()) { + + 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)) + + public void changeView(String seqID) { + int position = -1; + int i = 0; + + for (Msg msg : listMessages) { + if (msg.seqID.equals(seqID)) position = i; - + i++; } - - if(position != -1 && hash.size() > position) - { + + 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) - { + ViewHolder view = null; + if (con != null) { + view = (ViewHolder) con.getTag(); + } + + switch (Boolean.TRUE.equals(ackPositions.get(position)) ? 1 : 0) { case 1: - view.imageAck.setVisibility(View.INVISIBLE); - view.textViewNotACK.setVisibility(View.INVISIBLE); + if (view != null) { + view.getImageAck().setVisibility(View.INVISIBLE); + view.getTextViewNotACK().setVisibility(View.INVISIBLE); + } break; case 0: - view.imageAck.setVisibility(View.VISIBLE); - view.textViewNotACK.setVisibility(View.VISIBLE); + if (view != null) { + view.getImageAck().setVisibility(View.VISIBLE); + view.getTextViewNotACK().setVisibility(View.VISIBLE); + } break; + default: + throw new IllegalStateException("Unexpected value: " + (Boolean.TRUE.equals(ackPositions.get(position)) ? 1 : 0)); } } } diff --git a/libSafeMobile/src/main/java/com/safemobile/adapters/MessagesGridViewAdapter.java b/libSafeMobile/src/main/java/com/safemobile/adapters/MessagesGridViewAdapter.java index d575684..2fb5b9d 100644 --- a/libSafeMobile/src/main/java/com/safemobile/adapters/MessagesGridViewAdapter.java +++ b/libSafeMobile/src/main/java/com/safemobile/adapters/MessagesGridViewAdapter.java @@ -5,7 +5,6 @@ import java.util.ArrayList; import java.util.Calendar; import android.app.Activity; -import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -18,20 +17,16 @@ import com.safemobile.lib.Msg; import com.safemobile.lib.R; import com.safemobile.lib.SM; -public class MessagesGridViewAdapter extends BaseAdapter -{ - private ArrayList listMessages; - private Activity activity; - //public String time; - //private int[] colors = new int[] { Color.parseColor("#FFFFFF"), Color.parseColor("#D2E4FC") }; - - - public MessagesGridViewAdapter(Activity activity, ArrayList listMessages, Context context) { +public class MessagesGridViewAdapter extends BaseAdapter { + private final ArrayList listMessages; + private final Activity activity; + + public MessagesGridViewAdapter(Activity activity, ArrayList listMessages) { super(); this.activity = activity; this.listMessages = listMessages; } - + @Override public int getCount() { return listMessages.size(); @@ -47,86 +42,58 @@ public class MessagesGridViewAdapter extends BaseAdapter return 0; } - public static class ViewHolder - { + public static class ViewHolder { public ImageView imgViewContact; public TextView txtViewContact; public TextView txtViewDateTime; public TextView txtViewLastMsg; public LinearLayout layoutMessage; } - - + + @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder view; LayoutInflater inflator = activity.getLayoutInflater(); - - if(convertView==null) - { + + if (convertView == null) { view = new ViewHolder(); convertView = inflator.inflate(R.layout.row_message, null); - - view.imgViewContact = (ImageView) convertView.findViewById(R.id.imageViewContact); - view.txtViewContact = (TextView) convertView.findViewById(R.id.textViewContact); - view.txtViewDateTime = (TextView) convertView.findViewById(R.id.textViewLastDate); - view.txtViewLastMsg = (TextView) convertView.findViewById(R.id.textViewLastMsg); - view.layoutMessage = (LinearLayout) convertView.findViewById(R.id.layoutMessage); - + + view.imgViewContact = convertView.findViewById(R.id.imageViewContact); + view.txtViewContact = convertView.findViewById(R.id.textViewContact); + view.txtViewDateTime = convertView.findViewById(R.id.textViewLastDate); + view.txtViewLastMsg = convertView.findViewById(R.id.textViewLastMsg); + view.layoutMessage = convertView.findViewById(R.id.layoutMessage); + convertView.setTag(view); - } - else - { + } else { view = (ViewHolder) convertView.getTag(); } - - try - { + + try { view.imgViewContact.setImageResource(listMessages.get(position).from.getLargeIcon()); - //view.imgViewContact.setImageResource(R.drawable.peopleblue); - view.txtViewContact.setText(listMessages.get(position).from.name+ " :"); - if(listMessages.get(position).message.length() > 25) - view.txtViewLastMsg.setText(listMessages.get(position).message.substring(0, 25) + "..."); + view.txtViewContact.setText(String.format("%s :", listMessages.get(position).from.name)); + if (listMessages.get(position).message.length() > 25) + view.txtViewLastMsg.setText(String.format("%s...", listMessages.get(position).message.substring(0, 25))); else view.txtViewLastMsg.setText(listMessages.get(position).message); - + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.HOUR_OF_DAY,0); + 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())) + if (listMessages.get(position).received.after(calendar.getTime())) sdf = new SimpleDateFormat("HH:mm:ss"); else sdf = new SimpleDateFormat("MMM-dd HH:mm"); - + view.txtViewDateTime.setText(sdf.format(listMessages.get(position).received)); - } - catch(Exception ex) - { + } catch (Exception ex) { SM.Exception(ex.toString()); } return convertView; } - - public int getIcon(int user_type, String username) - { - // if request was send by MessagesActivity -> Spinner - if(user_type == -1) - { - // get unit_type for selected username - for (Msg mes: listMessages) - { - // if user is selected - if(mes.from.name.equals(username)) - { - user_type = (int) mes.from.driver_id; // save user_type - - return mes.from.getLargeIcon(); - } - } - } - return 0; - } } diff --git a/libSafeMobile/src/main/java/com/safemobile/adapters/PadConversationGridViewAdapter.java b/libSafeMobile/src/main/java/com/safemobile/adapters/PadConversationGridViewAdapter.java deleted file mode 100644 index a55ee65..0000000 --- a/libSafeMobile/src/main/java/com/safemobile/adapters/PadConversationGridViewAdapter.java +++ /dev/null @@ -1,215 +0,0 @@ -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 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.R; -import com.safemobile.lib.SM; -import com.safemobile.libpad.PadTextMessage; - -public class PadConversationGridViewAdapter extends BaseAdapter -{ - private ArrayList listMessages; - private Activity activity; - //public String time; - private ArrayList outgoingPositions = new ArrayList(); - private ArrayList ackPositions = new ArrayList(); - private Hashtable hash = new Hashtable(); - - - public PadConversationGridViewAdapter(Activity activity, ArrayList listMessages, Context context, ArrayList outgoingPositions, ArrayList ackPositions) { - this.activity = activity; - this.listMessages = listMessages; - this.outgoingPositions = outgoingPositions; - this.ackPositions = ackPositions; - } - - @Override - public int getCount() { - return listMessages.size(); - } - - @Override - public PadTextMessage getItem(int position) { - return listMessages.get(position); - } - - @Override - public long getItemId(int position) { - return 0; - } - - /** return the list of messages in the adapter - * @return an ArrayList of PadTextMessages - */ - public ArrayList getMessages() { - return listMessages; - } - - 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", Locale.getDefault()); - 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); - - Date date = new Date(listMessages.get(position).timeGMT * 1000); - - if(date.after(calendar.getTime())) - sdf = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()); - else - sdf = new SimpleDateFormat("HH:mm MMM-dd", Locale.getDefault()); - - // set gmt time - //sdf.setTimeZone(TimeZone.getTimeZone("GMT")); - - //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(date)); - //view.imgViewReceivedContact.setImageResource(getIcon(listMessages.get(position).from.user_type)); - view.imgViewReceivedContact.setImageResource(R.drawable.peopleblue_large); - view.txtViewReceivedMsg.setText(listMessages.get(position).message); - - view.txtViewReceivedDateTime.setText(sdf.format(date)); - - 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(outgoingPositions.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++; - } - - 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; - } - } - } - */ -} diff --git a/libSafeMobile/src/main/res/layout/row_conversation.xml b/libSafeMobile/src/main/res/layout/row_conversation.xml index 4273df7..2c386bc 100644 --- a/libSafeMobile/src/main/res/layout/row_conversation.xml +++ b/libSafeMobile/src/main/res/layout/row_conversation.xml @@ -1,13 +1,14 @@ - + - + - + - - - - - - - + + + + + + + - - - + - - - - - - - - + + + + + + + - - + + \ No newline at end of file diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/MessagesActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/MessagesActivity.java index 9f1dd26..b40e85d 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/MessagesActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/MessagesActivity.java @@ -1,23 +1,16 @@ -/* - * Author : ErVaLt / techwavedev.com - * Description : TabLayout Andorid App - */ package com.safemobile.dispatch; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.res.Configuration; import android.graphics.Typeface; import android.os.Bundle; import android.os.Handler; +import android.os.Looper; import android.view.View; -import android.view.View.OnClickListener; -import android.widget.AdapterView; -import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; @@ -42,830 +35,665 @@ import java.util.Calendar; import java.util.Date; import java.util.Hashtable; import java.util.Locale; +import java.util.Objects; /** * fix import */ public class MessagesActivity extends Activity { - /** Called when the activity is first created. */ - + /** + * Called when the activity is first created. + */ + private MessagesGridViewAdapter mAdapter; private ConversationGridViewAdapter convAdapter; - private ArrayList listLastMessages = new ArrayList(); - private ArrayList listSpecificConversation = new ArrayList(); - private ArrayList dispatcher_positions = new ArrayList(); - + private ArrayList listLastMessages = new ArrayList<>(); + private ArrayList listSpecificConversation = new ArrayList<>(); + private ArrayList dispatcherPositions = new ArrayList<>(); + private GridView gridView; private Context context; private Activity activity; - //private IconContextMenu iconContextMenu = null; - - private Hashtable> tableSMS = new Hashtable>(); - private Hashtable seqIDSMSHash = new Hashtable(); - + + private final Hashtable> tableSMS = new Hashtable<>(); + private final Hashtable seqIDSMSHash = new Hashtable<>(); + // Need handler for callbacks to the UI thread - private final Handler myHandler = new Handler(); - + private final Handler myHandler = new Handler(Looper.getMainLooper()); + /* Visual resources */ - private LinearLayout layoutSend, layoutHeader, layoutHeaderConversation; + private LinearLayout layoutSend; + private LinearLayout layoutHeader; + private LinearLayout layoutHeaderConversation; private TextView textViewSelectedContact; - private ImageView imageViewSelectedContact, imageBarcode; - - /* Buttons and EditBoxes */ - private ImageButton imageButtonAdd, imageButtonBack; + private ImageView imageViewSelectedContact; + private Button imageButtonSend; private EditText editTextMsg; - + private TabLayoutActivity parentTab; - + /* Message args */ - private int ACTION, MSGUpdate = 0; - - private ArrayList allVehicleNames = new ArrayList(); - public ArrayList allVehicle = new ArrayList(); - private Msg selectedVehicle; - + private int ACTION; + private static final int MSG_UPDATE = 0; + + private ArrayList allVehicleNames = new ArrayList<>(); + private ArrayList allVehicle = new ArrayList<>(); + // tip of Messages and flag first load public boolean LASTMESSAGES = true; - private boolean FIRST = true; - - // store selected sc_id and selected unit_type - public long sc_id=0; - public int unit_type=0; - - private String seqID; // store sms seqId to set to ACK in adapter - - public Bundle savedInstanceState; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - this.savedInstanceState = savedInstanceState; - - // get parentTab - parentTab = (TabLayoutActivity)getParent(); - - context = this; - activity = this; - - Locale locale = new Locale(AppParams.LANGUAGETMP); - Locale.setDefault(locale); - Configuration config = new Configuration(); - config.locale = locale; - getBaseContext().getResources().updateConfiguration(config, - getBaseContext().getResources().getDisplayMetrics()); - - setContentView(R.layout.tabtext); - - // get LayoutSend and hide - layoutSend = (LinearLayout) findViewById(R.id.layoutSendMsg); - layoutSend.setVisibility(View.GONE); - // get header layout - layoutHeader = (LinearLayout) findViewById(R.id.layoutHeader); - layoutHeaderConversation = (LinearLayout) findViewById(R.id.layoutHeaderConversation); - // show only header layout - layoutHeaderConversation.setVisibility(View.GONE); - - // get SelectedContact TextView and ImageView - textViewSelectedContact = (TextView) findViewById(R.id.textViewSelectedContact); - imageViewSelectedContact = (ImageView) findViewById(R.id.imageViewSelectedContact); - - imageBarcode = (ImageView) findViewById(R.id.imageBarcode); - imageBarcode.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - try - { - Intent intent = new Intent("com.google.zxing.client.android.SCAN"); - // intent.putExtra("SCAN_MODE", "ONE_D_MODE"); - startActivityForResult(intent, 0); - } - catch (Exception e) - { - showErrorDialog(getResources().getString(R.string.barcodeError)); - //Log.d("Error",e.toString()); - } - } - }); - - // change tab header fontface - TextView textView1 = (TextView) findViewById(R.id.textView1); - textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf")); - textView1.setTextSize(24); + private boolean FIRST = true; - // prepared arraylist and passed it to the Adapter class - //mAdapter = new GridviewAdapter(this,listFrom, listMessages, listReceived); - mAdapter = new MessagesGridViewAdapter(this, listLastMessages, context); - convAdapter = new ConversationGridViewAdapter(this, listSpecificConversation, context, sc_id, unit_type, dispatcher_positions, new ArrayList()); - // Set custom adapter to gridview - gridView = (GridView) findViewById(R.id.gridView1); - gridView.setAdapter(mAdapter); - - // Implement On Item click listener - gridView.setOnItemClickListener(new OnItemClickListener() - { - @Override - public void onItemClick(AdapterView arg0, View arg1, int position, - long arg3) { - //if (layoutHeader.getVisibility() == View.VISIBLE) - if(LASTMESSAGES) - { - // get position - Msg item = mAdapter.getItem(position); - // get Specific Conversation - sc_id = item.from.sc_id; - SM.Debug("Selected sc_id: " + sc_id); - // set Conversation type - LASTMESSAGES = false; - // call get SMS - GetSMS4unit(sc_id); - // create crt_Vehicle - unit_type = (int)item.from.driver_id; - // save selected vehicle - selectedVehicle = item; - - } - - if(AppParams.DEMO) - { - // modify UI - ACTION = MSGUpdate; - updateResultsInUi(); - } + // store selected scId and selected unitType + private long scId = 0; + private int unitType = 0; + + private Bundle savedInstanceState; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + this.setSavedInstanceState(savedInstanceState); + + // get parentTab + parentTab = (TabLayoutActivity) getParent(); + + context = this; + activity = this; + + Locale locale = new Locale(AppParams.LANGUAGETMP); + Locale.setDefault(locale); + Configuration config = new Configuration(); + config.locale = locale; + getBaseContext().getResources().updateConfiguration(config, + getBaseContext().getResources().getDisplayMetrics()); + + setContentView(R.layout.tabtext); + + // get LayoutSend and hide + layoutSend = findViewById(R.id.layoutSendMsg); + layoutSend.setVisibility(View.GONE); + // get header layout + layoutHeader = findViewById(R.id.layoutHeader); + layoutHeaderConversation = findViewById(R.id.layoutHeaderConversation); + // show only header layout + layoutHeaderConversation.setVisibility(View.GONE); + + // get SelectedContact TextView and ImageView + textViewSelectedContact = findViewById(R.id.textViewSelectedContact); + imageViewSelectedContact = findViewById(R.id.imageViewSelectedContact); + + ImageView imageBarcode = findViewById(R.id.imageBarcode); + imageBarcode.setOnClickListener(v -> { + try { + Intent intent = new Intent("com.google.zxing.client.android.SCAN"); + startActivityForResult(intent, 0); + } catch (Exception e) { + showErrorDialog(getResources().getString(R.string.barcodeError)); } }); - - // button create message - imageButtonAdd = (ImageButton) findViewById(R.id.imageButtonAdd); - imageButtonAdd.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - showDialog(); + + // change tab header fontFace + TextView textView1 = findViewById(R.id.textView1); + textView1.setTypeface(Typeface.createFromAsset(getAssets(), "Sketch_Block.ttf")); + textView1.setTextSize(24); + + // prepared arraylist and passed it to the Adapter class + mAdapter = new MessagesGridViewAdapter(this, listLastMessages); + convAdapter = new ConversationGridViewAdapter(this, listSpecificConversation, dispatcherPositions, new ArrayList<>()); + // Set custom adapter to gridview + gridView = findViewById(R.id.gridView1); + gridView.setAdapter(mAdapter); + + // Implement On Item click listener + gridView.setOnItemClickListener((arg0, arg1, position, arg3) -> { + if (LASTMESSAGES) { + // get position + Msg item = mAdapter.getItem(position); + // get Specific Conversation + setScId(item.from.sc_id); + SM.Debug("Selected scId: " + getScId()); + // set Conversation type + LASTMESSAGES = false; + // call get SMS + getSMS4unit(getScId()); + // create crt_Vehicle + setUnitType((int) item.from.driver_id); + // save selected vehicle } - }); - - // button send message - imageButtonSend = (Button) findViewById(R.id.imageButtonSend); - imageButtonSend.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - - //SM.Debug("SC ID:" + sc_id); - - SendSMS(sc_id, editTextMsg.getText().toString()); - Toast.makeText(context, "Sending message...", 500).show(); - /* - // show busy indicator - dialogHandler.handleMessage(new Message()); - - ACTION = SHOWLoading; - myHandler.post(UpdateResults); - */ - // disable send button and editBox - editTextMsg.setEnabled(false); - imageButtonSend.setEnabled(false); - - new Thread(new Runnable() { - public void run() { - try { - Thread.sleep(500); - myHandler.post(enableButtonRUN); - - //LASTMESSAGES = false; - if(AppParams.DEMO) - { - Thread.sleep(5500); - myHandler.post(demoReceveidSMSRUN); - } - } catch (InterruptedException e) { - e.printStackTrace(); - } - - } - }).start(); - - } - }); - - // button back to conversations - imageButtonBack = (ImageButton) findViewById(R.id.imageButtonBack); - imageButtonBack.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - // set LastMessage conversation type - LASTMESSAGES = true; - // refresh Grid - GetLastSMS(); - if(AppParams.DEMO) - updateResultsInUi(); - } - }); - - // get Message editText - editTextMsg = (EditText) findViewById(R.id.editTextMsg); - - gridView.setId(1); // id needed for IconContextMenu - registerForContextMenu(gridView); - parentTab.messageActivity = this; - } - - // Create runnable for posting - final Runnable demoReceveidSMSRUN = new Runnable() { - public void run() { - parentTab.setImei(sc_id + ""); - parentTab.updateResultsInUi("realpha"); - - int timeGMT = (int) (System.currentTimeMillis() / 1000L); - String SendSMSSeqID = "1."+timeGMT; - // add mess to not ack list - seqIDSMSHash.put(SendSMSSeqID, sc_id); - // get sc_id conversation and add message - ArrayList crtSMSlist = tableSMS.get(sc_id); - SMS sms = new SMS(0, 0, timeGMT, "i got your sms", 0, sc_id); - sms.seq_idx = SendSMSSeqID; - crtSMSlist.add(sms); - - // add message to listLast - boolean exists = false; - for (Msg msg : listLastMessages) - // if conversation exists in lastMessages - if(msg.from.sc_id == sc_id) - { - exists = true; - msg.message = "i got your sms"; - msg.received = Calendar.getInstance().getTime(); - } - - // if last messages doesn't contain this conversation - if(!exists) - { - Vehicle sentVehicle = null; - for(Vehicle veh : allVehicle) - if(veh.sc_id == sc_id) - sentVehicle = veh; - - listLastMessages.add(new Msg(sentVehicle, "i got your sms", Calendar.getInstance().getTime(), SendSMSSeqID)); - } - SM.Debug("time: " + timeGMT + " | " + Calendar.getInstance().getTime().toString() ); - + + if (AppParams.DEMO) { + // modify UI + ACTION = MSG_UPDATE; updateResultsInUi(); - - } - }; - - - @Override - public void onBackPressed() - { - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage(getString(R.string.exit)) - .setCancelable(false) - .setNeutralButton(getString(R.string.logout), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - parentTab.whenBackPressed(AppParams.ActivityResult.logout); - } - }) - .setPositiveButton(getString(R.string.ext), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - parentTab.whenBackPressed(AppParams.ActivityResult.exit); - } - }) - .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.cancel(); - } - }); - AlertDialog alert = builder.create(); - alert.show(); - } - - @Override - public void onPause() - { - super.onPause(); - SM.Debug("onPause"); - } - - @Override - public void onResume() - { - super.onResume(); - if(parentTab.getTCPState() != null){ - if(FIRST) - { - UpdateVehs(parentTab.getAllVehicle()); - FIRST = false; - if(LASTMESSAGES) - parentTab.executeNetworkStuff(new String[] {OperationCodes.GetLastSMS + "", AppParams.USERID + ""}); - } - - //GetLastSMS(); - } - SM.Debug("onResume"); - } + } + }); - public void onActivityResult(int requestCode, int resultCode, Intent intent) { - if (requestCode == 0) { - if (resultCode == RESULT_OK) { - String contents = intent.getStringExtra("SCAN_RESULT"); - String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); - editTextMsg.setText(editTextMsg.getText().toString() + contents); - // Handle successful scan - Toast.makeText(this, getResources().getString(R.string.barcodeContent) + ":"+contents+" with format:"+format, 6000).show(); - } else if (resultCode == RESULT_CANCELED) { - // Handle cancel - //Toast.makeText(this, "TRY AGAIN", 6000).show(); - } - } - } - - - - // Request SMS 4 Unit from AppServer - private void GetSMS4UnitWithTime(long sc_id, long time) { - if(!AppParams.DEMO) { - parentTab.executeNetworkStuff(new String[] {OperationCodes.GetRecentSMSs + "", sc_id + "", time + ""}); - - SM.Debug(" #### GetSMS4uni:" + sc_id); - } - } - - private void GetSMS4unit(long sc_id) - { - if(!AppParams.DEMO) - { - SM.Debug("GetSMS4unit : " + sc_id); - ArrayList listSMS = tableSMS.get(sc_id); - long timeGMT = 0; - if(!listSMS.isEmpty()) - timeGMT = listSMS.get(listSMS.size()-1).timeGMT; - - // error in DB - if(String.valueOf(timeGMT).contains(".")) - { - try { - // remove the dot and the parse it to String - timeGMT = Long.parseLong(String.valueOf(timeGMT).split(".")[1]); - } - catch (Exception e) { - timeGMT = Long.parseLong(String.valueOf(timeGMT).replace(".","")); + /* Buttons and EditBoxes */ + ImageButton imageButtonAdd = findViewById(R.id.imageButtonAdd); + imageButtonAdd.setOnClickListener(v -> showDialog()); + + // button send message + imageButtonSend = findViewById(R.id.imageButtonSend); + imageButtonSend.setOnClickListener(v -> { + sendSMS(getScId(), editTextMsg.getText().toString()); + Toast.makeText(context, "Sending message...", Toast.LENGTH_SHORT).show(); + // disable send button and editBox + editTextMsg.setEnabled(false); + imageButtonSend.setEnabled(false); + + new Thread(() -> { + try { + Thread.sleep(500); + myHandler.post(enableButtonRUN); + + if (AppParams.DEMO) { + Thread.sleep(5500); + myHandler.post(demoReceivedSMSRUN); + } + } catch (InterruptedException e) { + e.printStackTrace(); + Thread.currentThread().interrupt(); } - - } - - parentTab.executeNetworkStuff(new String[] {OperationCodes.GetRecentSMSs + "", sc_id + "", timeGMT + ""}); - - //parent.getRecentSMSs(sc_id, timeGMT); - SM.Debug(" #### GetSMS4uni:" + sc_id); - } + }).start(); + }); + + // button back to conversations + ImageButton imageButtonBack = findViewById(R.id.imageButtonBack); + imageButtonBack.setOnClickListener(v -> { + // set LastMessage conversation type + LASTMESSAGES = true; + // refresh Grid + getLastSMS(); + if (AppParams.DEMO) + updateResultsInUi(); + }); + + // get Message editText + editTextMsg = findViewById(R.id.editTextMsg); + + gridView.setId(1); // id needed for IconContextMenu + registerForContextMenu(gridView); + parentTab.messageActivity = this; } - - // Request Last SMS from AppServer - public void GetLastSMS() - { - if(!AppParams.DEMO) - { - if(LASTMESSAGES) - parentTab.executeNetworkStuff(new String[] {OperationCodes.GetLastSMS + "", AppParams.USERID + ""}); - //parent.getLastSMSs(AppParams.USERID); - else - { - ArrayList listSMS = tableSMS.get(sc_id); - long timeGMT = 0; - if(listSMS!= null && !listSMS.isEmpty()) - timeGMT = listSMS.get(listSMS.size()-1).timeGMT; - //parent.getRecentSMSs(sc_id, timeGMT); - parentTab.executeNetworkStuff(new String[] {OperationCodes.GetRecentSMSs + "", sc_id + "", timeGMT + ""}); - } - } - else - updateResultsInUi(); - } - - - private void SendSMS(long sc_id, String txt) - { - if(!AppParams.DEMO) - { - int timeGMT = (int) (System.currentTimeMillis() / 1000L); - String SendSMSSeqID = "1."+timeGMT; - // add mess to not ack list - seqIDSMSHash.put(SendSMSSeqID, sc_id); - // get sc_id conversation and add message - SMS sms = new SMS(0, 0, timeGMT, txt, sc_id, 0); - sms.seq_idx = SendSMSSeqID; - tableSMS.get(sc_id).add(sms); - //parent.sendSMS(SendSMSSeqID,sc_id, txt); - parentTab.executeNetworkStuff(new String[] {OperationCodes.SEND_TM + "", SendSMSSeqID, sc_id + "", txt}); - - updateResultsInUi(); - } - else - { + + // Create runnable for posting + final Runnable demoReceivedSMSRUN = new Runnable() { + public void run() { + parentTab.setImei(getScId() + ""); + parentTab.updateResultsInUi("realpha"); + int timeGMT = (int) (System.currentTimeMillis() / 1000L); - String SendSMSSeqID = "1."+timeGMT; - // add mess to not ack list - seqIDSMSHash.put(SendSMSSeqID, sc_id); - // get sc_id conversation and add message - ArrayList crtSMSlist = tableSMS.get(sc_id); - SMS sms = new SMS(0, 0, timeGMT, txt, sc_id, 0); - sms.seq_idx = SendSMSSeqID; - crtSMSlist.add(sms); - - + String sendSMSSeqID = "1." + timeGMT; + // add mess to not ack list + seqIDSMSHash.put(sendSMSSeqID, getScId()); + // get scId conversation and add message + ArrayList crtSmsList = tableSMS.get(getScId()); + SMS sms = new SMS(0, 0, timeGMT, "i got your sms", 0, getScId()); + sms.seq_idx = sendSMSSeqID; + if (crtSmsList != null) + crtSmsList.add(sms); + // add message to listLast boolean exists = false; for (Msg msg : listLastMessages) // if conversation exists in lastMessages - if(msg.from.sc_id == sc_id) - { + if (msg.from.sc_id == getScId()) { + exists = true; + msg.message = "i got your sms"; + msg.received = Calendar.getInstance().getTime(); + } + + // if last messages doesn't contain this conversation + if (!exists) { + Vehicle sentVehicle = null; + for (Vehicle veh : getAllVehicle()) + if (veh.sc_id == getScId()) + sentVehicle = veh; + + listLastMessages.add(new Msg(sentVehicle, "i got your sms", Calendar.getInstance().getTime(), sendSMSSeqID)); + } + SM.Debug("time: " + timeGMT + " | " + Calendar.getInstance().getTime()); + + updateResultsInUi(); + } + }; + + + @Override + public void onBackPressed() { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(getString(R.string.exit)) + .setCancelable(false) + .setNeutralButton(getString(R.string.logout), (dialog, id) -> parentTab.whenBackPressed(AppParams.ActivityResult.logout)) + .setPositiveButton(getString(R.string.ext), (dialog, id) -> parentTab.whenBackPressed(AppParams.ActivityResult.exit)) + .setNegativeButton(getString(R.string.cancel), (dialog, id) -> dialog.cancel()); + AlertDialog alert = builder.create(); + alert.show(); + } + + @Override + public void onPause() { + super.onPause(); + SM.Debug("onPause"); + } + + @Override + public void onResume() { + super.onResume(); + if (parentTab.getTCPState() != null && FIRST) { + updateVehicles(parentTab.getAllVehicle()); + FIRST = false; + if (LASTMESSAGES) + parentTab.executeNetworkStuff(new String[]{OperationCodes.GetLastSMS + "", AppParams.USERID + ""}); + } + SM.Debug("onResume"); + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent intent) { + if (requestCode == 0 && resultCode == RESULT_OK) { + String contents = intent.getStringExtra("SCAN_RESULT"); + String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); + editTextMsg.setText(String.format("%s%s", editTextMsg.getText().toString(), contents)); + // Handle successful scan + Toast.makeText(this, getResources().getString(R.string.barcodeContent) + ":" + contents + " with format:" + format, Toast.LENGTH_LONG).show(); + } + } + + // Request SMS 4 Unit from AppServer + private void getSMS4UnitWithTime(long scId, long time) { + if (!AppParams.DEMO) { + parentTab.executeNetworkStuff(new String[]{OperationCodes.GetRecentSMSs + "", scId + "", time + ""}); + + SM.Debug(" #### GetSMS4uni:" + scId); + } + } + + private void getSMS4unit(long scId) { + if (!AppParams.DEMO) { + SM.Debug("getSMS4unit : " + scId); + ArrayList listSMS = tableSMS.get(scId); + long timeGMT = 0; + if (listSMS != null && !listSMS.isEmpty()) + timeGMT = listSMS.get(listSMS.size() - 1).timeGMT; + + // error in DB + if (String.valueOf(timeGMT).contains(".")) { + try { + // remove the dot and the parse it to String + timeGMT = Long.parseLong(String.valueOf(timeGMT).split("\\.")[1]); + } catch (Exception e) { + timeGMT = Long.parseLong(String.valueOf(timeGMT).replace(".", "")); + } + } + + parentTab.executeNetworkStuff(new String[]{OperationCodes.GetRecentSMSs + "", scId + "", timeGMT + ""}); + + SM.Debug(" #### GetSMS4uni:" + scId); + } + } + + // Request Last SMS from AppServer + public void getLastSMS() { + if (!AppParams.DEMO) { + if (LASTMESSAGES) + parentTab.executeNetworkStuff(new String[]{OperationCodes.GetLastSMS + "", AppParams.USERID + ""}); + else { + ArrayList listSMS = tableSMS.get(getScId()); + long timeGMT = 0; + if (listSMS != null && !listSMS.isEmpty()) + timeGMT = listSMS.get(listSMS.size() - 1).timeGMT; + parentTab.executeNetworkStuff(new String[]{OperationCodes.GetRecentSMSs + "", getScId() + "", timeGMT + ""}); + } + } else + updateResultsInUi(); + } + + + private void sendSMS(long scIdd, String txt) { + if (!AppParams.DEMO) { + int timeGMT = (int) (System.currentTimeMillis() / 1000L); + String sendSMSSeqID = "1." + timeGMT; + // add mess to not ack list + seqIDSMSHash.put(sendSMSSeqID, scIdd); + // get scId conversation and add message + SMS sms = new SMS(0, 0, timeGMT, txt, scIdd, 0); + sms.seq_idx = sendSMSSeqID; + tableSMS.get(scIdd).add(sms); + parentTab.executeNetworkStuff(new String[]{OperationCodes.SEND_TM + "", sendSMSSeqID, scIdd + "", txt}); + + updateResultsInUi(); + } else { + int timeGMT = (int) (System.currentTimeMillis() / 1000L); + String sendSMSSeqID = "1." + timeGMT; + // add mess to not ack list + seqIDSMSHash.put(sendSMSSeqID, scIdd); + // get scId conversation and add message + ArrayList crtSmsList = tableSMS.get(scIdd); + SMS sms = new SMS(0, 0, timeGMT, txt, scIdd, 0); + sms.seq_idx = sendSMSSeqID; + crtSmsList.add(sms); + + // add message to listLast + boolean exists = false; + for (Msg msg : listLastMessages) + // if conversation exists in lastMessages + if (msg.from.sc_id == scIdd) { exists = true; msg.message = txt; msg.received = Calendar.getInstance().getTime(); } - + // if last messages doesn't contain this conversation - if(!exists) - { + if (!exists) { Vehicle sentVehicle = null; - for(Vehicle veh : allVehicle) - if(veh.sc_id == sc_id) + for (Vehicle veh : getAllVehicle()) + if (veh.sc_id == scIdd) sentVehicle = veh; - - listLastMessages.add(new Msg(sentVehicle, txt, Calendar.getInstance().getTime(), SendSMSSeqID)); + + listLastMessages.add(new Msg(sentVehicle, txt, Calendar.getInstance().getTime(), sendSMSSeqID)); } - SM.Debug("time: " + timeGMT + " | " + Calendar.getInstance().getTime().toString() ); + SM.Debug("time: " + timeGMT + " | " + Calendar.getInstance().getTime()); LASTMESSAGES = false; - + updateResultsInUi(); } } - + // Update Vehicles received from AppServer - public void UpdateVehs(ArrayList list) - { - SM.Debug("## UpdateVehs: " + list.size()); - allVehicle = list; - allVehicleNames = new ArrayList(); - for(Vehicle v: allVehicle) - allVehicleNames.add(v.name); - - if(tableSMS.size() == 0) - { - for(Vehicle veh: allVehicle) - { - ArrayList lista = new ArrayList(); + public void updateVehicles(ArrayList list) { + SM.Debug("## updateVehicles: " + list.size()); + setAllVehicle(list); + allVehicleNames = new ArrayList<>(); + for (Vehicle v : getAllVehicle()) + allVehicleNames.add(v.name); + + if (tableSMS.size() == 0) { + for (Vehicle veh : getAllVehicle()) { + ArrayList smsList = new ArrayList<>(); // populate conversation list if demo - if(AppParams.DEMO) - lista = getDemoConversation(veh.sc_id); - - tableSMS.put(veh.sc_id, lista); + if (AppParams.DEMO) + smsList = getDemoConversation(veh.sc_id); + + tableSMS.put(veh.sc_id, smsList); } } } - - + // gets DEMO conversations - private ArrayList getDemoConversation(long sc_id) - { - ArrayList lista = new ArrayList(); - if(sc_id == 101) - lista.add(new SMS(1, 2, 1324016412, "Only one left", 101, 0)); - else if (sc_id == 102) - lista.add(new SMS(1, 2, 1328060100, "i'm at the train station", 0, 102)); - else if (sc_id == 103) { - lista.add(new SMS(1, 2, 1121016637, "Where are you now?", 103, 0)); - lista.add(new SMS(2, 2, 1121016693, "Near Elementary School 81", 0, 103)); - lista.add(new SMS(3, 2, 1121016693, "We have a client on Belmont Ave", 103, 0)); - lista.add(new SMS(4, 2, 1121016724, "It's only 4 blocks away", 103, 0)); - lista.add(new SMS(5, 2, 1121016693, "Can you take him?", 103, 0)); - lista.add(new SMS(6, 2, 1121016818, "I'll be right there", 0, 103)); - } - else if (sc_id == 105) - lista.add(new SMS(1, 2, 1328061660, "Thanks", 0, 105)); - return lista; + private ArrayList getDemoConversation(long scId) { + ArrayList smsList = new ArrayList<>(); + if (scId == 101) + smsList.add(new SMS(1, 2, 1324016412, "Only one left", 101, 0)); + else if (scId == 102) + smsList.add(new SMS(1, 2, 1328060100, "i'm at the train station", 0, 102)); + else if (scId == 103) { + smsList.add(new SMS(1, 2, 1121016637, "Where are you now?", 103, 0)); + smsList.add(new SMS(2, 2, 1121016693, "Near Elementary School 81", 0, 103)); + smsList.add(new SMS(3, 2, 1121016693, "We have a client on Belmont Ave", 103, 0)); + smsList.add(new SMS(4, 2, 1121016724, "It's only 4 blocks away", 103, 0)); + smsList.add(new SMS(5, 2, 1121016693, "Can you take him?", 103, 0)); + smsList.add(new SMS(6, 2, 1121016818, "I'll be right there", 0, 103)); + } else if (scId == 105) + smsList.add(new SMS(1, 2, 1328061660, "Thanks", 0, 105)); + return smsList; } - - - - public void UpdateSMS(ArrayList list) - { - SM.Debug("## UpdateSMS: " + list.size() + " [LASTMESSAGES:" + LASTMESSAGES + "]"); - + + public void updateSMS(ArrayList list) { + SM.Debug("## updateSMS: " + list.size() + " [LASTMESSAGES:" + LASTMESSAGES + "]"); + // populate listLastMessages - if(LASTMESSAGES) - { - listLastMessages = new ArrayList(); - for(SMS sms: list) - { + if (LASTMESSAGES) { + listLastMessages = new ArrayList<>(); + for (SMS sms : list) { // get for sender - long id_sender = sms.sc_id_dest; - if (id_sender == 0) - id_sender = sms.sc_id_sour; - //SM.Debug(sms.toString()); + long senderId = sms.sc_id_dest; + if (senderId == 0) + senderId = sms.sc_id_sour; // get vehicle with sender id - Vehicle messageVeh= null; - messageVeh = getVehicleById(id_sender); - listLastMessages.add(0,new Msg(messageVeh, sms.mess, new Date((long)sms.timeGMT * 1000), sms.seq_idx)); + Vehicle messageVeh; + messageVeh = getVehicleById(senderId); + listLastMessages.add(0, new Msg(messageVeh, sms.mess, new Date((long) sms.timeGMT * 1000), sms.seq_idx)); } - + // update GridView - - //SM.Debug(" ########### " + parentTab.allVehicle.size() + " ||| " + listLastMessages.size()); - - mAdapter = new MessagesGridViewAdapter(activity, listLastMessages, context); - //SM.Debug("list count : " + listLastMessages.size()); - //gridView.setAdapter(mAdapter); - //mAdapter.notifyDataSetChanged(); - } - else - { - // add new values to hashTable for key = sc_id - ArrayList listScId = tableSMS.get(sc_id); - if(list.size() != 0) - for(SMS sms:list) - { + mAdapter = new MessagesGridViewAdapter(activity, listLastMessages); + } else { + // add new values to hashTable for key = scId + ArrayList listScId = tableSMS.get(getScId()); + if (!list.isEmpty()) + for (SMS sms : list) { // compare last item in hashList with first elem in arrived list // protect is listSc_Id size = 0 - if ((listScId.size()>0)&&(sms.sc_id_dest == listScId.get(listScId.size()-1).sc_id_dest && sms.sc_id_sour == listScId.get(listScId.size()-1).sc_id_sour && sms.mess == listScId.get(listScId.size()-1).mess)) - // drop element - ; - else + if (listScId != null && (listScId.isEmpty() + || (sms.sc_id_dest != listScId.get(listScId.size() - 1).sc_id_dest + || sms.sc_id_sour != listScId.get(listScId.size() - 1).sc_id_sour + || !Objects.equals(sms.mess, listScId.get(listScId.size() - 1).mess)))) listScId.add(sms); } } // modify UI - ACTION = MSGUpdate; - myHandler.post(new Runnable() { - @Override - public void run() { - updateResultsInUi(); - } - }); + ACTION = MSG_UPDATE; + myHandler.post(this::updateResultsInUi); } - + // Confirmation for sending message - public void ConfirmSMS(String data, final String seqID) - { - SM.Debug("ConfirmSMS"); - if(data.equals("0")) - { + public void confirmSMS(String data, final String seqID) { + SM.Debug("confirmSMS"); + if (data.equals("0")) { SM.Debug("Error on sending SMS"); showErrorDialog("Error on sending message."); - } - else - { + } else { SM.Debug("ACK received for text message"); - - //get sc_id for crt message - long sc_id = seqIDSMSHash.get(seqID); - // get SMS list for crt sc_id - ArrayList crtSMSList = tableSMS.get(sc_id); - for(SMS sms: crtSMSList) - { - - if(sms.seq_idx.equals(seqID)) - { - SM.Debug("######### AM SCHIMBAT STATUSUL pt: " + sms.mess + " | " + sc_id + " | " + seqID + " || " + sms.seq_idx); - // set ACK - sms.status = 2; + //get scId for crt message + long scId = seqIDSMSHash.get(seqID); + // get SMS list for crt scId + ArrayList crtSMSList = tableSMS.get(scId); + if (crtSMSList != null) { + for (SMS sms : crtSMSList) { + + if (sms.seq_idx.equals(seqID)) { + SM.Debug("######### AM SCHIMBAT STATUSUL pt: " + sms.mess + " | " + scId + " | " + seqID + " || " + sms.seq_idx); + // set ACK + sms.status = 2; + } } } // remove message from seqIDSMS Hash = don't wait confirmation for it seqIDSMSHash.remove(seqID); - - // refresh MSG List - //GetSMS4unit(sc_id); - - /* - // TODO -> this is a small bug fix, should talk with Bigu to change it - // remove message from list because it will be brought back by GetSMS4Unit, and it will have different time - ArrayList listWithTextMessage = tableSMS.get(sc_id); - if(listWithTextMessage.size() > 0) - listWithTextMessage.remove(listWithTextMessage.size() - 1); // remove last message - */ // store sms seqId to set to ACK in adapter - this.seqID = seqID; - myHandler.post(new Runnable() { - @Override - public void run() { - convAdapter.setACK(seqID); - convAdapter.changeView(seqID); - convAdapter.notifyDataSetChanged(); - } + myHandler.post(() -> { + convAdapter.setACK(seqID); + convAdapter.changeView(seqID); + convAdapter.notifyDataSetChanged(); }); - - myHandler.post(new Runnable() { - @Override - public void run() { - // clear text - editTextMsg.setText(""); - } - }); - - } - } - - - public void NewSMS(String imei, String message, final long time) - { - SM.Debug(" ## NewSMS: " + imei + " | " + message); - if(!LASTMESSAGES) - { - // if received message from current conversation - if(getVehicleByImei(imei).sc_id == sc_id) - GetSMS4UnitWithTime(sc_id, time); // refresh MSG List - //else - // parentTab.myHandler.post(parentTab.showPopUpRUN); // show PopUp - } - else - GetLastSMS(); // get last SMS - } - - - // Create runnable for posting - final Runnable enableButtonRUN = new Runnable() { - public void run() { - updateEnableButtonsUI(); - } - }; - // enable buttons in UI after 200ms from send - private void updateEnableButtonsUI() - { + myHandler.post(() -> editTextMsg.setText("")); + } + } + + + public void newSMS(String imei, String message, final long time) { + SM.Debug(" ## newSMS: " + imei + " | " + message); + if (!LASTMESSAGES) { + // if received message from current conversation + if (getVehicleByImei(imei).sc_id == getScId()) + getSMS4UnitWithTime(getScId(), time); // refresh MSG List + } else + getLastSMS(); // get last SMS + } + + // Create runnable for posting + final Runnable enableButtonRUN = this::updateEnableButtonsUI; + + // enable buttons in UI after 200ms from send + private void updateEnableButtonsUI() { // enable buttons imageButtonSend.setEnabled(true); editTextMsg.setEnabled(true); editTextMsg.setText(""); } - - private void updateResultsInUi() - { - if(allVehicle == null) - UpdateVehs(parentTab.getAllVehicle()); - - //SM.Debug("updateResultsInUi: " + ACTION); - if(ACTION == MSGUpdate) - { - if(LASTMESSAGES) - { - // show Header Layout - layoutHeader.setVisibility(View.VISIBLE); - // hide Conversation Header Layout - layoutHeaderConversation.setVisibility(View.GONE); - // hide Send Layout - layoutSend.setVisibility(View.GONE); - // change GridView adapter - gridView.setAdapter(mAdapter); - gridView.invalidate(); - } - else - { - SM.Debug(" #### Modify adapter for SMS4unit"); - // populate specific conversation - listSpecificConversation = new ArrayList(); - dispatcher_positions = new ArrayList(); - ArrayList ackPosition = new ArrayList(); - ArrayList list; - list = tableSMS.get(sc_id); - for(SMS sms: list) - { - // get for sender - long id_sender = sms.sc_id_dest; - if (id_sender == 0) - id_sender = sms.sc_id_sour; - // get vehicle with sender id - Vehicle messageVeh= null; - messageVeh = getVehicleById(id_sender); - // flag dispatcher message when source is 0 - dispatcher_positions.add(sms.sc_id_sour==0 ? true : false); - if(sms.status == 2) - ackPosition.add(true); - else - ackPosition.add(false); - - listSpecificConversation.add(new Msg(messageVeh, sms.mess, new Date((long)sms.timeGMT * 1000), sms.seq_idx)); - } - - - convAdapter = new ConversationGridViewAdapter(activity, listSpecificConversation, context, sc_id, unit_type, dispatcher_positions, ackPosition); - gridView.setAdapter(convAdapter); - if(listSpecificConversation.size() > 0) - gridView.setSelection(listSpecificConversation.size()-1); - - // set unit name and image in Header Conversation - textViewSelectedContact.setText(getVehicleBySc_Id(sc_id).name); - imageViewSelectedContact.setImageResource(getVehicleBySc_Id(sc_id).getLargeIcon()); - - // clear editText - editTextMsg.setText(""); - - // change layouts visibility - layoutSend.setVisibility(View.VISIBLE); - layoutHeader.setVisibility(View.GONE); - layoutHeaderConversation.setVisibility(View.VISIBLE); - - } - gridView.invalidate(); - // hide dialog - try - { - //dialogLoading.cancel(); - } - catch(Exception ex) - { - ; - } - } -} - - // show new message after layoutNewMessage Click - public void showSMS4unit(int sc_id) - { - // show dialog - //dialogLoading = ProgressDialog.show(activity, "", "Loading messages. Please wait...", true); - - ACTION = MSGUpdate; - LASTMESSAGES = false; - GetSMS4unit(sc_id); + + private void updateResultsInUi() { + if (getAllVehicle() == null) + updateVehicles(parentTab.getAllVehicle()); + + if (ACTION == MSG_UPDATE) { + if (LASTMESSAGES) { + // show Header Layout + layoutHeader.setVisibility(View.VISIBLE); + // hide Conversation Header Layout + layoutHeaderConversation.setVisibility(View.GONE); + // hide Send Layout + layoutSend.setVisibility(View.GONE); + // change GridView adapter + gridView.setAdapter(mAdapter); + gridView.invalidate(); + } else { + SM.Debug(" #### Modify adapter for SMS4unit"); + // populate specific conversation + listSpecificConversation = new ArrayList<>(); + dispatcherPositions = new ArrayList<>(); + ArrayList ackPosition = new ArrayList<>(); + ArrayList list; + list = tableSMS.get(getScId()); + if (list != null) { + for (SMS sms : list) { + // get for sender + long senderId = sms.sc_id_dest; + if (senderId == 0) + senderId = sms.sc_id_sour; + // get vehicle with sender id + Vehicle messageVeh; + messageVeh = getVehicleById(senderId); + // flag dispatcher message when source is 0 + dispatcherPositions.add(sms.sc_id_sour == 0); + ackPosition.add(sms.status == 2); + + listSpecificConversation.add(new Msg(messageVeh, sms.mess, new Date((long) sms.timeGMT * 1000), sms.seq_idx)); + } + } + + convAdapter = new ConversationGridViewAdapter(activity, listSpecificConversation, dispatcherPositions, ackPosition); + gridView.setAdapter(convAdapter); + if (!listSpecificConversation.isEmpty()) + gridView.setSelection(listSpecificConversation.size() - 1); + + // set unit name and image in Header Conversation + textViewSelectedContact.setText(getVehicleByScId(getScId()).name); + imageViewSelectedContact.setImageResource(getVehicleByScId(getScId()).getLargeIcon()); + + // clear editText + editTextMsg.setText(""); + + // change layouts visibility + layoutSend.setVisibility(View.VISIBLE); + layoutHeader.setVisibility(View.GONE); + layoutHeaderConversation.setVisibility(View.VISIBLE); + + } + gridView.invalidate(); + } } - + // gets Vehicle from id - public Vehicle getVehicleById(long id_vehicle) - { - for(Vehicle vehicle: allVehicle) - if(vehicle.sc_id == id_vehicle) - return vehicle; + public Vehicle getVehicleById(long vehicleId) { + for (Vehicle vehicle : getAllVehicle()) + if (vehicle.sc_id == vehicleId) + return vehicle; return null; } - + // get Vehicle from imei - public Vehicle getVehicleByImei(String imei) - { - for(Vehicle vehicle: allVehicle) - if(vehicle.imei.equalsIgnoreCase(imei)) + public Vehicle getVehicleByImei(String imei) { + for (Vehicle vehicle : getAllVehicle()) + if (vehicle.imei.equalsIgnoreCase(imei)) return vehicle; return null; } - - - public Vehicle getVehicleBySc_Id(long sc_id) - { - for(Vehicle vehicle: allVehicle) - if(vehicle.sc_id == sc_id) + + public Vehicle getVehicleByScId(long scId) { + for (Vehicle vehicle : getAllVehicle()) + if (vehicle.sc_id == scId) return vehicle; return null; } - - // show a dialog - public void showDialog() - { - ArrayAdapter adapter = new ArrayAdapter(this, R.layout.template_simple_list_item, allVehicleNames); - + + // show a dialog + public void showDialog() { + ArrayAdapter adapter = new ArrayAdapter<>(this, R.layout.template_simple_list_item, allVehicleNames); + AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(getString(R.string.selectVehicle)); - builder.setAdapter(adapter , new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // get position - Vehicle item = allVehicle.get(which); - // get Specific Conversation - sc_id = item.sc_id; - SM.Debug("Selected sc_id: " + sc_id); - // set Conversation type - LASTMESSAGES = false; - // call get SMS - GetSMS4unit(sc_id); - // create crt_Vehicle - unit_type = (int) item.driver_id; - - SM.Debug("AM SELECTAT: " + sc_id + " | " + item.name + " | " + unit_type + "\n\t " + item.toString()); - selectedVehicle = new Msg(item, "", Calendar.getInstance().getTime(), ""); - - if(AppParams.DEMO) - updateResultsInUi(); - } - }); + builder.setAdapter(adapter, (dialog, which) -> { + // get position + Vehicle item = getAllVehicle().get(which); + // get Specific Conversation + setScId(item.sc_id); + SM.Debug("Selected scId: " + getScId()); + // set Conversation type + LASTMESSAGES = false; + // call get SMS + getSMS4unit(getScId()); + // create crt_Vehicle + setUnitType((int) item.driver_id); + + SM.Debug("AM SELECTAT: " + getScId() + " | " + item.name + " | " + getUnitType() + "\n\t " + item); + + if (AppParams.DEMO) + updateResultsInUi(); + }); AlertDialog alert = builder.create(); alert.show(); } - - public void showErrorDialog(String errorMsg) - { + public void showErrorDialog(String errorMsg) { Dialog dialog = new Dialog(context); dialog.setTitle(getString(R.string.sendingError)); dialog.setContentView(R.layout.dialog); dialog.setCancelable(true); dialog.setCanceledOnTouchOutside(true); - TextView text = (TextView) dialog.findViewById(R.id.text); - ImageView image = (ImageView) dialog.findViewById(R.id.image); - + TextView text = dialog.findViewById(R.id.text); + ImageView image = dialog.findViewById(R.id.image); + image.setImageResource(R.drawable.error); text.setText(errorMsg); dialog.show(); } -} + + public ArrayList getAllVehicle() { + return allVehicle; + } + + public void setAllVehicle(ArrayList allVehicle) { + this.allVehicle = allVehicle; + } + + public long getScId() { + return scId; + } + + public void setScId(long scId) { + this.scId = scId; + } + + public int getUnitType() { + return unitType; + } + + public void setUnitType(int unitType) { + this.unitType = unitType; + } + + public Bundle getSavedInstanceState() { + return savedInstanceState; + } + + public void setSavedInstanceState(Bundle savedInstanceState) { + this.savedInstanceState = savedInstanceState; + } +} \ No newline at end of file diff --git a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java index ac25ba6..16de642 100644 --- a/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java +++ b/safeDispatch/src/main/java/com/safemobile/dispatch/TabLayoutActivity.java @@ -405,7 +405,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ tabHost.setCurrentTabByTag("Text"); AppParams.crtTab = AppParams.Tabs.message; - if (AppParams.DEMO && messageActivity.allVehicle.size()== 0) { + if (AppParams.DEMO && messageActivity.getAllVehicle().size()== 0) { // select button buttonText.setSelected(true); // deselect other buttons @@ -419,9 +419,9 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ tabHost.setCurrentTabByTag("Text"); AppParams.crtTab = AppParams.Tabs.message; - if (AppParams.DEMO && messageActivity.allVehicle.size()== 0) { - messageActivity.UpdateVehs(getAllVehicle()); - messageActivity.UpdateSMS(listSMS); + if (AppParams.DEMO && messageActivity.getAllVehicle().size()== 0) { + messageActivity.updateVehicles(getAllVehicle()); + messageActivity.updateSMS(listSMS); } } } @@ -674,8 +674,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ //list for SMS if(currentActivity instanceof MessagesActivity) { - // run update showSMS4unit(int sc_id) form MessageActivity - ((MessagesActivity)currentActivity).showSMS4unit(getVehicle4Imei(imei).sc_id); + // run update showSMS4unit(int scId) form MessageActivity + ((MessagesActivity)currentActivity).showSMS4unit(getVehicle4Imei(imei).scId); } */ } @@ -821,9 +821,9 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ tabHost.setCurrentTabByTag("Text"); AppParams.crtTab = AppParams.Tabs.message; - messageActivity.sc_id = getVehicle4Imei(getImei()).sc_id; + messageActivity.setScId(getVehicle4Imei(getImei()).sc_id); messageActivity.LASTMESSAGES = false; - messageActivity.GetLastSMS(); + messageActivity.getLastSMS(); // disable notification if(mNotificationManager!=null) @@ -1019,7 +1019,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ if(radioActivity!=null) radioActivity.onCreate(radioActivity.savedInstanceState); if(messageActivity!=null) - messageActivity.onCreate(messageActivity.savedInstanceState); + messageActivity.onCreate(messageActivity.getSavedInstanceState()); if(recordingsActivity!=null) recordingsActivity.onCreate(recordingsActivity.savedInstanceState); if(alarmActivity!=null) @@ -1319,9 +1319,9 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ //list for SMS if(AppParams.crtTab == AppParams.Tabs.message) { - //SM.Debug("currentActivity instanceof MessagesActivity - NewSMS"); + //SM.Debug("currentActivity instanceof MessagesActivity - newSMS"); if(messageActivity != null) - messageActivity.UpdateSMS(sms.smsList); + messageActivity.updateSMS(sms.smsList); } } catch(Exception ex) @@ -1370,7 +1370,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ { SM.Debug("currentActivity instanceof MessagesActivity"); if(messageActivity != null) - messageActivity.UpdateVehs(vMSG.vehList); + messageActivity.updateVehicles(vMSG.vehList); } setAllVehicle(vMSG.vehList); } @@ -1387,7 +1387,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ { //SM.Debug("currentActivity instanceof MessagesActivity"); if(messageActivity != null) - messageActivity.UpdateSMS(sms.smsList); + messageActivity.updateSMS(sms.smsList); } } catch (Exception ex) @@ -1433,7 +1433,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ SM.Debug("Got smsComfirm msg.data:" + msg.data); if (messageActivity != null) - messageActivity.ConfirmSMS(sms.data, msg.seqID); + messageActivity.confirmSMS(sms.data, msg.seqID); } @Override @@ -1466,8 +1466,8 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ }); //list for SMS if(AppParams.crtTab == AppParams.Tabs.message && messageActivity!= null) { - SM.Debug("currentActivity instanceof MessagesActivity - NewSMS | " + tempArr[0] + " | " + tempArr[1]); - messageActivity.NewSMS(tempArr[0], tempArr[1], time); + SM.Debug("currentActivity instanceof MessagesActivity - newSMS | " + tempArr[0] + " | " + tempArr[1]); + messageActivity.newSMS(tempArr[0], tempArr[1], time); } } @@ -1858,7 +1858,7 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ //list for SMS if(AppParams.crtTab == AppParams.Tabs.alarms) { - SM.Debug("currentActivity instanceof AlarmActivity - NewSMS | " + tempArr[0] + " | " + tempArr[1]); + SM.Debug("currentActivity instanceof AlarmActivity - newSMS | " + tempArr[0] + " | " + tempArr[1]); getAlarms(AppParams.USERID); } // if tab is not TextTab @@ -2315,19 +2315,19 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } } - public void optionForUnit(int radioCode, int opCode, int sc_id, int value) + public void optionForUnit(int radioCode, int opCode, int scId, int value) { - boolean res = tcp.Write("0.0", "#"+radioCode+"#"+opCode+"#" + sc_id+"#" +value + "#"); + boolean res = tcp.Write("0.0", "#"+radioCode+"#"+opCode+"#" + scId+"#" +value + "#"); if(res){ - SM.Debug("Message (optionForUnit) sent to app server radioCode:"+radioCode+ " opCode:"+opCode+ " sc_id:"+sc_id+ " value:"+value); + SM.Debug("Message (optionForUnit) sent to app server radioCode:"+radioCode+ " opCode:"+opCode+ " scId:"+scId+ " value:"+value); }else{ SM.Debug("Could not send message(optionForUnit)!!"); } } - public void getSMS4unit(int sc_id, long timeGMT) + public void getSMS4unit(int scId, long timeGMT) { - boolean res = tcp.Write("0.0", "#22#"+sc_id+"#" +timeGMT+"#"); + boolean res = tcp.Write("0.0", "#22#"+scId+"#" +timeGMT+"#"); if(res){ SM.Debug("Message (getLastSMS) sent to app server"); }else{ @@ -2345,11 +2345,11 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } } - public void SendSMS(String seqID,int sc_id, String txt) + public void SendSMS(String seqID,int scId, String txt) { - boolean res = tcp.Write(seqID, "#24#" + AppParams.USERID + "#" + sc_id + "#" + txt + "#"); + boolean res = tcp.Write(seqID, "#24#" + AppParams.USERID + "#" + scId + "#" + txt + "#"); if(res){ - SM.Debug("Message (SendSMS) sent to app server sc_id:"+sc_id+ " txt:"+txt); + SM.Debug("Message (SendSMS) sent to app server scId:"+scId+ " txt:"+txt); }else{ SM.Debug("Could not send message(getLastSMS)!!"); } @@ -2385,10 +2385,10 @@ public class TabLayoutActivity extends AbstractSDParentActivity{ } } - public void getHistoryPos(int sc_id, long timeGMTStart, long timeGMTStop) + public void getHistoryPos(int scId, long timeGMTStart, long timeGMTStop) { HistSeqID = "1."+Integer.toString((int) (System.currentTimeMillis() / 1000L)); - boolean res = tcp.Write(HistSeqID,"#26#"+sc_id+"#"+timeGMTStart+"#"+timeGMTStop+"#"); + boolean res = tcp.Write(HistSeqID,"#26#"+scId+"#"+timeGMTStart+"#"+timeGMTStop+"#"); if(res){ SM.Debug("Message (getHistoryPos) sent to app server"); }else{ diff --git a/safeDispatch/src/main/res/layout-large/tabtext.xml b/safeDispatch/src/main/res/layout-large/tabtext.xml index 433085a..d3d2309 100644 --- a/safeDispatch/src/main/res/layout-large/tabtext.xml +++ b/safeDispatch/src/main/res/layout-large/tabtext.xml @@ -1,243 +1,244 @@ - - + android:orientation="vertical" + android:layout_width="fill_parent" + android:layout_height="fill_parent" android:weightSum="1" + android:id="@+id/layoutMain" + style="?bg"> - - + - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:id="@+id/imageViewSelectedContact" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@drawable/ambulance_large" + android:layout_margin="3dp" /> + + - - - - - - - - - - - - - - - -