attach contact to notification

This commit is contained in:
Daniel Gultsch 2016-08-26 13:35:01 +02:00
parent f931c08da7
commit e33d8451a8
3 changed files with 30 additions and 15 deletions

View file

@ -3,6 +3,8 @@ package eu.siacs.conversations.entities;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import org.json.JSONArray;
import org.json.JSONException;
@ -265,8 +267,18 @@ public class Contact implements ListItem, Blockable {
this.presenceName = presenceName;
}
public String getSystemAccount() {
return systemAccount;
public Uri getSystemAccount() {
if (systemAccount == null) {
return null;
} else {
String[] parts = systemAccount.split("#");
if (parts.length != 2) {
return null;
} else {
long id = Long.parseLong(parts[0]);
return ContactsContract.Contacts.getLookupUri(id, parts[1]);
}
}
}
public void setSystemAccount(String account) {

View file

@ -35,6 +35,7 @@ import java.util.regex.Pattern;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.ConversationActivity;
@ -324,6 +325,13 @@ public class NotificationService {
createShowLocationIntent(message));
}
}
if (conversation.getMode() == Conversation.MODE_SINGLE) {
Contact contact = conversation.getContact();
Uri systemAccount = contact.getSystemAccount();
if (systemAccount != null) {
mBuilder.addPerson(systemAccount.toString());
}
}
mBuilder.setWhen(conversation.getLatestMessage().getTimeSent());
mBuilder.setSmallIcon(R.drawable.ic_notification);
mBuilder.setDeleteIntent(createDeleteIntent(conversation));

View file

@ -10,7 +10,6 @@ import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Intents;
@ -137,7 +136,8 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
@Override
public void onClick(View v) {
if (contact.getSystemAccount() == null) {
Uri systemAccount = contact.getSystemAccount();
if (systemAccount == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(
ContactDetailsActivity.this);
builder.setTitle(getString(R.string.action_add_phone_book));
@ -147,11 +147,8 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
builder.setPositiveButton(getString(R.string.add), addToPhonebook);
builder.create().show();
} else {
String[] systemAccount = contact.getSystemAccount().split("#");
long id = Long.parseLong(systemAccount[0]);
Uri uri = ContactsContract.Contacts.getLookupUri(id, systemAccount[1]);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.setData(systemAccount);
startActivity(intent);
}
}
@ -253,7 +250,8 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
removeFromRoster).create().show();
break;
case R.id.action_edit_contact:
if (contact.getSystemAccount() == null) {
Uri systemAccount = contact.getSystemAccount();
if (systemAccount == null) {
quickEdit(contact.getDisplayName(), 0, new OnValueEdited() {
@Override
@ -266,10 +264,7 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd
});
} else {
Intent intent = new Intent(Intent.ACTION_EDIT);
String[] systemAccount = contact.getSystemAccount().split("#");
long id = Long.parseLong(systemAccount[0]);
Uri uri = Contacts.getLookupUri(id, systemAccount[1]);
intent.setDataAndType(uri, Contacts.CONTENT_ITEM_TYPE);
intent.setDataAndType(systemAccount, Contacts.CONTENT_ITEM_TYPE);
intent.putExtra("finishActivityOnSaveCompleted", true);
startActivity(intent);
}