reworked notification a bit
This commit is contained in:
parent
cfc74e7c8e
commit
b673af2ba0
BIN
res/drawable-hdpi/notification.png
Normal file
BIN
res/drawable-hdpi/notification.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 932 B |
BIN
res/drawable-xhdpi/notification.png
Normal file
BIN
res/drawable-xhdpi/notification.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
res/drawable-xxhdpi/notification.png
Normal file
BIN
res/drawable-xxhdpi/notification.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 3.8 KiB |
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue