Android: Team-Chat eingebaut. Nicht optimal, funktioniert aber. Verbesserungen am Chat-Server und an der App.

This commit is contained in:
staccatomamba
2016-08-17 12:20:27 +02:00
parent 2390fa5e17
commit 0b9a5e2a32
29 changed files with 1272 additions and 788 deletions

View File

@@ -0,0 +1,583 @@
package Database;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import beyondsoft.bewomitarbeiterapp.ContactListItem;
import entities.ChatMessage;
import soapConnection.SoapConnectionManager;
/**
* Created by bib on 07.06.2016.
*/
public class DatabaseHandler extends SQLiteOpenHelper {
//DataBase version
private static final int DATABASE_VERSION = 1;
//Database name
private static final String DATABASE_NAME = "Contacts_Manager";
//Table Name
private static final String TABLE_CONTACTS = "Contactlist";
private static final String TABLE_CHATMESSAGE = "ChatMessage";
private static final String TABLE_DATABASEOWNER = "DatabaseOwner";
//Table Columns name
private static final String KEY_ID_OWNER = "id";
private static final String KEY_OWNER_PERSON_OID = "ownerpersonoid";
// Contacts-Tabelle
private static final String KEY_ID ="id";
private static final String KEY_KONTAKT_NAME = "kontaktname";
private static final String KEY_PERSONOID = "personoid";
private static final String KEY_PICTURE_BLOB = "bild";
private static final String KEY_IS_TEAM = "isteam";
private static final String KEY_TEAM_MEMBER_OIDS = "teammemberoids";
private static final String KEY_TEAM_MEMBER_NAMES = "teammembernames";
// ChatMessage-Tabelle
private static final String KEY_ID_CHATMESSAGE = "id";
private static final String KEY_SENDER_PERSON_OID_CHATMESSAGE = "senderpersonoid";
private static final String KEY_RECIPIENT_PERSON_OID_CHATMESSAGE = "recipientpersonoid";
private static final String KEY_INSTS_CHATMESSAGE = "insts";
private static final String KEY_CHAT_TEXT_CHATMESSAGE = "chattext";
private static final String KEY_IS_DELIVERED_CHATMESSAGE = "isdelivered";
private static final String KEY_SERVERSEITIGE_OID_CHATMESSAGE = "serverseitigeoid";
private static final String KEY_IS_TEAM_CHATMESSAGE = "isteam";
private static DatabaseHandler mInstance = null;
private Context mContext;
public static DatabaseHandler getInstance(Context context) {
if(mInstance == null) {
mInstance = new DatabaseHandler(context.getApplicationContext());
}
return mInstance;
}
private DatabaseHandler(Context context){
super(context,DATABASE_NAME, null, DATABASE_VERSION);
this.mContext = context;
}
public void clearDatabase() {
SQLiteDatabase db = this.getWritableDatabase();
String deleteQuery = "DELETE FROM " + TABLE_DATABASEOWNER;
db.execSQL(deleteQuery);
deleteQuery = "DELETE FROM " + TABLE_CHATMESSAGE;
db.execSQL(deleteQuery);
deleteQuery = "DELETE FROM " + TABLE_CONTACTS;
db.execSQL(deleteQuery);
db.close();
}
public void onCreate(SQLiteDatabase db) {
String CREATE_CONTACTS_TABLE =
"CREATE TABLE " + TABLE_CONTACTS + "(" +
KEY_ID + " INTEGER PRIMARY KEY," +
KEY_KONTAKT_NAME + " TEXT,"+
KEY_PERSONOID + " INTEGER," +
KEY_PICTURE_BLOB + " BLOB, " +
KEY_IS_TEAM + " INTEGER, " +
KEY_TEAM_MEMBER_NAMES + " TEXT, " +
KEY_TEAM_MEMBER_OIDS + " TEXT)";
db.execSQL(CREATE_CONTACTS_TABLE);
String createChatMessageTable =
"CREATE TABLE " + TABLE_CHATMESSAGE + "(" +
KEY_ID_CHATMESSAGE + " INTEGER PRIMARY KEY," +
KEY_SENDER_PERSON_OID_CHATMESSAGE + " INTEGER," +
KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + " INTEGER," +
KEY_INSTS_CHATMESSAGE + " DATETIME DEFAULT CURRENT_TIMESTAMP," +
KEY_CHAT_TEXT_CHATMESSAGE + " TEXT," +
KEY_IS_DELIVERED_CHATMESSAGE + " INTEGER," +
KEY_SERVERSEITIGE_OID_CHATMESSAGE + " INTEGER DEFAULT NULL," +
KEY_IS_TEAM_CHATMESSAGE + " INTEGER DEFAULT 0)";
db.execSQL(createChatMessageTable);
String createOwnerTable = "CREATE TABLE " + TABLE_DATABASEOWNER + " (" +
KEY_ID_OWNER + " INTEGER PRIMARY KEY," +
KEY_OWNER_PERSON_OID + " INTEGER" +
")";
db.execSQL(createOwnerTable);
}
public void insertOwnerOid(int ownerOid) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_ID_OWNER, ownerOid);
db.insert(TABLE_DATABASEOWNER, null, values);
db.close();
}
public int getOwnerOid() {
SQLiteDatabase db = this.getReadableDatabase();
String selectQuery = "SELECT * FROM " + TABLE_DATABASEOWNER;
Cursor cursor = db.rawQuery(selectQuery, null);
int ownerOid = 0;
if(cursor.moveToFirst()) {
ownerOid = cursor.getInt(0);
}
cursor.close();
db.close();
return ownerOid;
}
public void addChatMessages(ArrayList<ChatMessage> messages) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
try {
db.beginTransaction();
for(ChatMessage message : messages) {
values.put(KEY_SENDER_PERSON_OID_CHATMESSAGE, message.SenderPersonOid);
values.put(KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, message.RecipientPersonOid);
values.put(KEY_INSTS_CHATMESSAGE, getDateTimeString(message.InsTs));
values.put(KEY_CHAT_TEXT_CHATMESSAGE, message.ChatText);
values.put(KEY_IS_DELIVERED_CHATMESSAGE, (message.IsDelivered ? 1 : 0));
values.put(KEY_SERVERSEITIGE_OID_CHATMESSAGE, message.ServerseitigeOid);
values.put(KEY_IS_TEAM_CHATMESSAGE, message.IsTeam);
db.insertOrThrow(TABLE_CHATMESSAGE, null, values);
values.clear();
}
db.setTransactionSuccessful();
} finally {
if(db.inTransaction()) {
db.endTransaction();
}
db.close();
}
}
public long addChatMessage(ChatMessage message) {
SQLiteDatabase db = this.getWritableDatabase();
long rowId = db.insert(TABLE_CHATMESSAGE, null, fillValuesForChatMessage(message));
db.close();
return rowId;
}
private ContentValues fillValuesForChatMessage(ChatMessage message) {
ContentValues values = new ContentValues();
values.put(KEY_SENDER_PERSON_OID_CHATMESSAGE, message.SenderPersonOid);
values.put(KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, message.RecipientPersonOid);
values.put(KEY_INSTS_CHATMESSAGE, getDateTimeString(message.InsTs));
values.put(KEY_CHAT_TEXT_CHATMESSAGE, message.ChatText);
values.put(KEY_IS_DELIVERED_CHATMESSAGE, (message.IsDelivered ? 1 : 0));
values.put(KEY_SERVERSEITIGE_OID_CHATMESSAGE, message.ServerseitigeOid);
values.put(KEY_IS_TEAM_CHATMESSAGE, message.IsTeam);
return values;
}
public int updateChatMessage(ChatMessage message) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_SENDER_PERSON_OID_CHATMESSAGE, message.SenderPersonOid);
values.put(KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, message.RecipientPersonOid);
values.put(KEY_INSTS_CHATMESSAGE, getDateTimeString(message.InsTs));
values.put(KEY_CHAT_TEXT_CHATMESSAGE, message.ChatText);
values.put(KEY_IS_DELIVERED_CHATMESSAGE, (message.IsDelivered ? 1 : 0));
values.put(KEY_SERVERSEITIGE_OID_CHATMESSAGE, message.ServerseitigeOid);
values.put(KEY_IS_TEAM_CHATMESSAGE, message.IsTeam);
int result = db.update(TABLE_CHATMESSAGE, values, KEY_ID_CHATMESSAGE + " = ?", new String[] { String.valueOf(message.Id)});
db.close();
return result;
}
public ArrayList<Integer> getExistingChatMessageIds() {
ArrayList<Integer> result = new ArrayList<Integer>();
SQLiteDatabase db = this.getReadableDatabase();
String selectQuery = "SELECT "+ KEY_SERVERSEITIGE_OID_CHATMESSAGE + " FROM " + TABLE_CHATMESSAGE + " WHERE " + KEY_SERVERSEITIGE_OID_CHATMESSAGE + " <> 0";
Cursor cursor = db.rawQuery(selectQuery, null);
if(cursor.moveToFirst()) {
do {
result.add(cursor.getInt(0));
} while(cursor.moveToNext());
}
cursor.close();
db.close();
return result;
}
public ArrayList<Integer> getExistingTeamChatMessageIds() {
ArrayList<Integer> result = new ArrayList<Integer>();
SQLiteDatabase db = this.getReadableDatabase();
String selectQuery = "SELECT " + KEY_SERVERSEITIGE_OID_CHATMESSAGE + " FROM " + TABLE_CHATMESSAGE + " WHERE " + KEY_SERVERSEITIGE_OID_CHATMESSAGE + " <> 0 AND " + KEY_IS_TEAM_CHATMESSAGE + " = 1";
Cursor cursor = db.rawQuery(selectQuery, null);
if(cursor.moveToFirst()) {
do {
result.add(cursor.getInt(0));
} while(cursor.moveToNext());
}
cursor.close();
db.close();
return result;
}
private String getDateTimeString(Date date) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);
return dateFormat.format(date);
}
private Date getDateFromString(String dateString) {
Date result = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);
try {
result = df.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
return result;
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CHATMESSAGE);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_DATABASEOWNER);
onCreate(db);
}
public void addContact(ContactListItem contact) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_KONTAKT_NAME, contact.getChatName());
values.put(KEY_PERSONOID, contact.getPersonOid());
values.put(KEY_PICTURE_BLOB, contact.getPicture());
values.put(KEY_IS_TEAM, contact.isTeam);
values.put(KEY_TEAM_MEMBER_NAMES, contact.teamMemberNames);
values.put(KEY_TEAM_MEMBER_OIDS, contact.teamMemberOids);
db.insert(TABLE_CONTACTS, null, values);
db.close();
}
public ChatMessage getChatMessageById(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(
TABLE_CHATMESSAGE,
new String[] {KEY_ID_CHATMESSAGE, KEY_SENDER_PERSON_OID_CHATMESSAGE, KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, KEY_INSTS_CHATMESSAGE, KEY_CHAT_TEXT_CHATMESSAGE, KEY_IS_DELIVERED_CHATMESSAGE, KEY_SERVERSEITIGE_OID_CHATMESSAGE, KEY_IS_TEAM_CHATMESSAGE},
KEY_ID_CHATMESSAGE + "=?",
new String[]{String.valueOf(id)},
null, null, null, null);
if(cursor != null) {
cursor.moveToFirst();
int messageId = cursor.getInt(0);
int senderPersonOid = cursor.getInt(1);
int recipientPersonOid = cursor.getInt(2);
Date insTs = getDateFromString(cursor.getString(3));
String chatText = cursor.getString(4);
boolean isDelivered = cursor.getInt(5) != 0;
int serverseitigeOid = cursor.getInt(6);
boolean isTeam = cursor.getInt(7) != 0;
cursor.close();
db.close();
return new ChatMessage(messageId, senderPersonOid, recipientPersonOid, insTs, chatText, isDelivered, serverseitigeOid, isTeam);
}
db.close();
return null;
}
public ArrayList<ChatMessage> getMessagesForRecipient(int recipientOid) {
ArrayList<ChatMessage> messages = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(
TABLE_CHATMESSAGE,
new String[] {KEY_ID_CHATMESSAGE, KEY_SENDER_PERSON_OID_CHATMESSAGE, KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, KEY_INSTS_CHATMESSAGE, KEY_CHAT_TEXT_CHATMESSAGE, KEY_IS_DELIVERED_CHATMESSAGE, KEY_SERVERSEITIGE_OID_CHATMESSAGE, KEY_IS_TEAM_CHATMESSAGE},
KEY_SENDER_PERSON_OID_CHATMESSAGE + "=? AND " + KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + "=? OR " + KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + "=? AND " + KEY_SENDER_PERSON_OID_CHATMESSAGE + "=?",
new String[] {String.valueOf(SoapConnectionManager.User.getPersonOid()), String.valueOf(recipientOid), String.valueOf(SoapConnectionManager.User.getPersonOid()), String.valueOf(recipientOid)},
null, null, null, null);
if(cursor.moveToFirst()) {
do{
ChatMessage message = new ChatMessage(
cursor.getInt(0),
cursor.getInt(1),
cursor.getInt(2),
getDateFromString(cursor.getString(3)),
cursor.getString(4),
cursor.getInt(5) != 0,
cursor.getInt(6),
cursor.getInt(7) != 0
);
messages.add(message);
} while(cursor.moveToNext());
}
cursor.close();
db.close();
return messages;
}
public ArrayList<ChatMessage> getMessagesForTeam(int teamOid) {
ArrayList<ChatMessage> messages = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(
TABLE_CHATMESSAGE,
new String[] {KEY_ID_CHATMESSAGE, KEY_SENDER_PERSON_OID_CHATMESSAGE, KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, KEY_INSTS_CHATMESSAGE, KEY_CHAT_TEXT_CHATMESSAGE, KEY_IS_DELIVERED_CHATMESSAGE, KEY_SERVERSEITIGE_OID_CHATMESSAGE, KEY_IS_TEAM_CHATMESSAGE},
KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + "=? AND " + KEY_IS_TEAM_CHATMESSAGE + "= 1",
new String[] {String.valueOf(teamOid)},
null, null, null, null);
if(cursor.moveToFirst()) {
do{
ChatMessage message = new ChatMessage(
cursor.getInt(0),
cursor.getInt(1),
cursor.getInt(2),
getDateFromString(cursor.getString(3)),
cursor.getString(4),
cursor.getInt(5) != 0,
cursor.getInt(6),
cursor.getInt(7) != 0
);
messages.add(message);
} while(cursor.moveToNext());
}
cursor.close();
db.close();
return messages;
}
public ContactListItem getContact(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS,
new String[]{
KEY_ID,
KEY_KONTAKT_NAME,
KEY_PERSONOID,
KEY_PICTURE_BLOB,
KEY_IS_TEAM,
KEY_TEAM_MEMBER_NAMES,
KEY_TEAM_MEMBER_OIDS},
KEY_ID + "=?",
new String[]{String.valueOf(id)},
null,null,null,null);
if(cursor != null) {
cursor.moveToFirst();
int contactId = cursor.getInt(0);
String contactName = cursor.getString(1);
int contactPersonOid = cursor.getInt(2);
byte[] contactPicture = cursor.getBlob(3);
boolean contactIsTeam = cursor.getInt(4) == 1;
String teamMemberOids = cursor.getString(5);
String teamMemberNames = cursor.getString(6);
ContactListItem contact = new ContactListItem(contactId, contactName, contactPersonOid, contactPicture, contactIsTeam, teamMemberOids, teamMemberNames);
cursor.close();
db.close();
return contact;
}
db.close();
return null;
}
public List<ContactListItem> getAllContacts(){
List<ContactListItem> contactList = new ArrayList<ContactListItem>();
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
ContactListItem contact = new ContactListItem();
contact.setId(cursor.getInt(0));
contact.setChatName(cursor.getString(1));
contact.setPersonOid(cursor.getInt(2));
contact.setPicture(cursor.getBlob(3));
contact.isTeam = cursor.getInt(4) == 1;
contact.teamMemberNames = cursor.getString(5);
contact.teamMemberOids = cursor.getString(6);
contactList.add(contact);
} while (cursor.moveToNext());
}
cursor.close();
db.close();
return contactList;
}
public int updateContact(ContactListItem contact) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_KONTAKT_NAME, contact.getChatName());
values.put(KEY_PERSONOID, contact.getPersonOid());
values.put(KEY_PICTURE_BLOB, contact.getPicture());
values.put(KEY_IS_TEAM, (contact.isTeam ? 1 : 0));
values.put(KEY_TEAM_MEMBER_NAMES, contact.teamMemberNames);
values.put(KEY_TEAM_MEMBER_OIDS, contact.teamMemberOids);
int result = db.update(TABLE_CONTACTS, values, KEY_ID + " = ?", new String[] { String.valueOf(contact.getId()) });
db.close();
return result;
}
public void deleteContacts(ContactListItem contact){
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_CONTACTS, KEY_ID + " = ?", new String[] { String.valueOf(contact.getId()) });
db.close();
}
public int getContactsCount(){
String countQuery = "SELECT COUNT(*) FROM " + TABLE_CONTACTS;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
int result = 0;
if(cursor.moveToFirst()) {
result = cursor.getInt(0);
}
cursor.close();
db.close();
return result;
}
public byte[] getUserImage(Integer personOid) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS, new String[] {KEY_PERSONOID}, KEY_PERSONOID + " = " + personOid, null, null, null, null);
byte[] picture = cursor.getBlob(0);
cursor.close();
db.close();
return picture;
}
public ContactListItem getContactByPersonOid(int personOid) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS,
new String[]{
KEY_ID,
KEY_KONTAKT_NAME,
KEY_PERSONOID,
KEY_PICTURE_BLOB,
KEY_IS_TEAM,
KEY_TEAM_MEMBER_NAMES,
KEY_TEAM_MEMBER_OIDS},
KEY_PERSONOID + "=?",
new String[]{String.valueOf(personOid)},
null,null,null,null);
if(cursor != null && cursor.moveToFirst()) {
int contactId = cursor.getInt(0);
String contactName = cursor.getString(1);
int contactPersonOid = cursor.getInt(2);
byte[] contactPicture = cursor.getBlob(3);
boolean contactIsTeam = cursor.getInt(4) == 1;
String teamMemberOids = cursor.getString(5);
String teamMemberNames = cursor.getString(6);
ContactListItem contact = new ContactListItem(contactId, contactName, contactPersonOid, contactPicture, contactIsTeam, teamMemberOids, teamMemberNames);
cursor.close();
db.close();
return contact;
} else {
Log.i("DATABASE_HANDLER", "Keinen Kontakt mit PersonOid " + personOid + " gefunden.");
}
db.close();
return null;
}
}

View File

@@ -40,10 +40,10 @@ import com.octo.android.robospice.UncachedSpiceService;
import com.octo.android.robospice.persistence.exception.SpiceException;
import com.octo.android.robospice.request.listener.RequestListener;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapPrimitive;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.security.InvalidAlgorithmParameterException;
@@ -53,15 +53,21 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;
import javax.crypto.NoSuchPaddingException;
import Database.DatabaseHandler;
import entities.ChatMessage;
import soapConnection.DataIdentifier;
import soapConnection.JsonSoapPrimitiveRequest;
import soapConnection.Packet;
import soapConnection.SoapCalls;
import soapConnection.SoapConnectionManager;
import tcpConnection.SocketManager;
import tcpConnection.UIHandler;
import util.ChatMessageDeserializer;
import util.SecurityUtils;
import util.Util;
@@ -69,11 +75,8 @@ import util.Util;
* Created by bib on 03.05.2016.
*/
public class ChatActivity extends ActionBarActivity {
private static final String LOG_TAG = "CHAT";
private DatabaseHandler databaseHandler;
protected TextView chat;
protected EditText text;
protected Button senden;
@@ -81,15 +84,18 @@ public class ChatActivity extends ActionBarActivity {
public static List<ChatMessage> chatMessages;
public static ArrayAdapter<ChatMessage> adapter;
File file;
protected String recipientName;
protected int recipientPersonOid;
protected String teamMemberOids;
protected String teamMemberNames;
protected boolean isTeam;
private SpiceManager spiceManager = new SpiceManager(UncachedSpiceService.class);
private UIHandler chatUIHandler;
private View mCustomView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -102,37 +108,53 @@ public class ChatActivity extends ActionBarActivity {
action.setDisplayShowTitleEnabled(false);
LayoutInflater inflate = LayoutInflater.from(this);
View mCustomView = inflate.inflate(R.layout.custom_menuebar, null);
mCustomView = inflate.inflate(R.layout.custom_menuebar, null);
TextView titlename = (TextView)mCustomView.findViewById(R.id.PersonalName);
ImageView titlepic = (ImageView)mCustomView.findViewById(R.id.PersonalPic);
action.setCustomView(mCustomView);
action.setDisplayShowCustomEnabled(true);
Bundle zielkorb = getIntent().getExtras();
databaseHandler = DatabaseHandler.getInstance(this);
senden = (Button)findViewById(R.id.Sendebutton);
listView = (ListView)findViewById(R.id.list_msg);
Bundle zielkorb = getIntent().getExtras();
recipientName = zielkorb.getString("Name");
recipientPersonOid = zielkorb.getInt("RecipientOid");
byte[] bildArray = zielkorb.getByteArray("Bild");
isTeam = zielkorb.getBoolean("IsTeam");
teamMemberOids = zielkorb.getString("TeamMemberOids");
teamMemberNames = zielkorb.getString("TeamMemberNames");
ReloadChatView(recipientName, recipientPersonOid, bildArray, isTeam, teamMemberOids, teamMemberNames);
}
private void ReloadChatView(String contactName, int recipientOid, byte[] contactImage, boolean pIsTeam, String pTeamMemberOids, String pTeamMemberNames) {
chatMessages = new ArrayList<>();
recipientPersonOid = recipientOid;
recipientName = contactName;
isTeam = pIsTeam;
teamMemberOids = pTeamMemberOids;
teamMemberNames = pTeamMemberNames;
ImageView status = (ImageView) mCustomView.findViewById(R.id.status);
TextView titlename = (TextView) mCustomView.findViewById(R.id.PersonalName);
ImageView titlepic = (ImageView) mCustomView.findViewById(R.id.PersonalPic);
status.setImageResource((SocketManager.onlinePersonOids.contains(recipientPersonOid) ? R.drawable.online : R.drawable.offline));
byte[] bildArray = zielkorb.getByteArray("Bild");
Bitmap customerImage;
if(bildArray != null) {
customerImage = BitmapFactory.decodeByteArray(bildArray, 0, bildArray.length);
if(contactImage != null) {
customerImage = BitmapFactory.decodeByteArray(contactImage, 0, contactImage.length);
titlepic.setImageBitmap(GetCircleBitmap(customerImage));
}
titlename.setText(recipientName);
action.setCustomView(mCustomView);
action.setDisplayShowCustomEnabled(true);
databaseHandler = new DatabaseHandler(this);
senden = (Button)findViewById(R.id.Sendebutton);
chatMessages = new ArrayList<>();
listView = (ListView)findViewById(R.id.list_msg);
chatMessages = databaseHandler.getMessagesForRecipient(recipientPersonOid);
chatMessages = isTeam ? databaseHandler.getMessagesForTeam(recipientPersonOid) : databaseHandler.getMessagesForRecipient(recipientPersonOid);
adapter = new MessageAdapter(this, R.layout.item_chat_left, chatMessages);
listView.setAdapter(adapter);
@@ -146,24 +168,57 @@ public class ChatActivity extends ActionBarActivity {
listView.post(new Runnable() {
@Override
public void run() {
chatPacket.writeToLog();
ChatMessage message = new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, false, chatPacket.ServerseitigeOid);
ChatMessage message = new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, false, chatPacket.ServerseitigeOid, false);
databaseHandler.addChatMessage(message);
chatMessages.add(message);
adapter.notifyDataSetChanged();
if(chatPacket.SenderPersonOid == recipientPersonOid) {
chatMessages.add(message);
adapter.notifyDataSetChanged();
} else {
SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.SenderPersonOid, false, null, null);
}
}
});
break;
case MESSAGE_RESPONSE:
ChatMessage cm = databaseHandler.getChatMessageById(chatPacket.ClientseitigeOid);
cm.ServerseitigeOid = chatPacket.ServerseitigeOid;
Log.i("CHAT_SOCKET_LISTENER", "" + cm.IsTeam + "; Clientseitige Id: " + cm.Id + "; Serverseitige Oid: " + cm.ServerseitigeOid);
databaseHandler.updateChatMessage(cm);
break;
case STATUS_NOTIFICATION_LOGIN:
if(!SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
SocketManager.onlinePersonOids.add(chatPacket.SenderPersonOid);
}
break;
case STATUS_NOTIFICATION_LOGOUT:
if(SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
SocketManager.onlinePersonOids.remove(Integer.valueOf(chatPacket.SenderPersonOid));
}
break;
case TEAM:
listView.post(new Runnable() {
@Override
public void run() {
ChatMessage message = new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, false, chatPacket.ServerseitigeOid, false);
databaseHandler.addChatMessage(message);
if(chatPacket.SenderPersonOid == recipientPersonOid) {
chatMessages.add(message);
adapter.notifyDataSetChanged();
} else {
SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.SenderPersonOid, isTeam, teamMemberOids, teamMemberNames);
}
}
});
break;
}
} catch(Exception pe) {
@@ -184,7 +239,7 @@ public class ChatActivity extends ActionBarActivity {
Packet packet = new Packet();
packet.ChatMessage = text.getText().toString();
packet.ChatDataIdentifier = DataIdentifier.MESSAGE;
packet.ChatDataIdentifier = isTeam ? DataIdentifier.TEAM : DataIdentifier.MESSAGE;
packet.RecipientPersonOid = recipientPersonOid;
packet.MessageTimeStamp = now;
@@ -199,9 +254,7 @@ public class ChatActivity extends ActionBarActivity {
e.printStackTrace();
}
final ChatMessage message = new ChatMessage(packet.SenderPersonOid, packet.RecipientPersonOid, packet.MessageTimeStamp, packet.ChatMessage, false, 0);
final ChatMessage message = new ChatMessage(packet.SenderPersonOid, packet.RecipientPersonOid, packet.MessageTimeStamp, packet.ChatMessage, false, 0, isTeam);
long coid = databaseHandler.addChatMessage(message);
@@ -221,16 +274,30 @@ public class ChatActivity extends ActionBarActivity {
}
});
} else {
Toast.makeText(ChatActivity.this, "Sie müssen schon Text eingeben ", Toast.LENGTH_SHORT).show();
Toast.makeText(ChatActivity.this, "Dieses Feld darf nicht leer sein", Toast.LENGTH_SHORT).show();
}
}
});
ArrayList<Integer> test = databaseHandler.getExistingChatMessageIds();
ArrayList<Integer> test = isTeam ? databaseHandler.getExistingTeamChatMessageIds() : databaseHandler.getExistingChatMessageIds();
for(int id : test) {
Log.i("CHATMESSAGE-ID", "" + id);
String pExceptions = "";
for(int i = 0; i < test.size(); i++) {
pExceptions += test.get(i);
if(i < test.size() - 1) {
pExceptions += ";";
}
}
ArrayList<PropertyInfo> propertyInfos = new ArrayList<>();
propertyInfos.add(SoapConnectionManager.BuildProperty("pSenderPersonOid", SoapConnectionManager.User.getPersonOid(), Long.class));
propertyInfos.add(SoapConnectionManager.BuildProperty("pRecipientPersonOid", recipientPersonOid, Long.class));
propertyInfos.add(SoapConnectionManager.BuildProperty("pExceptions", pExceptions, String.class));
propertyInfos.add(SoapConnectionManager.BuildProperty("pIsForTeam", isTeam, Boolean.class));
JsonSoapPrimitiveRequest request = new JsonSoapPrimitiveRequest(SoapCalls.GET_ALL_CHAT_MESSAGES, propertyInfos);
spiceManager.execute(request, new JsonSoapPrimitiveRequestListener());
}
@Override
@@ -240,10 +307,23 @@ public class ChatActivity extends ActionBarActivity {
super.onResume();
}
public void onDestroy(){
Log.i("CHAT_ON_DESTROY", "Zerstöre...");
@Override
public void onStop(){
spiceManager.shouldStop();
databaseHandler.close();
super.onStop();
}
super.onDestroy();
@Override
public void onPause() {
databaseHandler.close();
super.onPause();
}
@Override
protected void onStart() {
super.onStart();
spiceManager.start(this);
}
public boolean onCreateOptionsMenu(Menu menu) {
@@ -256,7 +336,6 @@ public class ChatActivity extends ActionBarActivity {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_delet_Storage:
file.delete(); //Delet aktuell gespeicherte message
recreate(); // ---> gegebenenfals umändern, aber fürs erste reichts
return true;
default:
@@ -264,12 +343,31 @@ public class ChatActivity extends ActionBarActivity {
}
}
public void SetNotify(String Username, String message){
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Bundle zielkorb = intent.getExtras();
String rn = zielkorb.getString("Name");
int rpoid = zielkorb.getInt("RecipientOid");
boolean blahIsTeam = zielkorb.getBoolean("IsTeam");
String tMemberOids = zielkorb.getString("TeamMemberOids");
String tMemberNames = zielkorb.getString("TeamMemberNames");
byte[] imageAsByteArray = databaseHandler.getUserImage(rpoid);
Log.i("CHAT_ON_NEW_INTENT", "Bild ist null: " + (imageAsByteArray == null));
ReloadChatView(rn, rpoid, null, blahIsTeam, tMemberOids, tMemberNames);
}
public void SetNotify(String username, String message, int recipientOid, boolean isTeam, String teamMemberOids, String teamMemberNames){
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.bslogo)
.setContentTitle(Username)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle(username)
.setContentText(message)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND)
@@ -277,17 +375,27 @@ public class ChatActivity extends ActionBarActivity {
.setLights(Color.YELLOW, 3000, 3000) //Notification.Default_Lights
.setOngoing(true);
Bundle bundle = new Bundle();
bundle.putString("Name", username);
bundle.putInt("RecipientOid", recipientOid);
bundle.putBoolean("IsTeam", isTeam);
bundle.putString("TeamMemberOids", teamMemberOids);
bundle.putString("TeamMemberNames", teamMemberNames);
//TODO: Bild laden
Intent resultIntent = new Intent(this, ChatActivity.class);
resultIntent.putExtras(bundle);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this.getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this.getApplicationContext(), (int) (Math.random() * 100), resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mBuilder.setContentIntent(resultPendingIntent);
mNotifyMgr.notify(1, mBuilder.build());
mNotifyMgr.notify((new Random()).nextInt(9999 - 1000) + 1000, mBuilder.build());
}
private Bitmap GetCircleBitmap(Bitmap bitmap) {
@@ -315,8 +423,6 @@ public class ChatActivity extends ActionBarActivity {
return output;
}
// TODO: die alten Nachrichten vom Server holen
private final class JsonSoapPrimitiveRequestListener implements RequestListener<SoapPrimitive> {
@Override
@@ -326,13 +432,24 @@ public class ChatActivity extends ActionBarActivity {
@Override
public void onRequestSuccess(SoapPrimitive soapPrimitive) {
Gson gson = new GsonBuilder().create();
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(ChatMessage.class, new ChatMessageDeserializer());
Gson gson = builder.create();
Type listType = new TypeToken<ArrayList<ChatMessage>>(){}.getType();
ArrayList<ChatMessage> result = gson.fromJson(soapPrimitive.toString(), listType);
final ArrayList<ChatMessage> result = gson.fromJson(soapPrimitive.toString(), listType);
// Duplikate vermeiden
databaseHandler.addChatMessages(result);
listView.post(new Runnable() {
@Override
public void run() {
chatMessages.addAll(result);
adapter.notifyDataSetChanged();
}
});
}
}
}

View File

@@ -9,34 +9,30 @@ public class ContactListItem {
private byte[] mPicture;
private int mPersonOid;
public boolean isTeam;
public boolean isOnline;
public String teamMemberOids;
public String teamMemberNames;
public ContactListItem(){}
public ContactListItem(int id, String kontaktname, int personOid, byte[] picture){
public ContactListItem(int id, String kontaktname, int personOid, byte[] picture, boolean isTeam, String teamMemberOids, String teamMemberNames){
this.mId = id;
this.mChatName = kontaktname;
this.mPersonOid = personOid;
this.mPicture = picture;
this.isTeam = isTeam;
this.teamMemberNames = teamMemberNames;
this.teamMemberOids = teamMemberOids;
}
public ContactListItem(String kontaktname, int personOid, byte[] picture){
this.mChatName = kontaktname;
this.mPersonOid = personOid;
this.mPicture = picture;
}
public ContactListItem(String kontaktname, int personOid){
this.mChatName = kontaktname;
this.mPersonOid = personOid;
this.mPicture = null;
}
public ContactListItem(int id, String kontaktname, int personOid){
this.mId = id;
public ContactListItem(String kontaktname, int personOid, boolean isTeam, String teamMemberOids, String teamMemberNames){
this.mChatName = kontaktname;
this.mPersonOid = personOid;
this.mPicture = null;
this.isTeam = isTeam;
this.teamMemberNames = teamMemberNames;
this.teamMemberOids = teamMemberOids;
}
public int getId(){

View File

@@ -1,300 +0,0 @@
package beyondsoft.bewomitarbeiterapp;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import entities.ChatMessage;
import soapConnection.SoapConnectionManager;
/**
* Created by bib on 07.06.2016.
*/
public class DatabaseHandler extends SQLiteOpenHelper {
//DataBase version
private static final int DATABASE_VERSION = 1;
//Database name
private static final String DATABASE_NAME = "Contacts_Manager";
//Table Name
private static final String TABLE_CONTACTS = "Contactlist";
private static final String TABLE_CHATMESSAGE = "ChatMessage";
//Table Columns name
// Contacts-Tabelle
private static final String KEY_ID ="id";
private static final String KEY_KontaktName = "kontaktname";
private static final String KEY_PERSONOID = "personoid";
private static final String KEY_Picture_BLOB = "bild";
// ChatMessage-Tabelle
private static final String KEY_ID_CHATMESSAGE = "id";
private static final String KEY_SENDER_PERSON_OID_CHATMESSAGE = "senderpersonoid";
private static final String KEY_RECIPIENT_PERSON_OID_CHATMESSAGE = "recipientpersonoid";
private static final String KEY_INSTS_CHATMESSAGE = "insts";
private static final String KEY_CHAT_TEXT_CHATMESSAGE = "chattext";
private static final String KEY_IS_DELIVERED_CHATMESSAGE = "isdelivered";
private static final String KEY_SERVERSEITIGE_OID_CHATMESSAGE = "serverseitigeoid";
public DatabaseHandler(Context context){
super(context,DATABASE_NAME, null, DATABASE_VERSION);
}
// Erstelle Tabelle | Tabellen construct
public void onCreate(SQLiteDatabase db){
String CREATE_CONTACTS_TABLE ="CREATE TABLE "+TABLE_CONTACTS +"("+
KEY_ID +" INTEGER PRIMARY KEY,"+KEY_KontaktName+ " TEXT,"+
KEY_PERSONOID +" INTEGER," + KEY_Picture_BLOB+ " BLOB)";
db.execSQL(CREATE_CONTACTS_TABLE);
String createChatMessageTable =
"CREATE TABLE " + TABLE_CHATMESSAGE + "(" +
KEY_ID_CHATMESSAGE + " INTEGER PRIMARY KEY," +
KEY_SENDER_PERSON_OID_CHATMESSAGE + " INTEGER," +
KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + " INTEGER," +
KEY_INSTS_CHATMESSAGE + " DATETIME DEFAULT CURRENT_TIMESTAMP," +
KEY_CHAT_TEXT_CHATMESSAGE + " TEXT," +
KEY_IS_DELIVERED_CHATMESSAGE + " INTEGER," +
KEY_SERVERSEITIGE_OID_CHATMESSAGE + " INTEGER DEFAULT NULL)";
db.execSQL(createChatMessageTable);
}
long addChatMessage(ChatMessage message) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_SENDER_PERSON_OID_CHATMESSAGE, message.SenderPersonOid);
values.put(KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, message.RecipientPersonOid);
values.put(KEY_INSTS_CHATMESSAGE, getDateTimeString(message.InsTs));
values.put(KEY_CHAT_TEXT_CHATMESSAGE, message.ChatText);
values.put(KEY_IS_DELIVERED_CHATMESSAGE, (message.IsDelivered ? 1 : 0));
values.put(KEY_SERVERSEITIGE_OID_CHATMESSAGE, message.ServerseitigeOid);
long rowId = db.insert(TABLE_CHATMESSAGE, null, values);
db.close();
return rowId;
}
void updateChatMessage(ChatMessage message) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_SENDER_PERSON_OID_CHATMESSAGE, message.SenderPersonOid);
values.put(KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, message.RecipientPersonOid);
values.put(KEY_INSTS_CHATMESSAGE, getDateTimeString(message.InsTs));
values.put(KEY_CHAT_TEXT_CHATMESSAGE, message.ChatText);
values.put(KEY_IS_DELIVERED_CHATMESSAGE, (message.IsDelivered ? 1 : 0));
values.put(KEY_SERVERSEITIGE_OID_CHATMESSAGE, message.ServerseitigeOid);
db.update(TABLE_CHATMESSAGE, values, KEY_ID_CHATMESSAGE + " = ?", new String[] { String.valueOf(message.Id)});
}
ArrayList<Integer> getExistingChatMessageIds() {
ArrayList<Integer> result = new ArrayList<Integer>();
SQLiteDatabase db = this.getWritableDatabase();
String selectQuery = "SELECT "+ KEY_SERVERSEITIGE_OID_CHATMESSAGE + " FROM " + TABLE_CHATMESSAGE + " WHERE " + KEY_SERVERSEITIGE_OID_CHATMESSAGE + " <> 0";
Cursor cursor = db.rawQuery(selectQuery, null);
if(cursor.moveToFirst()) {
do {
result.add(cursor.getInt(0));
} while(cursor.moveToNext());
}
return result;
}
private String getDateTimeString(Date date) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);
return dateFormat.format(date);
}
private Date getDateFromString(String dateString) {
Date result = new Date();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);
try {
result = df.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
return result;
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
//drop older Table if existed
db.execSQL("DROP TABLE IF EXISTS "+ TABLE_CONTACTS);
db.execSQL("DROP TABLE IF EXISTS "+ TABLE_CHATMESSAGE);
onCreate(db);
}
//Add Neuen Contact
void addContact(ContactListItem contact) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
//Values übergabe
values.put(KEY_KontaktName,contact.getChatName());
values.put(KEY_PERSONOID,contact.getPersonOid());
values.put(KEY_Picture_BLOB,contact.getPicture());
db.insert(TABLE_CONTACTS,null,values);
db.close();
}
public ChatMessage getChatMessageById(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(
TABLE_CHATMESSAGE,
new String[] {KEY_ID_CHATMESSAGE, KEY_SENDER_PERSON_OID_CHATMESSAGE, KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, KEY_INSTS_CHATMESSAGE, KEY_CHAT_TEXT_CHATMESSAGE, KEY_IS_DELIVERED_CHATMESSAGE, KEY_SERVERSEITIGE_OID_CHATMESSAGE},
KEY_ID_CHATMESSAGE + "=?",
new String[]{String.valueOf(id)},
null, null, null, null);
if(cursor != null) {
cursor.moveToFirst();
}
ChatMessage message = new ChatMessage(cursor.getInt(0), cursor.getInt(1), cursor.getInt(2), getDateFromString(cursor.getString(3)), cursor.getString(4), cursor.getInt(5) != 0, cursor.getInt(6));
return message;
}
public ArrayList<ChatMessage> getMessagesForRecipient(int recipientOid) {
ArrayList<ChatMessage> messages = new ArrayList<>();
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.query(
TABLE_CHATMESSAGE,
new String[] {KEY_ID_CHATMESSAGE, KEY_SENDER_PERSON_OID_CHATMESSAGE, KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, KEY_INSTS_CHATMESSAGE, KEY_CHAT_TEXT_CHATMESSAGE, KEY_IS_DELIVERED_CHATMESSAGE, KEY_SERVERSEITIGE_OID_CHATMESSAGE},
KEY_SENDER_PERSON_OID_CHATMESSAGE + "=? AND " + KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + "=? OR " + KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + "=? AND " + KEY_SENDER_PERSON_OID_CHATMESSAGE + "=?",
new String[] {String.valueOf(SoapConnectionManager.User.getPersonOid()), String.valueOf(recipientOid), String.valueOf(SoapConnectionManager.User.getPersonOid()), String.valueOf(recipientOid)},
null, null, null, null);
if(cursor.moveToFirst()) {
do{
ChatMessage message = new ChatMessage(
cursor.getInt(0),
cursor.getInt(1),
cursor.getInt(2),
getDateFromString(cursor.getString(3)),
cursor.getString(4),
cursor.getInt(5) != 0,
cursor.getInt(6)
);
messages.add(message);
} while(cursor.moveToNext());
}
return messages;
}
// Lade einen bestimmten Kontakt
ContactListItem getContact(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS, new String[]{KEY_ID,KEY_KontaktName,
KEY_PERSONOID,KEY_Picture_BLOB},KEY_ID +"=?",new String[]{String.valueOf(id)}
,null,null,null,null);
if(cursor !=null) {
cursor.moveToFirst();
}
ContactListItem clist = new ContactListItem(Integer.parseInt(cursor.getString(0)),cursor.getString(1), Integer.parseInt(cursor.getString(2)),cursor.getBlob(3));
return clist;
}
//Holle alle Contacts
public List<ContactListItem> getAllContacts(){
List<ContactListItem> contactList = new ArrayList<ContactListItem>();
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
ContactListItem contact = new ContactListItem();
contact.setId(cursor.getInt(0));
contact.setChatName(cursor.getString(1));
contact.setPersonOid(cursor.getInt(2));
contact.setPicture(cursor.getBlob(3));
// Adding contact to list
contactList.add(contact);
} while (cursor.moveToNext());
}
return contactList;
}
//updating single Contact
public int updateContact(ContactListItem contact) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_KontaktName, contact.getChatName());
values.put(KEY_PERSONOID, contact.getPersonOid());
values.put(KEY_Picture_BLOB, contact.getPicture());
// updating row
return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?",
new String[] { String.valueOf(contact.getId()) });
}
//Delet single Contact
public void deleteContacts(ContactListItem contact){
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_CONTACTS, KEY_ID + " = ?", new String[] { String.valueOf(contact.getId()) });
db.close();
}
public int getContactsCount(){
String countQuery = "SELECT * FROM " + TABLE_CONTACTS;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
// return count
return cursor.getCount();
}
public byte[] getUserImage(Integer personOid) {
SQLiteDatabase database = this.getReadableDatabase();
Cursor cursor = database.query(TABLE_CONTACTS, new String[] {KEY_PERSONOID}, " = " + personOid, null, null, null, null);
cursor.close();
return cursor.getBlob(0);
}
}

View File

@@ -11,7 +11,6 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -19,10 +18,6 @@ import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
/**
@@ -63,53 +58,24 @@ public class KontaktAdapter extends ArrayAdapter<ContactListItem> {
textView.setText(values.get(position).getChatName());
if(values.get(position).isTeam) {
minitext.setText(values.get(position).teamMemberNames);
}
// if(values[position].getChatName().equals("Demo")) {
// getM = new Thread(new ReadLastMessage(values[position].getChatName(), inflater));
// getM.start();
// } else {
// minitext.setText("Hier könnte auch ihre Nachricht stehen");
// }
//ab hier fehlerhaft
if(values.get(position).getPicture() != null) {
byte[] imageAsByteArray = values.get(position).getPicture();
//Konvert byte[] to Image
Bitmap i = BitmapFactory.decodeByteArray(values.get(position).getPicture(),0,values.get(position).getPicture().length);
Bitmap i = BitmapFactory.decodeByteArray(imageAsByteArray, 0, imageAsByteArray.length);
getPic = new Thread(new CircleBitmapCreator(i));
getPic.start();
// t.interrupt();
// imageView.setImageBitmap(CircleBitmapCreator(i));
} else {
//wenn der kontakt kein bild besitzt dann nimm Default bild
//Bitmap customerImage =((BitmapDrawable).getDrawable(R.drawable.katze3)).getBitmap();
Bitmap bitmap = decodeSampledBitmapFromResource(inflater.getContext().getResources(), R.drawable.katze3, 100, 100);//BitmapFactory.decodeResource(inflater.getContext().getResources(), R.drawable.katze3);
// imageView.setImageResource(CircleBitmapCreator(bitmap));
getPic = new Thread(new CircleBitmapCreator(bitmap));
getPic.start();
// imageView.setImageBitmap(CircleBitmapCreator(bitmap));
}
//if statement ob kontakt online oder net
// if(values[position].getArt().equals("1"))
// onlinestats.setImageResource(R.drawable.online);
// else if(values[position].getArt().equals("2"))
// onlinestats.setImageResource(R.drawable.beschaftigt);
// else if(values[position].getArt().equals("3"))
// onlinestats.setImageResource(R.drawable.offline);
onlinestats.setImageResource((values.get(position).isOnline ? R.drawable.online : R.drawable.offline));
return rowView;
@@ -180,144 +146,4 @@ public class KontaktAdapter extends ArrayAdapter<ContactListItem> {
return inSampleSize;
}
/* private Bitmap CircleBitmapCreator(Bitmap bitmap ) {
final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(output);
final int color = Color.RED;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawOval(rectF, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
bitmap.recycle();
return output;
}*/
public class ReadLastMessage implements Runnable{
LayoutInflater inflater;
String filename;
ReadLastMessage(String _filename,LayoutInflater _inflater){
this.inflater = _inflater;
this.filename = _filename;
}
public void run(){
try{
File filesDir = inflater.getContext().getFilesDir();
File file = new File(filesDir, "demo" +".txt"); //---->filename
FileInputStream stream = new FileInputStream(file);
InputStreamReader in = new InputStreamReader(stream);
BufferedReader readLn = new BufferedReader(in);
String line = readLn.readLine();
String allLines="";
String [] ret= new String[2];
while (line != null) {
allLines += line;
String[] splitt = line.split("/");
if(splitt.length >1 ) {
String[] ArtDate = splitt[1].split("%");
final String message = splitt[0];
final boolean art = Boolean.valueOf(ArtDate[0]);
final String datetime = ArtDate[1];
if(!art) {
ret[0] = message;
ret[1] = datetime;
}
}
line = readLn.readLine();
}
stream.close();
in.close();
// filedaten =ret;
if(minitext != null) {
minitext.setText(ret[0]);
}
}catch(Exception e){
Log.v("Fehler 2 ",e.getMessage());
e.printStackTrace();
// return null;
}
}
}
public String[] ReadLastMessage(String filename, LayoutInflater inflater){
try{
File filesDir = inflater.getContext().getFilesDir();
File file = new File(filesDir, "demo" +".txt"); //---->filename
FileInputStream stream = new FileInputStream(file);
InputStreamReader in = new InputStreamReader(stream);
BufferedReader readLn = new BufferedReader(in);
String line = readLn.readLine();
String allLines="";
String [] ret= new String[2];
while (line != null) {
allLines += line;
String[] splitt = line.split("/");
if(splitt.length >1 ) {
String[] ArtDate = splitt[1].split("%");
final String message = splitt[0];
final boolean art = Boolean.valueOf(ArtDate[0]);
final String datetime = ArtDate[1];
if(!art) {
ret[0] = message;
ret[1] = datetime;
}
}
line = readLn.readLine();
}
stream.close();
in.close();
return ret;
}catch(Exception e){
Log.v("Fehler 2 ",e.getMessage());
e.printStackTrace();
return null;
}
}
}

View File

@@ -34,9 +34,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import Database.DatabaseHandler;
import entities.ChatMessage;
import entities.ChatPerson;
import soapConnection.DataIdentifier;
import soapConnection.JsonSoapPrimitiveRequest;
import soapConnection.Packet;
import soapConnection.SoapCalls;
@@ -52,8 +52,6 @@ public class KontaktChatActivity extends ListActivity {
private SpiceManager spiceManager = new SpiceManager(UncachedSpiceService.class);
private DatabaseHandler databaseHandler;
private static ArrayList<Integer> onlinePersonOids = new ArrayList<>();
private UIHandler kontaktChatUIHandler;
public static ListView listView;
@@ -64,13 +62,9 @@ public class KontaktChatActivity extends ListActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
databaseHandler = new DatabaseHandler(this);
databaseHandler = DatabaseHandler.getInstance(this);
//TODO: nicht löschen, sondern updaten...
//databaseHandler.onUpgrade(databaseHandler.getReadableDatabase(), 1, 2);
Bundle bundle = getIntent().getExtras();
onlinePersonOids = bundle.getIntegerArrayList("OnlineContacts");
listView = getListView();
ArrayList<PropertyInfo> propertyInfos = new ArrayList<>();
propertyInfos.add(SoapConnectionManager.BuildProperty("pPersonOid", SoapConnectionManager.User.getPersonOid(), Long.class));
@@ -78,23 +72,30 @@ public class KontaktChatActivity extends ListActivity {
JsonSoapPrimitiveRequest request = new JsonSoapPrimitiveRequest(SoapCalls.GET_CONTACTS_FOR_PERSON, propertyInfos);
spiceManager.execute(request, new JsonSoapPrimitiveRequestListener());
listView = getListView();
kontaktChatUIHandler = new UIHandler() {
@Override
public void updateUserInterface(final Packet chatPacket) {
try {
switch(chatPacket.ChatDataIdentifier) {
case MESSAGE:
ChatMessage message = new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, false, chatPacket.ServerseitigeOid);
ChatMessage message = new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, false, chatPacket.ServerseitigeOid, false);
databaseHandler.addChatMessage(message);
SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.SenderPersonOid);
break;
case TEAM:
ChatMessage teamMessage = new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, false, chatPacket.ServerseitigeOid, true);
databaseHandler.addChatMessage(teamMessage);
SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.SenderPersonOid);
break;
case STATUS_NOTIFICATION_LOGIN:
if(!onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
onlinePersonOids.add(chatPacket.SenderPersonOid);
Log.i("KONTAKTLISTE", "Login registriert: (" + chatPacket.SenderPersonOid + ") " + chatPacket.ChatName);
if(!SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
SocketManager.onlinePersonOids.add(chatPacket.SenderPersonOid);
runOnUiThread(new Runnable() {
@Override
@@ -114,8 +115,8 @@ public class KontaktChatActivity extends ListActivity {
}
break;
case STATUS_NOTIFICATION_LOGOUT:
if(onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
onlinePersonOids.remove(Integer.valueOf(chatPacket.SenderPersonOid));
if(SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
SocketManager.onlinePersonOids.remove(Integer.valueOf(chatPacket.SenderPersonOid));
runOnUiThread(new Runnable() {
@Override
@@ -174,6 +175,9 @@ public class KontaktChatActivity extends ListActivity {
bundle.putString("Name", selectedValue.getChatName());
bundle.putInt("RecipientOid", selectedValue.getPersonOid());
bundle.putBoolean("IsTeam", selectedValue.isTeam);
bundle.putString("TeamMemberOids", selectedValue.teamMemberOids);
bundle.putString("TeamMemberNames", selectedValue.teamMemberNames);
Intent in = new Intent(getBaseContext(), ChatActivity.class);
in.putExtras(bundle);
@@ -196,8 +200,15 @@ public class KontaktChatActivity extends ListActivity {
public void onResume() {
SocketManager.uiHandler = kontaktChatUIHandler;
// Update der Kontaktliste
KontaktAdapter adapter = (KontaktAdapter) listView.getAdapter();
if(adapter != null) {
for(ContactListItem item : adapter.values) {
item.isOnline = SocketManager.onlinePersonOids.contains(item.getPersonOid());
}
adapter.notifyDataSetChanged();
}
super.onResume();
}
@@ -205,9 +216,16 @@ public class KontaktChatActivity extends ListActivity {
@Override
public void onStop(){
spiceManager.shouldStop();
databaseHandler.close();
super.onStop();
}
@Override
public void onPause() {
super.onPause();
}
@Override
protected void onStart() {
super.onStart();
@@ -223,7 +241,6 @@ public class KontaktChatActivity extends ListActivity {
@Override
public void onRequestSuccess(SoapPrimitive soapPrimitive) {
if(soapPrimitive == null) {
Log.i("KONTAKT_CHAT_ACTIVITY", "soapPrimitive ist NULL!");
}
@@ -244,20 +261,29 @@ public class KontaktChatActivity extends ListActivity {
for(ChatPerson cp : result) {
if(!oidList.contains(cp.Oid)) {
databaseHandler.addContact(new ContactListItem(cp.Name, cp.Oid));
databaseHandler.addContact(new ContactListItem(cp.Name, cp.Oid, cp.IsTeam, cp.TeamMemberOids, cp.TeamMemberNames));
}
}
lc = databaseHandler.getAllContacts();
for(ContactListItem item : lc) {
if(onlinePersonOids.contains(item.getPersonOid())){
if(SocketManager.onlinePersonOids.contains(item.getPersonOid())){
item.isOnline = true;
}
}
contactList = new ArrayList<>(lc);
setListAdapter(new KontaktAdapter(KontaktChatActivity.this, contactList));
databaseHandler.close();
KontaktAdapter adapter = (KontaktAdapter) listView.getAdapter();
if(adapter == null) {
adapter = new KontaktAdapter(KontaktChatActivity.this, contactList);
}
setListAdapter(adapter);
((KontaktAdapter) listView.getAdapter()).notifyDataSetChanged();
}
}

View File

@@ -3,9 +3,10 @@ package beyondsoft.bewomitarbeiterapp;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
@@ -37,8 +38,6 @@ import org.ksoap2.serialization.SoapPrimitive;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
@@ -47,6 +46,7 @@ import java.util.ArrayList;
import javax.crypto.NoSuchPaddingException;
import Database.DatabaseHandler;
import soapConnection.ApplicationUser;
import soapConnection.JsonSoapPrimitiveRequest;
import soapConnection.SoapCalls;
@@ -75,23 +75,6 @@ public class LoginActivity extends ActionBarActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
try {
FileOutputStream fos = openFileOutput(Util.DEVICE_ID_FILE_NAME, Context.MODE_PRIVATE);
FileInputStream fis = openFileInput(Util.DEVICE_ID_FILE_NAME);
byte[] blah = new byte[fis.available()];
int bytesRead = fis.read(blah, 0, fis.available());
String test = new String(blah, "UTF-8");
Log.i("TEST", test);
} catch (IOException e) {
e.printStackTrace();
}
mChatCodeView = (EditText) findViewById(R.id.token);
mTenantView = (EditText) findViewById(R.id.tenant);
mUsernameView = (EditText) findViewById(R.id.username);
@@ -265,13 +248,11 @@ public class LoginActivity extends ActionBarActivity {
@Override
public void onRequestSuccess(SoapPrimitive soapPrimitive) {
//TODO: UserDC statt bool zurückgeben. Null bei fehlgeschlagenem Login
if(soapPrimitive == null) {
showProgress(false);
showLoginUIErrors(true, true, true, true);
Toast.makeText(LoginActivity.this, "Login returned null", Toast.LENGTH_SHORT).show();
Toast.makeText(LoginActivity.this, "Login nicht möglich", Toast.LENGTH_SHORT).show();
return;
}
@@ -282,6 +263,16 @@ public class LoginActivity extends ActionBarActivity {
String[] blubb = abc.split(";");
SoapConnectionManager.User = new ApplicationUser(blubb[1], blubb[2], Long.valueOf(blubb[0]), Long.valueOf(blubb[3]));
DatabaseHandler databaseHandler = DatabaseHandler.getInstance(getApplicationContext());
int owner = databaseHandler.getOwnerOid();
if(owner == 0) {
databaseHandler.insertOwnerOid(SoapConnectionManager.User.getPersonOid().intValue());
} else if(owner != SoapConnectionManager.User.getPersonOid().intValue()) {
databaseHandler.clearDatabase();
databaseHandler.insertOwnerOid(SoapConnectionManager.User.getPersonOid().intValue());
}
if(mRememberMeCheckBoxView.isChecked()) {
ByteArrayOutputStream tokenOutputStream = new ByteArrayOutputStream();
ByteArrayOutputStream tenantOutputStream = new ByteArrayOutputStream();
@@ -311,9 +302,6 @@ public class LoginActivity extends ActionBarActivity {
SocketManager.tenant = mTenantView.getText().toString();
SocketManager.connectToServer();
SocketManager.LoginOnServer();
Intent mainActivityMitarbeiter = new Intent(LoginActivity.this, MainActivityMitarbeiter.class);
LoginActivity.this.startActivity(mainActivityMitarbeiter);
}

View File

@@ -8,16 +8,14 @@ import android.content.Intent;
import android.graphics.Color;
import android.support.v4.app.NotificationCompat;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import java.util.ArrayList;
import java.util.Random;
import soapConnection.DataIdentifier;
import soapConnection.Packet;
import soapConnection.SoapConnectionManager;
@@ -37,37 +35,48 @@ public class MainActivityMitarbeiter extends Activity {
int loggedInUserPersonOid;
private ArrayList<Integer> onlinePersonOids;
@Override
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity_mitarbeiter);
SocketManager.connectToServer();
SocketManager.loginOnServer();
setzeButtonListener();
loggedInUserName = SoapConnectionManager.User.getFullName();
loggedInUserPersonOid = SoapConnectionManager.User.getPersonOid() <= Integer.MAX_VALUE ? SoapConnectionManager.User.getPersonOid().intValue() : 0;
onlinePersonOids = new ArrayList<>();
mainUIHandler = new UIHandler() {
@Override
public void updateUserInterface(Packet chatPacket) {
if(chatPacket.ChatDataIdentifier.equals(DataIdentifier.MESSAGE)) {
Log.i("MAIN_ACTIVIY_LISTENER", "Empfange Nachricht... <<" + chatPacket.ChatMessage + ">>");
chatPacket.writeToLog();
SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.SenderPersonOid);
} else if(chatPacket.ChatDataIdentifier.equals(DataIdentifier.STATUS_NOTIFICATION_LOGIN_BROADCAST)) {
switch(chatPacket.ChatDataIdentifier) {
case MESSAGE:
SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.SenderPersonOid);
String[] bitch = chatPacket.ChatMessage.split(",");
onlinePersonOids = new ArrayList<>();
break;
case STATUS_NOTIFICATION_LOGIN_BROADCAST:
String[] bitch = chatPacket.ChatMessage.split(",");
for (String aBitch : bitch) {
onlinePersonOids.add(Integer.parseInt(aBitch));
}
for (String aBitch : bitch) {
SocketManager.onlinePersonOids.add(Integer.parseInt(aBitch));
}
break;
case STATUS_NOTIFICATION_LOGIN:
if(!SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
SocketManager.onlinePersonOids.add(chatPacket.SenderPersonOid);
}
break;
case STATUS_NOTIFICATION_LOGOUT:
if(SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
SocketManager.onlinePersonOids.remove(Integer.valueOf(chatPacket.SenderPersonOid));
}
break;
}
}
};
@@ -110,20 +119,7 @@ public class MainActivityMitarbeiter extends Activity {
chatbutton = (Button) findViewById(R.id.Chatbutton);
chatbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// if(socket == null || !socket.isConnected()) {
// Toast.makeText(getApplicationContext(), "Der Chatserver ist zurzeit nicht erreichbar. \nBitte versuchen Sie es später erneut.", Toast.LENGTH_LONG).show();
//
// return;
// }
Bundle bundle = new Bundle();
bundle.putIntegerArrayList("OnlineContacts", onlinePersonOids);
Intent kontaktChatActivity = new Intent(getBaseContext(),KontaktChatActivity.class);
kontaktChatActivity.putExtras(bundle);
Intent kontaktChatActivity = new Intent(getBaseContext(), KontaktChatActivity.class);
startActivity(kontaktChatActivity);
}
@@ -132,20 +128,7 @@ public class MainActivityMitarbeiter extends Activity {
logoutbutton = (Button) findViewById(R.id.Logoutbutton);
logoutbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// if(socket != null && socket.isConnected()) {
// try {
// Packet p = new Packet();
//
// p.ChatDataIdentifier = DataIdentifier.LOGOUT;
//
// new Thread(new MessageSender(p.getDataStream())).start();
// } catch(Exception e) {
// Log.e("SendAfterGetConnection", "Fehler beim Logout: " + e.getMessage());
// }
// }
SocketManager.Logout();
SocketManager.logout();
finish();
System.exit(0);

View File

@@ -1,6 +1,7 @@
package beyondsoft.bewomitarbeiterapp;
import android.app.Activity;
import android.provider.ContactsContract;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
@@ -11,6 +12,7 @@ import android.widget.TextView;
import java.util.List;
import Database.DatabaseHandler;
import entities.ChatMessage;
import soapConnection.SoapConnectionManager;
@@ -37,20 +39,30 @@ public class MessageAdapter extends ArrayAdapter<ChatMessage> {
int layoutResource;
ChatMessage chatMessage = getItem(position);
if (chatMessage.SenderPersonOid == SoapConnectionManager.User.getPersonOid()) {
layoutResource = R.layout.item_chat_right;
}else {
layoutResource = R.layout.item_chat_left;
}
convertView = inflater.inflate(layoutResource, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
holder.msg.setText(chatMessage.ChatText);
if(chatMessage.IsTeam && chatMessage.SenderPersonOid != SoapConnectionManager.User.getPersonOid()) {
DatabaseHandler instance = DatabaseHandler.getInstance(this.getContext());
ContactListItem sender = instance.getContactByPersonOid(chatMessage.SenderPersonOid);
String name = sender != null ? sender.getChatName() : "";
holder.teamMemberName.setText(name);
holder.teamMemberName.setVisibility(View.VISIBLE);
}
if(chatMessage.SenderPersonOid == SoapConnectionManager.User.getPersonOid()){
holder.dateIn.setText(chatMessage.getInsTsAsString());
} else {
@@ -77,15 +89,15 @@ public class MessageAdapter extends ArrayAdapter<ChatMessage> {
private TextView msg;
private TextView dateOut;
private TextView dateIn;
private TextView send_tick;
private TextView teamMemberName;
//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);
msg = (TextView) v.findViewById(R.id.txt_msg);
dateOut = (TextView)v.findViewById(R.id.DateOUT);
dateIn = (TextView)v.findViewById(R.id.DateIN);
teamMemberName = (TextView) v.findViewById(R.id.teamMember);
//send_tick = (TextView)v.findViewById(R.id.txt_msg_tick);
}
}
}

View File

@@ -15,8 +15,9 @@ public class ChatMessage {
public String ChatText;
public boolean IsDelivered;
public int ServerseitigeOid;
public boolean IsTeam;
public ChatMessage(int id, int senderPersonOid, int recipientPersonOid, Date insTs, String chatText, boolean isDelivered, int serverseitigeOid) {
public ChatMessage(int id, int senderPersonOid, int recipientPersonOid, Date insTs, String chatText, boolean isDelivered, int serverseitigeOid, boolean isTeam) {
Id = id;
SenderPersonOid = senderPersonOid;
RecipientPersonOid = recipientPersonOid;
@@ -24,19 +25,37 @@ public class ChatMessage {
ChatText = chatText;
IsDelivered = isDelivered;
ServerseitigeOid = serverseitigeOid;
IsTeam = isTeam;
}
public ChatMessage(int senderPersonOid, int recipientPersonOid, Date insTs, String chatText, boolean isDelivered, int serverseitigeOid) {
public ChatMessage(int senderPersonOid, int recipientPersonOid, Date insTs, String chatText, boolean isDelivered, int serverseitigeOid, boolean isTeam) {
SenderPersonOid = senderPersonOid;
RecipientPersonOid = recipientPersonOid;
InsTs = insTs;
ChatText = chatText;
IsDelivered = isDelivered;
ServerseitigeOid = serverseitigeOid;
IsTeam = isTeam;
}
public String getInsTsAsString() {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss", Locale.GERMAN);
return dateFormat.format(InsTs);
}
@Override
public String toString() {
String asString = "";
asString += "Id: " + Id;
asString += "\nSenderPersonOid: " + SenderPersonOid;
asString += "\nRecipientPersonOid: " + RecipientPersonOid;
asString += "\nInsTs: " + getInsTsAsString();
asString += "\nChatText: " + ChatText;
asString += "\nIsDelivered: " + IsDelivered;
asString += "\nServerseitigeOid: " + ServerseitigeOid;
asString += "\nIsTeam: " + IsTeam;
return asString;
}
}

View File

@@ -6,4 +6,7 @@ package entities;
public class ChatPerson {
public int Oid;
public String Name;
public boolean IsTeam;
public String TeamMemberNames;
public String TeamMemberOids;
}

View File

@@ -14,7 +14,10 @@ public enum DataIdentifier {
DELIVERING_STATUS_CHANGE(7),
STATUS_NOTIFICATION_LOGIN_BROADCAST(8),
TEAM(9),
MESSAGE_RESPONSE(10);
MESSAGE_RESPONSE(10),
STATUS_NOTIFICATION_BESCHAEFTIGT(11),
STATUS_NOTIFICATION_ONLINE(12),
STATUS_NOTIFICATION_OFFLINE(13);
private final int value;
DataIdentifier(int value) {

View File

@@ -25,6 +25,7 @@ public class Packet {
public boolean IsDelivered;
public int ServerseitigeOid;
public int ClientseitigeOid;
public boolean IsTeam;
public Packet() {
ChatDataIdentifier = DataIdentifier.NULL;
@@ -34,7 +35,6 @@ public class Packet {
SenderPersonOid = SoapConnectionManager.User.getPersonOid().intValue();
RecipientPersonOid = 0;
IsDelivered = false;
MessageTimeStamp = Calendar.getInstance().getTime();
}

View File

@@ -6,6 +6,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
@@ -27,6 +28,8 @@ public class SocketManager {
public static UIHandler uiHandler;
public static DataOutputStream dataOutputStream;
public static ArrayList<Integer> onlinePersonOids = new ArrayList<>();
public static void connectToServer(){
new Thread(new OpenConnection()).start();
}
@@ -40,7 +43,7 @@ public class SocketManager {
try {
socket = new Socket(SoapCalls.DESTINATION_ADDRESS, SoapCalls.DESTINATION_PORT);
LoginOnServer();
loginOnServer();
dataOutputStream = new DataOutputStream(socket.getOutputStream());
@@ -76,7 +79,7 @@ public class SocketManager {
}
}
public static void Logout() {
public static void logout() {
if(socket != null && socket.isConnected()) {
try {
Packet packet = new Packet();
@@ -91,7 +94,7 @@ public class SocketManager {
}
}
public static void LoginOnServer() {
public static void loginOnServer() {
if(socket != null && socket.isConnected()) {
try {
Packet packet = new Packet();
@@ -100,7 +103,6 @@ public class SocketManager {
packet.ChatDataIdentifier = DataIdentifier.LOGIN;
new Thread(new MessageSender(packet.getDataStream())).start();
} catch(Exception exception) {
exception.printStackTrace();
}
@@ -174,25 +176,11 @@ public class SocketManager {
continue;
}
StringBuilder total = new StringBuilder(stream.available());
int counter = 0;
byte[] message = new byte[size];
stream.read(message, 0, size);
// while(counter < size) {
//
// char c = (char) stream.read();
//
// total.append(c);
//
// counter++;
// }
try {
//chatPacket = new Packet(total.toString());
chatPacket = new Packet(new String(message, "UTF-8"));
Log.i(TAG, "Empfange Nachricht... " + chatPacket.ChatMessage);

View File

@@ -0,0 +1,57 @@
package util;
import android.util.Log;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import entities.ChatMessage;
/**
* Created by JettenM on 09.08.2016.
*/
public class ChatMessageDeserializer implements JsonDeserializer<ChatMessage> {
@Override
public ChatMessage deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
JsonObject json = (JsonObject) jsonElement;
int senderPersonOid = Long.valueOf(json.get("SenderPersonOid").getAsLong()).intValue();
int recipientPersonOid = Long.valueOf(json.get("EmpfängerPersonOid").getAsLong()).intValue();
int serverseitigeOid = Long.valueOf(json.get("Oid").getAsLong()).intValue();
String chatText = json.get("ChatText").getAsString();
boolean isDelivered = json.get("istZugestellt").getAsBoolean();
boolean isTeam = json.get("TeamOid") == null;
if(isTeam)
{
Log.i("MESSAGE_DESERIALIZATION", "" + Long.valueOf(json.get("TeamOid").getAsString()));
}
if(isTeam) {
recipientPersonOid = json.get("TeamOid").getAsInt();
}
Date insTs = Calendar.getInstance().getTime();
try {
insTs = simpleDateFormat.parse(json.get("InsTs").getAsString());
} catch (ParseException e) {
e.printStackTrace();
}
return new ChatMessage(senderPersonOid, recipientPersonOid, insTs, chatText, isDelivered, serverseitigeOid, isTeam);
}
}

View File

@@ -0,0 +1,32 @@
package util;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by JettenM on 08.08.2016.
*/
public class DateDeserializer implements JsonDeserializer<Date> {
@Override
public Date deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
SimpleDateFormat sdf = new SimpleDateFormat("\"yyyy-MM-dd'T'HH:mm:ss\"");
Date date = null;
try {
date = sdf.parse(jsonElement.getAsJsonPrimitive().toString());
return date;
} catch(ParseException e) {
e.printStackTrace();
}
return date;
}
}

View File

@@ -32,10 +32,6 @@
android:orientation="horizontal"
>
<!--Linear Layout: android:layout_height="0dp" //50
Edit Text : android:layout_height="match_parent" android:minHeight="75dp"
-->
<EditText
android:layout_width="275dp"
android:layout_height="wrap_content"
@@ -46,28 +42,6 @@
android:maxLength="1024"
/>
<!-- width -> 300dp heigh -> 60dp android:layout_marginBottom="30dp" android:layout_marginBottom="30dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
match parent
android:background="@drawable/roundedbutton"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_below="@+id/ChatText"
android:layout_toRightOf="@+id/editText"
Button height match parent
-->
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@@ -38,8 +38,7 @@
/>
<!-- Merke das design muss noch angepasst werden da der text über dem bild liegt /
vorläufig gelöst mit margin dies kann aber nicht die endgültige lösung sein -->
<!-- Merke: Das Design muss noch angepasst werden, da der Text über dem Bild liegt. /
Vorläufig gelöst mit margin. Dies kann aber nicht die endgültige Lösung sein. -->
</RelativeLayout>

View File

@@ -16,16 +16,24 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/DateOUT"
android:textSize="8dp"
android:textSize="10dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/teamMember"
android:textSize="12sp"
android:visibility="gone"
/>
<TextView
android:id="@+id/txt_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:paddingBottom="5dp"
android:maxWidth="250dp"
android:minWidth="80dp"
android:textColor="@android:color/black" />
</LinearLayout>

View File

@@ -16,7 +16,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/DateIN"
android:textSize="8dp"
android:textSize="10dp"
/>
<LinearLayout
@@ -30,17 +30,18 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxWidth="250dp"
android:padding="5dp"
android:minWidth="80dp"
android:paddingBottom="5dp"
android:textColor="@android:color/black"/>
<!-- 5 dp-->
<TextView
android:id="@+id/txt_msg_tick"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="end"
android:padding="5dp"
android:textColor="@android:color/holo_blue_light"/>
<!--<TextView-->
<!--android:id="@+id/txt_msg_tick"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="match_parent"-->
<!--android:gravity="end"-->
<!--android:padding="5dp"-->
<!--android:textColor="@android:color/holo_blue_light"/>-->
</LinearLayout>

View File

@@ -6,8 +6,6 @@
<item
android:id="@+id/action_delet_Storage"
android:title="@string/Clear"
android:orderInCategory="100"
/>
android:orderInCategory="100" />
</menu>