ChatServer: Oid der ChatMessages dem Packet hinzugefügt
This commit is contained in:
@@ -64,14 +64,6 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
||||
@@ -80,6 +72,14 @@
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
|
||||
|
||||
@@ -32,6 +32,16 @@ import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.octo.android.robospice.SpiceManager;
|
||||
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.SoapPrimitive;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -41,6 +51,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.Socket;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
@@ -83,7 +94,6 @@ public class ChatActivity extends ActionBarActivity{
|
||||
|
||||
//Design View
|
||||
protected ListView listView;
|
||||
protected boolean isMe = true;
|
||||
public static List<ChatMessage> chatMessages;
|
||||
public static ArrayAdapter<ChatMessage> adapter;
|
||||
public static ChatMessageFormat chatMessage;
|
||||
@@ -94,6 +104,8 @@ public class ChatActivity extends ActionBarActivity{
|
||||
protected String recipientName;
|
||||
protected int recipientPersonOid;
|
||||
|
||||
private SpiceManager spiceManager = new SpiceManager(UncachedSpiceService.class);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -107,7 +119,6 @@ public class ChatActivity extends ActionBarActivity{
|
||||
LayoutInflater inflate = LayoutInflater.from(this);
|
||||
View mCustomView = inflate.inflate(R.layout.custom_menuebar, null);
|
||||
|
||||
|
||||
// Initialiesiere die Variablen
|
||||
TextView titlename = (TextView)mCustomView.findViewById(R.id.PersonalName);
|
||||
ImageView titlepic = (ImageView)mCustomView.findViewById(R.id.PersonalPic);
|
||||
@@ -139,7 +150,6 @@ public class ChatActivity extends ActionBarActivity{
|
||||
|
||||
listView = (ListView)findViewById(R.id.list_msg);
|
||||
|
||||
DatabaseHandler handler = new DatabaseHandler(this);
|
||||
chatMessages = databaseHandler.getMessagesForRecipient(recipientPersonOid);
|
||||
|
||||
adapter = new MessageAdapter(this, R.layout.item_chat_left, chatMessages);
|
||||
@@ -171,23 +181,22 @@ public class ChatActivity extends ActionBarActivity{
|
||||
}
|
||||
});
|
||||
|
||||
Thread t1 = new Thread(new RequestSender());
|
||||
t1.start();
|
||||
|
||||
Thread t = new Thread(new SocketListener());
|
||||
t.start();
|
||||
|
||||
SharedPreferences sp = getSharedPreferences(Util.PREFS_NAME, 0);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.putBoolean("IsInChatActivity", true);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public class MessageSender implements Runnable{
|
||||
public void run(){
|
||||
try{
|
||||
if(socket != null ) {
|
||||
public class RequestSender implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if(socket != null ) {
|
||||
Packet p = new Packet();
|
||||
p.ChatMessage = text.getText().toString();
|
||||
p.ChatDataIdentifier = DataIdentifier.MESSAGE;
|
||||
//p.ChatMessage = text.getText().toString(); // Hier Datum von bis?
|
||||
p.ChatDataIdentifier = DataIdentifier.OLD_MESSAGE;
|
||||
p.RecipientPersonOid = recipientPersonOid;
|
||||
|
||||
SharedPreferences settings = getSharedPreferences(Util.PREFS_NAME, 0);
|
||||
@@ -200,37 +209,59 @@ public class ChatActivity extends ActionBarActivity{
|
||||
socketOutputStream.write(p.GetDataStream());
|
||||
socketOutputStream.flush();
|
||||
}
|
||||
} catch(IOException s){
|
||||
Log.v("Status: ","Senden einer Anfrage, alle vergangenen Nachrichten zu laden konnte nicht ausgeführt werden.");
|
||||
|
||||
s.printStackTrace();
|
||||
} catch (NoSuchPaddingException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MessageSender implements Runnable{
|
||||
public void run(){
|
||||
try{
|
||||
if(socket != null ) {
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
final Date now = c.getTime();
|
||||
|
||||
final Packet p = new Packet();
|
||||
p.ChatMessage = text.getText().toString();
|
||||
p.ChatDataIdentifier = DataIdentifier.MESSAGE;
|
||||
p.RecipientPersonOid = recipientPersonOid;
|
||||
p.MessageTimeStamp = now;
|
||||
|
||||
SharedPreferences settings = getSharedPreferences(Util.PREFS_NAME, 0);
|
||||
|
||||
byte[] tenantByteArray = Base64.decode(settings.getString(Util.PREFS_TENANT_KEY, null), Base64.DEFAULT);
|
||||
ByteArrayInputStream tenantStream = new ByteArrayInputStream(tenantByteArray);
|
||||
|
||||
p.Tenant = SecurityUtils.decrypt(tenantStream).toString();
|
||||
|
||||
socketOutputStream.write(p.GetDataStream());
|
||||
socketOutputStream.flush();
|
||||
|
||||
listView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatMessage message = new ChatMessage(SoapConnectionManager.User.getPersonOid().intValue(), recipientPersonOid, p.MessageTimeStamp, text.getText().toString(), false, 0);
|
||||
|
||||
databaseHandler.addChatMessage(message);
|
||||
|
||||
chatMessages.add(message);
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
text.setText("");
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
Log.i("SEND_CHAT_MESSAGE","Socket ist null");
|
||||
}
|
||||
|
||||
// Update der GUI
|
||||
listView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
Date now = c.getTime();
|
||||
|
||||
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
|
||||
String formattedDate = df.format(now);
|
||||
|
||||
// saveCompleteMessage = text.getText().toString()+"/"+isMe+"%"+formattedDate+"\n";
|
||||
//
|
||||
// WriteMessagesfromStorage(text.getText().toString()+"/"+isMe+"%"+formattedDate+"\n");
|
||||
|
||||
// TODO: In Datenbank speichern
|
||||
ChatMessage message = new ChatMessage(SoapConnectionManager.User.getPersonOid().intValue(), recipientPersonOid, now, text.getText().toString(), false);
|
||||
|
||||
databaseHandler.addChatMessage(message);
|
||||
|
||||
chatMessage = new ChatMessageFormat(text.getText().toString(), isMe, formattedDate);
|
||||
chatMessages.add(message);
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
text.setText("");
|
||||
}
|
||||
});
|
||||
}catch(IOException s){
|
||||
Log.v("Status: ","Senden einer Nachricht konnte nicht ausgeführt werden. Save wird ausgeführt");
|
||||
|
||||
@@ -273,40 +304,37 @@ public class ChatActivity extends ActionBarActivity{
|
||||
counter++;
|
||||
}
|
||||
|
||||
chatPacket = new Packet(total.toString());
|
||||
try {
|
||||
chatPacket = new Packet(total.toString());
|
||||
|
||||
if(!chatPacket.ChatDataIdentifier.equals(DataIdentifier.MESSAGE)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Log.i("CHAT_ACTIVITY", "Erhaltene Nachricht: " + chatPacket.ChatMessage);
|
||||
|
||||
listV.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// TODO: Nachricht in Datenbank speichern
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
Date now = c.getTime();
|
||||
|
||||
ChatMessage message = new ChatMessage(SoapConnectionManager.User.getPersonOid().intValue(), recipientPersonOid, now, chatPacket.ChatMessage, false);
|
||||
|
||||
databaseHandler.addChatMessage(message);
|
||||
|
||||
chatMessage = new ChatMessageFormat(chatPacket.ChatMessage, false, chatPacket.getFormattedMessageTimeStamp());
|
||||
chatMessages.add(message);
|
||||
adapter.notifyDataSetChanged();
|
||||
if(!chatPacket.ChatDataIdentifier.equals(DataIdentifier.MESSAGE)) {
|
||||
continue;
|
||||
}
|
||||
});
|
||||
|
||||
chatPacket.WriteToLog();
|
||||
|
||||
listV.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
ChatMessage message = new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, false, chatPacket.ServerseitigeOid);
|
||||
|
||||
databaseHandler.addChatMessage(message);
|
||||
|
||||
chatMessages.add(message);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
} catch(Exception pe) {
|
||||
Log.e("CONVERTING JSON: ", pe.getMessage());
|
||||
}
|
||||
} else {
|
||||
Log.i("SOCKETLISTENER/CHAT", "Nicht mit dem Socket verbunden");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
Log.e("Status ","Verbindung zum Server wurde seitens dem Server getrennt ");
|
||||
} catch(Exception e) {
|
||||
Log.e("Status ","Verbindung zum Server wurde seitens dem Server getrennt: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,7 +401,6 @@ public class ChatActivity extends ActionBarActivity{
|
||||
}
|
||||
|
||||
public void run() {
|
||||
//String al = text.getText().toString();
|
||||
|
||||
byte[] ts = al.getBytes();
|
||||
try {
|
||||
@@ -448,77 +475,6 @@ public class ChatActivity extends ActionBarActivity{
|
||||
mNotifyMgr.notify(1, mBuilder.build());
|
||||
}
|
||||
|
||||
// Internal Storage
|
||||
public void WriteMessagesfromStorage(String message){
|
||||
try{
|
||||
FileOutputStream stream = new FileOutputStream(file,true);
|
||||
|
||||
try{
|
||||
stream.write(message.getBytes());
|
||||
}finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
// Log.v("Status","Text: "+message+" wurde gespeichert." );
|
||||
|
||||
}catch (Exception e){
|
||||
Log.v("Fehler 1 ",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//Internal storage
|
||||
public void ReadMessageToStorage(){
|
||||
try{
|
||||
int lenght = (int) file.length();
|
||||
|
||||
byte[] bytes = new byte[lenght];
|
||||
|
||||
FileInputStream stream = new FileInputStream(file);
|
||||
|
||||
|
||||
// Log.v("Status","Verbindung steht 2");
|
||||
InputStreamReader in = new InputStreamReader(stream);
|
||||
|
||||
BufferedReader readLn = new BufferedReader(in);
|
||||
|
||||
String line = readLn.readLine();
|
||||
String allLines = "";
|
||||
//Build a readLine konstrukt
|
||||
while (line != null) {
|
||||
allLines += line;
|
||||
|
||||
String[] splitt = line.split("/");
|
||||
|
||||
if(splitt.length > 1) {
|
||||
String[] ArtDate = splitt[1].split("%"); //<------------ im code sind als seperator ? gesetzt // lösung einfach alle löschen und neuen chat speichern !!
|
||||
|
||||
final String message = splitt[0];
|
||||
final boolean art = Boolean.valueOf(ArtDate[0]);
|
||||
final String datetime = ArtDate[1];
|
||||
|
||||
Log.i("NACHRICHT AUS DATEI", splitt[0]);
|
||||
|
||||
listView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
chatMessage = new ChatMessageFormat(message, art, datetime);
|
||||
//chatMessages.add(message);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
line = readLn.readLine();
|
||||
}
|
||||
|
||||
stream.close();
|
||||
in.close();
|
||||
}catch(Exception e){
|
||||
Log.v("Fehler 2 ",e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap GetCircleBitmap(Bitmap bitmap) {
|
||||
|
||||
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
|
||||
@@ -543,4 +499,25 @@ public class ChatActivity extends ActionBarActivity{
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
// TODO: die alten Nachrichten vom Server holen
|
||||
private final class JsonSoapPrimitiveRequestListener implements RequestListener<SoapPrimitive> {
|
||||
|
||||
@Override
|
||||
public void onRequestFailure(SpiceException spiceException) {
|
||||
Log.e("GET_ALL_MESSAGES", "" + spiceException.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestSuccess(SoapPrimitive soapPrimitive) {
|
||||
Gson gson = new GsonBuilder().create();
|
||||
|
||||
Type listType = new TypeToken<ArrayList<ChatMessage>>(){}.getType();
|
||||
|
||||
ArrayList<ChatMessage> result = gson.fromJson(soapPrimitive.toString(), listType);
|
||||
|
||||
// Duplikate vermeiden
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,77 +4,77 @@ package beyondsoft.bewomitarbeiterapp;
|
||||
* Created by JettenM on 05.07.2016.
|
||||
*/
|
||||
public class ContactListItem {
|
||||
private int _id;
|
||||
private String _kontaktname;
|
||||
private byte[] _picture;
|
||||
private int _personOid;
|
||||
private int mId;
|
||||
private String mChatName;
|
||||
private byte[] mPicture;
|
||||
private int mPersonOid;
|
||||
|
||||
public boolean isOnline;
|
||||
|
||||
//default Construkt
|
||||
public ContactListItem(){}
|
||||
|
||||
//Construkt 1
|
||||
public ContactListItem(int id, String kontaktname, int personOid, byte[] picture){
|
||||
this._id = id;
|
||||
this._kontaktname = kontaktname;
|
||||
this._personOid = personOid;
|
||||
this._picture = picture;
|
||||
this.mId = id;
|
||||
this.mChatName = kontaktname;
|
||||
this.mPersonOid = personOid;
|
||||
this.mPicture = picture;
|
||||
}
|
||||
|
||||
//Construkt 2
|
||||
public ContactListItem(String kontaktname, int personOid, byte[] picture){
|
||||
this._kontaktname = kontaktname;
|
||||
this._personOid = personOid;
|
||||
this._picture = picture;
|
||||
this.mChatName = kontaktname;
|
||||
this.mPersonOid = personOid;
|
||||
this.mPicture = picture;
|
||||
}
|
||||
|
||||
//Construkt 3
|
||||
public ContactListItem(String kontaktname, int personOid){
|
||||
this._kontaktname = kontaktname;
|
||||
this._personOid = personOid;
|
||||
this._picture = null;
|
||||
this.mChatName = kontaktname;
|
||||
this.mPersonOid = personOid;
|
||||
this.mPicture = null;
|
||||
}
|
||||
|
||||
//Construkt4
|
||||
public ContactListItem(int id, String kontaktname, int personOid){
|
||||
this._id = id;
|
||||
this._kontaktname = kontaktname;
|
||||
this._personOid = personOid;
|
||||
this._picture = null;
|
||||
this.mId = id;
|
||||
this.mChatName = kontaktname;
|
||||
this.mPersonOid = personOid;
|
||||
this.mPicture = null;
|
||||
}
|
||||
|
||||
//ID
|
||||
public int getID(){
|
||||
return this._id;
|
||||
public int getId(){
|
||||
|
||||
return this.mId;
|
||||
}
|
||||
|
||||
public void setID(int id){
|
||||
this._id = id;
|
||||
public void setId(int id){
|
||||
|
||||
this.mId = id;
|
||||
}
|
||||
|
||||
public String getChatName(){
|
||||
|
||||
// KONTAKT
|
||||
public String getKontaktName(){
|
||||
return this._kontaktname;
|
||||
return this.mChatName;
|
||||
}
|
||||
|
||||
public void setKontaktName(String k){
|
||||
this._kontaktname = k;
|
||||
public void setChatName(String mChatName){
|
||||
this.mChatName = mChatName;
|
||||
}
|
||||
|
||||
//Picture
|
||||
public byte[] getPicture(){
|
||||
return this._picture;
|
||||
|
||||
return this.mPicture;
|
||||
}
|
||||
|
||||
public void setPicture(byte[] d){
|
||||
this._picture = d;
|
||||
public void setPicture(byte[] mPicture){
|
||||
|
||||
this.mPicture = mPicture;
|
||||
}
|
||||
|
||||
public int get_personOid() {
|
||||
return _personOid;
|
||||
public int getPersonOid() {
|
||||
|
||||
return mPersonOid;
|
||||
}
|
||||
|
||||
public void set_personOid(int _personOid) {
|
||||
this._personOid = _personOid;
|
||||
public void setPersonOid(int mPersonOid) {
|
||||
|
||||
this.mPersonOid = mPersonOid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ 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;
|
||||
@@ -43,6 +44,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
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);
|
||||
@@ -63,7 +65,8 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + " INTEGER," +
|
||||
KEY_INSTS_CHATMESSAGE + " DATETIME DEFAULT CURRENT_TIMESTAMP," +
|
||||
KEY_CHAT_TEXT_CHATMESSAGE + " TEXT," +
|
||||
KEY_IS_DELIVERED_CHATMESSAGE + " INTEGER)";
|
||||
KEY_IS_DELIVERED_CHATMESSAGE + " INTEGER," +
|
||||
KEY_SERVERSEITIGE_OID_CHATMESSAGE + " INTEGER DEFAULT NULL)";
|
||||
|
||||
db.execSQL(createChatMessageTable);
|
||||
}
|
||||
@@ -72,11 +75,14 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
Log.i("ZEIT_CHECK_DB", getDateTimeString(message.InsTs));
|
||||
|
||||
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.insert(TABLE_CHATMESSAGE, null, values);
|
||||
db.close();
|
||||
@@ -89,7 +95,8 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
|
||||
private Date getDateFromString(String dateString) {
|
||||
Date result = new Date();
|
||||
DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss", Locale.GERMAN);
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN);
|
||||
|
||||
try {
|
||||
result = df.parse(dateString);
|
||||
} catch (ParseException e) {
|
||||
@@ -114,8 +121,8 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
//Values übergabe
|
||||
values.put(KEY_KontaktName,contact.getKontaktName());
|
||||
values.put(KEY_PERSONOID,contact.get_personOid());
|
||||
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);
|
||||
@@ -127,7 +134,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
|
||||
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},
|
||||
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);
|
||||
@@ -136,7 +143,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
@@ -148,9 +155,9 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
|
||||
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_SENDER_PERSON_OID_CHATMESSAGE + "=? AND " + KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + "=?",
|
||||
new String[] {String.valueOf(SoapConnectionManager.User.getPersonOid()), String.valueOf(recipientOid)},
|
||||
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()) {
|
||||
@@ -161,7 +168,8 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
cursor.getInt(2),
|
||||
getDateFromString(cursor.getString(3)),
|
||||
cursor.getString(4),
|
||||
cursor.getInt(5) != 0
|
||||
cursor.getInt(5) != 0,
|
||||
cursor.getInt(6)
|
||||
);
|
||||
|
||||
messages.add(message);
|
||||
@@ -191,19 +199,18 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
//Holle alle Contacts
|
||||
public List<ContactListItem> getAllContacts(){
|
||||
List<ContactListItem> contactList = new ArrayList<ContactListItem>();
|
||||
// Select All Query
|
||||
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
|
||||
|
||||
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
|
||||
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
Cursor cursor = db.rawQuery(selectQuery, null);
|
||||
|
||||
// looping through all rows and adding to list
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
ContactListItem contact = new ContactListItem();
|
||||
contact.setID(Integer.parseInt(cursor.getString(0)));
|
||||
contact.setKontaktName(cursor.getString(1));
|
||||
contact.set_personOid(Integer.parseInt(cursor.getString(2)));
|
||||
contact.setId(cursor.getInt(0));
|
||||
contact.setChatName(cursor.getString(1));
|
||||
contact.setPersonOid(cursor.getInt(2));
|
||||
contact.setPicture(cursor.getBlob(3));
|
||||
|
||||
// Adding contact to list
|
||||
@@ -219,19 +226,19 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
SQLiteDatabase db = this.getWritableDatabase();
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(KEY_KontaktName, contact.getKontaktName());
|
||||
values.put(KEY_PERSONOID, contact.get_personOid());
|
||||
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()) });
|
||||
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.delete(TABLE_CONTACTS, KEY_ID + " = ?", new String[] { String.valueOf(contact.getId()) });
|
||||
db.close();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,15 +31,11 @@ public class KontaktAdapter extends ArrayAdapter<ContactListItem> {
|
||||
|
||||
private final Context context;
|
||||
private final ContactListItem[] values;
|
||||
// private final List<ContactListItem> contactlist;
|
||||
|
||||
private Bitmap bitmaping;
|
||||
ImageView imageView;
|
||||
TextView minitext;
|
||||
|
||||
private String[] filedaten;
|
||||
|
||||
Thread getM;
|
||||
Thread getPic;
|
||||
|
||||
public KontaktAdapter(Context context, ContactListItem[] values) {
|
||||
@@ -59,23 +55,15 @@ public class KontaktAdapter extends ArrayAdapter<ContactListItem> {
|
||||
ImageView onlinestats = (ImageView)rowView.findViewById(R.id.status);
|
||||
imageView = (ImageView) rowView.findViewById(R.id.logo);
|
||||
|
||||
textView.setText(values[position].getKontaktName());
|
||||
textView.setText(values[position].getChatName());
|
||||
|
||||
|
||||
if(values[position].getKontaktName().equals("Demo")) {
|
||||
getM = new Thread(new ReadLastMessage(values[position].getKontaktName(), inflater));
|
||||
getM.start();
|
||||
}else
|
||||
minitext.setText("Hier könnte auch ihre Nachricht stehen");
|
||||
|
||||
|
||||
/*if(values[position].getKontaktName().equals("Demo") && filedaten != null)
|
||||
minitext.setText(filedaten[0]);
|
||||
else
|
||||
minitext.setText("Hier könnte auch ihre Nachricht stehen");*/
|
||||
|
||||
|
||||
//lasttime.setText(filedaten[1]);
|
||||
// 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[position].getPicture() != null) {
|
||||
@@ -116,6 +104,7 @@ public class KontaktAdapter extends ArrayAdapter<ContactListItem> {
|
||||
// else if(values[position].getArt().equals("3"))
|
||||
// onlinestats.setImageResource(R.drawable.offline);
|
||||
|
||||
onlinestats.setImageResource((values[position].isOnline ? R.drawable.online : R.drawable.offline));
|
||||
|
||||
return rowView;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.app.ListActivity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
@@ -42,6 +41,8 @@ public class KontaktChatActivity extends ListActivity {
|
||||
private SpiceManager spiceManager = new SpiceManager(UncachedSpiceService.class);
|
||||
private DatabaseHandler databaseHandler;
|
||||
|
||||
private ArrayList<Integer> onlinePersonOids = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -49,7 +50,10 @@ public class KontaktChatActivity extends ListActivity {
|
||||
databaseHandler = new DatabaseHandler(this);
|
||||
|
||||
//TODO: nicht löschen, sondern updaten
|
||||
//databaseHandler.onUpgrade(databaseHandler.getReadableDatabase(), 1, 2);
|
||||
databaseHandler.onUpgrade(databaseHandler.getReadableDatabase(), 1, 2);
|
||||
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
onlinePersonOids = bundle.getIntegerArrayList("OnlineContacts");
|
||||
|
||||
ArrayList<PropertyInfo> propertyInfos = new ArrayList<>();
|
||||
propertyInfos.add(SoapConnectionManager.BuildProperty("pPersonOid", SoapConnectionManager.User.getPersonOid(), Long.class));
|
||||
@@ -86,13 +90,13 @@ public class KontaktChatActivity extends ListActivity {
|
||||
//get selected items
|
||||
ContactListItem selectedValue = (ContactListItem) getListAdapter().getItem(position);
|
||||
|
||||
Bundle korb = new Bundle();
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
korb.putString("Name", selectedValue.getKontaktName());
|
||||
korb.putInt("RecipientOid", selectedValue.get_personOid());
|
||||
bundle.putString("Name", selectedValue.getChatName());
|
||||
bundle.putInt("RecipientOid", selectedValue.getPersonOid());
|
||||
|
||||
Intent in = new Intent(getBaseContext(), ChatActivity.class);
|
||||
in.putExtras(korb);
|
||||
in.putExtras(bundle);
|
||||
|
||||
//Gib Bild für den Chat mit
|
||||
if(selectedValue.getPicture() == null){
|
||||
@@ -139,15 +143,30 @@ public class KontaktChatActivity extends ListActivity {
|
||||
|
||||
ArrayList<ChatPerson> result = gson.fromJson(soapPrimitive.toString(), listType);
|
||||
|
||||
for(ChatPerson cp : result) {
|
||||
databaseHandler.addContact(new ContactListItem(cp.Name, cp.Oid));
|
||||
List<ContactListItem> lc = databaseHandler.getAllContacts();
|
||||
|
||||
List<Integer> oidList = new ArrayList<>();
|
||||
|
||||
for(ContactListItem item : lc) {
|
||||
oidList.add(item.getPersonOid());
|
||||
}
|
||||
|
||||
List<ContactListItem> lc = databaseHandler.getAllContacts();
|
||||
for(ChatPerson cp : result) {
|
||||
if(!oidList.contains(cp.Oid)) {
|
||||
databaseHandler.addContact(new ContactListItem(cp.Name, cp.Oid));
|
||||
}
|
||||
}
|
||||
|
||||
lc = databaseHandler.getAllContacts();
|
||||
|
||||
for(ContactListItem item : lc) {
|
||||
if(onlinePersonOids.contains(item.getPersonOid())){
|
||||
item.isOnline = true;
|
||||
}
|
||||
}
|
||||
|
||||
ContactListItem[] Klientel = lc.toArray(new ContactListItem[lc.size()]);
|
||||
|
||||
// TODO: neuen Adapter schreiben
|
||||
setListAdapter(new KontaktAdapter(KontaktChatActivity.this, Klientel));
|
||||
databaseHandler.close();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@@ -44,22 +45,19 @@ public class MainActivityMitarbeiter extends Activity {
|
||||
|
||||
public static Socket socket;
|
||||
DataOutputStream dataOutputStream;
|
||||
// public static BufferedReader inputReader = null;
|
||||
|
||||
//Name, der Zum Server gesendet wird
|
||||
protected String name;
|
||||
|
||||
//Name, der vom Server erhalten wird
|
||||
//protected String recname;
|
||||
protected String loggedInUserName;
|
||||
|
||||
File file;
|
||||
|
||||
File Unsendfile;
|
||||
File unsentFile;
|
||||
|
||||
public static Thread listen;
|
||||
public static SocketListener socketListener;
|
||||
|
||||
int personOid;
|
||||
int loggedInUserPersonOid;
|
||||
|
||||
private ArrayList<Integer> onlinePersonOids;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -68,9 +66,9 @@ public class MainActivityMitarbeiter extends Activity {
|
||||
|
||||
setzeButtonListener();
|
||||
|
||||
name = SoapConnectionManager.User.getFullName();
|
||||
loggedInUserName = SoapConnectionManager.User.getFullName();
|
||||
|
||||
personOid = SoapConnectionManager.User.getPersonOid() <= Integer.MAX_VALUE ? SoapConnectionManager.User.getPersonOid().intValue() : 0;
|
||||
loggedInUserPersonOid = SoapConnectionManager.User.getPersonOid() <= Integer.MAX_VALUE ? SoapConnectionManager.User.getPersonOid().intValue() : 0;
|
||||
|
||||
StartServerConnection();
|
||||
}
|
||||
@@ -114,8 +112,14 @@ public class MainActivityMitarbeiter extends Activity {
|
||||
chatbutton.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
|
||||
startActivity(new Intent(getBaseContext(),KontaktChatActivity.class));
|
||||
//SendAfterGetConnection();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putIntegerArrayList("OnlineContacts", onlinePersonOids);
|
||||
|
||||
Intent kontaktChatActivity = new Intent(getBaseContext(),KontaktChatActivity.class);
|
||||
|
||||
kontaktChatActivity.putExtras(bundle);
|
||||
|
||||
startActivity(kontaktChatActivity);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -129,7 +133,7 @@ public class MainActivityMitarbeiter extends Activity {
|
||||
|
||||
p.ChatDataIdentifier = DataIdentifier.LOGOUT;
|
||||
|
||||
new Thread(new TestMessageSender(p.GetDataStream())).start();
|
||||
new Thread(new MessageSender(p.GetDataStream())).start();
|
||||
} catch(Exception e) {
|
||||
Log.e("SendAfterGetConnection", "Fehler beim Logout: " + e.getMessage());
|
||||
}
|
||||
@@ -151,18 +155,10 @@ public class MainActivityMitarbeiter extends Activity {
|
||||
try {
|
||||
socket = new Socket(SoapCalls.DESTINATION_ADDRESS, SoapCalls.DESTINATION_PORT);
|
||||
|
||||
Log.d("OpenConnection","Verbindung hergestellt");
|
||||
SendAfterGetConnection();
|
||||
|
||||
//nachricht an server senden welcher name jetz aktiv connected ist
|
||||
dataOutputStream = new DataOutputStream(socket.getOutputStream());
|
||||
|
||||
// name = name + "/1" + "?" + personOid;
|
||||
// byte[] ts = name.getBytes();
|
||||
// dataOutputStream.write(ts);
|
||||
// dataOutputStream.flush();
|
||||
|
||||
// Starte SocketListener
|
||||
socketListener = new SocketListener();
|
||||
listen = new Thread(socketListener);
|
||||
listen.start();
|
||||
@@ -187,7 +183,7 @@ public class MainActivityMitarbeiter extends Activity {
|
||||
}
|
||||
|
||||
public static void CloseMainActivitySocketListener() {
|
||||
if(listen.isAlive()) {
|
||||
if(listen != null && listen.isAlive()) {
|
||||
try {
|
||||
socketListener.terminate();
|
||||
listen.join();
|
||||
@@ -238,6 +234,14 @@ public class MainActivityMitarbeiter extends Activity {
|
||||
|
||||
if(chatPacket.ChatDataIdentifier.equals(DataIdentifier.MESSAGE)) {
|
||||
SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.RecipientPersonOid);
|
||||
} else if(chatPacket.ChatDataIdentifier.equals(DataIdentifier.STATUS_NOTIFICATION_LOGIN_BROADCAST)) {
|
||||
|
||||
String[] bitch = chatPacket.ChatMessage.split(",");
|
||||
onlinePersonOids = new ArrayList<>();
|
||||
|
||||
for (String aBitch : bitch) {
|
||||
onlinePersonOids.add(Integer.parseInt(aBitch));
|
||||
}
|
||||
}
|
||||
|
||||
Log.i("MAIN_ACTIVITY", "Erhaltene Nachricht: " + chatPacket.ChatMessage);
|
||||
@@ -271,28 +275,8 @@ public class MainActivityMitarbeiter extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateFile(String filename){
|
||||
|
||||
try{
|
||||
|
||||
File pfad = getBaseContext().getFilesDir();
|
||||
|
||||
//Für external Save
|
||||
//File pfad = getBaseContext().getExternalFilesDir(null);
|
||||
|
||||
//Erstelle das File Objekt
|
||||
file = new File(pfad,filename+".txt");
|
||||
|
||||
}catch(Exception e){
|
||||
Log.v("Fehler"," Das erstellen/öffnen einer Datei ist Derzeit nicht möglich");
|
||||
}
|
||||
// WriteMessagesfromStorage("\n ich teste weiter mit "+name);
|
||||
} //---> Zum Sortieren der Message zum jeweiligen Kontakt
|
||||
|
||||
public void SendAfterGetConnection(){
|
||||
|
||||
// Wird immer nach dem Login aufgerufen, um den Mitarbeiter beim Server anzumelden
|
||||
|
||||
if(socket.isConnected()) {
|
||||
try {
|
||||
Packet p = new Packet();
|
||||
@@ -305,75 +289,18 @@ public class MainActivityMitarbeiter extends Activity {
|
||||
p.Tenant = SecurityUtils.decrypt(tenantStream).toString();
|
||||
p.ChatDataIdentifier = DataIdentifier.LOGIN;
|
||||
|
||||
new Thread(new TestMessageSender(p.GetDataStream())).start();
|
||||
new Thread(new MessageSender(p.GetDataStream())).start();
|
||||
} catch(Exception e) {
|
||||
Log.e("SendAfterGetConnection", "Fehler beim Senden einer Nachricht an den Server: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// CreateCustomFileForUnSendMessage();
|
||||
//
|
||||
// if(Unsendfile.canRead() && socket.isConnected()){
|
||||
// try{
|
||||
// Log.v("Info","Eine ungesendete NAchricht wurde gefunden");
|
||||
//
|
||||
// FileInputStream stream = new FileInputStream(Unsendfile);
|
||||
// InputStreamReader in = new InputStreamReader(stream);
|
||||
// BufferedReader readLn = new BufferedReader(in);
|
||||
//
|
||||
// String line = readLn.readLine();
|
||||
// String allLines="";
|
||||
//
|
||||
// while (line != null) {
|
||||
// allLines += line;
|
||||
//
|
||||
// Log.v("Info","Eine ungesendete NAchricht 4");
|
||||
// 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];
|
||||
//
|
||||
// Log.v("Info","Eine ungesendete NAchricht 5");
|
||||
// //für jede Gelesene Line Sende Nachricht
|
||||
// new Thread(new SendUnsentMessages(message)).start();
|
||||
// Log.v("Info","Eine ungesendete NAchricht 6");
|
||||
// }
|
||||
// line = readLn.readLine();
|
||||
// }
|
||||
// stream.close();
|
||||
// in.close();
|
||||
// Unsendfile.delete();
|
||||
// }catch(Exception fe){
|
||||
// Log.v("Status","Ein problem ist im BEreich Unsend Ms Aufgetreten");
|
||||
// }
|
||||
// //recreate();
|
||||
// }
|
||||
}
|
||||
|
||||
public void CreateCustomFileForUnSendMessage(){
|
||||
try{
|
||||
File pfad = getBaseContext().getFilesDir();
|
||||
|
||||
//Für external Save
|
||||
//File pfad = getBaseContext().getExternalFilesDir(null);
|
||||
|
||||
//Erstelle das File Objekt | name
|
||||
Unsendfile = new File(pfad,"hier der name"+"_Unsend"+".txt");
|
||||
|
||||
}catch(Exception e){
|
||||
Log.v("Fehler"," Das erstellen/öffnen einer Datei ist Derzeit nicht möglich");
|
||||
}
|
||||
}
|
||||
|
||||
public class TestMessageSender implements Runnable {
|
||||
public class MessageSender implements Runnable {
|
||||
|
||||
byte[] packetToSend;
|
||||
|
||||
public TestMessageSender(byte[] packet2Send) {
|
||||
public MessageSender(byte[] packet2Send) {
|
||||
packetToSend = packet2Send;
|
||||
}
|
||||
|
||||
@@ -386,51 +313,11 @@ public class MainActivityMitarbeiter extends Activity {
|
||||
dataOutputStream.flush();
|
||||
}
|
||||
} catch(Exception e) {
|
||||
Log.e("TestMessageSender", "Fehler beim Senden der TestMessage " + e.getMessage());
|
||||
Log.e("MessageSender", "Fehler beim Senden der TestMessage " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SendUnsentMessages implements Runnable{
|
||||
String al;
|
||||
SendUnsentMessages(String unMS){
|
||||
this.al = unMS;
|
||||
}
|
||||
public void run() {
|
||||
//String al = text.getText().toString();
|
||||
|
||||
byte[] ts = al.getBytes();
|
||||
try {
|
||||
if (socket != null && dataOutputStream != null) {
|
||||
|
||||
//try catch bei catch SaveAfterLoseConnection();
|
||||
dataOutputStream.write(ts);
|
||||
dataOutputStream.flush();
|
||||
}
|
||||
}catch(Exception xs){
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteMessagesfromStorage(String message){
|
||||
try{
|
||||
|
||||
FileOutputStream stream = new FileOutputStream(file,true);
|
||||
|
||||
try{
|
||||
stream.write(message.getBytes());
|
||||
}finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
// Log.v("Status","Text: "+message+" wurde gespeichert." );
|
||||
|
||||
}catch (Exception e){
|
||||
Log.v("Fehler",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
//setze Notification
|
||||
public void SetNotify(String username, String message, int recipientOid){
|
||||
|
||||
//Convertiert in Pic Resource in ein Bitmap
|
||||
|
||||
@@ -2,6 +2,7 @@ package beyondsoft.bewomitarbeiterapp;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -36,6 +37,8 @@ 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 if(splitt[0].equals("Server")) {
|
||||
@@ -58,7 +61,7 @@ public class MessageAdapter extends ArrayAdapter<ChatMessage> {
|
||||
|
||||
if(chatMessage.SenderPersonOid == SoapConnectionManager.User.getPersonOid()){
|
||||
holder.dateIn.setText(chatMessage.getInsTsAsString());
|
||||
}else {
|
||||
} else {
|
||||
holder.dateOut.setText(chatMessage.getInsTsAsString());
|
||||
}
|
||||
|
||||
|
||||
@@ -14,22 +14,25 @@ public class ChatMessage {
|
||||
public Date InsTs;
|
||||
public String ChatText;
|
||||
public boolean IsDelivered;
|
||||
public int ServerseitigeOid;
|
||||
|
||||
public ChatMessage(int id, int senderPersonOid, int recipientPersonOid, Date insTs, String chatText, boolean isDelivered) {
|
||||
public ChatMessage(int id, int senderPersonOid, int recipientPersonOid, Date insTs, String chatText, boolean isDelivered, int serverseitigeOid) {
|
||||
Id = id;
|
||||
SenderPersonOid = senderPersonOid;
|
||||
RecipientPersonOid = recipientPersonOid;
|
||||
InsTs = insTs;
|
||||
ChatText = chatText;
|
||||
IsDelivered = isDelivered;
|
||||
ServerseitigeOid = serverseitigeOid;
|
||||
}
|
||||
|
||||
public ChatMessage(int senderPersonOid, int recipientPersonOid, Date insTs, String chatText, boolean isDelivered) {
|
||||
public ChatMessage(int senderPersonOid, int recipientPersonOid, Date insTs, String chatText, boolean isDelivered, int serverseitigeOid) {
|
||||
SenderPersonOid = senderPersonOid;
|
||||
RecipientPersonOid = recipientPersonOid;
|
||||
InsTs = insTs;
|
||||
ChatText = chatText;
|
||||
IsDelivered = isDelivered;
|
||||
ServerseitigeOid = serverseitigeOid;
|
||||
}
|
||||
|
||||
public String getInsTsAsString() {
|
||||
|
||||
@@ -9,7 +9,10 @@ public enum DataIdentifier {
|
||||
LOGOUT(2),
|
||||
NULL(3),
|
||||
STATUS_NOTIFICATION_LOGIN(4),
|
||||
STATUS_NOTIFICATION_LOGOUT(5);
|
||||
STATUS_NOTIFICATION_LOGOUT(5),
|
||||
OLD_MESSAGE(6),
|
||||
DELIVERING_STATUS_CHANGE(7),
|
||||
STATUS_NOTIFICATION_LOGIN_BROADCAST(8);
|
||||
|
||||
private final int value;
|
||||
DataIdentifier(int value) {
|
||||
|
||||
@@ -23,6 +23,7 @@ public class Packet {
|
||||
public Date MessageTimeStamp;
|
||||
public String Tenant;
|
||||
public boolean IsDelivered;
|
||||
public int ServerseitigeOid;
|
||||
|
||||
// TODO: IsDelivered einbauen
|
||||
|
||||
@@ -45,9 +46,9 @@ public class Packet {
|
||||
|
||||
//Aufbau Message:
|
||||
// die ersten fünf ";" ignorieren
|
||||
// SenderOid;RecipientOid;ClientNameLength;MessageLength;ChatDataIdentifier;Tenant;[ClientName][ChatMessage][MessageTimeStamp]
|
||||
// SenderOid;RecipientOid;ClientNameLength;MessageLength;ChatDataIdentifier;ServerseitigeOid;Tenant;[ClientName][ChatMessage][MessageTimeStamp][IsDelivered]
|
||||
|
||||
//23;281;20;389;1;[Tenant]; 6 Semikola
|
||||
//23;281;20;389;1;38;[Tenant]; 7 Semikola
|
||||
|
||||
public Packet(String message) {
|
||||
|
||||
@@ -58,17 +59,19 @@ public class Packet {
|
||||
String chatNameLengthString = gesplittet[2];
|
||||
String chatMessageLengthString = gesplittet[3];
|
||||
String chatIdentifierString = gesplittet[4];
|
||||
Tenant = gesplittet[5];
|
||||
String serverseitigeOidString = gesplittet[5];
|
||||
Tenant = gesplittet[6];
|
||||
|
||||
SenderPersonOid = Integer.parseInt(senderPersonOidString);
|
||||
RecipientPersonOid = Integer.parseInt(recipientPersonOidString);
|
||||
ServerseitigeOid = Integer.parseInt(serverseitigeOidString);
|
||||
|
||||
ChatDataIdentifier = DataIdentifier.getEnumValue(Integer.parseInt(chatIdentifierString));
|
||||
|
||||
int chatNameLength = Integer.parseInt(chatNameLengthString);
|
||||
int chatMessageLength = Integer.parseInt(chatMessageLengthString);
|
||||
|
||||
int headerLength = senderPersonOidString.length() + recipientPersonOidString.length() + chatNameLengthString.length() + chatMessageLengthString.length() + chatIdentifierString.length() + Tenant.length() + 7;
|
||||
int headerLength = senderPersonOidString.length() + recipientPersonOidString.length() + chatNameLengthString.length() + chatMessageLengthString.length() + chatIdentifierString.length() + Tenant.length() + serverseitigeOidString.length() + 8;
|
||||
String actualMessage = message.substring(headerLength - 1);
|
||||
|
||||
ChatName = actualMessage.substring(0, chatNameLength);
|
||||
@@ -89,9 +92,9 @@ public class Packet {
|
||||
|
||||
public byte[] GetDataStream() {
|
||||
|
||||
String dataStreamAsString = "" + SenderPersonOid + ";" + RecipientPersonOid + ";" + ChatName.length() + ";" + ChatMessage.length()+ ";" + ChatDataIdentifier.getValue() + ";" + Tenant + ";";
|
||||
String dataStreamAsString = "" + SenderPersonOid + ";" + RecipientPersonOid + ";" + ChatName.length() + ";" + ChatMessage.length()+ ";" + ChatDataIdentifier.getValue() + ";" + ServerseitigeOid + ";" + Tenant + ";";
|
||||
|
||||
dataStreamAsString += ChatName + ChatMessage + getFormattedMessageTimeStamp() + (IsDelivered ? 1 : 0);
|
||||
dataStreamAsString += ChatName + ChatMessage + getFormattedMessageTimeStamp() + "" + (IsDelivered ? 1 : 0);
|
||||
|
||||
byte[] blaaah = new byte[dataStreamAsString.length()];
|
||||
|
||||
@@ -103,4 +106,8 @@ public class Packet {
|
||||
|
||||
return blaaah;
|
||||
}
|
||||
|
||||
public void WriteToLog() {
|
||||
Log.i("PACKET_LOG", "SenderPersonOid: " + SenderPersonOid + "\nRecipientPersonOid: " + RecipientPersonOid + "\nChatDataIdentifier: " + ChatDataIdentifier.name() + "\nChatName: " + ChatName + "\nChatMessage: " + ChatMessage + "\nTenant: " + Tenant + "\nIsDelivered: " + IsDelivered + "\nMessageTimeStamp: " + MessageTimeStamp + "\nServerseitigeOid: " + ServerseitigeOid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ public class SoapCalls {
|
||||
public static String LOGIN_CALL = "Login";
|
||||
public static String GET_CONTACTS_FOR_PERSON = "GetContactsForPerson";
|
||||
|
||||
public static String GET_ALL_CHAT_MESSAGES = "GetAllChatMessagesForSenderAndRecipient";
|
||||
|
||||
public static String DESTINATION_ADDRESS = "192.168.1.103";
|
||||
public static int DESTINATION_PORT = 5000;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user