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" >