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.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -265,8 +267,18 @@ public class Contact implements ListItem, Blockable {
this.presenceName = presenceName; this.presenceName = presenceName;
} }
public String getSystemAccount() { public Uri getSystemAccount() {
return systemAccount; 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) { 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.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.ConversationActivity; import eu.siacs.conversations.ui.ConversationActivity;
@ -324,6 +325,13 @@ public class NotificationService {
createShowLocationIntent(message)); 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.setWhen(conversation.getLatestMessage().getTimeSent());
mBuilder.setSmallIcon(R.drawable.ic_notification); mBuilder.setSmallIcon(R.drawable.ic_notification);
mBuilder.setDeleteIntent(createDeleteIntent(conversation)); mBuilder.setDeleteIntent(createDeleteIntent(conversation));

View File

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