attach contact to notification

This commit is contained in:
Daniel Gultsch 2016-08-26 13:35:01 +02:00 committed by Christian Schneppe
parent 019dd0a23d
commit 634f461c84
3 changed files with 30 additions and 15 deletions

View file

@ -3,6 +3,8 @@ package de.pixart.messenger.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

@ -36,6 +36,7 @@ import java.util.regex.Pattern;
import de.pixart.messenger.Config;
import de.pixart.messenger.R;
import de.pixart.messenger.entities.Account;
import de.pixart.messenger.entities.Contact;
import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.entities.Message;
import de.pixart.messenger.ui.ConversationActivity;
@ -329,6 +330,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;
@ -138,7 +137,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));
@ -148,12 +148,9 @@ 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);
startActivity(intent);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(systemAccount);
startActivity(intent);
}
}
};
@ -254,7 +251,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
@ -267,10 +265,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);
}