Änderungen an der App
Chunkweises Herunterladen von Chatnachrichten
This commit is contained in:
@@ -100,8 +100,6 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/multi-dex" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
|
||||
|
||||
@@ -5,8 +5,15 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -15,9 +22,13 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
|
||||
import beyondsoft.bewomitarbeiterapp.ContactListItem;
|
||||
import entities.ChatMessage;
|
||||
import soapConnection.SoapConnectionManager;
|
||||
import util.BeWoLog;
|
||||
import util.SecurityUtils;
|
||||
|
||||
/**
|
||||
* Created by bib on 07.06.2016.
|
||||
@@ -27,7 +38,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
private static final String LOGTAG = "DATABASE_HANDLER";
|
||||
|
||||
//DataBase version
|
||||
private static final int DATABASE_VERSION = 8;
|
||||
private static final int DATABASE_VERSION = 9;
|
||||
|
||||
//Database name
|
||||
private static final String DATABASE_NAME = "Contacts_Manager";
|
||||
@@ -209,15 +220,23 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
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 ? 1 : 0);
|
||||
values.put(KEY_MESSAGE_ID_CHATMESSAGE, message.MessageId);
|
||||
values.put(KEY_SENDDATE_CHATMESSAGE, (message.SendDate == null ? null : getDateTimeString(message.SendDate)));
|
||||
ByteArrayOutputStream chatMessageOutputStream = new ByteArrayOutputStream();
|
||||
|
||||
try {
|
||||
SecurityUtils.encrypt(message.ChatText, chatMessageOutputStream);
|
||||
|
||||
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, Base64.encodeToString(chatMessageOutputStream.toByteArray(), Base64.DEFAULT));
|
||||
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 ? 1 : 0);
|
||||
values.put(KEY_MESSAGE_ID_CHATMESSAGE, message.MessageId);
|
||||
values.put(KEY_SENDDATE_CHATMESSAGE, (message.SendDate == null ? null : getDateTimeString(message.SendDate)));
|
||||
} catch (IOException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
@@ -233,7 +252,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
|
||||
String selectQuery = "SELECT "+ KEY_MESSAGE_ID_CHATMESSAGE + " FROM " + TABLE_CHATMESSAGE + " WHERE " + KEY_MESSAGE_ID_CHATMESSAGE + " IS NOT NULL";
|
||||
String selectQuery = "SELECT "+ KEY_MESSAGE_ID_CHATMESSAGE + " FROM " + TABLE_CHATMESSAGE + " WHERE " + KEY_MESSAGE_ID_CHATMESSAGE + " IS NOT NULL ORDER BY " + KEY_INSTS_CHATMESSAGE + " DESC";
|
||||
|
||||
Cursor cursor = db.rawQuery(selectQuery, null);
|
||||
|
||||
@@ -249,11 +268,11 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
}
|
||||
|
||||
public ArrayList<String> getExistingTeamChatMessageUUIDs() {
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
|
||||
SQLiteDatabase db = this.getReadableDatabase();
|
||||
|
||||
String selectQuery = "SELECT " + KEY_MESSAGE_ID_CHATMESSAGE + " FROM " + TABLE_CHATMESSAGE + " WHERE " + KEY_MESSAGE_ID_CHATMESSAGE + " IS NOT NULL AND " + KEY_IS_TEAM_CHATMESSAGE + " = 1";
|
||||
String selectQuery = "SELECT " + KEY_MESSAGE_ID_CHATMESSAGE + " FROM " + TABLE_CHATMESSAGE + " WHERE " + KEY_MESSAGE_ID_CHATMESSAGE + " IS NOT NULL AND " + KEY_IS_TEAM_CHATMESSAGE + " = 1 ORDER BY " + KEY_INSTS_CHATMESSAGE + " DESC";
|
||||
|
||||
Cursor cursor = db.rawQuery(selectQuery, null);
|
||||
|
||||
@@ -321,12 +340,11 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
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);
|
||||
String chatText = decryptChatMessage(cursor.getString(4));
|
||||
boolean isDelivered = cursor.getInt(5) == 1;
|
||||
int serverseitigeOid = cursor.getInt(6);
|
||||
boolean isTeam = cursor.getInt(7) == 1;
|
||||
@@ -373,7 +391,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
cursor.getInt(1),
|
||||
cursor.getInt(2),
|
||||
getDateFromString(cursor.getString(3)),
|
||||
cursor.getString(4),
|
||||
decryptChatMessage(cursor.getString(4)),
|
||||
cursor.getInt(5) == 1,
|
||||
cursor.getInt(6),
|
||||
cursor.getInt(7) == 1,
|
||||
@@ -412,7 +430,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
cursor.getInt(1),
|
||||
cursor.getInt(2),
|
||||
getDateFromString(cursor.getString(3)),
|
||||
cursor.getString(4),
|
||||
decryptChatMessage(cursor.getString(4)),
|
||||
cursor.getInt(5) == 1,
|
||||
cursor.getInt(6),
|
||||
cursor.getInt(7) == 1,
|
||||
@@ -465,7 +483,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
}
|
||||
|
||||
public List<ContactListItem> getAllContacts(){
|
||||
List<ContactListItem> contactList = new ArrayList<ContactListItem>();
|
||||
List<ContactListItem> contactList = new ArrayList<>();
|
||||
|
||||
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
|
||||
|
||||
@@ -510,7 +528,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
cursor.getInt(1),
|
||||
cursor.getInt(2),
|
||||
getDateFromString(cursor.getString(3)),
|
||||
cursor.getString(4),
|
||||
decryptChatMessage(cursor.getString(4)),
|
||||
cursor.getInt(5) == 1,
|
||||
cursor.getInt(6),
|
||||
cursor.getInt(7) == 1,
|
||||
@@ -626,7 +644,13 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
new String[] {pMessageId},
|
||||
null, null, null, null);
|
||||
|
||||
return cursor != null && cursor.moveToFirst();
|
||||
boolean result = cursor != null && cursor.moveToFirst();
|
||||
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ArrayList<ChatMessage> getUnsentChatMessages() {
|
||||
@@ -647,7 +671,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
cursor.getInt(1),
|
||||
cursor.getInt(2),
|
||||
getDateFromString(cursor.getString(3)),
|
||||
cursor.getString(4),
|
||||
decryptChatMessage(cursor.getString(4)),
|
||||
cursor.getInt(5) == 1,
|
||||
cursor.getInt(6),
|
||||
cursor.getInt(7) == 1,
|
||||
@@ -691,18 +715,13 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
cursor.getInt(1),
|
||||
cursor.getInt(2),
|
||||
getDateFromString(cursor.getString(3)),
|
||||
cursor.getString(4),
|
||||
decryptChatMessage(cursor.getString(4)),
|
||||
cursor.getInt(5) == 1,
|
||||
cursor.getInt(6),
|
||||
cursor.getInt(7) == 1,
|
||||
cursor.getString(8)
|
||||
);
|
||||
|
||||
String blubb = "";
|
||||
for(int i = 0; i < cursor.getColumnCount(); i++) {
|
||||
blubb += "" + i + ". " + cursor.getColumnName(i) + "; ";
|
||||
}
|
||||
|
||||
if(cursor.getString(9) != null) {
|
||||
message.SendDate = getDateFromString(cursor.getString(9));
|
||||
}
|
||||
@@ -711,6 +730,24 @@ public class DatabaseHandler extends SQLiteOpenHelper {
|
||||
} while(cursor.moveToNext());
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private String decryptChatMessage(String encryptedChatMessage) {
|
||||
String result = "";
|
||||
|
||||
byte[] chatMessageByteArray = Base64.decode(encryptedChatMessage, Base64.DEFAULT);
|
||||
ByteArrayInputStream chatMessageStream = new ByteArrayInputStream(chatMessageByteArray);
|
||||
|
||||
try {
|
||||
result = SecurityUtils.decrypt(chatMessageStream).toString();
|
||||
} catch (IOException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) {
|
||||
BeWoLog.writeExceptionToLog(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,16 +164,6 @@ public class BeWoChatApplication extends Application {
|
||||
ConnectivityReceiver.connectivityReceiverListener = listener;
|
||||
}
|
||||
|
||||
public static void writeExceptionToLog(Throwable ex) {
|
||||
String logText = "Ausnahme: " + ex.toString() + "; Message: " + ex.getMessage() + "; Cause: " + ex.getCause();
|
||||
for(StackTraceElement ste : ex.getStackTrace()) {
|
||||
String steAsString = ste.toString();
|
||||
logText += "\t" + steAsString;
|
||||
}
|
||||
|
||||
BeWoLog.writeToLogFile(logText);
|
||||
}
|
||||
|
||||
public BeWoChatApplication() {
|
||||
defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
|
||||
|
||||
@@ -183,7 +173,7 @@ public class BeWoChatApplication extends Application {
|
||||
Log.e("UNCAUGHT_EXCEPTION", "Eine unbehandelte Ausnahme ist aufgetreten!\n" + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
|
||||
writeExceptionToLog(ex);
|
||||
BeWoLog.writeExceptionToLog(ex);
|
||||
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
@@ -323,7 +313,7 @@ public class BeWoChatApplication extends Application {
|
||||
Thread.currentThread().sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
writeExceptionToLog(e);
|
||||
BeWoLog.writeExceptionToLog(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -368,7 +358,7 @@ public class BeWoChatApplication extends Application {
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendUnsentMessages(final Context context) {
|
||||
public static synchronized void sendUnsentMessages(final Context context) {
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
@@ -99,6 +100,7 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
|
||||
|
||||
private final static String LOGTAG = "CHAT_ACTIVITY";
|
||||
|
||||
private int mLastFirstVisibleItem = 0;
|
||||
|
||||
@Override
|
||||
public void onNetworkConnectionChanged(boolean isConnected) {
|
||||
@@ -132,20 +134,47 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
|
||||
|
||||
listView = (ListView)findViewById(R.id.list_msg);
|
||||
|
||||
// listView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
// if(scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
|
||||
// Log.i("ON_SCROLL_STATE_CHANGED", "Berühre das Ende");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
|
||||
@Override
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
int fvp = view.getFirstVisiblePosition();
|
||||
int cc = view.getChildCount();
|
||||
int lvp = view.getLastVisiblePosition();
|
||||
|
||||
ChatMessage oldest = chatMessages.get(view.getLastVisiblePosition());
|
||||
|
||||
String scrollStateName = "";
|
||||
switch (scrollState) {
|
||||
case 0:
|
||||
scrollStateName = "IDLE";
|
||||
break;
|
||||
case 1:
|
||||
scrollStateName = "TOUCH SCROLL";
|
||||
break;
|
||||
case 2:
|
||||
scrollStateName = "FLING";
|
||||
break;
|
||||
}
|
||||
|
||||
scrollStateName = String.format(Locale.GERMAN, "%1$12s", scrollStateName);
|
||||
|
||||
String fvpStr = String.format(Locale.GERMAN, "%1$3d", fvp);
|
||||
String lvpStr = String.format(Locale.GERMAN, "%1$3d", lvp);
|
||||
String ccStr = String.format(Locale.GERMAN, "%1$3d", cc);
|
||||
|
||||
Log.i("ON_SCROLL_STATE_CHANGED", "ScrollState: " + scrollStateName + "; FirstVisiblePosition: " + fvpStr + " LastVisiblePosition: " + lvpStr + "; ChildCount: " + ccStr + "; Id der ältesten Nachricht: " + oldest.MessageId);
|
||||
|
||||
if(fvp == 0) {
|
||||
//TODO: Nachichten nachladen
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||
// Log.i("ON_SCROLL", "Scrolle... firstVisibleItem: " + firstVisibleItem + "; visibleItemCount: " + visibleItemCount + "; totalItemCount" + totalItemCount);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
});
|
||||
|
||||
Bundle zielkorb = getIntent().getExtras();
|
||||
recipientName = zielkorb.getString("Name");
|
||||
@@ -161,7 +190,7 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
|
||||
ReloadChatView(recipientName, recipientPersonOid, image, isTeam, teamMemberOids, teamMemberNames, isEmployee);
|
||||
}
|
||||
|
||||
private void ReloadChatView(final String contactName, final int recipientOid, final byte[] contactImage, boolean pIsTeam, String pTeamMemberOids, String pTeamMemberNames, boolean pIsEmployee) {
|
||||
public void ReloadChatView(final String contactName, final int recipientOid, final byte[] contactImage, boolean pIsTeam, String pTeamMemberOids, String pTeamMemberNames, boolean pIsEmployee) {
|
||||
chatMessages = new ArrayList<>();
|
||||
|
||||
recipientPersonOid = recipientOid;
|
||||
@@ -354,13 +383,34 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<PropertyInfo> propertyInfos = new ArrayList<>();
|
||||
propertyInfos.add(SoapConnectionManager.BuildProperty("pSenderPersonOid", SoapConnectionManager.getUser().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));
|
||||
// TODO: Anfang Test ----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
String newestMessageId = "";
|
||||
|
||||
final JsonSoapPrimitiveRequest request = new JsonSoapPrimitiveRequest(SoapCalls.GET_ALL_CHAT_MESSAGES, propertyInfos);
|
||||
if(test.size() > 0) {
|
||||
newestMessageId = test.get(test.size() - 1);
|
||||
}
|
||||
|
||||
Log.i("CHUNKS", "MessageId der Nachricht, die nicht geladen wird: " + newestMessageId);
|
||||
|
||||
ArrayList<PropertyInfo> propertyInfos2 = new ArrayList<>();
|
||||
propertyInfos2.add(SoapConnectionManager.BuildProperty("messageId", newestMessageId, String.class));
|
||||
propertyInfos2.add(SoapConnectionManager.BuildProperty("pRecipientPersonOid", recipientPersonOid, Long.class));
|
||||
propertyInfos2.add(SoapConnectionManager.BuildProperty("pSenderPersonOid", SoapConnectionManager.getUser().getPersonOid(), Long.class));
|
||||
propertyInfos2.add(SoapConnectionManager.BuildProperty("pIsForTeam", isTeam, Boolean.class));
|
||||
propertyInfos2.add(SoapConnectionManager.BuildProperty("pExceptions", pExceptions, String.class));
|
||||
|
||||
final JsonSoapPrimitiveRequest request = new JsonSoapPrimitiveRequest(SoapCalls.LOAD_CHATMESSAGES_CHUNKWISE, propertyInfos2);
|
||||
// spiceManager.execute(request, new JsonSoapChunkRequestListener());
|
||||
|
||||
// TODO: Ende Test ------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// ArrayList<PropertyInfo> propertyInfos = new ArrayList<>();
|
||||
// propertyInfos.add(SoapConnectionManager.BuildProperty("pSenderPersonOid", SoapConnectionManager.getUser().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));
|
||||
//
|
||||
// final JsonSoapPrimitiveRequest request = new JsonSoapPrimitiveRequest(SoapCalls.GET_ALL_CHAT_MESSAGES, propertyInfos);
|
||||
|
||||
final Callback corruptedSpiceCallback = new Callback() {
|
||||
@Override
|
||||
@@ -484,27 +534,6 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
|
||||
ChatActivity.this.startActivity(dokuActivity);
|
||||
|
||||
return true;
|
||||
|
||||
// case R.id.action_show_unsent_messages:
|
||||
//
|
||||
// String message = "";
|
||||
// ArrayList<ChatMessage> unsentMessages = DatabaseHandler.getInstance(ChatActivity.this).getUnsentChatMessages();
|
||||
// for(ChatMessage cm : unsentMessages) {
|
||||
// String sendDateStr = "";
|
||||
//
|
||||
// if(cm.SendDate != null) {
|
||||
// SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss", Locale.GERMAN);
|
||||
// sendDateStr = dateFormat.format(cm.SendDate);
|
||||
// } else {
|
||||
// sendDateStr = "null";
|
||||
// }
|
||||
//
|
||||
// message += cm.MessageId + "; " + cm.IsDelivered + "; " + sendDateStr + "\n";
|
||||
// }
|
||||
//
|
||||
// Util.buildAlert(ChatActivity.this, message);
|
||||
//
|
||||
// return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
@@ -681,20 +710,14 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
|
||||
|
||||
BeWoLog.writeToLogFile("Erneuter Login war erfolgreich. (ChatActivity->ReLoginRequestListener->onRequestSuccess)");
|
||||
|
||||
Bundle zielkorb = new Bundle();
|
||||
zielkorb.putString("Name", recipientName);
|
||||
zielkorb.putInt("RecipientOid", recipientPersonOid);
|
||||
zielkorb.putByteArray("Bild", image);
|
||||
zielkorb.putBoolean("IsTeam", isTeam);
|
||||
zielkorb.putString("TeamMemberOids", teamMemberOids);
|
||||
zielkorb.putString("TeamMemberNames", teamMemberNames);
|
||||
zielkorb.putBoolean("IsEmployee", isEmployee);
|
||||
|
||||
if(abc != null) {
|
||||
if(abc.contains(";")) {
|
||||
Intent chatActivity = new Intent(getApplicationContext(), ChatActivity.class);
|
||||
chatActivity.putExtras(zielkorb);
|
||||
startActivity(chatActivity);
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReloadChatView(recipientName, recipientPersonOid, image, isTeam, teamMemberOids, teamMemberNames, isEmployee);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
BeWoLog.writeToLogFile("Der erneute Login ist fehlgeschlagen. Die Credentials waren inkorrekt. (ChatActivity->ReLoginRequestListener->onRequestSuccess)");
|
||||
|
||||
@@ -710,6 +733,61 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
|
||||
}
|
||||
}
|
||||
|
||||
private final class JsonSoapChunkRequestListener implements RequestListener<SoapPrimitive> {
|
||||
|
||||
@Override
|
||||
public void onRequestFailure(SpiceException spiceException) {
|
||||
BeWoLog.writeToLogFile("Das Chunkweise Laden der Nachrichten ist fehlgeschlagen. (ChatActivity->JsonSoapChunkRequestListener->onRequestFailure)");
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(ChatActivity.this, "Ein Fehler ist beim chunkweise Laden der Nachrichten auftegreten.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
Log.e("GET_ALL_MESSAGES", "Das Chunkweise Laden der Nachrichten ist gescheitert: " + spiceException.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestSuccess(SoapPrimitive soapPrimitive) {
|
||||
BeWoLog.writeToLogFile("Das chunkweise Laden der Nachrichten war erfolgreich. (ChatActivty, wo sonst?)");
|
||||
|
||||
BeWoChatApplication.lastOnlineTS = Calendar.getInstance().getTime();
|
||||
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
builder.registerTypeAdapter(ChatMessage.class, new ChatMessageDeserializer());
|
||||
|
||||
Gson gson = builder.create();
|
||||
|
||||
Type listType = new TypeToken<ArrayList<ChatMessage>>(){}.getType();
|
||||
|
||||
final ArrayList<ChatMessage> result = gson.fromJson(soapPrimitive.toString(), listType);
|
||||
|
||||
String abc = "Chunkweise geladenen Nachrichten:\n";
|
||||
for(ChatMessage m : result) {
|
||||
abc += m.MessageId + ": " + m.ChatText;
|
||||
|
||||
if(result.indexOf(m) != (result.size() - 1)) {
|
||||
abc += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
Log.i("CHUNKS", abc);
|
||||
|
||||
databaseHandler.addChatMessages(result);
|
||||
|
||||
listView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
chatMessages.addAll(result);
|
||||
adapter.sort(DATE_COMPARATOR);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static final Comparator<ChatMessage> DATE_COMPARATOR = new Comparator<ChatMessage>() {
|
||||
@Override
|
||||
public int compare(ChatMessage lhs, ChatMessage rhs) {
|
||||
|
||||
@@ -149,7 +149,7 @@ public class KontaktChatActivity extends ActionBarActivity implements Connectivi
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
Log.i(LOGTAG, "Führe onRefresh durch");
|
||||
Log.i(LOGTAG, "Föhre onRefresh durch");
|
||||
updateContactList();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ import java.util.Calendar;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
|
||||
import Database.DatabaseHandler;
|
||||
import entities.ChatMessage;
|
||||
import soapConnection.ApplicationUser;
|
||||
import soapConnection.JsonSoapPrimitiveRequest;
|
||||
import soapConnection.SoapCalls;
|
||||
@@ -382,6 +383,13 @@ public class LoginActivity extends ActionBarActivity {
|
||||
}
|
||||
}
|
||||
|
||||
DatabaseHandler dh = DatabaseHandler.getInstance(LoginActivity.this);
|
||||
ArrayList<ChatMessage> unsentMessages = dh.getUnsentChatMessages();
|
||||
Log.i("LOGIN_ACTIVITY", "Anzahl nicht verschickter Nachrichten: " + unsentMessages.size());
|
||||
for(ChatMessage cm : unsentMessages) {
|
||||
Log.i("LOGIN_ACTIVITY", cm.MessageId + ": " + cm.ChatText);
|
||||
}
|
||||
|
||||
SocketManager.tenant = mTenantView.getText().toString();
|
||||
|
||||
SocketManager.initialLoginCallback = new Callback() {
|
||||
|
||||
@@ -3,9 +3,12 @@ package beyondsoft.bewomitarbeiterapp;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.logging.Handler;
|
||||
|
||||
import util.BeWoLog;
|
||||
|
||||
/**
|
||||
* Created by bib on 02.05.2016.
|
||||
*/
|
||||
@@ -18,6 +21,12 @@ public class SplashScreenActivity extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.splashscreen);
|
||||
|
||||
if(!isTaskRoot()) {
|
||||
BeWoLog.writeToLogFile("Splash Screen gestartet, er ist aber nicht TaskRoot. Die Activity wird deshalb beendet.");
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
Thread logoTimer = new Thread() {
|
||||
public void run(){
|
||||
try{
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package soapConnection;
|
||||
|
||||
import util.BeWoLog;
|
||||
|
||||
/**
|
||||
* Created by JettenM on 05.07.2016.
|
||||
*/
|
||||
public class ApplicationUser {
|
||||
private String fullName;
|
||||
private String username;
|
||||
private Long employeeOid;
|
||||
private Long employeeOid; //TODO: redundant?
|
||||
private Long customerOid;
|
||||
private Long personOid;
|
||||
private String tenant;
|
||||
@@ -56,9 +58,23 @@ public class ApplicationUser {
|
||||
}
|
||||
|
||||
public ApplicationUser(String fullName, String username, Long employeeOid, Long personOid) {
|
||||
BeWoLog.writeToLogFile("Rufe den Konstruktor von ApplicationUser mit folgenden Werten auf: fullName: " + fullName + "; username: " + username + "; employeeOid: " + employeeOid + "; personOid: " + personOid);
|
||||
|
||||
this.fullName = fullName;
|
||||
this.username = username;
|
||||
this.employeeOid = employeeOid;
|
||||
this.personOid = personOid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String fn = (fullName == null ? "fullName ist NULL" : fullName);
|
||||
String un = (username == null ? "username ist NULL" : username);
|
||||
String eo = (employeeOid == null ? "employeeOid ist NULL" : employeeOid.toString());
|
||||
String co = (customerOid == null ? "customerOid ist NULL" : customerOid.toString());
|
||||
String po = (personOid == null ? "personOid ist NULL" : personOid.toString());
|
||||
String tn = (tenant == null ? "tenant ist NULL" : tenant);
|
||||
|
||||
return "fullName: " + fn + "; username: " + un + "; employeeOid: " + eo + "; customerOid: " + co + "; personOid: " + po + "; tenant: " + tn + "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
@@ -98,7 +99,7 @@ public class Packet {
|
||||
|
||||
IsDelivered = Integer.parseInt(actualMessage.substring(chatMessageLength + chatNameLength + 19, chatMessageLength + chatNameLength + 20)) != 0;
|
||||
|
||||
writeToLog("Konstruktor");
|
||||
// writeToLog("Konstruktor");
|
||||
}
|
||||
|
||||
public byte[] getDataStream() {
|
||||
@@ -139,76 +140,81 @@ public class Packet {
|
||||
"\n\tMessageId: " + MessageId;
|
||||
}
|
||||
|
||||
public static int analyzingPackets(String packetString) {
|
||||
int packetCount = 0;
|
||||
// private static final String ANALYZERLOGTAG = "PACKET_ANALYZER";
|
||||
public static ArrayList<Packet> analyzePackets(String packetString) {
|
||||
int messagesCharCount = packetString.length();
|
||||
ArrayList<Packet> packets = new ArrayList<>();
|
||||
|
||||
while (messagesCharCount > 0) {
|
||||
// Log.i(ANALYZERLOGTAG, "Packet Nr. " + (packetCount + 1));
|
||||
String[] gesplittet = packetString.split(";");
|
||||
|
||||
String[] gesplittet = packetString.split(";");
|
||||
// Log.i(ANALYZERLOGTAG, "Zu analysierender String: " + packetString);
|
||||
|
||||
Log.i("PACKET_ANALYZER", "Anzahl Semikola: " + (gesplittet.length - 1));
|
||||
Log.i("PACKET_ANALYZER", "Zu analysierender String: " + packetString);
|
||||
int senderPersonOidLength = gesplittet[0].length();
|
||||
int recipientPersonOidLength = gesplittet[1].length();
|
||||
int chatNameLength = gesplittet[2].length();
|
||||
int chatMessageLength = gesplittet[3].length();
|
||||
int chatIdentifierLength = gesplittet[4].length();
|
||||
int serverseitigeOidLength = gesplittet[5].length();
|
||||
int clientseitigeOidLength = gesplittet[6].length();
|
||||
int tenantLength = gesplittet[7].length();
|
||||
int isEmployeeLength = gesplittet[8].length();
|
||||
int messageIdLength = gesplittet[9].length();
|
||||
|
||||
//z.B. Header: 11;3;15;17;0;2657;43;demoapp4;1;5a50002f-464b-4763-91e2-d261463477e0;
|
||||
// Log.i(ANALYZERLOGTAG, "SenderPersonOidLength: " + senderPersonOidLength + "\n" +
|
||||
// "recipientPersonOidLength: " + recipientPersonOidLength + "\n" +
|
||||
// "chatNameLength: " + chatNameLength + "\n" +
|
||||
// "chatMessageLength: " + chatMessageLength + "\n" +
|
||||
// "chatIdentifierLength: " + chatIdentifierLength + "\n" +
|
||||
// "serverseitigeOidLength: " + serverseitigeOidLength + "\n" +
|
||||
// "clientseitigeOidLength: " + clientseitigeOidLength + "\n" +
|
||||
// "tenantLength: " + tenantLength + "\n" +
|
||||
// "isEmployeeLength: " + isEmployeeLength + "\n" +
|
||||
// "messageIdLength: " + messageIdLength + "\n" +
|
||||
// "actualChatNameLength: " + Integer.parseInt(gesplittet[2]));
|
||||
|
||||
// 11;3;15;17;0;2657;43;demoapp4;1;5a50002f-464b-4763-91e2-d261463477e0;Elliot Aldersonnoch eine antwort03.11.2016 14:14:150
|
||||
// 11;3;15;17;0;2657;43;demoapp4;1;5a50002f-464b-4763-91e2-d261463477e0;Elliot Alderson --> 84 Zeichen
|
||||
// noch eine antwort --> 17 Zeichen
|
||||
// 03.11.2016 14:14:150 --> 20 Zeichen --> 84 + 17 + 20 = 121
|
||||
int headerLength =
|
||||
10 +
|
||||
senderPersonOidLength +
|
||||
recipientPersonOidLength +
|
||||
chatNameLength +
|
||||
chatMessageLength +
|
||||
chatIdentifierLength +
|
||||
serverseitigeOidLength +
|
||||
clientseitigeOidLength +
|
||||
tenantLength +
|
||||
isEmployeeLength +
|
||||
messageIdLength +
|
||||
Integer.parseInt(gesplittet[2]);
|
||||
|
||||
int senderPersonOidLength = gesplittet[0].length(); // 2
|
||||
int recipientPersonOidLength = gesplittet[1].length(); // 1
|
||||
int chatNameLength = gesplittet[2].length(); // 2
|
||||
int chatMessageLength = gesplittet[3].length(); // 2
|
||||
int chatIdentifierLength = gesplittet[4].length(); // 1
|
||||
int serverseitigeOidLength = gesplittet[5].length(); // 4
|
||||
int clientseitigeOidLength = gesplittet[6].length(); // 2
|
||||
int tenantLength = gesplittet[7].length(); // 8
|
||||
int isEmployeeLength = gesplittet[8].length(); // 1
|
||||
int messageIdLength = gesplittet[9].length(); // 36
|
||||
// Log.i(ANALYZERLOGTAG, "Testausgabe: " + packetString.substring(0, headerLength));
|
||||
|
||||
int headerLength = gesplittet.length - 1 +
|
||||
senderPersonOidLength +
|
||||
recipientPersonOidLength +
|
||||
chatNameLength +
|
||||
chatMessageLength +
|
||||
chatIdentifierLength +
|
||||
serverseitigeOidLength +
|
||||
clientseitigeOidLength +
|
||||
tenantLength +
|
||||
isEmployeeLength +
|
||||
messageIdLength +
|
||||
Integer.parseInt(gesplittet[2]);
|
||||
int actualChatMessageLength = Integer.parseInt(gesplittet[3]);
|
||||
|
||||
Log.i("PACKET_ANALYZER", "Testausgabe: " + packetString.substring(0, headerLength));
|
||||
int firstMessageLength = headerLength + actualChatMessageLength + 20;
|
||||
|
||||
/*
|
||||
SenderPersonOid = Integer.parseInt(senderPersonOidString);
|
||||
RecipientPersonOid = Integer.parseInt(recipientPersonOidString);
|
||||
ServerseitigeOid = Integer.parseInt(serverseitigeOidString);
|
||||
ClientseitigeOid = Integer.parseInt(clientseitigeOidString);
|
||||
IsEmployee = Integer.parseInt(isEmployeeString) == 1;
|
||||
// Log.i(ANALYZERLOGTAG, "Header-Length: " + headerLength);
|
||||
// Log.i(ANALYZERLOGTAG, "Länge der ersten Nachricht: " + firstMessageLength);
|
||||
// Log.i(ANALYZERLOGTAG, "Länge des packetStrings: " + packetString.length());
|
||||
|
||||
String firstMessage = packetString.substring(0, firstMessageLength);
|
||||
|
||||
// Log.i(ANALYZERLOGTAG, "Eigentliche Nachricht: " + (actualChatMessageLength > 0 ? firstMessage.substring(headerLength, headerLength + actualChatMessageLength) : "<<LEER>>"));
|
||||
// Log.i(ANALYZERLOGTAG, "Header: " + firstMessage.substring(0, headerLength));
|
||||
//
|
||||
// Log.i(ANALYZERLOGTAG, "Erste Nachricht: " + firstMessage);
|
||||
//
|
||||
// Log.i(ANALYZERLOGTAG, "Länge erste Nachricht: " + firstMessage.length() + ". Länge gesamter packetString: " + packetString.length());
|
||||
|
||||
Logout von Elliot Alderson:
|
||||
packets.add(new Packet(firstMessage));
|
||||
|
||||
SenderPersonOid RecipientPersonOid ChatNameLength ChatMessageLength ChatIdentifier ServerseitigeOid ClientseitigeOid Tenant IsEmployee MessageId ChatName TimeStamp IsDelivered
|
||||
11; 0; 15; 0; 5; 0; 0; ; 1; ; Elliot Alderson 03.11.2016 15:00:05 0
|
||||
messagesCharCount -= firstMessage.length();
|
||||
packetString = packetString.substring(firstMessageLength);
|
||||
|
||||
// Log.i(ANALYZERLOGTAG, "Reduzierter packetString: " + packetString);
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
int actualChatNameLength = Integer.parseInt(gesplittet[2]); // 15 bei Elliot Alderson
|
||||
|
||||
int actualChatMessageLength = Integer.parseInt(gesplittet[3]);
|
||||
// + 20 -> 19 für den Timestamp und 1 für IsDelivered
|
||||
int firstMessageLength = headerLength + actualChatMessageLength + 20;
|
||||
|
||||
Log.i("PACKET_ANALYZER", "Header-Length: " + headerLength);
|
||||
Log.i("PACKET_ANALYZER", "Länge der ersten Nachricht: " + firstMessageLength);
|
||||
Log.i("PACKET_ANALYZER", "Erste Nachricht: " + packetString.substring(0, firstMessageLength));
|
||||
|
||||
return packetCount;
|
||||
return packets;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,25 +13,27 @@ public class SoapCalls {
|
||||
|
||||
public static String CHECK_MESSAGE_IDS = "CheckChatMessagesByUUIDs";
|
||||
|
||||
public static String LOAD_CHATMESSAGES_CHUNKWISE = "LoadChatMessagesChunkwise";
|
||||
|
||||
//TODO: "app4.bewoplaner.de";//
|
||||
public static String DESTINATION_ADDRESS = "app4.bewoplaner.de";
|
||||
public static int DESTINATION_PORT = 5000;
|
||||
|
||||
public static String TOKEN_CHECK_URL = "https://" + DESTINATION_ADDRESS + "/mobil/main/checktoken?token=";
|
||||
|
||||
public static String WEB_DOKU_URL = "https://app1.bewoplaner.de/mobil/login/1234567890";
|
||||
|
||||
public static String WSDL_TARGET_NAME = "bliblablubb.org/";
|
||||
public static String SOAP_ADDRESS = "https://" + DESTINATION_ADDRESS + "/BeWoPlanerAndroid/AndroidSoapService.asmx";
|
||||
|
||||
|
||||
// public static String DESTINATION_ADDRESS = "192.168.1.103";
|
||||
// public static String DESTINATION_ADDRESS = "app4.bewoplaner.de";
|
||||
// public static int DESTINATION_PORT = 5000;
|
||||
//
|
||||
// public static String TOKEN_CHECK_URL = "http://" + DESTINATION_ADDRESS + "/bewoplanermobil/main/checktoken?token=";
|
||||
// public static String TOKEN_CHECK_URL = "https://" + DESTINATION_ADDRESS + "/mobil/main/checktoken?token=";
|
||||
//
|
||||
// public static String WEB_DOKU_URL = "http://" + DESTINATION_ADDRESS + "/bewoplanermobil/login/demo";
|
||||
// public static String WEB_DOKU_URL = "https://app1.bewoplaner.de/mobil/login/1234567890";
|
||||
//
|
||||
// static String WSDL_TARGET_NAME = "bliblablubb.org/";
|
||||
// static String SOAP_ADDRESS = "http://" + DESTINATION_ADDRESS + "/BeWoPlanerAndroid/AndroidSoapService.asmx";
|
||||
// public static String WSDL_TARGET_NAME = "bliblablubb.org/";
|
||||
// public static String SOAP_ADDRESS = "https://" + DESTINATION_ADDRESS + "/BeWoPlanerAndroid/AndroidSoapService.asmx";
|
||||
|
||||
|
||||
public static String DESTINATION_ADDRESS = "192.168.1.103";
|
||||
public static int DESTINATION_PORT = 5000;
|
||||
|
||||
public static String TOKEN_CHECK_URL = "http://" + DESTINATION_ADDRESS + "/bewoplanermobil/main/checktoken?token=";
|
||||
|
||||
public static String WEB_DOKU_URL = "http://" + DESTINATION_ADDRESS + "/bewoplanermobil/login/demo";
|
||||
|
||||
static String WSDL_TARGET_NAME = "bliblablubb.org/";
|
||||
static String SOAP_ADDRESS = "http://" + DESTINATION_ADDRESS + "/BeWoPlanerAndroid/AndroidSoapService.asmx";
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import util.BeWoLog;
|
||||
|
||||
/**
|
||||
* Created by JettenM on 05.07.2016.
|
||||
*/
|
||||
@@ -24,6 +26,7 @@ public class SoapConnectionManager {
|
||||
}
|
||||
|
||||
public static void setUser(ApplicationUser pUser) {
|
||||
BeWoLog.writeToLogFile("User wird gesetzt: " + (pUser == null ? "NULL" : pUser.toString()));
|
||||
user = pUser;
|
||||
}
|
||||
|
||||
@@ -51,7 +54,10 @@ public class SoapConnectionManager {
|
||||
return (SoapPrimitive) envelope.getResponse();
|
||||
}
|
||||
catch(IOException |XmlPullParserException exception) {
|
||||
Log.e(LOGTAG, exception.getMessage());
|
||||
if(exception.getMessage() != null) {
|
||||
Log.e(LOGTAG, exception.getMessage());
|
||||
BeWoLog.writeExceptionToLog(exception);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -97,7 +97,7 @@ public class SocketManager {
|
||||
|
||||
BeWoChatApplication.lastOnlineTS = Calendar.getInstance().getTime();
|
||||
} catch(Exception e) {
|
||||
BeWoChatApplication.writeExceptionToLog(e);
|
||||
BeWoLog.writeExceptionToLog(e);
|
||||
|
||||
if(socketConnectionFailedCallback != null) {
|
||||
socketConnectionFailedCallback.doCallback();
|
||||
@@ -128,7 +128,7 @@ public class SocketManager {
|
||||
|
||||
loginOnServer();
|
||||
} catch(Exception exception) {
|
||||
BeWoChatApplication.writeExceptionToLog(exception);
|
||||
BeWoLog.writeExceptionToLog(exception);
|
||||
|
||||
socket = null;
|
||||
try {
|
||||
@@ -139,7 +139,7 @@ public class SocketManager {
|
||||
}
|
||||
}, 11000);
|
||||
} catch(Exception exception2) {
|
||||
BeWoChatApplication.writeExceptionToLog(exception2);
|
||||
BeWoLog.writeExceptionToLog(exception2);
|
||||
exception2.printStackTrace();
|
||||
if(connectionFailureCallback != null) {
|
||||
connectionFailureCallback.doCallback();
|
||||
@@ -163,7 +163,7 @@ public class SocketManager {
|
||||
new Thread(new MessageSender(packet.getDataStream())).start();
|
||||
//TODO: komplett beenden
|
||||
} catch(Exception exception) {
|
||||
BeWoChatApplication.writeExceptionToLog(exception);
|
||||
BeWoLog.writeExceptionToLog(exception);
|
||||
exception.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
@@ -183,7 +183,7 @@ public class SocketManager {
|
||||
|
||||
new Thread(new MessageSender(packet.getDataStream())).start();
|
||||
} catch(Exception exception) {
|
||||
BeWoChatApplication.writeExceptionToLog(exception);
|
||||
BeWoLog.writeExceptionToLog(exception);
|
||||
exception.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
@@ -224,7 +224,7 @@ public class SocketManager {
|
||||
BeWoLog.writeToLogFile("SendDate wurde erfolgreich aktualisiert: " + (affectedRows == 1));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
BeWoChatApplication.writeExceptionToLog(e);
|
||||
BeWoLog.writeExceptionToLog(e);
|
||||
|
||||
try {
|
||||
Packet packet = new Packet(new String(packetToSend, "UTF-8"));
|
||||
@@ -244,7 +244,7 @@ public class SocketManager {
|
||||
|
||||
SocketManager.connectToServer("MessageSender beim gescheiterten Versenden einer Nachricht.");
|
||||
} catch (UnsupportedEncodingException e1) {
|
||||
BeWoChatApplication.writeExceptionToLog(e1);
|
||||
BeWoLog.writeExceptionToLog(e1);
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -296,142 +296,145 @@ public class SocketManager {
|
||||
stream.read(message, 0, size);
|
||||
|
||||
try {
|
||||
Packet.analyzingPackets(new String(message, "UTF-8"));
|
||||
ArrayList<Packet> packets = Packet.analyzePackets(new String(message, "UTF-8"));
|
||||
Log.i(LOGTAG, "Anzahl packets: " + packets.size());
|
||||
|
||||
chatPacket = new Packet(new String(message, "UTF-8"));
|
||||
} catch(Exception e) {
|
||||
BeWoChatApplication.writeExceptionToLog(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
for(Packet chatPacket : packets) {
|
||||
if(chatPacket.ChatDataIdentifier.equals(DataIdentifier.LOGIN_SUCCESS)) {
|
||||
loginInProgress = false;
|
||||
|
||||
if(chatPacket.ChatDataIdentifier.equals(DataIdentifier.LOGIN_SUCCESS)) {
|
||||
loginInProgress = false;
|
||||
|
||||
BeWoLog.writeToLogFile("Der Login am TCP-Server war erfolgreich. (SocketManager)");
|
||||
Log.i(LOGTAG, "Der Login war erfolgreich");
|
||||
if(initialLoginCallback != null) {
|
||||
initialLoginCallback.doCallback();
|
||||
}
|
||||
|
||||
if(loginCallback != null) {
|
||||
loginCallback.doCallback();
|
||||
}
|
||||
|
||||
if(loginCallback2 != null) {
|
||||
loginCallback2.doCallback();
|
||||
}
|
||||
|
||||
if(loginCallbackAfterConnectionLost != null) {
|
||||
loginCallbackAfterConnectionLost.doCallback();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
BeWoLog.writeToLogFile("Erhalte Packet mit Identifier: " + chatPacket.ChatDataIdentifier.name());
|
||||
Log.i("SOCKET_MANAGER", "Erhalte Packet mit Identifier: " + chatPacket.ChatDataIdentifier.name());
|
||||
|
||||
switch (chatPacket.ChatDataIdentifier) {
|
||||
case KEEP_ALIVE:
|
||||
|
||||
BeWoLog.writeToLogFile("KeepAlive-Antwort erhalten. (SocketManger)");
|
||||
|
||||
break;
|
||||
case MESSAGE:
|
||||
BeWoLog.writeToLogFile("Empfange Nacahricht(" + chatPacket.MessageId + "). (SocketManager)");
|
||||
Log.i(LOGTAG, "Empfange Nacahricht");
|
||||
|
||||
databaseHandler.addChatMessage(new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, true, chatPacket.ServerseitigeOid, false, chatPacket.MessageId));
|
||||
|
||||
break;
|
||||
|
||||
case TEAM:
|
||||
BeWoLog.writeToLogFile("Empfange Team-Nacahricht(" + chatPacket.MessageId + "). (SocketManager)");
|
||||
databaseHandler.addChatMessage(new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, true, chatPacket.ServerseitigeOid, true, chatPacket.MessageId));
|
||||
|
||||
break;
|
||||
|
||||
case MESSAGE_RESPONSE:
|
||||
BeWoLog.writeToLogFile("Empfange Response für Message: " + chatPacket.MessageId + "; (SocketManager)");
|
||||
ChatMessage cm = databaseHandler.getChatMessageById(chatPacket.ClientseitigeOid);
|
||||
|
||||
cm.MessageId = chatPacket.MessageId;
|
||||
cm.IsDelivered = true;
|
||||
|
||||
int affectedRows = databaseHandler.updateChatMessage(cm);
|
||||
BeWoLog.writeToLogFile("Durch das Aktualisieren der ChatMessage bei Response betroffene Datensätze: " + affectedRows + ". (SocketManager -> MESSAGE_RESPONSE)");
|
||||
|
||||
break;
|
||||
case STATUS_NOTIFICATION_LOGIN:
|
||||
BeWoLog.writeToLogFile("Benutzer " + chatPacket.ChatName + " ist jetzt online. (SocketManager)");
|
||||
if(!SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
|
||||
SocketManager.onlinePersonOids.add(chatPacket.SenderPersonOid);
|
||||
BeWoLog.writeToLogFile("Der Login am TCP-Server war erfolgreich. (SocketManager)");
|
||||
Log.i(LOGTAG, "Der Login war erfolgreich");
|
||||
if(initialLoginCallback != null) {
|
||||
initialLoginCallback.doCallback();
|
||||
}
|
||||
|
||||
boolean isAlreadyLoggedIn = false;
|
||||
for(ChatEntity entity : SocketManager.onlineEntities)
|
||||
{
|
||||
if(entity.getOid() == chatPacket.SenderPersonOid) {
|
||||
isAlreadyLoggedIn = true;
|
||||
if(loginCallback != null) {
|
||||
loginCallback.doCallback();
|
||||
}
|
||||
|
||||
if(loginCallback2 != null) {
|
||||
loginCallback2.doCallback();
|
||||
}
|
||||
|
||||
if(loginCallbackAfterConnectionLost != null) {
|
||||
loginCallbackAfterConnectionLost.doCallback();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
BeWoLog.writeToLogFile("Erhalte Packet mit Identifier: " + chatPacket.ChatDataIdentifier.name());
|
||||
Log.i("SOCKET_MANAGER", "Erhalte Packet mit Identifier: " + chatPacket.ChatDataIdentifier.name());
|
||||
|
||||
switch (chatPacket.ChatDataIdentifier) {
|
||||
case KEEP_ALIVE:
|
||||
|
||||
BeWoLog.writeToLogFile("KeepAlive-Antwort erhalten. (SocketManger)");
|
||||
|
||||
break;
|
||||
case MESSAGE:
|
||||
BeWoLog.writeToLogFile("Empfange Nacahricht(" + chatPacket.MessageId + "). (SocketManager)");
|
||||
Log.i(LOGTAG, "Empfange Nacahricht");
|
||||
|
||||
databaseHandler.addChatMessage(new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, true, chatPacket.ServerseitigeOid, false, chatPacket.MessageId));
|
||||
|
||||
break;
|
||||
|
||||
case TEAM:
|
||||
BeWoLog.writeToLogFile("Empfange Team-Nacahricht(" + chatPacket.MessageId + "). (SocketManager)");
|
||||
databaseHandler.addChatMessage(new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, true, chatPacket.ServerseitigeOid, true, chatPacket.MessageId));
|
||||
|
||||
break;
|
||||
|
||||
case MESSAGE_RESPONSE:
|
||||
BeWoLog.writeToLogFile("Empfange Response für Message: " + chatPacket.MessageId + "; (SocketManager)");
|
||||
ChatMessage cm = databaseHandler.getChatMessageById(chatPacket.ClientseitigeOid);
|
||||
|
||||
cm.MessageId = chatPacket.MessageId;
|
||||
cm.IsDelivered = true;
|
||||
|
||||
int affectedRows = databaseHandler.updateChatMessage(cm);
|
||||
BeWoLog.writeToLogFile("Durch das Aktualisieren der ChatMessage bei Response betroffene Datensätze: " + affectedRows + ". (SocketManager -> MESSAGE_RESPONSE)");
|
||||
|
||||
break;
|
||||
case STATUS_NOTIFICATION_LOGIN:
|
||||
BeWoLog.writeToLogFile("Benutzer " + chatPacket.ChatName + " ist jetzt online. (SocketManager)");
|
||||
if(!SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
|
||||
SocketManager.onlinePersonOids.add(chatPacket.SenderPersonOid);
|
||||
}
|
||||
|
||||
boolean isAlreadyLoggedIn = false;
|
||||
for(ChatEntity entity : SocketManager.onlineEntities)
|
||||
{
|
||||
if(entity.getOid() == chatPacket.SenderPersonOid) {
|
||||
isAlreadyLoggedIn = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!isAlreadyLoggedIn) {
|
||||
SocketManager.onlineEntities.add(new ChatEntity(chatPacket.SenderPersonOid, false, chatPacket.IsEmployee));
|
||||
}
|
||||
|
||||
break;
|
||||
case STATUS_NOTIFICATION_LOGOUT:
|
||||
BeWoLog.writeToLogFile("Benutzer " + chatPacket.ChatName + " ist jetzt offline. (SocketManager)");
|
||||
if(SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
|
||||
SocketManager.onlinePersonOids.remove(Integer.valueOf(chatPacket.SenderPersonOid));
|
||||
}
|
||||
|
||||
ChatEntity entity2delete = Util.getChatEntityFromOnlineEntitiesByOid(chatPacket.SenderPersonOid, chatPacket.ChatDataIdentifier == DataIdentifier.TEAM);
|
||||
|
||||
SocketManager.onlineEntities.remove(entity2delete);
|
||||
|
||||
break;
|
||||
|
||||
case STATUS_NOTIFICATION_LOGIN_BROADCAST:
|
||||
BeWoLog.writeToLogFile("Aktualisiere Onlinestatusliste. (SocketManager)");
|
||||
String[] onlinePersons = chatPacket.ChatMessage.split(",");
|
||||
|
||||
for (String onlinePerson : onlinePersons) {
|
||||
|
||||
int personOid = Integer.parseInt(onlinePerson);
|
||||
|
||||
if(!SocketManager.onlinePersonOids.contains(personOid)) {
|
||||
SocketManager.onlinePersonOids.add(personOid);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case STATUS_REQUEST:
|
||||
BeWoLog.writeToLogFile("Empfange eingeloggte User. (SocketManager)");
|
||||
String contactsCsv = chatPacket.ChatMessage;
|
||||
|
||||
String[] stringOids = contactsCsv.split(",");
|
||||
|
||||
SocketManager.onlinePersonOids.clear();
|
||||
|
||||
for(String item : stringOids) {
|
||||
SocketManager.onlinePersonOids.add(Integer.valueOf(item));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
BeWoLog.writeExceptionToLog(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(!isAlreadyLoggedIn) {
|
||||
SocketManager.onlineEntities.add(new ChatEntity(chatPacket.SenderPersonOid, false, chatPacket.IsEmployee));
|
||||
}
|
||||
|
||||
break;
|
||||
case STATUS_NOTIFICATION_LOGOUT:
|
||||
BeWoLog.writeToLogFile("Benutzer " + chatPacket.ChatName + " ist jetzt offline. (SocketManager)");
|
||||
if(SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
|
||||
SocketManager.onlinePersonOids.remove(Integer.valueOf(chatPacket.SenderPersonOid));
|
||||
}
|
||||
|
||||
ChatEntity entity2delete = Util.getChatEntityFromOnlineEntitiesByOid(chatPacket.SenderPersonOid, chatPacket.ChatDataIdentifier == DataIdentifier.TEAM);
|
||||
|
||||
SocketManager.onlineEntities.remove(entity2delete);
|
||||
|
||||
break;
|
||||
|
||||
case STATUS_NOTIFICATION_LOGIN_BROADCAST:
|
||||
BeWoLog.writeToLogFile("Aktualisiere Onlinestatusliste. (SocketManager)");
|
||||
String[] onlinePersons = chatPacket.ChatMessage.split(",");
|
||||
|
||||
for (String onlinePerson : onlinePersons) {
|
||||
|
||||
int personOid = Integer.parseInt(onlinePerson);
|
||||
|
||||
if(!SocketManager.onlinePersonOids.contains(personOid)) {
|
||||
SocketManager.onlinePersonOids.add(personOid);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case STATUS_REQUEST:
|
||||
BeWoLog.writeToLogFile("Empfange eingeloggte User. (SocketManager)");
|
||||
String contactsCsv = chatPacket.ChatMessage;
|
||||
|
||||
String[] stringOids = contactsCsv.split(",");
|
||||
|
||||
SocketManager.onlinePersonOids.clear();
|
||||
|
||||
for(String item : stringOids) {
|
||||
SocketManager.onlinePersonOids.add(Integer.valueOf(item));
|
||||
}
|
||||
|
||||
break;
|
||||
if(uiHandler != null) {
|
||||
uiHandler.updateUserInterface(chatPacket);
|
||||
} else {
|
||||
Log.e("ERROR_SOCKETLISTENER", "uiHandler ist null");
|
||||
}
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
BeWoChatApplication.writeExceptionToLog(e);
|
||||
BeWoLog.writeExceptionToLog(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(uiHandler != null) {
|
||||
uiHandler.updateUserInterface(chatPacket);
|
||||
} else {
|
||||
Log.e("ERROR_SOCKETLISTENER", "uiHandler ist null");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BeWoLog.writeToLogFile("Socket ist null. (SocketListener)");
|
||||
@@ -441,7 +444,7 @@ public class SocketManager {
|
||||
}
|
||||
}
|
||||
} catch(Exception exception) {
|
||||
BeWoChatApplication.writeExceptionToLog(exception);
|
||||
BeWoLog.writeExceptionToLog(exception);
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -473,7 +476,7 @@ public class SocketManager {
|
||||
return res1.toString();
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
BeWoChatApplication.writeExceptionToLog(ex);
|
||||
BeWoLog.writeExceptionToLog(ex);
|
||||
Log.e("GET_MAC_ADDRESS", ex.getMessage());
|
||||
}
|
||||
|
||||
|
||||
@@ -60,4 +60,14 @@ public class BeWoLog {
|
||||
|
||||
return logFile.delete();
|
||||
}
|
||||
|
||||
public static void writeExceptionToLog(Throwable ex) {
|
||||
String logText = "Ausnahme: " + ex.toString() + "; Message: " + ex.getMessage() + "; Cause: " + ex.getCause();
|
||||
for(StackTraceElement ste : ex.getStackTrace()) {
|
||||
String steAsString = ste.toString();
|
||||
logText += "\t" + steAsString;
|
||||
}
|
||||
|
||||
writeToLogFile(logText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,7 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
*/
|
||||
public class SecurityUtils {
|
||||
private static final byte[] iV16 = { (byte)35, (byte)138, (byte)177, (byte)253, (byte)227, (byte)63, (byte)2, (byte)27, (byte)9, (byte)17, (byte)192, (byte)230, (byte)1, (byte)24, (byte)165, (byte)99 };
|
||||
|
||||
public static final byte[] key = { (byte)174, (byte)130, (byte)219, (byte)185, (byte)185, (byte)221, (byte)96, (byte)50, (byte)37, (byte)212, (byte)81, (byte)121, (byte)71, (byte)206, (byte)130, (byte)153};
|
||||
private static final byte[] key = { (byte)174, (byte)130, (byte)219, (byte)185, (byte)185, (byte)221, (byte)96, (byte)50, (byte)37, (byte)212, (byte)81, (byte)121, (byte)71, (byte)206, (byte)130, (byte)153 };
|
||||
|
||||
private static final IvParameterSpec ivSpec16 = new IvParameterSpec(iV16);
|
||||
private static final String transformation = "AES/CBC/PKCS5Padding";
|
||||
|
||||
Reference in New Issue
Block a user