diff options
author | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-10 22:45:59 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel.gultsch@rwth-aachen.de> | 2014-02-10 22:45:59 +0100 |
commit | b673af2ba0b46e7444f536fbc7429f9ef74560fb (patch) | |
tree | f33e36a559d3a2b574c25962579fa161f1f968d8 | |
parent | cfc74e7c8e912c7a194ad674ec5f98ab6950640f (diff) |
reworked notification a bit
-rw-r--r-- | res/drawable-hdpi/notification.png | bin | 0 -> 932 bytes | |||
-rw-r--r-- | res/drawable-xhdpi/notification.png | bin | 0 -> 1508 bytes | |||
-rw-r--r-- | res/drawable-xxhdpi/notification.png | bin | 0 -> 1899 bytes | |||
-rw-r--r-- | res/drawable/notification.png | bin | 3847 -> 0 bytes | |||
-rw-r--r-- | src/de/gultsch/chat/entities/Account.java | 2 | ||||
-rw-r--r-- | src/de/gultsch/chat/entities/Conversation.java | 21 | ||||
-rw-r--r-- | src/de/gultsch/chat/entities/Message.java | 13 | ||||
-rw-r--r-- | src/de/gultsch/chat/services/XmppConnectionService.java | 11 | ||||
-rw-r--r-- | src/de/gultsch/chat/ui/ConversationActivity.java | 36 | ||||
-rw-r--r-- | src/de/gultsch/chat/ui/ConversationFragment.java | 8 | ||||
-rw-r--r-- | src/de/gultsch/chat/utils/UIHelper.java | 32 |
11 files changed, 86 insertions, 37 deletions
diff --git a/res/drawable-hdpi/notification.png b/res/drawable-hdpi/notification.png Binary files differnew file mode 100644 index 00000000..4a978d43 --- /dev/null +++ b/res/drawable-hdpi/notification.png diff --git a/res/drawable-xhdpi/notification.png b/res/drawable-xhdpi/notification.png Binary files differnew file mode 100644 index 00000000..b7ab9e4d --- /dev/null +++ b/res/drawable-xhdpi/notification.png diff --git a/res/drawable-xxhdpi/notification.png b/res/drawable-xxhdpi/notification.png Binary files differnew file mode 100644 index 00000000..870fcb47 --- /dev/null +++ b/res/drawable-xxhdpi/notification.png diff --git a/res/drawable/notification.png b/res/drawable/notification.png Binary files differdeleted file mode 100644 index dcda28dc..00000000 --- a/res/drawable/notification.png +++ /dev/null diff --git a/src/de/gultsch/chat/entities/Account.java b/src/de/gultsch/chat/entities/Account.java index bd2e14c6..0f7bfd52 100644 --- a/src/de/gultsch/chat/entities/Account.java +++ b/src/de/gultsch/chat/entities/Account.java @@ -60,10 +60,8 @@ public class Account extends AbstractEntity{ public void setOption(int option, boolean value) { if (value) { this.options = (this.options | 1 << option); - Log.d("xmppService","enabling option "+this.options); } else { this.options = (this.options & 0 << option); - Log.d("xmppService","disabeling option "+this.options); } } diff --git a/src/de/gultsch/chat/entities/Conversation.java b/src/de/gultsch/chat/entities/Conversation.java index 8be35aa4..bddd1356 100644 --- a/src/de/gultsch/chat/entities/Conversation.java +++ b/src/de/gultsch/chat/entities/Conversation.java @@ -6,6 +6,7 @@ import java.util.List; import android.content.ContentValues; import android.database.Cursor; import android.net.Uri; +import android.util.Log; public class Conversation extends AbstractEntity { @@ -71,6 +72,20 @@ public class Conversation extends AbstractEntity { return messages; } + public boolean isRead() { + if (this.messages == null) return true; + return this.messages.get(this.messages.size() - 1).isRead(); + } + + public void markRead() { + Log.d("xmppService", "inside mark read method"); + if (this.messages == null) return; + for(int i = this.messages.size() -1; i >= 0; --i) { + if (messages.get(i).isRead()) return; + this.messages.get(i).markRead(); + } + } + public String getLatestMessage() { if ((this.messages == null)||(this.messages.size()==0)) { return null; @@ -121,7 +136,9 @@ public class Conversation extends AbstractEntity { public void setContact(Contact contact) { this.contact = contact; - this.contactUuid = contact.getUuid(); + if (contact!=null) { + this.contactUuid = contact.getUuid(); + } } public void setAccount(Account account) { @@ -151,7 +168,7 @@ public class Conversation extends AbstractEntity { ContentValues values = new ContentValues(); values.put(UUID, uuid); values.put(NAME, name); - values.put(CONTACT, contact.getUuid()); + values.put(CONTACT, contactUuid); values.put(ACCOUNT, accountUuid); values.put(CONTACTJID, contactJid); values.put(CREATED, created); diff --git a/src/de/gultsch/chat/entities/Message.java b/src/de/gultsch/chat/entities/Message.java index 4349e341..d53e93c1 100644 --- a/src/de/gultsch/chat/entities/Message.java +++ b/src/de/gultsch/chat/entities/Message.java @@ -30,6 +30,7 @@ public class Message extends AbstractEntity { protected long timeSent; protected int encryption; protected int status; + protected boolean read = true; protected transient Conversation conversation = null; @@ -115,4 +116,16 @@ public class Message extends AbstractEntity { this.status = status; } + public boolean isRead() { + return this.read; + } + + public void markRead() { + this.read = true; + } + + public void markUnread() { + this.read = false; + } + } diff --git a/src/de/gultsch/chat/services/XmppConnectionService.java b/src/de/gultsch/chat/services/XmppConnectionService.java index 1160754e..5a43f99f 100644 --- a/src/de/gultsch/chat/services/XmppConnectionService.java +++ b/src/de/gultsch/chat/services/XmppConnectionService.java @@ -86,6 +86,7 @@ public class XmppConnectionService extends Service { forwarded = packet.findChild("sent").findChild( "forwarded"); status = Message.STATUS_SEND; + notify = false; } else { return; // massage has no body and is not carbon. just // skip @@ -128,6 +129,9 @@ public class XmppConnectionService extends Service { } Message message = new Message(conversation, counterPart, body, Message.ENCRYPTION_NONE, status); + if(notify) { + message.markUnread(); + } conversation.getMessages().add(message); databaseBackend.createMessage(message); if (convChangedListener != null) { @@ -398,6 +402,7 @@ public class XmppConnectionService extends Service { Account account = accountLookupTable.get(conv.getAccountUuid()); conv.setAccount(account); conv.setContact(findContact(account, conv.getContactJid())); + conv.setMessages(databaseBackend.getMessages(conv, 50)); } } return this.conversations; @@ -406,11 +411,7 @@ public class XmppConnectionService extends Service { public List<Account> getAccounts() { return this.accounts; } - - public List<Message> getMessages(Conversation conversation) { - return databaseBackend.getMessages(conversation, 100); - } - + public Contact findContact(Account account, String jid) { return databaseBackend.findContact(account, jid); } diff --git a/src/de/gultsch/chat/ui/ConversationActivity.java b/src/de/gultsch/chat/ui/ConversationActivity.java index ed328c46..66cec2e7 100644 --- a/src/de/gultsch/chat/ui/ConversationActivity.java +++ b/src/de/gultsch/chat/ui/ConversationActivity.java @@ -16,6 +16,7 @@ import android.app.FragmentTransaction; import android.app.NotificationManager; import android.content.Context; import android.content.Intent; +import android.graphics.Typeface; import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; import android.util.Log; @@ -138,9 +139,20 @@ public class ConversationActivity extends XmppActivity { view = (View) inflater.inflate( R.layout.conversation_list_row, null); } - ((TextView) view.findViewById(R.id.conversation_name)) - .setText(getItem(position).getName()); - ((TextView) view.findViewById(R.id.conversation_lastmsg)).setText(getItem(position).getLatestMessage()); + Conversation conv = getItem(position); + TextView convName = (TextView) view.findViewById(R.id.conversation_name); + convName.setText(conv.getName()); + TextView convLastMsg = (TextView) view.findViewById(R.id.conversation_lastmsg); + convLastMsg.setText(conv.getLatestMessage()); + + if(!conv.isRead()) { + convName.setTypeface(null,Typeface.BOLD); + convLastMsg.setTypeface(null,Typeface.BOLD); + } else { + convName.setTypeface(null,Typeface.NORMAL); + convLastMsg.setTypeface(null,Typeface.NORMAL); + } + ((TextView) view.findViewById(R.id.conversation_lastupdate)) .setText(UIHelper.readableTimeDifference(getItem(position).getLatestMessageDate())); @@ -208,6 +220,10 @@ public class ConversationActivity extends XmppActivity { getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setTitle(getSelectedConversation().getName()); invalidateOptionsMenu(); + if (!getSelectedConversation().isRead()) { + getSelectedConversation().markRead(); + updateConversationList(); + } } } @@ -310,16 +326,6 @@ public class ConversationActivity extends XmppActivity { } } - /*@Override - protected void onPause() { - super.onPause(); - if (xmppConnectionServiceBound) { - xmppConnectionService.removeOnConversationListChangedListener(); - unbindService(mConnection); - xmppConnectionServiceBound = false; - } - }*/ - @Override protected void onStop() { Log.d("gultsch","called on stop in conversation activity"); @@ -346,10 +352,6 @@ public class ConversationActivity extends XmppActivity { conversationList.addAll(xmppConnectionService .getConversations()); - for(Conversation conversation : conversationList) { - conversation.setMessages(xmppConnectionService.getMessages(conversation)); - } - this.updateConversationList(); } diff --git a/src/de/gultsch/chat/ui/ConversationFragment.java b/src/de/gultsch/chat/ui/ConversationFragment.java index e6cb9196..7305bcfb 100644 --- a/src/de/gultsch/chat/ui/ConversationFragment.java +++ b/src/de/gultsch/chat/ui/ConversationFragment.java @@ -180,6 +180,10 @@ public class ConversationFragment extends Fragment { activity.getActionBar().setDisplayHomeAsUpEnabled(true); activity.getActionBar().setTitle(conversation.getName()); activity.invalidateOptionsMenu(); + if (!conversation.isRead()) { + conversation.markRead(); + activity.updateConversationList(); + } } } } @@ -194,6 +198,10 @@ public class ConversationFragment extends Fragment { activity.getActionBar().setDisplayHomeAsUpEnabled(true); activity.getActionBar().setTitle(conversation.getName()); activity.invalidateOptionsMenu(); + if (!conversation.isRead()) { + conversation.markRead(); + activity.updateConversationList(); + } } } diff --git a/src/de/gultsch/chat/utils/UIHelper.java b/src/de/gultsch/chat/utils/UIHelper.java index 75c91682..8e6d8e5f 100644 --- a/src/de/gultsch/chat/utils/UIHelper.java +++ b/src/de/gultsch/chat/utils/UIHelper.java @@ -4,39 +4,31 @@ import java.io.FileDescriptor; import java.io.FileNotFoundException; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.List; import de.gultsch.chat.R; import de.gultsch.chat.entities.Contact; import de.gultsch.chat.entities.Conversation; +import de.gultsch.chat.entities.Message; import de.gultsch.chat.ui.ConversationActivity; import android.app.Activity; -import android.app.AlertDialog; import android.app.Notification; import android.app.PendingIntent; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.AssetFileDescriptor; import android.content.res.Resources; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; import android.net.Uri; import android.preference.PreferenceManager; -import android.provider.ContactsContract; -import android.provider.ContactsContract.CommonDataKinds; import android.provider.ContactsContract.Contacts; -import android.provider.ContactsContract.Intents; import android.support.v4.app.NotificationCompat; import android.support.v4.app.TaskStackBuilder; -import android.util.DisplayMetrics; import android.util.Log; -import android.view.View; -import android.view.View.OnClickListener; import android.widget.QuickContactBadge; public class UIHelper { @@ -100,7 +92,25 @@ public class UIHelper { .getName(), (int) res .getDimension(android.R.dimen.notification_large_icon_width))); mBuilder.setContentTitle(conversation.getName()); - mBuilder.setContentText(conversation.getLatestMessage()); + mBuilder.setTicker(conversation.getLatestMessage().trim()); + StringBuilder bigText = new StringBuilder(); + List<Message> messages = conversation.getMessages(); + String firstLine = ""; + for(int i = messages.size() -1; i >= 0; --i) { + if (!messages.get(i).isRead()) { + if (i == messages.size() -1 ) { + firstLine = messages.get(i).getBody().trim(); + bigText.append(firstLine); + } else { + firstLine = messages.get(i).getBody().trim(); + bigText.insert(0, firstLine+"\n"); + } + } else { + break; + } + } + mBuilder.setContentText(firstLine); + mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(bigText.toString())); mBuilder.setSmallIcon(R.drawable.notification); mBuilder.setLights(0xffffffff, 2000, 4000); if (ringtone != null) { |