From b673af2ba0b46e7444f536fbc7429f9ef74560fb Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 10 Feb 2014 22:45:59 +0100 Subject: [PATCH] reworked notification a bit --- res/drawable-hdpi/notification.png | Bin 0 -> 932 bytes res/drawable-xhdpi/notification.png | Bin 0 -> 1508 bytes res/drawable-xxhdpi/notification.png | Bin 0 -> 1899 bytes res/drawable/notification.png | Bin 3847 -> 0 bytes src/de/gultsch/chat/entities/Account.java | 2 - .../gultsch/chat/entities/Conversation.java | 21 +++++++++- src/de/gultsch/chat/entities/Message.java | 13 +++++++ .../chat/services/XmppConnectionService.java | 11 +++--- .../gultsch/chat/ui/ConversationActivity.java | 36 +++++++++--------- .../gultsch/chat/ui/ConversationFragment.java | 8 ++++ src/de/gultsch/chat/utils/UIHelper.java | 32 ++++++++++------ 11 files changed, 86 insertions(+), 37 deletions(-) create mode 100644 res/drawable-hdpi/notification.png create mode 100644 res/drawable-xhdpi/notification.png create mode 100644 res/drawable-xxhdpi/notification.png delete mode 100644 res/drawable/notification.png diff --git a/res/drawable-hdpi/notification.png b/res/drawable-hdpi/notification.png new file mode 100644 index 0000000000000000000000000000000000000000..4a978d43a7a2f78d5c9de48f673fad9b76ce14c1 GIT binary patch literal 932 zcmV;V16%xwP)500006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY1f2i?1f2nVG;5&%000McNliru-U130C@yOIrUd{112IWN zK~z}7y_dg>T}2efzvulTF(|rOk{D!Nuy7j_Fpz2`MFJZT`~e0F#X=h!|AzD_(gf@i zNMa+RffOli@`Df-Nn<6bkOhCNO5VEr-hKCzB4^AndH3GAZ=X4EnLEGEeCM3+oH--4 z5Wu`#0nP*Wf#3c60k{I32KGjC1Zb`T47|L;6PYkw)`3IOoUAphC7|ymtwwYImUK(f zKay4?y)J3s{SPI*AgLp1VrILx#(%p4KJ{IXy!?2|_&va7?=OLyv95W5=>dJBdL_ssjy7C!9{OlCNO}K zUGIszlkchN4mQZX^h8x1^IjDYplfE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FJQJEQj}$_Ia}$~T_M`xj5TFn^?l!YL)|dc}lXVNY$~mZR z&%HCt0A)_pe~@&t`y>Acj&siKz}X2hpS5bxx`gikNx(k0WbH_Ua^N;#Z;j;Ks3{g( zvpGqpMI;=i(w~6u5^#^z4bZ|Ag304KTJMTOkQ5mMMZQ=q0L>=^CIGOpBuA4vow8UL zK)oqw&<3V2{U&J8ScExi8l)*|5KROq$R|^H*btjBg<@Z5|H!1O9U3|~1%S?xbU2E% zKTQ-~#Ql1E94k_q5Axq{2JTA?&_ZN(%{#F^;neB?+s*95${OU}Z3es%A)m_hwi0Q} zFk1PKnSCfJbFY1T4)WkJcYqEgbom27?ZPJ&|FnQTD@~zfBQyvzlbL-7-0KbJG+PXK z4|q&cXC($<Hu&d@T%W*amIm}_vgIJ z!ReUULb7#2(JN0~e@$D_OSrQn@q4nDM^r)ad+h-EF=YSdeA(Ok2|HOu-jei}xF}f_ z7^?zO$QuVIOVT!$-j&!1oWj!jp-n8MYkyghRL%Xb7dSS-E}z~#_re$a`#bKp9W=AA zLqxDDJ2gbwWL`Gz#4ogYRbul5TClIeGiCl9SzWJ-SN2$=3aBIvJeIO(LBKl3Px$xz znmf$wHea~aUnb~0Mzb2Rr-!6z}6yEqGyCDx8nNh^SV0A~O_Gh2+78?Olt>Pp%&!U4R$#ARU3 z$Pj?SjtPGZ=d3wk3ILrLHXwwfPMe~ literal 0 HcmV?d00001 diff --git a/res/drawable/notification.png b/res/drawable/notification.png deleted file mode 100644 index dcda28dc6efbeca8d58ab658707f650fed394ef9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3847 zcmXX}3pmqXAKz@hnPIMDZZ%BIEhLibTsNUG_l20G5JQX5_M@@AsVV=X}m{p7S~1!`>C(qlnT*K_C!CGRZSY z+6&ez5+QBd!rRYDJ9vgWnSzv-TqLbXYRjdOA~K}z`t=IUwLQ=vb!ugLg=YpI+?&bR zLr;J(7!1p#)B_pud(sjt57HBB#ZKA~2)dB$Nu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qYmrxil>3h-=qj|Kk&oCK+7 diff --git a/src/de/gultsch/chat/entities/Account.java b/src/de/gultsch/chat/entities/Account.java index bd2e14c6d..0f7bfd52a 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 8be35aa4f..bddd1356a 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 4349e3412..d53e93c18 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 1160754e7..5a43f99f6 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 getAccounts() { return this.accounts; } - - public List 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 ed328c461..66cec2e7b 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 e6cb9196a..7305bcfb6 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 75c916825..8e6d8e5fd 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 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) {