Bessere Sortierung der Chatnachrichten

This commit is contained in:
staccatomamba
2016-09-30 10:19:11 +02:00
parent a79346e145
commit fbb6db4dd2
86 changed files with 465 additions and 248 deletions

View File

@@ -66,14 +66,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
@@ -82,6 +74,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />

View File

@@ -303,7 +303,16 @@ public class DatabaseHandler extends SQLiteOpenHelper {
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},
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);
@@ -334,8 +343,22 @@ public class DatabaseHandler extends SQLiteOpenHelper {
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 + "=?",
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_TEAM_CHATMESSAGE + " = 0 AND " +
KEY_SENDER_PERSON_OID_CHATMESSAGE + "=? AND " +
KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + "=? OR " +
KEY_RECIPIENT_PERSON_OID_CHATMESSAGE + "=? AND " +
KEY_SENDER_PERSON_OID_CHATMESSAGE + "=?"
,
new String[] {String.valueOf(SoapConnectionManager.User.getPersonOid()), String.valueOf(recipientOid), String.valueOf(SoapConnectionManager.User.getPersonOid()), String.valueOf(recipientOid)},
null, null, null, null);
@@ -587,6 +610,28 @@ public class DatabaseHandler extends SQLiteOpenHelper {
return null;
}
public boolean GetIsMessageInDatabase(int pServerseitigeOid) {
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_SERVERSEITIGE_OID_CHATMESSAGE + " =?",
new String[] {String.valueOf(pServerseitigeOid)},
null, null, null, null);
return cursor != null && cursor.moveToFirst();
}
public ArrayList<ChatMessage> getUnsentChatMessages() {
ArrayList<ChatMessage> messages = new ArrayList<>();

View File

@@ -27,6 +27,20 @@ import util.ConnectivityReceiver;
* Created by JettenM on 24.08.2016.
*/
public class BeWoChatApplication extends Application {
private static boolean activityVisible;
public static boolean isActivityVisible() {
return activityVisible;
}
public static void activityResumed() {
activityVisible = true;
}
public static void activityPaused() {
activityVisible = false;
}
private Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler;
private static final SpiceManager spiceManager = new SpiceManager(UncachedSpiceService.class);

View File

@@ -20,6 +20,7 @@ import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
@@ -46,12 +47,10 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Map;
import Database.DatabaseHandler;
import entities.ChatEntity;
import entities.ChatMessage;
import entities.NotificationLog;
import soapConnection.DataIdentifier;
import soapConnection.JsonSoapPrimitiveRequest;
import soapConnection.Packet;
@@ -119,6 +118,21 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
listView = (ListView)findViewById(R.id.list_msg);
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if(scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
Log.i("ON_SCROLL_STATE_CHANGED", "Berühre das Ende");
}
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
Log.i("ON_SCROLL", "Scrolle... firstVisibleItem: " + firstVisibleItem + "; visibleItemCount: " + visibleItemCount + "; totalItemCount" + totalItemCount);
}
});
Bundle zielkorb = getIntent().getExtras();
recipientName = zielkorb.getString("Name");
recipientPersonOid = zielkorb.getInt("RecipientOid");
@@ -158,9 +172,8 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
chatMessages = isTeam ? databaseHandler.getMessagesForTeam(recipientPersonOid) : databaseHandler.getMessagesForRecipient(recipientPersonOid);
Collections.sort(chatMessages, DATE_COMPARATOR);
adapter = new MessageAdapter(this, R.layout.item_chat_left, chatMessages);
adapter.sort(DATE_COMPARATOR);
listView.setAdapter(adapter);
chatUIHandler = new UIHandler() {
@@ -172,8 +185,9 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
listView.post(new Runnable() {
@Override
public void run() {
if(chatPacket.SenderPersonOid == recipientPersonOid) {
if(chatPacket.SenderPersonOid == recipientPersonOid && BeWoChatApplication.isActivityVisible()) {
chatMessages.add(new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, true, chatPacket.ServerseitigeOid, false));
adapter.sort(DATE_COMPARATOR);
adapter.notifyDataSetChanged();
} else {
Util.SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.SenderPersonOid, false, null, null, getApplicationContext());
@@ -210,8 +224,9 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
listView.post(new Runnable() {
@Override
public void run() {
if(isTeam && chatPacket.RecipientPersonOid == recipientPersonOid) {
if(isTeam && chatPacket.RecipientPersonOid == recipientPersonOid && BeWoChatApplication.isActivityVisible()) {
chatMessages.add(new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, true, chatPacket.ServerseitigeOid, true));
adapter.sort(DATE_COMPARATOR);
adapter.notifyDataSetChanged();
} else {
Util.SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.RecipientPersonOid, true, teamMemberOids, teamMemberNames, getApplicationContext());
@@ -250,7 +265,6 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
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();
@@ -261,7 +275,7 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
@Override
public void run() {
chatMessages.add(message);
adapter.sort(DATE_COMPARATOR);
adapter.notifyDataSetChanged();
text.setText("");
@@ -275,8 +289,6 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
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);
@@ -292,6 +304,8 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
propertyInfos.add(SoapConnectionManager.BuildProperty("pExceptions", pExceptions, String.class));
propertyInfos.add(SoapConnectionManager.BuildProperty("pIsForTeam", isTeam, Boolean.class));
Log.i(LOGTAG, "IsTeam: " + isTeam);
JsonSoapPrimitiveRequest request = new JsonSoapPrimitiveRequest(SoapCalls.GET_ALL_CHAT_MESSAGES, propertyInfos);
spiceManager.execute(request, new JsonSoapPrimitiveRequestListener());
@@ -308,6 +322,8 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
@Override
public void onResume() {
BeWoChatApplication.activityResumed();
SocketManager.uiHandler = chatUIHandler;
BeWoChatApplication.getInstance().setConnectivityListener(this);
@@ -324,6 +340,7 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
@Override
public void onPause() {
super.onPause();
BeWoChatApplication.activityPaused();
}
@Override
@@ -421,27 +438,13 @@ public class ChatActivity extends ActionBarActivity implements ConnectivityRecei
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() {
@Override
public void run() {
Collections.sort(result, DATE_COMPARATOR);
chatMessages.addAll(result);
adapter.sort(DATE_COMPARATOR);
adapter.notifyDataSetChanged();
}
});

View File

@@ -17,6 +17,9 @@ public class ContactListItem {
public String teamMemberOids;
public String teamMemberNames;
private String messagePreview;
private boolean isNewMessage2Preview;
public ContactListItem(){}
public ContactListItem(int id, String kontaktname, int personOid, byte[] picture, boolean isTeam, String teamMemberOids, String teamMemberNames, int version){
@@ -87,6 +90,22 @@ public class ContactListItem {
this.mVersion = mVersion;
}
public String getMessagePreview() {
return messagePreview;
}
public void setMessagePreview(String message) {
messagePreview = message;
}
public boolean getIsNewMessage2Preview() {
return isNewMessage2Preview;
}
public void setIsNewMessage2Preview(boolean isNewMessage2Preview) {
this.isNewMessage2Preview = isNewMessage2Preview;
}
@Override
public String toString() {
String result = "";

View File

@@ -26,20 +26,18 @@ import java.util.ArrayList;
public class KontaktAdapter extends ArrayAdapter<ContactListItem> {
private final Context context;
public final ArrayList<ContactListItem> values;
final ArrayList<ContactListItem> values;
private Bitmap bitmaping;
ImageView imageView;
private ImageView imageView;
private TextView messagePreview;
private TextView minitext;
public void setMinitext(TextView minitext) {
this.minitext = minitext;
}
TextView minitext;
Thread getPic;
public KontaktAdapter(Context context, ArrayList<ContactListItem> values) {
KontaktAdapter(Context context, ArrayList<ContactListItem> values) {
super(context, R.layout.kontakt_list_chat, values);
this.context = context;
this.values = values;
@@ -52,16 +50,20 @@ public class KontaktAdapter extends ArrayAdapter<ContactListItem> {
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);
ImageView onlinestats = (ImageView)rowView.findViewById(R.id.status);
messagePreview = (TextView) rowView.findViewById(R.id.messagePreview);
ImageView onlinestats = (ImageView) rowView.findViewById(R.id.status);
imageView = (ImageView) rowView.findViewById(R.id.logo);
textView.setText(values.get(position).getChatName());
messagePreview.setText(values.get(position).getMessagePreview());
messagePreview.setTypeface(messagePreview.getTypeface(), values.get(position).getIsNewMessage2Preview() ? 1 : 0);
if(values.get(position).isTeam) {
minitext.setText(values.get(position).teamMemberNames);
}
Thread getPic;
if(values.get(position).getPicture() != null) {
byte[] imageAsByteArray = values.get(position).getPicture();
@@ -82,7 +84,7 @@ public class KontaktAdapter extends ArrayAdapter<ContactListItem> {
return rowView;
}
public class CircleBitmapCreator implements Runnable{
private class CircleBitmapCreator implements Runnable{
Bitmap bitmap;
CircleBitmapCreator(Bitmap _bitmap){
@@ -119,7 +121,7 @@ public class KontaktAdapter extends ArrayAdapter<ContactListItem> {
}
}
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {
private static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) {
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(res, resId, options);
@@ -130,7 +132,7 @@ public class KontaktAdapter extends ArrayAdapter<ContactListItem> {
return BitmapFactory.decodeResource(res, resId, options);
}
public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;

View File

@@ -26,6 +26,7 @@ import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapPrimitive;
import java.io.ByteArrayOutputStream;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
@@ -34,6 +35,7 @@ import java.util.Map;
import Database.DatabaseHandler;
import entities.ChatEntity;
import entities.ChatMessage;
import entities.ChatPerson;
import soapConnection.JsonSoapPrimitiveRequest;
import soapConnection.OnRequestSuccessCallback;
@@ -42,6 +44,7 @@ import soapConnection.SoapCalls;
import soapConnection.SoapConnectionManager;
import tcpConnection.SocketManager;
import tcpConnection.UIHandler;
import util.ChatMessageDeserializer;
import util.ConnectivityReceiver;
import util.Util;
@@ -122,12 +125,6 @@ public class KontaktChatActivity extends ActionBarActivity implements Connectivi
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());
}
@Override
@@ -148,6 +145,12 @@ public class KontaktChatActivity extends ActionBarActivity implements Connectivi
Util.sendStatusRequest();
swipeRefreshLayout.setRefreshing(false);
ArrayList<PropertyInfo> propertyInfos = new ArrayList<>();
propertyInfos.add(SoapConnectionManager.BuildProperty("pRecipientPersonOid", SoapConnectionManager.User.getPersonOid(), Long.class));
JsonSoapPrimitiveRequest request = new JsonSoapPrimitiveRequest("GetNewestMessages", propertyInfos);
spiceManager.execute(request, new JsonSoapPrimitiveRequestListenerForNewestMessages());
}
}));
}
@@ -158,15 +161,53 @@ public class KontaktChatActivity extends ActionBarActivity implements Connectivi
try {
switch(chatPacket.ChatDataIdentifier) {
case MESSAGE:
//TODO: Statt Notification Nachricht fett in der Liste darstellen? Oder beides?
Util.SetNotify(chatPacket.ChatName, chatPacket.ChatMessage, chatPacket.SenderPersonOid, false, null, null, getApplicationContext());
runOnUiThread(new Runnable() {
@Override
public void run() {
KontaktAdapter ka =((KontaktAdapter) listView.getAdapter());
for(ContactListItem item : ka.values) {
if(item.getPersonOid() == chatPacket.SenderPersonOid && !item.isTeam) {
item.setMessagePreview(chatPacket.ChatMessage);
item.setIsNewMessage2Preview(true);
break;
}
}
ka.notifyDataSetChanged();
}
});
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());
runOnUiThread(new Runnable() {
@Override
public void run() {
KontaktAdapter ka =((KontaktAdapter) listView.getAdapter());
for(ContactListItem item : ka.values) {
if(item.getPersonOid() == chatPacket.RecipientPersonOid && !item.isTeam) {
item.setMessagePreview(chatPacket.ChatMessage);
item.setIsNewMessage2Preview(true);
break;
}
}
ka.notifyDataSetChanged();
}
});
break;
case STATUS_NOTIFICATION_LOGIN:
runOnUiThread(new Runnable() {
@@ -223,9 +264,6 @@ public class KontaktChatActivity extends ActionBarActivity implements Connectivi
break;
case STATUS_REQUEST:
Log.i(LOGTAG, "Aktualisiere die Kontaktliste");
runOnUiThread(new Runnable() {
@Override
public void run() {
@@ -278,6 +316,8 @@ public class KontaktChatActivity extends ActionBarActivity implements Connectivi
@Override
public void onResume() {
BeWoChatApplication.activityResumed();
SocketManager.uiHandler = kontaktChatActivityUIHandler;
BeWoChatApplication.getInstance().setConnectivityListener(this);
@@ -305,6 +345,7 @@ public class KontaktChatActivity extends ActionBarActivity implements Connectivi
@Override
public void onPause() {
super.onPause();
BeWoChatApplication.activityPaused();
}
@Override
@@ -324,9 +365,47 @@ public class KontaktChatActivity extends ActionBarActivity implements Connectivi
super.onBackPressed();
}
private final class JsonSoapPrimitiveRequestListenerForNewestMessages implements RequestListener<SoapPrimitive> {
@Override
public void onRequestFailure(SpiceException spiceException) {
Toast.makeText(KontaktChatActivity.this, "Ein Fehler ist beim laden der neuesten Nachrichten aufgetreten.", Toast.LENGTH_SHORT).show();
}
@Override
public void onRequestSuccess(SoapPrimitive soapPrimitive) {
if(soapPrimitive == null) {
Log.e("KONTAKT_CHAT_ACTIVITY", "Neueste Nachrichten ist NULL!");
}
GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(ChatMessage.class, new ChatMessageDeserializer());
Gson gson = builder.create();
Type listType = new TypeToken<ArrayList<ChatMessage>>(){}.getType();
ArrayList<ChatMessage> result = gson.fromJson(soapPrimitive.toString(), listType);
KontaktAdapter adapter = (KontaktAdapter) listView.getAdapter();
for(ChatMessage message : result) {
if(adapter != null) {
for(ContactListItem item : adapter.values) {
if(item.getPersonOid() == message.SenderPersonOid && !item.isTeam && !message.IsTeam || item.isTeam && message.IsTeam && item.getPersonOid() == message.RecipientPersonOid) {
item.setMessagePreview(message.ChatText);
item.setIsNewMessage2Preview(!databaseHandler.GetIsMessageInDatabase(message.ServerseitigeOid));
}
}
adapter.notifyDataSetChanged();
}
}
}
}
private final class JsonSoapPrimitiveRequestListener implements RequestListener<SoapPrimitive> {
//TODO: zusätzliches onRequestSuccess-Callback einbauen
OnRequestSuccessCallback callback;
JsonSoapPrimitiveRequestListener(OnRequestSuccessCallback callback) {
@@ -344,8 +423,6 @@ public class KontaktChatActivity extends ActionBarActivity implements Connectivi
Log.e("KONTAKT_CHAT_ACTIVITY", "soapPrimitive ist NULL!");
}
Log.i(LOGTAG, "Lade Kontakte vom Server herunter");
Gson gson = new GsonBuilder().create();
Type listType = new TypeToken<ArrayList<ChatPerson>>(){}.getType();

View File

@@ -257,61 +257,83 @@ public class LoginActivity extends ActionBarActivity {
String abc = soapPrimitive.toString();
if(abc != null) {
String[] blubb = abc.split(";");
SoapConnectionManager.User = new ApplicationUser(blubb[1], blubb[2], Long.valueOf(blubb[0]), Long.valueOf(blubb[3]));
DatabaseHandler databaseHandler = DatabaseHandler.getInstance(getApplicationContext());
Log.i("LOGIN", abc);
int owner = databaseHandler.getOwnerOid();
if(owner == 0) {
databaseHandler.insertOwnerOid(SoapConnectionManager.User.getPersonOid().intValue());
} else if(owner != SoapConnectionManager.User.getPersonOid().intValue()) {
databaseHandler.clearDatabase();
databaseHandler.insertOwnerOid(SoapConnectionManager.User.getPersonOid().intValue());
}
if(abc.contains(";")) {
String[] blubb = abc.split(";");
SoapConnectionManager.User = new ApplicationUser(blubb[1], blubb[2], Long.valueOf(blubb[0]), Long.valueOf(blubb[3]));
SoapConnectionManager.User.setTenant(mTenantView.getText().toString());
DatabaseHandler databaseHandler = DatabaseHandler.getInstance(getApplicationContext());
if(mRememberMeCheckBoxView.isChecked()) {
ByteArrayOutputStream tokenOutputStream = new ByteArrayOutputStream();
ByteArrayOutputStream tenantOutputStream = new ByteArrayOutputStream();
ByteArrayOutputStream usernameOutputStream = new ByteArrayOutputStream();
ByteArrayOutputStream passwordOutputStream = new ByteArrayOutputStream();
int owner = databaseHandler.getOwnerOid();
if(owner == 0) {
databaseHandler.insertOwnerOid(SoapConnectionManager.User.getPersonOid().intValue());
} else if(owner != SoapConnectionManager.User.getPersonOid().intValue()) {
databaseHandler.clearDatabase();
databaseHandler.insertOwnerOid(SoapConnectionManager.User.getPersonOid().intValue());
}
try {
SecurityUtils.encrypt(mChatCodeView.getText().toString(), tokenOutputStream);
SecurityUtils.encrypt(mTenantView.getText().toString(), tenantOutputStream);
SecurityUtils.encrypt(mUsernameView.getText().toString(), usernameOutputStream);
SecurityUtils.encrypt(mPasswordView.getText().toString(), passwordOutputStream);
SoapConnectionManager.User.setTenant(mTenantView.getText().toString());
SharedPreferences settings = getSharedPreferences(Util.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
if(mRememberMeCheckBoxView.isChecked()) {
ByteArrayOutputStream tokenOutputStream = new ByteArrayOutputStream();
ByteArrayOutputStream tenantOutputStream = new ByteArrayOutputStream();
ByteArrayOutputStream usernameOutputStream = new ByteArrayOutputStream();
ByteArrayOutputStream passwordOutputStream = new ByteArrayOutputStream();
editor.putString(Util.PREFS_TOKEN_KEY, Base64.encodeToString(tokenOutputStream.toByteArray(), Base64.DEFAULT));
editor.putString(Util.PREFS_TENANT_KEY, Base64.encodeToString(tenantOutputStream.toByteArray(), Base64.DEFAULT));
editor.putString(Util.PREFS_USERNAME_KEY, Base64.encodeToString(usernameOutputStream.toByteArray(), Base64.DEFAULT));
editor.putString(Util.PREFS_PASSWORD, Base64.encodeToString(passwordOutputStream.toByteArray(), Base64.DEFAULT));
try {
SecurityUtils.encrypt(mChatCodeView.getText().toString(), tokenOutputStream);
SecurityUtils.encrypt(mTenantView.getText().toString(), tenantOutputStream);
SecurityUtils.encrypt(mUsernameView.getText().toString(), usernameOutputStream);
SecurityUtils.encrypt(mPasswordView.getText().toString(), passwordOutputStream);
editor.apply();
SharedPreferences settings = getSharedPreferences(Util.PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
} catch (IOException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) {
e.printStackTrace();
editor.putString(Util.PREFS_TOKEN_KEY, Base64.encodeToString(tokenOutputStream.toByteArray(), Base64.DEFAULT));
editor.putString(Util.PREFS_TENANT_KEY, Base64.encodeToString(tenantOutputStream.toByteArray(), Base64.DEFAULT));
editor.putString(Util.PREFS_USERNAME_KEY, Base64.encodeToString(usernameOutputStream.toByteArray(), Base64.DEFAULT));
editor.putString(Util.PREFS_PASSWORD, Base64.encodeToString(passwordOutputStream.toByteArray(), Base64.DEFAULT));
editor.apply();
} catch (IOException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) {
e.printStackTrace();
}
}
SocketManager.tenant = mTenantView.getText().toString();
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);
switch(abc) {
case "WrongTenant":
showLoginUIErrors(false, true, false, false);
break;
case "WrongCredentials":
showLoginUIErrors(false, false, true, true);
break;
case "Unauthorized":
Toast.makeText(getApplicationContext(), "Sie sind nicht zum Chatten autorisiert. Bitte wenden Sie sich an Ihren Administrator.", Toast.LENGTH_LONG).show();
break;
default:
Toast.makeText(getApplicationContext(), "Ein unbekannter Fehler ist aufgetreten. Bitte versuchen Sie es später erneut.", Toast.LENGTH_LONG).show();
break;
}
}
SocketManager.tenant = mTenantView.getText().toString();
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

@@ -45,16 +45,14 @@ public class ChatMessage {
@Override
public String toString() {
String asString = "";
asString += "Id: " + Id;
asString += "\nSenderPersonOid: " + SenderPersonOid;
asString += "\nRecipientPersonOid: " + RecipientPersonOid;
asString += "\nInsTs: " + getInsTsAsString();
asString += "\nChatText: " + ChatText;
asString += "\nIsDelivered: " + IsDelivered;
asString += "\nServerseitigeOid: " + ServerseitigeOid;
asString += "\nIsTeam: " + IsTeam;
String asString = "Id: " + Id;
asString += "\nSenderPersonOid: " + SenderPersonOid;
asString += "\nRecipientPersonOid: " + RecipientPersonOid;
asString += "\nInsTs: " + getInsTsAsString();
asString += "\nChatText: " + ChatText;
asString += "\nIsDelivered: " + IsDelivered;
asString += "\nServerseitigeOid: " + ServerseitigeOid;
asString += "\nIsTeam: " + IsTeam;
return asString;
}

View File

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

View File

@@ -1,7 +1,6 @@
package tcpConnection;
import android.util.Log;
import android.widget.ImageView;
import java.io.DataOutputStream;
import java.io.IOException;
@@ -25,7 +24,6 @@ import entities.NotificationLog;
import soapConnection.DataIdentifier;
import soapConnection.Packet;
import soapConnection.SoapCalls;
import soapConnection.SoapConnectionManager;
import util.Util;
/**
@@ -33,7 +31,7 @@ import util.Util;
*/
public class SocketManager {
private static final String TAG = "SOCKET_MANAGER";
private static final String LOGTAG = "SOCKET_MANAGER";
private static DatabaseHandler databaseHandler = DatabaseHandler.getInstance(BeWoChatApplication.getInstance());
@@ -216,7 +214,7 @@ public class SocketManager {
}
if(chatPacket.ChatDataIdentifier.equals(DataIdentifier.LOGIN_SUCCESS) && loginCallback != null) {
Log.i(TAG, "Der Login war erfolgreich");
Log.i(LOGTAG, "Der Login war erfolgreich");
loginCallback.doCallback();
}
@@ -225,6 +223,8 @@ public class SocketManager {
switch (chatPacket.ChatDataIdentifier) {
case MESSAGE:
Log.i(LOGTAG, "Empfange Nacahricht");
databaseHandler.addChatMessage(new ChatMessage(chatPacket.SenderPersonOid, chatPacket.RecipientPersonOid, chatPacket.MessageTimeStamp, chatPacket.ChatMessage, true, chatPacket.ServerseitigeOid, false));
break;
@@ -249,17 +249,6 @@ public class SocketManager {
SocketManager.onlinePersonOids.add(chatPacket.SenderPersonOid);
}
//if(!SocketManager.onlineEntities.)
/*
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());
}
}
*/
boolean isAlreadyLoggedIn = false;
for(ChatEntity entity : SocketManager.onlineEntities)
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 529 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 908 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1013 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 908 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1013 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 296 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 908 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1013 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 932 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 938 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 932 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 938 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 932 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 938 B

View File

@@ -2,44 +2,44 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
android:state_enabled="true"
android:drawable="@drawable/btn_check_on" />
android:drawable="@drawable/chk_on" />
<item android:state_checked="false" android:state_window_focused="false"
android:state_enabled="true"
android:drawable="@drawable/btn_check_off" />
android:drawable="@drawable/chk_off" />
<item android:state_checked="true" android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/btn_check_on_pressed" />
android:drawable="@drawable/chk_on" />
<item android:state_checked="false" android:state_pressed="true"
android:state_enabled="true"
android:drawable="@drawable/btn_check_off_pressed" />
android:drawable="@drawable/chk_off_pressed" />
<item android:state_checked="true" android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/btn_check_on_selected" />
android:drawable="@drawable/chk_on" />
<item android:state_checked="false" android:state_focused="true"
android:state_enabled="true"
android:drawable="@drawable/btn_check_off_selected" />
android:drawable="@drawable/chk_off" />
<item android:state_checked="false"
android:state_enabled="true"
android:drawable="@drawable/btn_check_off" />
android:drawable="@drawable/chk_off" />
<item android:state_checked="true"
android:state_enabled="true"
android:drawable="@drawable/btn_check_on" />
android:drawable="@drawable/chk_on" />
<!-- Disabled states -->
<!--&lt;!&ndash; Disabled states &ndash;&gt;-->
<item android:state_checked="true" android:state_window_focused="false"
android:drawable="@drawable/btn_check_on_disable" />
android:drawable="@drawable/chk_on_disabled" />
<item android:state_checked="false" android:state_window_focused="false"
android:drawable="@drawable/btn_check_off_disable" />
android:drawable="@drawable/chk_off_disabled" />
<item android:state_checked="true" android:state_focused="true"
android:drawable="@drawable/btn_check_on_disable_focused" />
android:drawable="@drawable/chk_on_disabled" />
<item android:state_checked="false" android:state_focused="true"
android:drawable="@drawable/btn_check_off_disable_focused" />
android:drawable="@drawable/chk_off_disabled" />
<item android:state_checked="false" android:drawable="@drawable/btn_check_off_disable" />
<item android:state_checked="false" android:drawable="@drawable/chk_off_disabled" />
</selector>

View File

@@ -3,12 +3,12 @@
<item android:state_pressed="true" >
<shape>
<solid
android:color="#ef4444" />
android:color="#FF9B60" />
<stroke
android:width="1dp"
android:color="#992f2f" />
android:width="0dp"
android:color="#FF5E00" />
<corners
android:radius="6dp" />
android:radius="30dp" />
<padding
android:left="10dp"
android:top="10dp"
@@ -19,7 +19,7 @@
<item>
<shape>
<gradient
android:startColor="#ff6e1a"
android:startColor="#FF6E1A"
android:centerX="0.2"
android:centerY="0.2"
android:centerColor="#FF5E00"
@@ -29,7 +29,7 @@
<stroke
android:width="0dp"
android:color="#992f2f" />
android:color="#FF5E00" />
<corners
android:radius="30dp" />
<padding

View File

@@ -90,7 +90,9 @@
android:text="@string/prompt_remember_me"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:onClick="rememberMeOnClick"/>
android:onClick="rememberMeOnClick"
android:button="@drawable/bewo_checkbox"
/>
<Button
android:id="@+id/sign_in_button"

View File

@@ -37,10 +37,10 @@
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:singleLine="true"
android:textColor="?android:attr/textColorPrimary"
android:textSize="16sp"
android:textStyle="bold" />
android:textStyle="bold"
android:maxLines="1"/>
<TextView
android:id="@+id/subtitle"
@@ -48,9 +48,20 @@
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" />
android:textStyle="normal"
android:maxLines="1"/>
<TextView
android:id="@+id/messagePreview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:textColor="?android:attr/textColorSecondary"
android:textSize="14sp"
android:textStyle="normal"
android:maxLines="1"/>
</LinearLayout>
</LinearLayout>

View File

@@ -3,6 +3,11 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<!--<item name="actionBarStyle">@style/MyActionBar</item>-->
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#FF5E00</item>
</style>
<style name="button_text" >

View File

@@ -1421,14 +1421,26 @@ namespace BeWo.View
{
try
{
NetworkStream serverStream = s.GetStream();
var serverStream = s.GetStream();
String abc = NetworkInterface.GetAllNetworkInterfaces().Where(inc => inc.OperationalStatus == OperationalStatus.Up).Select(inc => inc.GetPhysicalAddress().ToString()).FirstOrDefault();
var macAddress = NetworkInterface.GetAllNetworkInterfaces().Where(inc => inc.OperationalStatus == OperationalStatus.Up).Select(inc => inc.GetPhysicalAddress().ToString()).FirstOrDefault();
Packet a = new Packet();
var formattedMacAddress = "";
if(macAddress != null)
{
for(var i = 0; i < macAddress.Length; i++)
{
formattedMacAddress += macAddress[i];
if((i + 1) % 2 == 0 && i < macAddress.Length - 1)
{
formattedMacAddress += ":";
}
}
}
byte[] outStream = a.GetDataStream(BeWoApp.LoggedOnUser.Employee.PersonOid, 0,
BeWoApp.LoggedOnUser.LoginName, abc, DataIdentifier.Login, BeWoApp.Tenant, false);
var a = new Packet();
var outStream = a.GetDataStream(BeWoApp.LoggedOnUser.Employee.PersonOid, 0, BeWoApp.LoggedOnUser.LoginName, formattedMacAddress, DataIdentifier.Login, BeWoApp.Tenant, false);
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();

View File

@@ -259,7 +259,7 @@ namespace BeWoChatServer
{
SenderPersonOid = dataPacket.SenderPersonOid,
ChatText = Encoding.UTF8.GetBytes(dataPacket.ChatMessage),
EmpfängerPersonOid = dataPacket.RecipientPersonOid,
EmpfaengerPersonOid = dataPacket.RecipientPersonOid,
Uhrzeit = DateTime.Now,
InsUser = dataPacket.ClientName,
IsDelivered = dataPacket.IsDelivered
@@ -338,7 +338,7 @@ namespace BeWoChatServer
{
SenderPersonOid = dataPacket.SenderPersonOid,
ChatText = Encoding.UTF8.GetBytes(dataPacket.ChatMessage),
EmpfängerPersonOid = dataPacket.RecipientPersonOid,
EmpfaengerPersonOid = dataPacket.RecipientPersonOid,
Uhrzeit = dataPacket.MessageTimeStamp,
InsUser = dataPacket.ClientName,
TeamOid = dataPacket.RecipientPersonOid

View File

@@ -6,8 +6,6 @@ using System.Text;
using System.Web.Services;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.ServiceContracts;
using BeWo.Service.ServiceImplementations;
@@ -17,6 +15,7 @@ using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts.Compact;
using BS.Shared.Extensions;
using Newtonsoft.Json;
namespace BeWoPlanerAndroid
@@ -37,6 +36,11 @@ namespace BeWoPlanerAndroid
[WebMethod(EnableSession = true)]
public string Login(string pTenant, string pUsername, string pPassword)
{
if(!SoapHibernateSessionManager.TenantExists(pTenant))
{
return LoginFailReason.WrongTenant.ToString();
}
MobileSessionFacade.Tenant = pTenant;
Tenant = pTenant;
@@ -53,12 +57,12 @@ namespace BeWoPlanerAndroid
if (user == null || !DAOFactory.SearchDAO.CheckIfEmployeeIsAllowedToChat(user.Employee.Person.Oid.Value))
{
return null;
return LoginFailReason.Unauthorized.ToString();
}
if(!DAOFactory.UserDAO.CheckPassword(user, pPassword))
{
return null;
return LoginFailReason.WrongCredentials.ToString();
}
MobileSessionFacade.LoggedInUser = user;
@@ -66,7 +70,7 @@ namespace BeWoPlanerAndroid
return user.Employee.Oid.Value + ";" + user.Employee.Person.FirstNameLastName + ";" + user.LoginName + ";" + user.Employee.Person.Oid.Value;
}
return null;
return LoginFailReason.Unknown.ToString();
}
[WebMethod(EnableSession = true)]
@@ -102,16 +106,25 @@ namespace BeWoPlanerAndroid
var jsonMessages = new List<ChatMessageForJson>();
var messages = DAOFactory.SearchDAO.FindAllChatMessagesForAndroid(pSenderPersonOid, pRecipientPersonOid, exceptions, pIsForTeam).DoForEach(dfe => jsonMessages.Add(new ChatMessageForJson(dfe.EmpfängerPersonOid, dfe.SenderPersonOid, dfe.IsDelivered, dfe.IstGelesen, dfe.TeamOid, dfe.ChatText, dfe.Uhrzeit, dfe.Oid, dfe.InsTs)));
var messages = DAOFactory.SearchDAO.FindAllChatMessagesForAndroid(pSenderPersonOid, pRecipientPersonOid, exceptions, pIsForTeam).DoForEach(dfe => jsonMessages.Add(new ChatMessageForJson(dfe.EmpfaengerPersonOid, dfe.SenderPersonOid, dfe.IsDelivered, dfe.IstGelesen, dfe.TeamOid, dfe.ChatText, dfe.Uhrzeit, dfe.Oid, dfe.InsTs)));
return JsonConvert.SerializeObject(jsonMessages);
}
//[WebMethod(EnableSession = true)]
//public string GetAllUnreadMessages()
//{
[WebMethod(EnableSession = true)]
public string GetAllUnreadMessages()
{
return "";
}
//}
[WebMethod(EnableSession = true)]
public string GetNewestMessages(long pRecipientPersonOid)
{
var jsonMessages = new List<ChatMessageForJson>();
var liste = DAOFactory.SearchDAO.FindNewestChatMessages(pRecipientPersonOid).DoForEach(dfe => jsonMessages.Add(new ChatMessageForJson(dfe.EmpfaengerPersonOid, dfe.SenderPersonOid, dfe.IsDelivered, dfe.IstGelesen, dfe.TeamOid, dfe.ChatText, dfe.Uhrzeit, dfe.Oid, dfe.InsTs)));
return JsonConvert.SerializeObject(jsonMessages);
}
[WebMethod(EnableSession = true)]
public string GetServerAddressByToken(string pToken)

View File

@@ -124,5 +124,15 @@ namespace BeWoPlanerAndroid.Service
return true;
}
public static bool TenantExists(string pTenant)
{
var path2config = HttpContext.Current.Server.MapPath("");
path2config = Path.Combine(path2config, ConfigurationManager.AppSettings.Get("MultitenancyPath"));
path2config = Path.Combine(path2config, pTenant + ".config");
return File.Exists(path2config);
}
}
}

View File

@@ -11,6 +11,7 @@ using NHibernate.SqlCommand;
using BS.Shared.Core;
using BS.Shared;
using BS.Shared.DataContracts.Compact;
using NHibernate.Transform;
using Login = BeWo.Data.Entities.Login;
namespace BeWo.Data.Access
@@ -1526,10 +1527,10 @@ namespace BeWo.Data.Access
Restrictions.Or(
Restrictions.And(
Restrictions.Eq(ChatMessage.PropertyName_SenderPersonOid, senderOid),
Restrictions.Eq(ChatMessage.PropertyName_EmpfängerPersonOid, empfaengerOid)),
Restrictions.Eq(ChatMessage.PropertyName_EmpfaengerPersonOid, empfaengerOid)),
Restrictions.And(
Restrictions.Eq(ChatMessage.PropertyName_SenderPersonOid, empfaengerOid),
Restrictions.Eq(ChatMessage.PropertyName_EmpfängerPersonOid, senderOid))));
Restrictions.Eq(ChatMessage.PropertyName_EmpfaengerPersonOid, senderOid))));
return c.List<ChatMessage>();
}
@@ -1548,7 +1549,7 @@ namespace BeWo.Data.Access
var c = CreateCriteriaIsActive<ChatMessage>()
.Add(Restrictions.And(
Restrictions.Eq(ChatMessage.PropertyName_SenderPersonOid, senderOid),
Restrictions.Eq(ChatMessage.PropertyName_EmpfängerPersonOid, empfaengerOid)));
Restrictions.Eq(ChatMessage.PropertyName_EmpfaengerPersonOid, empfaengerOid)));
return c.List<ChatMessage>();
}
@@ -1604,10 +1605,10 @@ namespace BeWo.Data.Access
Restrictions.Or(
Restrictions.And(
Restrictions.Eq(ChatMessage.PropertyName_SenderPersonOid, pSenderOid),
Restrictions.Eq(ChatMessage.PropertyName_EmpfängerPersonOid, pRecipientOid)),
Restrictions.Eq(ChatMessage.PropertyName_EmpfaengerPersonOid, pRecipientOid)),
Restrictions.And(
Restrictions.Eq(ChatMessage.PropertyName_SenderPersonOid, pRecipientOid),
Restrictions.Eq(ChatMessage.PropertyName_EmpfängerPersonOid, pSenderOid))))
Restrictions.Eq(ChatMessage.PropertyName_EmpfaengerPersonOid, pSenderOid))))
.Add(Restrictions.Not(Restrictions.In(BeWoEntityBase.PropertyName_Oid, pExceptions)))
.Add(Restrictions.IsNull(ChatMessage.PropertyName_TeamOid));
@@ -1657,10 +1658,18 @@ namespace BeWo.Data.Access
public IEnumerable<ChatMessage> FindUnreadChatMessagesForRecipient(long pRecipientOid)
{
var c = CreateCriteriaIsActive<ChatMessage>()
.Add(Restrictions.Eq(ChatMessage.PropertyName_EmpfängerPersonOid, pRecipientOid))
.Add(Restrictions.Eq(ChatMessage.PropertyName_EmpfaengerPersonOid, pRecipientOid))
.Add(Restrictions.Eq(ChatMessage.PropertyName_IstGelesen, 0));
return c.List<ChatMessage>();
}
public IEnumerable<ChatMessage> FindNewestChatMessages(long pRecipientPersonOid)
{
var query = Session.CreateSQLQuery(string.Format("SELECT MAX({0}) FROM chatmessages WHERE {1} = {2} AND {3} IS NULL OR {3} IS NOT NULL AND {1} IN (SELECT t.{0} FROM Team t JOIN employee2team e ON e.{3} WHERE e.{4} = {2}) GROUP BY {1}, {5}", BeWoEntityBase.PropertyName_Oid, ChatMessage.PropertyName_EmpfaengerPersonOid, pRecipientPersonOid, "TeamOid", "EmployeeOid", ChatMessage.PropertyName_SenderPersonOid));
var result = query.List<long>();
return result.Count > 0 ? DAOFactory.GenericDAO.LoadByIDs<ChatMessage>(result) : new List<ChatMessage>();
}
}
}

View File

@@ -1,16 +1,15 @@
using BS.Shared;
using System;
using System;
using BS.Shared;
namespace BeWo.Data.Entities
{
public class ChatMessage : BeWoEntityBase
{
public static string PropertyName_ChatText = "ChatText";
public static string PropertyName_Uhrzeit = "Uhrzeit";
public static string PropertyName_EmpfängerPersonOid = "EmpfängerPersonOid";
public static string PropertyName_EmpfaengerPersonOid = "EmpfaengerPersonOid";
public static string PropertyName_SenderPersonOid = "SenderPersonOid";
@@ -22,18 +21,18 @@ namespace BeWo.Data.Entities
private byte[] _ChatText;
private DateTime _Uhrzeit;
private long? _EmpfängerPersonOid;
private long? _SenderPersonOid;
private long? _EmpfaengerPersonOid;
private bool _IsDelivered;
private int _IstGelesen;
private long? _SenderPersonOid;
private long? _TeamOid;
private DateTime _Uhrzeit;
public ChatMessage()
{
_Tid = TableID.ChatMessage;
@@ -41,77 +40,62 @@ namespace BeWo.Data.Entities
public virtual byte[] ChatText
{
get
{
return _ChatText;
}
get { return _ChatText; }
set
{
if (this.AreDifferent(this._ChatText, value))
if(AreDifferent(_ChatText, value))
{
this._ChatText = value;
_ChatText = value;
}
}
}
public virtual DateTime Uhrzeit
{
get
{
return this._Uhrzeit;
}
get { return _Uhrzeit; }
set
{
if (this.AreDifferent(this._Uhrzeit, value))
if(AreDifferent(_Uhrzeit, value))
{
this._Uhrzeit = value;
_Uhrzeit = value;
}
}
}
public virtual long? EmpfängerPersonOid
public virtual long? EmpfaengerPersonOid
{
get
{
return this._EmpfängerPersonOid;
}
get { return _EmpfaengerPersonOid; }
set
{
if (this.AreDifferent(this._EmpfängerPersonOid, value))
if(AreDifferent(_EmpfaengerPersonOid, value))
{
this._EmpfängerPersonOid = value;
_EmpfaengerPersonOid = value;
}
}
}
public virtual long? SenderPersonOid
{
get
{
return this._SenderPersonOid;
}
get { return _SenderPersonOid; }
set
{
if (this.AreDifferent(this._SenderPersonOid, value))
if(AreDifferent(_SenderPersonOid, value))
{
this._SenderPersonOid = value;
_SenderPersonOid = value;
}
}
}
public virtual bool IsDelivered
{
get
{
return _IsDelivered;
}
get { return _IsDelivered; }
set
{
if (AreDifferent(_IsDelivered, value))
if(AreDifferent(_IsDelivered, value))
{
_IsDelivered = value;
}
@@ -121,14 +105,11 @@ namespace BeWo.Data.Entities
public virtual int IstGelesen
{
get
{
return _IstGelesen;
}
get { return _IstGelesen; }
set
{
if (AreDifferent(_IstGelesen, value))
if(AreDifferent(_IstGelesen, value))
{
_IstGelesen = value;
}
@@ -138,16 +119,13 @@ namespace BeWo.Data.Entities
public virtual long? TeamOid
{
get
{
return _TeamOid;
}
get { return _TeamOid; }
set
{
if (this.AreDifferent(this._TeamOid, value))
if(AreDifferent(_TeamOid, value))
{
this._TeamOid = value;
_TeamOid = value;
}
}
}

View File

@@ -7,7 +7,7 @@
</id>
<version type="Int64" column="Version" name="Version" />
<property name="SenderPersonOid" column="SenderPersonOid" />
<property name="EmpfängerPersonOid" column="EmpfaengerPersonOid" />
<property name="EmpfaengerPersonOid" column="EmpfaengerPersonOid" />
<property name="InsTs" />
<property name="InsUser" />
<property column="Tid" type="BS.Shared.TableID, BS.Shared" name="_Tid" access="field" />

View File

@@ -9,7 +9,7 @@ namespace BeWo.Service.DCEntityMapper
public override ChatMessageDC MergeWithDC(ChatMessage pEntity, ChatMessageDC pDataContract)
{
pDataContract.SenderPersonOid = pEntity.SenderPersonOid;
pDataContract.EmpfängerPersonOid = pEntity.EmpfängerPersonOid;
pDataContract.EmpfängerPersonOid = pEntity.EmpfaengerPersonOid;
pDataContract.ChatText = System.Text.Encoding.UTF8.GetString(pEntity.ChatText);
pDataContract.Uhrzeit = pEntity.Uhrzeit;
pDataContract.IsDelivered = pEntity.IsDelivered;
@@ -22,7 +22,7 @@ namespace BeWo.Service.DCEntityMapper
public override ChatMessage MergeWithEntity(ChatMessageDC pDataContract, ChatMessage pEntity)
{
pEntity.SenderPersonOid = pDataContract.SenderPersonOid;
pEntity.EmpfängerPersonOid = pDataContract.EmpfängerPersonOid;
pEntity.EmpfaengerPersonOid = pDataContract.EmpfängerPersonOid;
pEntity.Uhrzeit = pDataContract.Uhrzeit;
pEntity.IsDelivered = pDataContract.IsDelivered;
pEntity.ChatText = System.Text.Encoding.Default.GetBytes(pDataContract.ChatText);

View File

@@ -3134,7 +3134,7 @@ namespace BeWo.Service.ServiceImplementations
{
var chatMessage = new ChatMessage
{
EmpfängerPersonOid = empfängerOid,
EmpfaengerPersonOid = empfängerOid,
SenderPersonOid = senderOid,
Uhrzeit = DateTime.Now,
IsDelivered = isDeliverd,

View File

@@ -856,4 +856,12 @@ namespace BS.Shared
Offline,
Beschäftigt
}
public enum LoginFailReason
{
WrongCredentials,
WrongTenant,
Unauthorized,
Unknown
}
}