Diverse Änderungen am ChatServer

This commit is contained in:
staccatomamba
2016-09-13 11:32:25 +02:00
parent e3dd894a21
commit 988ac1ff4c
52 changed files with 1977 additions and 1402 deletions

View File

@@ -96,6 +96,7 @@
<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/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" />

View File

@@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="beyondsoft.bewomitarbeiterapp">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
@@ -14,25 +14,20 @@
<activity
android:name=".SplashScreenActivity"
android:theme="@android:style/Theme.NoTitleBar">
android:theme="@android:style/Theme.NoTitleBar"
android:configChanges="orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivityMitarbeiter"
android:label="@string/app_name_haupt">
<intent-filter>
<action android:name="android.intent.activity_main_activity_mitarbeiter"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".KontaktChatActivity"
android:label="@string/app_name_kontakt">
android:configChanges="orientation"
android:screenOrientation="portrait"
android:label="@string/contact_list_activity_name">
<intent-filter>
<action android:name="android.intent.kontakt_list_chat"/>
@@ -41,7 +36,9 @@
</activity>
<activity
android:name=".WebdokuActivity"
android:label="@string/app_name">
android:configChanges="orientation"
android:screenOrientation="portrait"
android:label="@string/Doku">
<intent-filter>
<action android:name="android.intent.webdoku"/>
@@ -50,6 +47,8 @@
</activity>
<activity
android:name=".ChatActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:label="@string/app_name_chat">
<intent-filter>
<action android:name="android.intent.chat"/>
@@ -58,18 +57,30 @@
</intent-filter>
</activity>
<!-- android:noHistory="true" -->
<activity
android:name=".LoginActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:label="@string/title_activity_login">
</activity>
<!--<activity android:name=".TokenActivity">
</activity>-->
<service
android:name="com.octo.android.robospice.UncachedSpiceService"
android:exported="false" />
<receiver
android:name="util.ConnectivityReceiver"
android:enabled="true">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<receiver android:name="util.NotificationBroadcastReceiver">
<intent-filter>
<action android:name="notification_cancelled"/>
</intent-filter>
</receiver>
</application>
</manifest>

View File

@@ -24,6 +24,8 @@ import soapConnection.SoapConnectionManager;
*/
public class DatabaseHandler extends SQLiteOpenHelper {
private static final String LOGTAG = "DATABASE_HANDLER";
//DataBase version
private static final int DATABASE_VERSION = 1;
@@ -62,8 +64,6 @@ public class DatabaseHandler extends SQLiteOpenHelper {
private static DatabaseHandler mInstance = null;
private Context mContext;
public static DatabaseHandler getInstance(Context context) {
if(mInstance == null) {
mInstance = new DatabaseHandler(context.getApplicationContext());
@@ -74,7 +74,6 @@ public class DatabaseHandler extends SQLiteOpenHelper {
private DatabaseHandler(Context context){
super(context,DATABASE_NAME, null, DATABASE_VERSION);
this.mContext = context;
}
public void clearDatabase() {
@@ -88,8 +87,6 @@ public class DatabaseHandler extends SQLiteOpenHelper {
deleteQuery = "DELETE FROM " + TABLE_CONTACTS;
db.execSQL(deleteQuery);
db.close();
}
public void onCreate(SQLiteDatabase db) {
@@ -127,21 +124,20 @@ public class DatabaseHandler extends SQLiteOpenHelper {
}
public void insertOwnerOid(int ownerOid) {
SQLiteDatabase db = this.getWritableDatabase();
SQLiteDatabase writableDatabase = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_ID_OWNER, ownerOid);
db.insert(TABLE_DATABASEOWNER, null, values);
db.close();
writableDatabase.insertOrThrow(TABLE_DATABASEOWNER, null, values);
}
public int getOwnerOid() {
SQLiteDatabase db = this.getReadableDatabase();
SQLiteDatabase readableDatabase = this.getReadableDatabase();
String selectQuery = "SELECT * FROM " + TABLE_DATABASEOWNER;
Cursor cursor = db.rawQuery(selectQuery, null);
Cursor cursor = readableDatabase.rawQuery(selectQuery, null);
int ownerOid = 0;
@@ -150,7 +146,6 @@ public class DatabaseHandler extends SQLiteOpenHelper {
}
cursor.close();
db.close();
return ownerOid;
}
@@ -182,18 +177,13 @@ public class DatabaseHandler extends SQLiteOpenHelper {
if(db.inTransaction()) {
db.endTransaction();
}
db.close();
}
}
public long addChatMessage(ChatMessage message) {
SQLiteDatabase db = this.getWritableDatabase();
SQLiteDatabase writableDatabase = this.getWritableDatabase();
long rowId = db.insert(TABLE_CHATMESSAGE, null, fillValuesForChatMessage(message));
db.close();
return rowId;
return writableDatabase.insertOrThrow(TABLE_CHATMESSAGE, null, fillValuesForChatMessage(message));
}
private ContentValues fillValuesForChatMessage(ChatMessage message) {
@@ -211,7 +201,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
}
public int updateChatMessage(ChatMessage message) {
SQLiteDatabase db = this.getWritableDatabase();
SQLiteDatabase writableDatabase = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_SENDER_PERSON_OID_CHATMESSAGE, message.SenderPersonOid);
@@ -222,10 +212,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
values.put(KEY_SERVERSEITIGE_OID_CHATMESSAGE, message.ServerseitigeOid);
values.put(KEY_IS_TEAM_CHATMESSAGE, message.IsTeam ? 1 : 0);
int result = db.update(TABLE_CHATMESSAGE, values, KEY_ID_CHATMESSAGE + " = ?", new String[] { String.valueOf(message.Id)});
db.close();
return result;
return writableDatabase.update(TABLE_CHATMESSAGE, values, KEY_ID_CHATMESSAGE + " = ?", new String[] { String.valueOf(message.Id)});
}
public ArrayList<Integer> getExistingChatMessageIds() {
@@ -244,7 +231,6 @@ public class DatabaseHandler extends SQLiteOpenHelper {
}
cursor.close();
db.close();
return result;
}
@@ -265,7 +251,6 @@ public class DatabaseHandler extends SQLiteOpenHelper {
}
cursor.close();
db.close();
return result;
}
@@ -289,7 +274,6 @@ public class DatabaseHandler extends SQLiteOpenHelper {
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CHATMESSAGE);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_DATABASEOWNER);
@@ -298,7 +282,7 @@ public class DatabaseHandler extends SQLiteOpenHelper {
}
public void addContact(ContactListItem contact) {
SQLiteDatabase db = this.getWritableDatabase();
SQLiteDatabase writableDatabase = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_KONTAKT_NAME, contact.getChatName());
@@ -308,22 +292,20 @@ public class DatabaseHandler extends SQLiteOpenHelper {
values.put(KEY_TEAM_MEMBER_NAMES, contact.teamMemberNames);
values.put(KEY_TEAM_MEMBER_OIDS, contact.teamMemberOids);
db.insert(TABLE_CONTACTS, null, values);
db.close();
writableDatabase.insertOrThrow(TABLE_CONTACTS, null, values);
}
public ChatMessage getChatMessageById(int id) {
SQLiteDatabase db = this.getReadableDatabase();
SQLiteDatabase readableDatabase = this.getReadableDatabase();
Cursor cursor = db.query(
Cursor cursor = readableDatabase.query(
TABLE_CHATMESSAGE,
new String[] {KEY_ID_CHATMESSAGE, KEY_SENDER_PERSON_OID_CHATMESSAGE, KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, KEY_INSTS_CHATMESSAGE, KEY_CHAT_TEXT_CHATMESSAGE, KEY_IS_DELIVERED_CHATMESSAGE, KEY_SERVERSEITIGE_OID_CHATMESSAGE, KEY_IS_TEAM_CHATMESSAGE},
KEY_ID_CHATMESSAGE + "=?",
new String[]{String.valueOf(id)},
null, null, null, null);
if(cursor != null) {
cursor.moveToFirst();
if(cursor != null && cursor.moveToFirst()){
int messageId = cursor.getInt(0);
int senderPersonOid = cursor.getInt(1);
@@ -335,22 +317,19 @@ public class DatabaseHandler extends SQLiteOpenHelper {
boolean isTeam = cursor.getInt(7) == 1;
cursor.close();
db.close();
return new ChatMessage(messageId, senderPersonOid, recipientPersonOid, insTs, chatText, isDelivered, serverseitigeOid, isTeam);
}
db.close();
return null;
}
public ArrayList<ChatMessage> getMessagesForRecipient(int recipientOid) {
ArrayList<ChatMessage> messages = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
SQLiteDatabase readableDatabase = this.getReadableDatabase();
Cursor cursor = db.query(
Cursor cursor = readableDatabase.query(
TABLE_CHATMESSAGE,
new String[] {KEY_ID_CHATMESSAGE, KEY_SENDER_PERSON_OID_CHATMESSAGE, KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, KEY_INSTS_CHATMESSAGE, KEY_CHAT_TEXT_CHATMESSAGE, KEY_IS_DELIVERED_CHATMESSAGE, KEY_SERVERSEITIGE_OID_CHATMESSAGE, KEY_IS_TEAM_CHATMESSAGE},
KEY_SENDER_PERSON_OID_CHATMESSAGE + "=? AND " + KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + "=? OR " + KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + "=? AND " + KEY_SENDER_PERSON_OID_CHATMESSAGE + "=?",
@@ -375,7 +354,6 @@ public class DatabaseHandler extends SQLiteOpenHelper {
}
cursor.close();
db.close();
return messages;
}
@@ -383,9 +361,9 @@ public class DatabaseHandler extends SQLiteOpenHelper {
public ArrayList<ChatMessage> getMessagesForTeam(int teamOid) {
ArrayList<ChatMessage> messages = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
SQLiteDatabase readableDatabase = this.getReadableDatabase();
Cursor cursor = db.query(
Cursor cursor = readableDatabase.query(
TABLE_CHATMESSAGE,
new String[] {KEY_ID_CHATMESSAGE, KEY_SENDER_PERSON_OID_CHATMESSAGE, KEY_RECIPIENT_PERSON_OID_CHATMESSAGE, KEY_INSTS_CHATMESSAGE, KEY_CHAT_TEXT_CHATMESSAGE, KEY_IS_DELIVERED_CHATMESSAGE, KEY_SERVERSEITIGE_OID_CHATMESSAGE, KEY_IS_TEAM_CHATMESSAGE},
KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + "=? AND " + KEY_IS_TEAM_CHATMESSAGE + "= 1",
@@ -411,16 +389,13 @@ public class DatabaseHandler extends SQLiteOpenHelper {
cursor.close();
db.close();
return messages;
}
public ContactListItem getContact(int id) {
SQLiteDatabase readableDatabase = this.getReadableDatabase();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS,
Cursor cursor = readableDatabase.query(TABLE_CONTACTS,
new String[]{
KEY_ID,
KEY_KONTAKT_NAME,
@@ -447,13 +422,10 @@ public class DatabaseHandler extends SQLiteOpenHelper {
ContactListItem contact = new ContactListItem(contactId, contactName, contactPersonOid, contactPicture, contactIsTeam, teamMemberOids, teamMemberNames);
cursor.close();
db.close();
return contact;
}
db.close();
return null;
}
@@ -462,8 +434,8 @@ public class DatabaseHandler extends SQLiteOpenHelper {
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
SQLiteDatabase writableDatabase = this.getWritableDatabase();
Cursor cursor = writableDatabase.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
@@ -481,13 +453,44 @@ public class DatabaseHandler extends SQLiteOpenHelper {
}
cursor.close();
db.close();
return contactList;
}
public ArrayList<ChatMessage> getAllChatMessages() {
ArrayList<ChatMessage> result = new ArrayList<>();
String selectQuery = "SELECT * FROM " + TABLE_CHATMESSAGE;
SQLiteDatabase readableDatabase = this.getReadableDatabase();
Cursor cursor = readableDatabase.rawQuery(selectQuery, null);
if(cursor.moveToFirst()) {
do {
ChatMessage message = new ChatMessage(
cursor.getInt(0),
cursor.getInt(1),
cursor.getInt(2),
getDateFromString(cursor.getString(3)),
cursor.getString(4),
cursor.getInt(5) == 1,
cursor.getInt(6),
cursor.getInt(7) == 1
);
result.add(message);
} while(cursor.moveToNext());
cursor.close();
}
return result;
}
public int updateContact(ContactListItem contact) {
SQLiteDatabase db = this.getWritableDatabase();
SQLiteDatabase writableDatabase = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_KONTAKT_NAME, contact.getChatName());
@@ -497,23 +500,18 @@ public class DatabaseHandler extends SQLiteOpenHelper {
values.put(KEY_TEAM_MEMBER_NAMES, contact.teamMemberNames);
values.put(KEY_TEAM_MEMBER_OIDS, contact.teamMemberOids);
int result = db.update(TABLE_CONTACTS, values, KEY_ID + " = ?", new String[] { String.valueOf(contact.getId()) });
db.close();
return result;
return writableDatabase.update(TABLE_CONTACTS, values, KEY_ID + " = ?", new String[] { String.valueOf(contact.getId()) });
}
public void deleteContacts(ContactListItem contact){
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_CONTACTS, KEY_ID + " = ?", new String[] { String.valueOf(contact.getId()) });
db.close();
SQLiteDatabase writableDatabase = this.getWritableDatabase();
writableDatabase.delete(TABLE_CONTACTS, KEY_ID + " = ?", new String[] { String.valueOf(contact.getId()) });
}
public int getContactsCount(){
String countQuery = "SELECT COUNT(*) FROM " + TABLE_CONTACTS;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
SQLiteDatabase readableDatabase = this.getReadableDatabase();
Cursor cursor = readableDatabase.rawQuery(countQuery, null);
int result = 0;
@@ -522,32 +520,30 @@ public class DatabaseHandler extends SQLiteOpenHelper {
}
cursor.close();
db.close();
return result;
}
public byte[] getUserImage(Integer personOid) {
SQLiteDatabase db = this.getReadableDatabase();
SQLiteDatabase readableDatabase = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS, new String[] {KEY_PICTURE_BLOB}, KEY_PERSONOID + " = " + personOid, null, null, null, null);
Cursor cursor = readableDatabase.query(TABLE_CONTACTS, new String[] {KEY_PICTURE_BLOB}, KEY_PERSONOID + " = " + personOid, null, null, null, null);
byte[] picture = null;
if(cursor != null && cursor.moveToFirst()) {
cursor.getBlob(0);
}
picture = cursor.getBlob(0);
cursor.close();
db.close();
cursor.close();
}
return picture;
}
public ContactListItem getContactByPersonOid(int personOid, boolean isTeam) {
SQLiteDatabase db = this.getReadableDatabase();
SQLiteDatabase readableDatabase = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_CONTACTS,
Cursor cursor = readableDatabase.query(TABLE_CONTACTS,
new String[]{
KEY_ID,
KEY_KONTAKT_NAME,
@@ -573,15 +569,53 @@ public class DatabaseHandler extends SQLiteOpenHelper {
ContactListItem contact = new ContactListItem(contactId, contactName, contactPersonOid, contactPicture, contactIsTeam, teamMemberOids, teamMemberNames);
cursor.close();
db.close();
return contact;
} else {
Log.i("DATABASE_HANDLER", "Keinen Kontakt mit PersonOid " + personOid + " gefunden.");
Log.i(LOGTAG, "Keinen Kontakt mit PersonOid " + personOid + " gefunden.");
}
db.close();
return null;
}
public ArrayList<ChatMessage> getUnsentChatMessages() {
ArrayList<ChatMessage> messages = new ArrayList<>();
SQLiteDatabase readableDatabase = this.getReadableDatabase();
Cursor cursor = readableDatabase.query(TABLE_CHATMESSAGE,
new String[] {
KEY_ID_CHATMESSAGE,
KEY_SENDER_PERSON_OID_CHATMESSAGE,
KEY_RECIPIENT_PERSON_OID_CHATMESSAGE,
KEY_INSTS_CHATMESSAGE,
KEY_CHAT_TEXT_CHATMESSAGE,
KEY_IS_DELIVERED_CHATMESSAGE,
KEY_SERVERSEITIGE_OID_CHATMESSAGE,
KEY_IS_TEAM_CHATMESSAGE
},
KEY_IS_DELIVERED_CHATMESSAGE + " =? AND " + KEY_SENDER_PERSON_OID_CHATMESSAGE + " =?",
new String[] {String.valueOf(0), String.valueOf(SoapConnectionManager.User.getPersonOid())}, null, null, null, null);
if(cursor.moveToFirst()) {
do{
ChatMessage message = new ChatMessage(
cursor.getInt(0),
cursor.getInt(1),
cursor.getInt(2),
getDateFromString(cursor.getString(3)),
cursor.getString(4),
cursor.getInt(5) == 1,
cursor.getInt(6),
cursor.getInt(7) == 1
);
messages.add(message);
} while(cursor.moveToNext());
}
cursor.close();
return messages;
}
}

View File

@@ -5,19 +5,38 @@ import android.app.NotificationManager;
import android.content.Context;
import android.util.Log;
import util.ConnectivityReceiver;
/**
* Created by JettenM on 24.08.2016.
*/
public class BeWoChatApplication extends Application {
private Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler;
private static BeWoChatApplication mInstance;
@Override
public void onCreate() {
super.onCreate();
mInstance = this;
}
public static synchronized BeWoChatApplication getInstance() {
return mInstance;
}
public void setConnectivityListener(ConnectivityReceiver.ConnectivityReceiverListener listener) {
ConnectivityReceiver.connectivityReceiverListener = listener;
}
public BeWoChatApplication() {
defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.UncaughtExceptionHandler uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
Log.e("UNCAUGHT_EXCEPTION", "Eine unbehandelte Ausnahme ist aufgetreten!");
Log.e("UNCAUGHT_EXCEPTION", "Eine unbehandelte Ausnahme ist aufgetreten!\n" + ex.getMessage());
ex.printStackTrace();
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

View File

@@ -1,10 +1,6 @@
package beyondsoft.bewomitarbeiterapp;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
@@ -15,10 +11,8 @@ import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.util.Base64;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -43,21 +37,13 @@ import com.octo.android.robospice.request.listener.RequestListener;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapPrimitive;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.lang.reflect.Type;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Random;
import javax.crypto.NoSuchPaddingException;
import Database.DatabaseHandler;
import entities.ChatMessage;
@@ -70,13 +56,13 @@ import soapConnection.SoapConnectionManager;
import tcpConnection.SocketManager;
import tcpConnection.UIHandler;
import util.ChatMessageDeserializer;
import util.SecurityUtils;
import util.ConnectivityReceiver;
import util.Util;
/**
* Created by bib on 03.05.2016.
*/
public class ChatActivity extends ActionBarActivity {
public class ChatActivity extends ActionBarActivity implements ConnectivityReceiver.ConnectivityReceiverListener {
private DatabaseHandler databaseHandler;
protected EditText text;
@@ -98,6 +84,16 @@ public class ChatActivity extends ActionBarActivity {
private View mCustomView;
private final static String LOGTAG = "CHAT_ACTIVITY";
@Override
public void onNetworkConnectionChanged(boolean isConnected) {
//TODO: Socket neustarten
// Broken Pipe, weil die Internetverbindung abgerissen ist
Util.reconnectWithServer(isConnected, ChatActivity.this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -129,6 +125,8 @@ public class ChatActivity extends ActionBarActivity {
teamMemberOids = zielkorb.getString("TeamMemberOids");
teamMemberNames = zielkorb.getString("TeamMemberNames");
Log.i(LOGTAG, "onCreate aufgerufen");
ReloadChatView(recipientName, recipientPersonOid, bildArray, isTeam, teamMemberOids, teamMemberNames);
}
@@ -145,7 +143,9 @@ public class ChatActivity extends ActionBarActivity {
TextView titlename = (TextView) mCustomView.findViewById(R.id.PersonalName);
ImageView titlepic = (ImageView) mCustomView.findViewById(R.id.PersonalPic);
status.setImageResource((SocketManager.onlinePersonOids.contains(recipientPersonOid) ? R.drawable.statusonline : R.drawable.statusoffline));
if(!isTeam) {
status.setImageResource((SocketManager.onlinePersonOids.contains(recipientPersonOid) ? R.drawable.statusonline : R.drawable.statusoffline));
}
Bitmap customerImage;
@@ -167,47 +167,22 @@ public class ChatActivity extends ActionBarActivity {
@Override
public void updateUserInterface(final Packet chatPacket) {
try {
Log.i("CHAT_SOCKET_LISTENER", "Nachricht vom Typ " + chatPacket.ChatDataIdentifier.name() + " empfangen");
switch(chatPacket.ChatDataIdentifier) {
case MESSAGE:
listView.post(new Runnable() {
@Override
public void run() {
ChatMessage message = new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, false, chatPacket.ServerseitigeOid, false);
databaseHandler.addChatMessage(message);
if(chatPacket.SenderPersonOid == recipientPersonOid) {
chatMessages.add(message);
chatMessages.add(new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, true, chatPacket.ServerseitigeOid, false));
adapter.notifyDataSetChanged();
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), "ChatName: " + chatPacket.ChatName, Toast.LENGTH_LONG).show();
}
});
Util.SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.SenderPersonOid, false, null, null, getApplicationContext());
}
}
});
break;
case MESSAGE_RESPONSE:
ChatMessage cm = databaseHandler.getChatMessageById(chatPacket.ClientseitigeOid);
cm.ServerseitigeOid = chatPacket.ServerseitigeOid;
databaseHandler.updateChatMessage(cm);
break;
case STATUS_NOTIFICATION_LOGIN:
if(!SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
SocketManager.onlinePersonOids.add(chatPacket.SenderPersonOid);
}
if(chatPacket.SenderPersonOid == recipientPersonOid) {
runOnUiThread(new Runnable() {
@Override
@@ -220,29 +195,23 @@ public class ChatActivity extends ActionBarActivity {
break;
case STATUS_NOTIFICATION_LOGOUT:
if(SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
SocketManager.onlinePersonOids.remove(Integer.valueOf(chatPacket.SenderPersonOid));
if(chatPacket.SenderPersonOid == recipientPersonOid) {
runOnUiThread(new Runnable() {
@Override
public void run() {
ImageView status = (ImageView) mCustomView.findViewById(R.id.status);
status.setImageResource(R.drawable.statusoffline);
}
});
}
runOnUiThread(new Runnable() {
@Override
public void run() {
ImageView status = (ImageView) mCustomView.findViewById(R.id.status);
status.setImageResource(R.drawable.statusoffline);
}
});
break;
case TEAM:
listView.post(new Runnable() {
@Override
public void run() {
ChatMessage message = new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, false, chatPacket.ServerseitigeOid, true);
databaseHandler.addChatMessage(message);
if(isTeam && chatPacket.RecipientPersonOid == recipientPersonOid) {
chatMessages.add(message);
chatMessages.add(new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, true, chatPacket.ServerseitigeOid, true));
adapter.notifyDataSetChanged();
} else {
Util.SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.RecipientPersonOid, true, teamMemberOids, teamMemberNames, getApplicationContext());
@@ -281,6 +250,7 @@ public class ChatActivity extends ActionBarActivity {
final ChatMessage message = new ChatMessage(packet.SenderPersonOid, packet.RecipientPersonOid, packet.MessageTimeStamp, packet.ChatMessage, false, 0, isTeam);
Log.i("MESSAGE_TRACER", "ChatActivity: Speichere Nachricht in der Datenbank " + message.ChatText);
long coid = databaseHandler.addChatMessage(message);
packet.ClientseitigeOid = Long.valueOf(coid).intValue();
@@ -305,6 +275,8 @@ public class ChatActivity extends ActionBarActivity {
ArrayList<Integer> test = isTeam ? databaseHandler.getExistingTeamChatMessageIds() : databaseHandler.getExistingChatMessageIds();
Log.i(LOGTAG, "Chat-Messages in der Datenbank: " + test.size());
String pExceptions = "";
for(int i = 0; i < test.size(); i++) {
pExceptions += test.get(i);
@@ -328,19 +300,19 @@ public class ChatActivity extends ActionBarActivity {
public void onResume() {
SocketManager.uiHandler = chatUIHandler;
BeWoChatApplication.getInstance().setConnectivityListener(this);
super.onResume();
}
@Override
public void onStop(){
spiceManager.shouldStop();
databaseHandler.close();
super.onStop();
}
@Override
public void onPause() {
databaseHandler.close();
super.onPause();
}
@@ -350,6 +322,7 @@ public class ChatActivity extends ActionBarActivity {
spiceManager.start(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menue_chat, menu);
@@ -359,8 +332,18 @@ public class ChatActivity extends ActionBarActivity {
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_delet_Storage:
recreate(); // ---> gegebenenfals umändern, aber fürs erste reichts
case R.id.action_logout:
SocketManager.logout();
Intent intent = new Intent(ChatActivity.this, LoginActivity.class);
ChatActivity.this.startActivity(intent);
return true;
case R.id.action_doku:
Intent dokuActivity = new Intent(ChatActivity.this, WebdokuActivity.class);
ChatActivity.this.startActivity(dokuActivity);
return true;
default:
return super.onOptionsItemSelected(item);
@@ -378,10 +361,10 @@ public class ChatActivity extends ActionBarActivity {
String tMemberOids = zielkorb.getString("TeamMemberOids");
String tMemberNames = zielkorb.getString("TeamMemberNames");
Toast.makeText(getApplicationContext(), "" + blahIsTeam, Toast.LENGTH_LONG).show();
byte[] imageAsByteArray = databaseHandler.getUserImage(rpoid);
Log.i("ON_NEW_INTENT", "Erzeuge neuen Intent");
ReloadChatView(rn, rpoid, imageAsByteArray, blahIsTeam, tMemberOids, tMemberNames);
}
@@ -428,6 +411,19 @@ public class ChatActivity extends ActionBarActivity {
final ArrayList<ChatMessage> result = gson.fromJson(soapPrimitive.toString(), listType);
Log.i(LOGTAG, "Chat-Messages aus der Serveranfrage: " + result.size());
String abc = "";
for(ChatMessage m : result) {
abc += "\t" + m.ChatText;
if(result.indexOf(m) < result.size() - 1) {
abc += "\n";
}
}
Log.i(LOGTAG, "Heruntergeladene Nachrichten:\n" + abc);
databaseHandler.addChatMessages(result);
listView.post(new Runnable() {

View File

@@ -49,7 +49,7 @@ public class KontaktAdapter extends ArrayAdapter<ContactListItem> {
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.kontakt_list_chat, parent, false);
View rowView = inflater.inflate(R.layout.contact_listview_item, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
minitext = (TextView) rowView.findViewById(R.id.subtitle);

View File

@@ -1,19 +1,16 @@
package beyondsoft.bewomitarbeiterapp;
import android.app.ListActivity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
@@ -32,7 +29,6 @@ import java.io.ByteArrayOutputStream;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import Database.DatabaseHandler;
import entities.ChatMessage;
@@ -43,164 +39,189 @@ import soapConnection.SoapCalls;
import soapConnection.SoapConnectionManager;
import tcpConnection.SocketManager;
import tcpConnection.UIHandler;
import util.ConnectivityReceiver;
import util.Util;
/**
* Created by bib on 02.05.2016.
*/
public class KontaktChatActivity extends ListActivity {
public class KontaktChatActivity extends ActionBarActivity implements ConnectivityReceiver.ConnectivityReceiverListener {
private SpiceManager spiceManager = new SpiceManager(UncachedSpiceService.class);
private DatabaseHandler databaseHandler;
private UIHandler kontaktChatUIHandler;
// private UIHandler kontaktChatUIHandler;
public static ListView listView;
ArrayList<ContactListItem> contactList = new ArrayList<>();
@Override
public void onNetworkConnectionChanged(boolean isConnected) {
Util.reconnectWithServer(isConnected, KontaktChatActivity.this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.kontakt_list_chat);
databaseHandler = DatabaseHandler.getInstance(this);
listView = getListView();
listView = (ListView) findViewById(R.id.contact_listview);
listView.setAdapter(new KontaktAdapter(this, new ArrayList<ContactListItem>()));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ContactListItem selectedValue = (ContactListItem) listView.getAdapter().getItem(position);
Bundle bundle = new Bundle();
bundle.putString("Name", selectedValue.getChatName());
bundle.putInt("RecipientOid", selectedValue.getPersonOid());
bundle.putBoolean("IsTeam", selectedValue.isTeam);
bundle.putString("TeamMemberOids", selectedValue.teamMemberOids);
bundle.putString("TeamMemberNames", selectedValue.teamMemberNames);
Intent in = new Intent(getBaseContext(), ChatActivity.class);
in.putExtras(bundle);
//Gib Bild für den Chat mit
if(selectedValue.getPicture() == null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap a = BitmapFactory.decodeResource(getResources(), R.drawable.katze3);
a.compress(Bitmap.CompressFormat.JPEG,0,stream);
byte[] x = stream.toByteArray();
in.putExtra("Bild", x);
} else {
in.putExtra("Bild", selectedValue.getPicture());
}
startActivity(in);
}
});
if(SocketManager.uiHandler == null ||! SocketManager.uiHandler.equals(kontaktChatActivityUIHandler)) {
SocketManager.uiHandler = kontaktChatActivityUIHandler;
}
ArrayList<PropertyInfo> propertyInfos = new ArrayList<>();
propertyInfos.add(SoapConnectionManager.BuildProperty("pPersonOid", SoapConnectionManager.User.getPersonOid(), Long.class));
JsonSoapPrimitiveRequest request = new JsonSoapPrimitiveRequest(SoapCalls.GET_CONTACTS_FOR_PERSON, propertyInfos);
spiceManager.execute(request, new JsonSoapPrimitiveRequestListener());
kontaktChatUIHandler = new UIHandler() {
@Override
public void updateUserInterface(final Packet chatPacket) {
try {
switch(chatPacket.ChatDataIdentifier) {
case MESSAGE:
ChatMessage message = new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, false, chatPacket.ServerseitigeOid, false);
databaseHandler.addChatMessage(message);
Util.SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.SenderPersonOid, false, null, null, getApplicationContext());
break;
case TEAM:
ChatMessage teamMessage = new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, false, chatPacket.ServerseitigeOid, true);
databaseHandler.addChatMessage(teamMessage);
ContactListItem cli = DatabaseHandler.getInstance(getApplicationContext()).getContactByPersonOid(chatPacket.RecipientPersonOid, true);
Util.SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.RecipientPersonOid, true, cli.teamMemberOids, cli.teamMemberNames, getApplicationContext());
break;
case STATUS_NOTIFICATION_LOGIN:
Log.i("KONTAKTLISTE", "Login registriert: (" + chatPacket.SenderPersonOid + ") " + chatPacket.ChatName);
if(!SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
SocketManager.onlinePersonOids.add(chatPacket.SenderPersonOid);
runOnUiThread(new Runnable() {
@Override
public void run() {
KontaktAdapter ka =((KontaktAdapter) listView.getAdapter());
for(ContactListItem item : ka.values) {
if(item.getPersonOid() == chatPacket.SenderPersonOid) {
item.isOnline = true;
break;
}
}
ka.notifyDataSetChanged();
}
});
}
break;
case STATUS_NOTIFICATION_LOGOUT:
if(SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
SocketManager.onlinePersonOids.remove(Integer.valueOf(chatPacket.SenderPersonOid));
runOnUiThread(new Runnable() {
@Override
public void run() {
KontaktAdapter ka =((KontaktAdapter) listView.getAdapter());
for(ContactListItem item : ka.values) {
if(item.getPersonOid() == chatPacket.SenderPersonOid) {
item.isOnline = false;
break;
}
}
ka.notifyDataSetChanged();
}
});
}
break;
}
} catch(Exception pe) {
pe.printStackTrace();
}
}
};
}
public UIHandler kontaktChatActivityUIHandler = new UIHandler() {
@Override
public void updateUserInterface(final Packet chatPacket) {
try {
switch(chatPacket.ChatDataIdentifier) {
case MESSAGE:
Util.SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.SenderPersonOid, false, null, null, getApplicationContext());
break;
case TEAM:
ContactListItem cli = DatabaseHandler.getInstance(getApplicationContext()).getContactByPersonOid(chatPacket.RecipientPersonOid, true);
Util.SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.RecipientPersonOid, true, cli.teamMemberOids, cli.teamMemberNames, getApplicationContext());
break;
case STATUS_NOTIFICATION_LOGIN:
runOnUiThread(new Runnable() {
@Override
public void run() {
KontaktAdapter ka =((KontaktAdapter) listView.getAdapter());
for(ContactListItem item : ka.values) {
if(item.getPersonOid() == chatPacket.SenderPersonOid) {
item.isOnline = true;
break;
}
}
ka.notifyDataSetChanged();
}
});
break;
case STATUS_NOTIFICATION_LOGOUT:
runOnUiThread(new Runnable() {
@Override
public void run() {
KontaktAdapter ka =((KontaktAdapter) listView.getAdapter());
for(ContactListItem item : ka.values) {
if(item.getPersonOid() == chatPacket.SenderPersonOid) {
item.isOnline = false;
break;
}
}
ka.notifyDataSetChanged();
}
});
break;
case STATUS_NOTIFICATION_LOGIN_BROADCAST:
runOnUiThread(new Runnable() {
@Override
public void run() {
KontaktAdapter ka =((KontaktAdapter) listView.getAdapter());
for(ContactListItem item : ka.values) {
if(item.getPersonOid() == chatPacket.SenderPersonOid) {
item.isOnline = true;
break;
}
}
ka.notifyDataSetChanged();
}
});
break;
}
} catch(Exception pe) {
pe.printStackTrace();
}
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main_activity_mitarbeiter, menu);
getMenuInflater().inflate(R.menu.menu_kontaktchat_activity, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (item.getItemId()) {
case R.id.action_kontaktlist_doku:
//noinspection SimplifiableIfStatement
Intent dokuActivity = new Intent(KontaktChatActivity.this, WebdokuActivity.class);
KontaktChatActivity.this.startActivity(dokuActivity);
if (id == R.id.action_Logout) {
System.exit(0);
return true;
case R.id.action_kontaktlist_logout:
SocketManager.logout();
Intent intent = new Intent(KontaktChatActivity.this, LoginActivity.class);
KontaktChatActivity.this.startActivity(intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
ContactListItem selectedValue = (ContactListItem) getListAdapter().getItem(position);
Bundle bundle = new Bundle();
bundle.putString("Name", selectedValue.getChatName());
bundle.putInt("RecipientOid", selectedValue.getPersonOid());
bundle.putBoolean("IsTeam", selectedValue.isTeam);
bundle.putString("TeamMemberOids", selectedValue.teamMemberOids);
bundle.putString("TeamMemberNames", selectedValue.teamMemberNames);
Intent in = new Intent(getBaseContext(), ChatActivity.class);
in.putExtras(bundle);
//Gib Bild für den Chat mit
if(selectedValue.getPicture() == null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap a = BitmapFactory.decodeResource(getResources(), R.drawable.katze3);
a.compress(Bitmap.CompressFormat.JPEG,0,stream);
byte[] x = stream.toByteArray();
in.putExtra("Bild", x);
} else {
in.putExtra("Bild", selectedValue.getPicture());
}
startActivity(in);
}
@Override
public void onResume() {
SocketManager.uiHandler = kontaktChatUIHandler;
SocketManager.uiHandler = kontaktChatActivityUIHandler;
BeWoChatApplication.getInstance().setConnectivityListener(this);
KontaktAdapter adapter = (KontaktAdapter) listView.getAdapter();
@@ -218,7 +239,6 @@ public class KontaktChatActivity extends ListActivity {
@Override
public void onStop(){
spiceManager.shouldStop();
databaseHandler.close();
super.onStop();
}
@@ -283,9 +303,12 @@ public class KontaktChatActivity extends ListActivity {
if(adapter == null) {
adapter = new KontaktAdapter(KontaktChatActivity.this, contactList);
} else {
adapter.values.clear();
adapter.values.addAll(contactList);
}
setListAdapter(adapter);
listView.setAdapter(adapter);
((KontaktAdapter) listView.getAdapter()).notifyDataSetChanged();
}

View File

@@ -5,10 +5,7 @@ import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
@@ -24,11 +21,7 @@ import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.octo.android.robospice.SpiceManager;
import com.octo.android.robospice.UncachedSpiceService;
@@ -53,6 +46,7 @@ import soapConnection.ApplicationUser;
import soapConnection.JsonSoapPrimitiveRequest;
import soapConnection.SoapCalls;
import soapConnection.SoapConnectionManager;
import tcpConnection.LoginCallback;
import tcpConnection.SocketManager;
import util.SecurityUtils;
import util.Util;
@@ -275,18 +269,6 @@ public class LoginActivity extends ActionBarActivity {
databaseHandler.insertOwnerOid(SoapConnectionManager.User.getPersonOid().intValue());
}
ContactListItem cli = databaseHandler.getContactByPersonOid(4, false);
if (getResources().getDrawable(R.drawable.katyperry) != null && cli != null) {
Bitmap bitch = ((BitmapDrawable) getResources().getDrawable(R.drawable.katyperry)).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitch.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
cli.setPicture(byteArray);
databaseHandler.getInstance(getApplicationContext()).updateContact(cli);
}
SoapConnectionManager.User.setTenant(mTenantView.getText().toString());
if(mRememberMeCheckBoxView.isChecked()) {
@@ -318,8 +300,18 @@ public class LoginActivity extends ActionBarActivity {
SocketManager.tenant = mTenantView.getText().toString();
Intent mainActivityMitarbeiter = new Intent(LoginActivity.this, MainActivityMitarbeiter.class);
LoginActivity.this.startActivity(mainActivityMitarbeiter);
//TODO: stattdessen ConnectToServer und im Callback die ChatActivity aufrufen
SocketManager.loginCallback = new LoginCallback() {
@Override
public void doCallback() {
Log.e("LOGIN_CALLBACK", "LoginCallback aufgerufen. Ist verbunden und ruft die ChatActivity nun auf.");
Intent kontaktChatActivity = new Intent(LoginActivity.this, KontaktChatActivity.class);
LoginActivity.this.startActivity(kontaktChatActivity);
}
};
SocketManager.connectToServer();
}
else {
showProgress(false);

View File

@@ -1,13 +1,7 @@
package beyondsoft.bewomitarbeiterapp;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Color;
import android.os.Looper;
import android.support.v4.app.NotificationCompat;
import android.os.Bundle;
import android.util.Log;
@@ -15,20 +9,23 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import java.util.Random;
import java.util.ArrayList;
import Database.DatabaseHandler;
import entities.ChatMessage;
import soapConnection.Packet;
import soapConnection.SoapConnectionManager;
import tcpConnection.SocketManager;
import tcpConnection.UIHandler;
import util.ConnectivityReceiver;
import util.Util;
public class MainActivityMitarbeiter extends Activity {
public class MainActivityMitarbeiter extends Activity implements ConnectivityReceiver.ConnectivityReceiverListener {
protected Button dokubutton;
protected Button chatbutton;
@@ -40,13 +37,19 @@ public class MainActivityMitarbeiter extends Activity {
int loggedInUserPersonOid;
@Override
private final static String LOGTAG = "MAIN_ACTIVITY";
@Override
public void onNetworkConnectionChanged(boolean isConnected) {
Util.reconnectWithServer(isConnected, MainActivityMitarbeiter.this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity_mitarbeiter);
SocketManager.connectToServer();
SocketManager.loginOnServer();
setzeButtonListener();
@@ -61,6 +64,18 @@ public class MainActivityMitarbeiter extends Activity {
case MESSAGE:
Util.SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.SenderPersonOid, false, null, null, getApplicationContext());
break;
case MESSAGE_RESPONSE:
DatabaseHandler databaseHandler = DatabaseHandler.getInstance(getApplicationContext());
ChatMessage cm = databaseHandler.getChatMessageById(chatPacket.ClientseitigeOid);
cm.ServerseitigeOid = chatPacket.ServerseitigeOid;
cm.IsDelivered = true;
databaseHandler.updateChatMessage(cm);
break;
case STATUS_NOTIFICATION_LOGIN_BROADCAST:
String[] bitch = chatPacket.ChatMessage.split(",");
@@ -91,6 +106,8 @@ public class MainActivityMitarbeiter extends Activity {
}
}
};
Util.sendUnsentMessages(MainActivityMitarbeiter.this);
}
@Override
@@ -151,11 +168,15 @@ public class MainActivityMitarbeiter extends Activity {
public void onResume() {
SocketManager.uiHandler = mainUIHandler;
BeWoChatApplication.getInstance().setConnectivityListener(this);
super.onResume();
}
@Override
public void onBackPressed() {
Log.i(LOGTAG, "Logge aus...");
SocketManager.logout();
finish();

View File

@@ -1,6 +1,7 @@
package beyondsoft.bewomitarbeiterapp;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
@@ -9,6 +10,7 @@ import android.webkit.WebView;
import android.webkit.WebViewClient;
import soapConnection.SoapCalls;
import tcpConnection.SocketManager;
/**
* Created by bib on 02.05.2016.
@@ -29,4 +31,29 @@ public class WebdokuActivity extends ActionBarActivity {
view.loadUrl(SoapCalls.WEB_DOKU_URL);
view.setWebViewClient(new WebViewClient());
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_webdoku, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.action_chat:
Intent kontaktChatActivity = new Intent(getBaseContext(), KontaktChatActivity.class);
startActivity(kontaktChatActivity);
return true;
case R.id.action_Logout:
SocketManager.logout();
finish();
System.exit(0);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}

View File

@@ -0,0 +1,22 @@
package entities;
/**
* Created by JettenM on 08.09.2016.
*/
public class ChatEntity {
private long oid;
private boolean isTeam;
public ChatEntity(long pOid, boolean pIsTeam) {
oid = pOid;
isTeam = pIsTeam;
}
public long getOid() {
return oid;
}
public boolean isTeam() {
return isTeam;
}
}

View File

@@ -4,10 +4,10 @@ package entities;
* Created by JettenM on 05.07.2016.
*/
public class ChatPerson {
public int Oid;
public String Name;
public int Oid;
public String Name;
public boolean IsTeam;
public String TeamMemberNames;
public String TeamMemberOids;
public int Version;
public String TeamMemberNames;
public String TeamMemberOids;
public int Version;
}

View File

@@ -0,0 +1,24 @@
package entities;
import java.util.Date;
/**
* Created by JettenM on 09.09.2016.
*/
public class NotificationLog {
private int notificationId;
private Date notificationDate;
public NotificationLog(int notificationId, Date notificationDate) {
this.notificationId = notificationId;
this.notificationDate = notificationDate;
}
public int getNotificationId() {
return notificationId;
}
public Date getNotificationDate() {
return notificationDate;
}
}

View File

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

View File

@@ -49,6 +49,8 @@ public class Packet {
//23;281;20;389;1;38;932[Tenant]; 8 Semikola
public Packet(String message) {
Log.i("PACKET_CONSTRUCTOR_MSG", message);
String[] gesplittet = message.split(";");
String senderPersonOidString = gesplittet[0];

View File

@@ -10,14 +10,26 @@ public class SoapCalls {
public static String GET_ALL_CHAT_MESSAGES = "GetAllChatMessagesForSenderAndRecipient";
//"app4.bewoplaner.de";//
public static String DESTINATION_ADDRESS = "app4.bewoplaner.de";//"192.168.1.103";
//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://" + DESTINATION_ADDRESS + "/mobil/login/demo";
//
// 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 = "https://" + DESTINATION_ADDRESS + "/mobil/main/checktoken?token=";
public static String TOKEN_CHECK_URL = "http://" + DESTINATION_ADDRESS + "/bewoplanermobil/main/checktoken?token=";
public static String WEB_DOKU_URL = "https://" + DESTINATION_ADDRESS + "/mobil/login/demo";
public static String WEB_DOKU_URL = "http://" + DESTINATION_ADDRESS + "/bewoplanermobil/login/demo";
public static String WSDL_TARGET_NAME = "bliblablubb.org/";
public static String SOAP_ADDRESS = "https://" + DESTINATION_ADDRESS + "/BeWoPlanerAndroid/AndroidSoapService.asmx";
public static String SOAP_ADDRESS = "http://" + DESTINATION_ADDRESS + "/BeWoPlanerAndroid/AndroidSoapService.asmx";
}

View File

@@ -0,0 +1,9 @@
package tcpConnection;
/**
* Created by JettenM on 08.09.2016.
*/
public interface LoginCallback {
void doCallback();
}

View File

@@ -1,15 +1,28 @@
package tcpConnection;
import android.util.Log;
import android.widget.ImageView;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.NetworkInterface;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import Database.DatabaseHandler;
import beyondsoft.bewomitarbeiterapp.BeWoChatApplication;
import beyondsoft.bewomitarbeiterapp.R;
import entities.ChatEntity;
import entities.ChatMessage;
import entities.NotificationLog;
import soapConnection.DataIdentifier;
import soapConnection.Packet;
import soapConnection.SoapCalls;
@@ -21,35 +34,49 @@ public class SocketManager {
private static final String TAG = "SOCKET_MANAGER";
private static DatabaseHandler databaseHandler = DatabaseHandler.getInstance(BeWoChatApplication.getInstance());
public static String tenant;
public static Socket socket;
public static Thread listenerThread;
public static SocketListener socketListener;
public static UIHandler uiHandler;
public static LoginCallback loginCallback;
public static DataOutputStream dataOutputStream;
public static ArrayList<Integer> onlinePersonOids = new ArrayList<>();
public static ArrayList<ChatEntity> onlineEntities = new ArrayList<>();
public static HashMap<ChatEntity, NotificationLog> notificationEntities = new HashMap<>();
public static void connectToServer(){
new Thread(new OpenConnection()).start();
new Thread(new ConnectionOpener()).start();
}
public static void sendMessage(Packet packet) {
new Thread(new MessageSender(packet.getDataStream())).start();
}
public static class OpenConnection implements Runnable {
private static class ConnectionOpener implements Runnable {
public void run() {
try {
if(socket != null) {
socket.close();
}
socket = null;
socket = new Socket(SoapCalls.DESTINATION_ADDRESS, SoapCalls.DESTINATION_PORT);
loginOnServer();
dataOutputStream = null;
onlinePersonOids.clear();
onlineEntities.clear();
dataOutputStream = new DataOutputStream(socket.getOutputStream());
socketListener = new SocketListener();
listenerThread = new Thread(socketListener);
listenerThread.start();
loginOnServer();
} catch(Exception exception) {
socket = null;
try {
@@ -68,17 +95,6 @@ public class SocketManager {
}
}
public static void closeSocketListener() {
if(listenerThread != null && listenerThread.isAlive()) {
try {
socketListener.terminate();
listenerThread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void logout() {
if(socket != null && socket.isConnected()) {
try {
@@ -97,9 +113,9 @@ public class SocketManager {
public static void loginOnServer() {
if(socket != null && socket.isConnected()) {
try {
Packet packet = new Packet();
packet.Tenant = tenant;
Packet packet = new Packet();
packet.Tenant = tenant;
packet.ChatMessage = getMACAddress();
packet.ChatDataIdentifier = DataIdentifier.LOGIN;
new Thread(new MessageSender(packet.getDataStream())).start();
@@ -109,7 +125,7 @@ public class SocketManager {
}
}
public static class ConnectionClose implements Runnable{
public static class ConnectionCloser implements Runnable{
public void run(){
try {
if (dataOutputStream != null) {
@@ -121,7 +137,7 @@ public class SocketManager {
socket.close();
}
}catch(IOException se){
} catch (IOException se) {
se.printStackTrace();
}
}
@@ -136,7 +152,7 @@ public class SocketManager {
@Override
public void run() {
if(!socket.isConnected()) {
if(socket == null || !socket.isConnected()) {
Log.e("MESSAGE_SENDER", "Socket ist nicht verbunden");
}
@@ -145,6 +161,21 @@ public class SocketManager {
dataOutputStream.write(packetToSend);
dataOutputStream.flush();
} catch (IOException e) {
try {
Packet packet = new Packet(new String(packetToSend, "UTF-8"));
if(packet.ChatDataIdentifier == DataIdentifier.MESSAGE || packet.ChatDataIdentifier == DataIdentifier.TEAM) {
DatabaseHandler db = DatabaseHandler.getInstance(BeWoChatApplication.getInstance().getApplicationContext());
ChatMessage undeliveredMessage = db.getChatMessageById(packet.ClientseitigeOid);
if(undeliveredMessage != null) {
undeliveredMessage.IsDelivered = false;
int affectedRows = db.updateChatMessage(undeliveredMessage);
}
}
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}
}
@@ -182,9 +213,63 @@ public class SocketManager {
try {
chatPacket = new Packet(new String(message, "UTF-8"));
} catch(Exception e) {
e.printStackTrace();
}
Log.i(TAG, "Empfange Nachricht... " + chatPacket.ChatMessage);
if(chatPacket.ChatDataIdentifier.equals(DataIdentifier.LOGIN_SUCCESS) && loginCallback != null) {
Log.i(TAG, "Der Login war erfolgreich");
loginCallback.doCallback();
}
try {
switch (chatPacket.ChatDataIdentifier) {
case MESSAGE:
databaseHandler.addChatMessage(new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, true, chatPacket.ServerseitigeOid, false));
break;
case TEAM:
databaseHandler.addChatMessage(new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, true, chatPacket.ServerseitigeOid, true));
break;
case MESSAGE_RESPONSE:
ChatMessage cm = databaseHandler.getChatMessageById(chatPacket.ClientseitigeOid);
cm.ServerseitigeOid = chatPacket.ServerseitigeOid;
cm.IsDelivered = true;
databaseHandler.updateChatMessage(cm);
break;
case STATUS_NOTIFICATION_LOGIN:
if(!SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
SocketManager.onlinePersonOids.add(chatPacket.SenderPersonOid);
}
break;
case STATUS_NOTIFICATION_LOGOUT:
if(SocketManager.onlinePersonOids.contains(chatPacket.SenderPersonOid)) {
SocketManager.onlinePersonOids.remove(Integer.valueOf(chatPacket.SenderPersonOid));
}
break;
case STATUS_NOTIFICATION_LOGIN_BROADCAST:
String[] onlinePersons = chatPacket.ChatMessage.split(",");
for (String onlinePerson : onlinePersons) {
SocketManager.onlinePersonOids.add(Integer.parseInt(onlinePerson));
}
break;
}
} catch(Exception e) {
e.printStackTrace();
}
@@ -202,4 +287,36 @@ public class SocketManager {
}
}
}
public static String getMACAddress() {
try {
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
for(NetworkInterface nif : all) {
if(!nif.getName().equalsIgnoreCase("wlan0")) {
continue;
}
byte[] macBytes = nif.getHardwareAddress();
if(macBytes == null) {
return "MAC-ADRESSE NICHT ERMITTELBAR";
}
StringBuilder res1 = new StringBuilder();
for(byte b : macBytes) {
res1.append(Integer.toHexString(b & 0xFF) + ":");
}
if(res1.length() > 0) {
res1.deleteCharAt(res1.length() - 1);
}
return res1.toString();
}
} catch(Exception ex) {
Log.e("GET_MAC_ADDRESS", ex.getMessage());
}
return "02:00:00:00:00:00";
}
}

View File

@@ -31,7 +31,7 @@ public class ChatMessageDeserializer implements JsonDeserializer<ChatMessage> {
int recipientPersonOid = Long.valueOf(json.get("EmpfängerPersonOid").getAsLong()).intValue();
int serverseitigeOid = Long.valueOf(json.get("Oid").getAsLong()).intValue();
String chatText = json.get("ChatText").getAsString();
boolean isDelivered = json.get("istZugestellt").getAsBoolean();
boolean isDelivered = json.get("IsDelivered").getAsBoolean();
boolean isTeam = !json.get("TeamOid").isJsonNull();

View File

@@ -0,0 +1,67 @@
package util;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.preference.PreferenceManager;
import beyondsoft.bewomitarbeiterapp.BeWoChatApplication;
/**
* Created by JettenM on 26.08.2016.
*/
public class ConnectivityReceiver extends BroadcastReceiver {
public static ConnectivityReceiverListener connectivityReceiverListener;
private static final String LOGTAG = "CONNECTIVITY";
private static final Long SYNCTIME = 800L;
private static final String LASTTIMESYNC = "DATE";
SharedPreferences sharedPreferences;
public ConnectivityReceiver() {
super();
}
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
if(networkInfo != null && networkInfo.isConnected()) {
if(System.currentTimeMillis() - sharedPreferences.getLong(LASTTIMESYNC, 0) >= SYNCTIME) {
sharedPreferences.edit().putLong(LASTTIMESYNC, System.currentTimeMillis()).commit();
boolean isConnected = networkInfo.isConnected();
if(connectivityReceiverListener != null) {
connectivityReceiverListener.onNetworkConnectionChanged(isConnected);
}
}
} else {
boolean isConnected = networkInfo != null && networkInfo.isConnected();
if(connectivityReceiverListener != null) {
connectivityReceiverListener.onNetworkConnectionChanged(isConnected);
}
}
}
public static boolean isConnected() {
ConnectivityManager cm = (ConnectivityManager) BeWoChatApplication.getInstance().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
}
public interface ConnectivityReceiverListener {
void onNetworkConnectionChanged(boolean isConnected);
}
}

View File

@@ -0,0 +1,26 @@
package util;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
/**
* Created by JettenM on 09.09.2016.
*/
public class NotificationBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if(action.equals(Util.NOTIFICATION_CANCELLED))
{
Log.i("NOTIFICATION_CANCELLED", "Benachrichtigung gelöscht");
// nicht?
//Util.unreadMessagesCount--;
//TODO: auf die Konversationen achten
}
}
}

View File

@@ -1,19 +1,35 @@
package util;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Map;
import java.util.Random;
import Database.DatabaseHandler;
import beyondsoft.bewomitarbeiterapp.ChatActivity;
import beyondsoft.bewomitarbeiterapp.KontaktChatActivity;
import beyondsoft.bewomitarbeiterapp.R;
import entities.ChatEntity;
import entities.ChatMessage;
import entities.NotificationLog;
import soapConnection.DataIdentifier;
import soapConnection.Packet;
import soapConnection.SoapConnectionManager;
import tcpConnection.LoginCallback;
import tcpConnection.SocketManager;
/**
* Created by JettenM on 05.07.2016.
@@ -28,34 +44,40 @@ public class Util {
public static final String PREFS_USERNAME_KEY = "username";
public static final String PREFS_PASSWORD = "password";
public static final String NOTIFICATION_CANCELLED = "notification_cancelled";
public static int unreadMessagesCount = 0;
public static int conversationsCount = 0;
//TODO: Notifications zählen. Bei Nachrichten verschiedener Unterhaltungen nur noch eine kleine Notification anzeigen mit "Sie haben x Nachrichten in y Unterhaltungen
public static void SetNotify(String username, String message, int recipientOid, boolean isTeam, String teamMemberOids, String teamMemberNames, Context packageContext) {
unreadMessagesCount++;
//TODO: unterscheiden, ob es sich um eine einzelne Benachrichtigung handelt
String mUsername = conversationsCount > 1 ? String.valueOf(conversationsCount) + " Konversationen" : username;
String mMessage = unreadMessagesCount > 1 ? String.valueOf(unreadMessagesCount) + " Nachrichten" : message;
public static void SetNotify(String username, String message, int recipientOid, boolean isTeam, String teamMemberOids, String teamMemberNames, Context packageContext){
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(packageContext)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle(username)
.setContentText(message)
.setContentTitle(mUsername)
.setContentText(mMessage)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_SOUND)
.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }) //Notification.Default_Vibrate
.setLights(Color.YELLOW, 3000, 3000) //Notification.Default_Lights
.setOngoing(true);
.setLights(Color.YELLOW, 3000, 3000); //Notification.Default_Lights
Log.i("CHAT_SET_NOTIFY", username + "; " + recipientOid + "; " + isTeam + "; " + teamMemberOids + "; " + teamMemberNames);
Intent resultIntent = new Intent(packageContext, (conversationsCount > 1 ? KontaktChatActivity.class : ChatActivity.class));
Bundle bundle = new Bundle();
bundle.putString("Name", username);
bundle.putInt("RecipientOid", recipientOid);
bundle.putBoolean("IsTeam", isTeam);
bundle.putString("TeamMemberOids", teamMemberOids);
bundle.putString("TeamMemberNames", teamMemberNames);
//TODO: mehrere Notifications von mehrern Kontakten -> KontaktChatActivity öffnen, sonst ChatActivity
Intent resultIntent = new Intent(packageContext, ChatActivity.class);
resultIntent.putExtras(bundle);
if (conversationsCount <= 1) {
Bundle bundle = new Bundle();
bundle.putString("Name", username);
bundle.putInt("RecipientOid", recipientOid);
bundle.putBoolean("IsTeam", isTeam);
bundle.putString("TeamMemberOids", teamMemberOids);
bundle.putString("TeamMemberNames", teamMemberNames);
resultIntent.putExtras(bundle);
}
resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
@@ -63,11 +85,119 @@ public class Util {
NotificationManager mNotifyMgr = (NotificationManager) packageContext.getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder.setDeleteIntent(getDeletedIntent(packageContext));
mBuilder.setContentIntent(resultPendingIntent);
mNotifyMgr.notify((new Random()).nextInt(9999 - 1000) + 1000, mBuilder.build());
Random random = new Random();
int notificationId = 1;
ChatEntity chatEntity = new ChatEntity(SoapConnectionManager.User.getPersonOid(), isTeam);
NotificationLog notificationLog = new NotificationLog(notificationId, Calendar.getInstance().getTime());
while(SocketManager.notificationEntities.containsValue(notificationLog)) {
notificationId = random.nextInt(10000);
notificationLog = new NotificationLog(notificationId, Calendar.getInstance().getTime());
}
SocketManager.notificationEntities.put(chatEntity, notificationLog);
//TODO: alte Notifications löschen ---------------------------------
ArrayList<ChatEntity> entities2remove = new ArrayList<>();
if(conversationsCount > 1 || unreadMessagesCount > 1) {
//TODO: differenzieren, welche Notifications gelöscht werden müssen. Alle bis auf die aktuelle Benachrichtigungen löschen.
for(Map.Entry<ChatEntity, NotificationLog> entry : SocketManager.notificationEntities.entrySet()) {
if(!(entry.getKey().equals(chatEntity) && entry.getValue().equals(notificationLog))) {
mNotifyMgr.cancel(entry.getValue().getNotificationId());
entities2remove.add(entry.getKey());
}
}
}
//TODO: ------------------------------------------------------------
mNotifyMgr.notify(notificationId, mBuilder.build());
}
protected static PendingIntent getDeletedIntent(Context context) {
Intent intent = new Intent(context, NotificationBroadcastReceiver.class);
intent.setAction(Util.NOTIFICATION_CANCELLED);
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}
public static void buildAlert(Context context, String message) {
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setMessage(message);
alert.setTitle("Debug-Info");
alert.setCancelable(true);
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alert.create().show();
}
public static void reconnectWithServer(boolean isConnected, final Context context) {
Log.e("UTIL", isConnected ? "Ist mit dem Internet/WLAN verbunden" : "Ist mit keinem Netzwerk verbunden");
if(isConnected) {
try {
SocketManager.loginCallback = new LoginCallback() {
@Override
public void doCallback() {
Log.e("LOGIN_CALLBACK", "LoginCallback aufgerufen. Verschicke nicht verschickte Nachrichten...");
sendUnsentMessages(context);
}
};
SocketManager.connectToServer();
Log.i("RECONNECT_WITH_SERVER", "connectToServer aufgerufen...");
}
catch(Exception es) {
Log.e("RECONNECT_WITH_SERVER", "Ausnahme beim Login nach Reconnect");
es.printStackTrace();
}
}
}
public static void sendUnsentMessages(final Context context) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
DatabaseHandler databaseHandler = DatabaseHandler.getInstance(context);
ArrayList<ChatMessage> unsentMessages = databaseHandler.getUnsentChatMessages();
for(ChatMessage cm : unsentMessages) {
final Packet unsentPacket = new Packet();
unsentPacket.ChatDataIdentifier = cm.IsTeam ? DataIdentifier.TEAM : DataIdentifier.MESSAGE;
unsentPacket.ChatMessage = cm.ChatText;
unsentPacket.ChatName = SoapConnectionManager.User.getFullName();
unsentPacket.RecipientPersonOid = cm.RecipientPersonOid;
unsentPacket.ClientseitigeOid = cm.Id;
unsentPacket.MessageTimeStamp = cm.InsTs;
unsentPacket.SenderPersonOid = cm.SenderPersonOid;
unsentPacket.Tenant = SoapConnectionManager.User.getTenant();
unsentPacket.IsDelivered = cm.IsDelivered;
SocketManager.sendMessage(unsentPacket);
Thread.sleep(50);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
thread.start();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -22,7 +22,7 @@
<ScrollView
android:id="@+id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/email_login_form"

View File

@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin"
android:background="@android:color/holo_orange_dark"
>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".ChatActivity">
<LinearLayout
android:layout_width="match_parent"
@@ -47,7 +47,9 @@
android:layout_height="wrap_content"
android:text="@string/Chatbutton_name"
android:background="@drawable/abc_btn_radio_material"
android:textColor="@color/green"
android:id="@+id/Sendebutton"
android:padding="10dp"
/>
</LinearLayout>
</LinearLayout>

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="5dp"
>
<ImageView
android:id="@+id/logo"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="15dp"
android:layout_gravity="center_vertical"
android:scaleType="fitXY"
android:src="@drawable/bslogo" />
<ImageView
android:id="@+id/status"
android:layout_width="18dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
>
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:singleLine="true"
android:textColor="?android:attr/textColorPrimary"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:singleLine="true"
android:textColor="?android:attr/textColorSecondary"
android:textSize="12sp"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout>

View File

@@ -9,9 +9,9 @@
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/PersonalPic"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="2dp"
android:layout_marginStart="2dp"
android:scaleType="fitXY"
/>
@@ -19,7 +19,6 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:layout_centerInParent="true"
android:id="@+id/PersonalName"
@@ -28,15 +27,13 @@
/>
<ImageView
android:id="@+id/status"
android:layout_width="20dp"
android:src="@drawable/online"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical"
android:layout_marginEnd="20dp"
android:id="@+id/status"
android:layout_width="20dp"
android:src="@drawable/statusoffline"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_gravity="center_vertical" />
/>
<!-- Merke: Das Design muss noch angepasst werden, da der Text über dem Bild liegt. /
Vorläufig gelöst mit margin. Dies kann aber nicht die endgültige Lösung sein. -->

View File

@@ -1,74 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".KontaktChatActivity"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp"
>
<!--
<ListView
android:id="@+id/contact_listview"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_gravity="center_horizontal" />-->
<ImageView
android:id="@+id/logo"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="15dp"
android:layout_gravity="center_vertical"
android:scaleType="fitXY"
android:src="@drawable/bslogo" />
<ImageView
android:id="@+id/status"
android:layout_width="18dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
/>
<!--Dise layout muss nochmals horizontal sein -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
>
<!--Linear layout vertikal -->
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:singleLine="true"
android:textColor="?android:attr/textColorPrimary"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:singleLine="true"
android:textColor="?android:attr/textColorSecondary"
android:textSize="12sp"
android:textStyle="normal" />
<!-- und noch ein Layout vertical-->
</LinearLayout>
</ListView>
</LinearLayout>

View File

@@ -1,70 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="text"
android:ems="10"
android:id="@+id/KundennrText"
android:background="#ffffffff"
android:layout_marginTop="70dp"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:labelFor="@string/prompt_tenant"
android:hint="@string/prompt_tenant"
android:padding="10dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="text"
android:ems="10"
android:id="@+id/UsernameText"
android:layout_marginTop="50dp"
android:layout_below="@+id/KundennrText"
android:layout_marginEnd="25dp"
android:layout_marginStart="25dp"
android:background="#ffffffff"
android:padding="10dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/PWText"
android:background="#ffffffff"
android:layout_marginTop="50dp"
android:layout_marginStart="25dp"
android:layout_marginEnd="25dp"
android:layout_below="@+id/UsernameText"
android:padding="10dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:id="@+id/Loginbutton"
android:layout_alignTop="@+id/PWText"
android:layout_alignStart="@+id/PWText"
android:layout_marginTop="98dp"
android:layout_alignEnd="@+id/PWText" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Beenden"
android:id="@+id/Beendenbutton"
android:layout_below="@+id/Loginbutton"
android:layout_alignStart="@+id/Loginbutton"
android:layout_marginTop="30dp"
android:layout_alignEnd="@+id/Loginbutton" />
</RelativeLayout>

View File

@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".WebdokuActivity">

View File

@@ -1,15 +1,16 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" tools:context=".KontaktChatActivity">
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context=".KontaktChatActivity">
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
<item
android:id="@+id/action_kontaktlist_doku"
android:title="@string/Doku"
android:orderInCategory="100" />
<item android:id="@+id/action_Logout"
android:title="@string/back"
android:orderInCategory="100"
app:showAsAction="never" />
<item
android:id="@+id/action_kontaktlist_logout"
android:title="@string/Logout"
android:orderInCategory="100" />
</menu>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_chat"
android:title="@string/chat"
android:orderInCategory="100"
app:showAsAction="never" />
<item android:id="@+id/action_Logout"
android:title="@string/Logout"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>

View File

@@ -1,11 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context=".ChatActivity">
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context=".ChatActivity">
<item
android:id="@+id/action_delet_Storage"
android:title="@string/Clear"
android:id="@+id/action_doku"
android:title="@string/Doku"
android:orderInCategory="100" />
<item
android:id="@+id/action_logout"
android:title="@string/Logout"
android:orderInCategory="100" />
</menu>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#f12727</color>
<color name="green">#25ea20</color>
</resources>

View File

@@ -31,5 +31,10 @@
<string name="title_activity_login">Anmelden</string>
<string name="chat_code">Chat-Code</string>
<string name="prompt_remember_me">Passwort speichern</string>
<string name="database_reset">Datenbank zurücksetzen</string>
<string name="Doku">Doku</string>
<string name="Logout">Logout</string>
<string name="chat">Chat</string>
<string name="contact_list_activity_name">Kontakte</string>
</resources>

File diff suppressed because it is too large Load Diff

View File

@@ -904,7 +904,7 @@ namespace BeWo.View
}
else
{
SaveChatMessageinDB(BeWoApp.LoggedOnUser.Employee.PersonOid,empfängeroid, msg, 0, type);
SaveChatMessageinDB(BeWoApp.LoggedOnUser.Employee.PersonOid, empfängeroid, msg, false, type);
MessageBox.Show("Die Daten werden in der Datenbank Gespeichert, da der Server nicht zur Verfügung steht.", "Info ", MessageBoxButton.OK);
}
}
@@ -916,24 +916,24 @@ namespace BeWo.View
Dispatcher.Invoke(
DispatcherPriority.Normal,
(ThreadStart) // <--- Muss dass nicht Weg
(ThreadStart) // <--- Muss das nicht weg
delegate { ServerStats.Text = "Fehler: Die Nachricht konnte nicht gesendet werden."; });
}
}
}
public void SaveChatMessageinDB( long senderoid,long empfangid,string message,int istZugestellt,ChatType type)
public void SaveChatMessageinDB(long senderoid, long empfangid, string message, bool isDelivered,ChatType type)
{
try
{
if (type == ChatType.Team)
{
ServiceFacade.DoOperationsServiceSync(s => s.CreateNewChatMessagesDC(senderoid, empfangid, message, istZugestellt,empfangid));
ServiceFacade.DoOperationsServiceSync(s => s.CreateNewChatMessagesDC(senderoid, empfangid, message, isDelivered, empfangid));
}
else
{
ServiceFacade.DoOperationsServiceSync(s => s.CreateNewChatMessagesDC(senderoid, empfangid, message, istZugestellt,0));
ServiceFacade.DoOperationsServiceSync(s => s.CreateNewChatMessagesDC(senderoid, empfangid, message, isDelivered, 0));
}
}
catch (InvalidOperationException e)

View File

@@ -1,4 +1,3 @@
using BS.Shared;
using BS.Shared.DataContracts;
using System;
@@ -10,7 +9,7 @@ namespace BeWo.ViewModel
public static string PropertyName_Uhrzeit = "Uhrzeit";
public static string PropertyName_IstZugestellt = "IstZugestellt";
public static string PropertyName_IsDelivered = "IsDelivered";
public static string PropertyName_IstGelesen = "IstGelesen";
@@ -22,7 +21,7 @@ namespace BeWo.ViewModel
private long? _EmpfängerPersonOid;
private int _istZugestellt;
private bool _IsDelivered;
private int _IstGelesen;
@@ -37,28 +36,28 @@ namespace BeWo.ViewModel
public virtual string ChatText
{
get { return this._ChatText; }
get { return _ChatText; }
set
{
if (this.AreDifferent(this._ChatText, value))
if (AreDifferent(_ChatText, value))
{
this._ChatText = value;
_ChatText = value;
}
}
}
public DateTime Uhrzeit
{
get { return this._Uhrzeit; }
get { return _Uhrzeit; }
set
{
if (this.AreDifferent(this._Uhrzeit, value))
if (AreDifferent(_Uhrzeit, value))
{
this._Uhrzeit = value;
this.StoreDirtyInformation(this.AreDifferent(DataContract.Uhrzeit, value), PropertyName_Uhrzeit);
this.FirePropertyChanged(PropertyName_Uhrzeit);
_Uhrzeit = value;
StoreDirtyInformation(AreDifferent(DataContract.Uhrzeit, value), PropertyName_Uhrzeit);
FirePropertyChanged(PropertyName_Uhrzeit);
}
}
}
@@ -72,9 +71,9 @@ namespace BeWo.ViewModel
set
{
if (this.AreDifferent(this._SenderPersonOid, value))
if (AreDifferent(_SenderPersonOid, value))
{
this._SenderPersonOid = value;
_SenderPersonOid = value;
}
}
}
@@ -83,30 +82,30 @@ namespace BeWo.ViewModel
{
get
{
return this._EmpfängerPersonOid;
return _EmpfängerPersonOid;
}
set
{
if (this.AreDifferent(this._EmpfängerPersonOid, value))
if (AreDifferent(_EmpfängerPersonOid, value))
{
this._EmpfängerPersonOid = value;
_EmpfängerPersonOid = value;
}
}
}
public virtual int IstZugestellt
public virtual bool IsDelivered
{
get
{
return _istZugestellt;
return _IsDelivered;
}
set
{
if (AreDifferent(_istZugestellt, value))
if (AreDifferent(_IsDelivered, value))
{
_istZugestellt = value;
_IsDelivered = value;
}
}
}
@@ -136,22 +135,20 @@ namespace BeWo.ViewModel
set
{
if (this.AreDifferent(this._TeamOid, value))
if (AreDifferent(_TeamOid, value))
{
this._TeamOid = value;
_TeamOid = value;
}
}
}
protected override void InitByDataContract(ChatMessageDC pDataContract)
{
this._SenderPersonOid = pDataContract.SenderPersonOid;
this._EmpfängerPersonOid = pDataContract.EmpfängerPersonOid;
this._Uhrzeit = pDataContract.Uhrzeit;
this._ChatText = pDataContract.ChatText;
_istZugestellt = pDataContract.IstZugestellt;
_SenderPersonOid = pDataContract.SenderPersonOid;
_EmpfängerPersonOid = pDataContract.EmpfängerPersonOid;
_Uhrzeit = pDataContract.Uhrzeit;
_ChatText = pDataContract.ChatText;
_IsDelivered = pDataContract.IsDelivered;
_IstGelesen = pDataContract.IstGelesen;
_TeamOid = pDataContract.TeamOid;
}
@@ -162,7 +159,7 @@ namespace BeWo.ViewModel
pDataContract.EmpfängerPersonOid = _EmpfängerPersonOid;
pDataContract.Uhrzeit = _Uhrzeit;
pDataContract.ChatText = _ChatText;
pDataContract.IstZugestellt = _istZugestellt;
pDataContract.IsDelivered = _IsDelivered;
pDataContract.IstGelesen = _IstGelesen;
pDataContract.TeamOid = _TeamOid;

View File

@@ -62,6 +62,8 @@
<Reference Include="NHibernate.ByteCode.Castle">
<HintPath>..\..\beyondSoft\BeWoPlaner\Lib\NHibernate.ByteCode.Castle.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.ServiceModel" />

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
@@ -12,6 +12,7 @@ using BeWo.Data.Access;
using BeWo.Data.Entities;
using BS.Shared;
using BS.Shared.Extensions;
namespace BeWoChatServer
@@ -22,7 +23,7 @@ namespace BeWoChatServer
private static readonly object _Lock = string.Empty;
private static readonly Dictionary<Socket, long> clientList = new Dictionary<Socket, long>();
private static readonly ConcurrentDictionary<Socket, LoginData> clientList = new ConcurrentDictionary<Socket, LoginData>();
protected static Socket serverSocket;
private static AsyncCallback asyncCallback;
@@ -60,13 +61,20 @@ namespace BeWoChatServer
Interlocked.Increment(ref clientCount);
clientList.Add(workerSocket, 0);
var couldAdd = clientList.TryAdd(workerSocket, new LoginData(0, "", DateTime.Now));
Console.WriteLine(DateTime.Now + ": Client hinzugefügt");
if(!couldAdd)
{
Console.WriteLine("Socket war schon in der clientListe enthalten und konnte nicht hinzugefügt werden");
}
Console.WriteLine(DateTime.Now + ": Client hinzugefügt (" + workerSocket.RemoteEndPoint + ")");
WaitForClientData(workerSocket, "", 0, 0);
serverSocket.BeginAccept(OnClientConnected, null);
LogAllClients();
}
catch (SocketException e)
{
@@ -93,12 +101,29 @@ namespace BeWoChatServer
}
}
private static void LogAllClients()
{
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.DarkMagenta;
Console.WriteLine("Folgende Benutzer sind angemeldet:");
var abc = "";
clientList.DoForEach(c =>abc += "\t" + c.Key.RemoteEndPoint.ToString() + "; Angemeldete Person: " + c.Value.PersonOid + "; MAC: " + c.Value.MacAddress + "; Zeitpunkt: " + c.Value.LoginTime.ToString("dd.MM.yyyy HH:mm:ss.ffff") + "\n");
Console.Write(abc);
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.Gray;
}
public static void OnReceiveData(IAsyncResult asyncResult)
{
var dataPacket = (Packet) asyncResult.AsyncState;
Console.WriteLine(DateTime.Now + ": Empfange Nachricht");
LogAllClients();
try
{
var responseByteCount = dataPacket.Socket.EndReceive(asyncResult);
@@ -119,7 +144,7 @@ namespace BeWoChatServer
case DataIdentifier.Login:
try
{
Console.WriteLine(DateTime.Now + ": Login von " + dataPacket.ClientName);
Console.WriteLine(DateTime.Now + ": Login von " + dataPacket.ClientName + " mit MAC: " + dataPacket.ChatMessage);
Monitor.Enter(_Lock);
var endPoint = dataPacket.Socket.RemoteEndPoint;
@@ -127,21 +152,34 @@ namespace BeWoChatServer
var endPointCollection = clientList.Select(s => s.Key.RemoteEndPoint).ToList();
var istEnthalten = endPointCollection.Contains(endPoint);
var alteLogins = clientList.Values.Any(a => a.MacAddress.Equals(dataPacket.ChatMessage));
if(alteLogins)
{
var alt = clientList.Where(w => w.Value.MacAddress.Equals(dataPacket.ChatMessage) && !w.Key.Equals(dataPacket.Socket));
clientList.RemoveRange(alt);
}
if(istEnthalten)
{
clientList[dataPacket.Socket] = dataPacket.SenderPersonOid;
clientList[dataPacket.Socket].PersonOid = dataPacket.SenderPersonOid;
clientList[dataPacket.Socket].MacAddress = dataPacket.ChatMessage;
}
var notificationPacket = new Packet(dataPacket.Socket, dataPacket.ClientName, dataPacket.SenderPersonOid, 0) {DataIdentifier = DataIdentifier.StatusNotificationLogin, Tenant = dataPacket.Tenant};
Console.WriteLine(DateTime.Now + ": Benachrichtige die anderen angemeldeten Clients");
foreach (var client in clientList.Where(w => !w.Value.Equals(dataPacket.SenderPersonOid)))
Console.WriteLine(DateTime.Now + ": Benachrichtige die anderen angemeldeten Clients. Alte Logins enthalten: " + alteLogins);
foreach (var client in clientList.Where(w => !w.Value.PersonOid.Equals(dataPacket.SenderPersonOid)))
{
client.Key.Send(notificationPacket.GetDataStream());
}
var successfulLoginNotification = new Packet(dataPacket.Socket, dataPacket.ClientName, dataPacket.SenderPersonOid, 0) {DataIdentifier = DataIdentifier.LoginSuccess, Tenant = dataPacket.Tenant};
dataPacket.Socket.Send(successfulLoginNotification.GetDataStream());
// Boradcast
var abc = clientList.Where(w => w.Value != dataPacket.SenderPersonOid && w.Value > 0).Select(s => s.Value).Distinct().ToList();
var abc = clientList.Where(w => w.Value.PersonOid != dataPacket.SenderPersonOid && w.Value.PersonOid > 0).Select(s => s.Value.PersonOid).Distinct().ToList();
var msg = "";
foreach(var oid in abc)
@@ -160,6 +198,8 @@ namespace BeWoChatServer
dataPacket.Socket.Send(packet.GetDataStream());
}
LogAllClients();
}
finally
{
@@ -178,7 +218,13 @@ namespace BeWoChatServer
var notificationPacketLogout2 = new Packet(dataPacket.Socket, dataPacket.ClientName, dataPacket.SenderPersonOid, 0) {DataIdentifier = DataIdentifier.StatusNotificationLogout};
clientList.Remove(dataPacket.Socket);
LoginData wtf = null;
var wasAbleToRemoveClient = clientList.TryRemove(dataPacket.Socket, out wtf);
if(!wasAbleToRemoveClient)
{
Console.WriteLine("Konnte den Client nicht aus der Liste entfernen.");
}
Console.WriteLine(DateTime.Now + ": Leite Logout an die anderen Clients weiter");
foreach(var client in clientList)
@@ -200,8 +246,8 @@ namespace BeWoChatServer
try
{
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(DateTime.Now + ": Chat-Nachricht erhalten");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine(DateTime.Now + ": Chat-Nachricht erhalten: " + dataPacket.ChatMessage);
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.Gray;
@@ -211,11 +257,12 @@ namespace BeWoChatServer
var chatMessage = new ChatMessage
{
SenderPersonOid = dataPacket.SenderPersonOid,
ChatText = dataPacket.ChatMessage,
SenderPersonOid = dataPacket.SenderPersonOid,
ChatText = dataPacket.ChatMessage,
EmpfängerPersonOid = dataPacket.RecipientPersonOid,
Uhrzeit = dataPacket.MessageTimeStamp,
InsUser = dataPacket.ClientName
Uhrzeit = DateTime.Now,
InsUser = dataPacket.ClientName,
IsDelivered = dataPacket.IsDelivered
};
Console.WriteLine(DateTime.Now + ": Speichere die Chat-Nachricht in die Datenbank");
@@ -230,9 +277,9 @@ namespace BeWoChatServer
if(dataPacket.RecipientPersonOid > 0)
{
if (clientList.ContainsValue(dataPacket.RecipientPersonOid))
if (clientList.Values.Any(a => a.PersonOid.Equals(dataPacket.RecipientPersonOid)))
{
var recipients = clientList.Where(w => w.Value.Equals(dataPacket.RecipientPersonOid));
var recipients = clientList.Where(w => w.Value.PersonOid.Equals(dataPacket.RecipientPersonOid));
Console.WriteLine(DateTime.Now + ": Leite die Chat-Nachricht an die Empfänger (Derselbe User angemeldet an verschiedenen Clients) weiter");
foreach(var recipient in recipients)
@@ -260,17 +307,23 @@ namespace BeWoChatServer
break;
case DataIdentifier.Logout:
clientList.Remove(dataPacket.Socket);
LoginData ld;
var wasAbleToRemoveClient2 = clientList.TryRemove(dataPacket.Socket, out ld);
if(!wasAbleToRemoveClient2)
{
Console.WriteLine("Konnte den Client nicht aus der Liste entfernen.");
}
var notificationPacketLogout = new Packet(dataPacket.Socket, dataPacket.ClientName, dataPacket.SenderPersonOid, 0) {DataIdentifier = DataIdentifier.StatusNotificationLogout};
Console.WriteLine(DateTime.Now + ": Sende Logout an alle anderen Clients");
foreach (var client in clientList.Where(w => !w.Value.Equals(dataPacket.SenderPersonOid)))
foreach (var client in clientList.Where(w => !w.Value.PersonOid.Equals(dataPacket.SenderPersonOid)))
{
client.Key.Send(notificationPacketLogout.GetDataStream());
}
LogAllClients();
break;
case DataIdentifier.Team:
@@ -306,7 +359,7 @@ namespace BeWoChatServer
}
Console.WriteLine(DateTime.Now + ": Leite die Team-Nachricht an die Empfänger weiter");
foreach(var recipient in clientList.Where(w => w.Value != dataPacket.SenderPersonOid && personOids.Contains(w.Value)))
foreach (var recipient in clientList.Where(w => w.Value.PersonOid != dataPacket.SenderPersonOid && personOids.Contains(w.Value.PersonOid)))
{
recipient.Key.Send(dataPacket.GetDataStream());
}
@@ -344,6 +397,12 @@ namespace BeWoChatServer
SendNotificationPacket(dataPacket, DataIdentifier.StatusNotificationOffline);
break;
case DataIdentifier.Null:
var asfdabc = dataPacket.ChatMessage;
break;
}
@@ -363,7 +422,14 @@ namespace BeWoChatServer
if(clientList.ContainsKey(sender))
{
clientList.Remove(sender);
LoginData loginData;
var wasAbleToRemoveClient3 = clientList.TryRemove(sender, out loginData);
if(!wasAbleToRemoveClient3)
{
Console.WriteLine("Konnte den Client nicht aus der Liste entfernen.");
}
LogAllClients();
Console.WriteLine(DateTime.Now + ": Leite Logout an die anderen Clients weiter");
foreach(var client in clientList)
@@ -374,6 +440,10 @@ namespace BeWoChatServer
sender.Close();
}
}
catch(SocketException se)
{
WriteErrorMessageToConsole(se.Message, se.StackTrace);
}
finally
{
Monitor.Exit(_Lock);
@@ -388,7 +458,7 @@ namespace BeWoChatServer
var notificationPacket = new Packet(dataPacket.Socket, dataPacket.ClientName, dataPacket.SenderPersonOid, 0) { DataIdentifier = DataIdentifier.StatusNotificationLogout };
Console.WriteLine(DateTime.Now + ": Sende Statusänderung(" + dataIdentifier + ") an alle anderen Clients");
foreach (var client in clientList.Where(w => w.Value != dataPacket.SenderPersonOid))
foreach (var client in clientList.Where(w => w.Value.PersonOid != dataPacket.SenderPersonOid))
{
client.Key.Send(notificationPacket.GetDataStream());
}
@@ -404,4 +474,18 @@ namespace BeWoChatServer
Console.ForegroundColor = ConsoleColor.Gray;
}
}
public class LoginData
{
public long PersonOid { get; set; }
public string MacAddress { get; set; }
public DateTime LoginTime { get; set; }
public LoginData(long pPersonOid, string pMacAddress, DateTime pLoginTime)
{
PersonOid = pPersonOid;
MacAddress = pMacAddress;
LoginTime = pLoginTime;
}
}
}

Binary file not shown.

View File

@@ -86,11 +86,9 @@ namespace BeWoPlanerAndroid
[WebMethod(EnableSession = true)]
public string GetAllChatMessagesForSenderAndRecipient(long pSenderPersonOid, long pRecipientPersonOid, string pExceptions, bool pIsForTeam)
{
Debug.WriteLine(pExceptions);
var exceptions = new List<long>();
if (pExceptions.Length > 0 && pExceptions.Contains(";"))
if (pExceptions.Length > 0)
{
var splittedString = pExceptions.Split(';');
exceptions = splittedString.Select(item => Convert.ToInt64(item)).ToList();
@@ -98,7 +96,7 @@ namespace BeWoPlanerAndroid
var messages = DAOFactory.SearchDAO.FindAllChatMessagesForAndroid(pSenderPersonOid, pRecipientPersonOid, exceptions, pIsForTeam);
messages.DoForEach(dfe => Debug.WriteLine(dfe.Oid.Value));
messages.DoForEach(m => Debug.WriteLine("Team: " + (m.TeamOid == null ? "Nein" : m.TeamOid.Value.ToString()) + "; Text: " + m.ChatText));
return JsonConvert.SerializeObject(messages);
}

File diff suppressed because one or more lines are too long

View File

@@ -5,10 +5,12 @@ using System.Globalization;
using System.IO;
using System.ServiceModel;
using System.Threading;
using log4net;
using log4net.Appender;
using log4net.Layout;
using log4net.Repository.Hierarchy;
using NHibernate;
using NHibernate.Cfg;

View File

@@ -16,7 +16,7 @@ namespace BeWo.Data.Entities
public static string PropertyName_TeamOid = "TeamOid";
public static string PropertyName_IstZugestellt = "IstZugestellt";
public static string PropertyName_IsDelivered = "IsDelivered";
public static string PropertyName_IstGelesen = "IstGelesen";
@@ -28,7 +28,7 @@ namespace BeWo.Data.Entities
private long? _SenderPersonOid;
private int _istZugestellt;
private bool _IsDelivered;
private int _IstGelesen;
@@ -103,17 +103,17 @@ namespace BeWo.Data.Entities
}
}
public virtual int istZugestellt
public virtual bool IsDelivered
{
get
{
return _istZugestellt;
return _IsDelivered;
}
set
{
if (AreDifferent(_istZugestellt, value))
if (AreDifferent(_IsDelivered, value))
{
_istZugestellt = value;
_IsDelivered = value;
}
}
}

View File

@@ -17,7 +17,7 @@
<property name="Notice" />
<property name="Uhrzeit" column="Uhrzeit" />
<property name="ChatText" column="ChatText" />
<property name="istZugestellt" column="IstZugestellt" />
<property name="IsDelivered" column="istZugestellt" />
<property name="IstGelesen" column="IstGelesen" />
<property name="TeamOid" column="TeamOid" />

View File

@@ -1,5 +1,4 @@
using System.IO;
using BeWo.Data.Entities;
using BeWo.Data.Entities;
using BS.Shared.DataContracts;
@@ -9,12 +8,11 @@ namespace BeWo.Service.DCEntityMapper
{
public override ChatMessageDC MergeWithDC(ChatMessage pEntity, ChatMessageDC pDataContract)
{
pDataContract.SenderPersonOid = pEntity.SenderPersonOid;
pDataContract.EmpfängerPersonOid = pEntity.EmpfängerPersonOid;
pDataContract.ChatText = pEntity.ChatText;
pDataContract.Uhrzeit = pEntity.Uhrzeit;
pDataContract.IstZugestellt = pEntity.istZugestellt;
pDataContract.IsDelivered = pEntity.IsDelivered;
pDataContract.IstGelesen = pEntity.IstGelesen;
pDataContract.TeamOid = pEntity.TeamOid;
@@ -27,7 +25,7 @@ namespace BeWo.Service.DCEntityMapper
pEntity.EmpfängerPersonOid = pDataContract.EmpfängerPersonOid;
pEntity.Uhrzeit = pDataContract.Uhrzeit;
pEntity.ChatText = pDataContract.ChatText;
pEntity.istZugestellt = pDataContract.IstZugestellt;
pEntity.IsDelivered = pDataContract.IsDelivered;
pEntity.IstGelesen = pDataContract.IstGelesen;
pEntity.TeamOid = pDataContract.TeamOid;

View File

@@ -515,7 +515,7 @@ namespace BeWo.Service.ServiceContracts
[FaultContract(typeof (BeWoFault))]
[OperationContract]
ChatMessageDC CreateNewChatMessagesDC(long senderOid, long empfängerOid, string message, int istZugestellt,long teamid);
ChatMessageDC CreateNewChatMessagesDC(long senderOid, long empfängerOid, string message, bool isDeliverd, long teamid);
[FaultContract(typeof(BeWoFault))]
[OperationContract]

View File

@@ -3128,7 +3128,7 @@ namespace BeWo.Service.ServiceImplementations
}
}
public ChatMessageDC CreateNewChatMessagesDC(long senderOid, long empfängerOid, string message, int istZugestellt, long teamid)
public ChatMessageDC CreateNewChatMessagesDC(long senderOid, long empfängerOid, string message, bool isDeliverd, long teamid)
{
try
{
@@ -3137,7 +3137,7 @@ namespace BeWo.Service.ServiceImplementations
newCode.SenderPersonOid = senderOid;
newCode.Uhrzeit = DateTime.Now;
newCode.ChatText = message;
newCode.istZugestellt = istZugestellt;
newCode.IsDelivered = isDeliverd;
newCode.IstGelesen = 0;
if (teamid != 0)

View File

@@ -837,7 +837,8 @@ namespace BS.Shared
MessageResponse,
StatusNotificationBeschäftigt,
StatusNotificationOnline,
StatusNotificationOffline
StatusNotificationOffline,
LoginSuccess
}
public enum ChatType

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace BS.Shared.DataContracts
@@ -23,7 +22,7 @@ namespace BS.Shared.DataContracts
public string ChatText { get; set; }
[DataMember]
public int IstZugestellt { get; set; }
public bool IsDelivered { get; set; }
[DataMember]
public int IstGelesen { get; set; }