Added option to chosse whether the contact shortcut sends to last chatroom or contact details

This commit is contained in:
Sylvain Berfini 2019-09-17 10:14:46 +02:00
parent 8d5e5f0c8f
commit 396609102d
7 changed files with 90 additions and 20 deletions

View file

@ -70,7 +70,9 @@ public class PhoneAccountLinkingAssistantActivity extends AssistantActivity {
unexpectedError(); unexpectedError();
} }
if (!mProxyConfig.getDomain().equals(getString(R.string.default_domain))) { if (!mProxyConfig.getDomain().equals(getString(R.string.default_domain))) {
Log.e("[Account Linking] Can't link account on domain " + mProxyConfig.getDomain()); Log.e(
"[Account Linking] Can't link account on domain "
+ mProxyConfig.getDomain());
unexpectedError(); unexpectedError();
} }
mAccountCreator.setUsername(identity.getUsername()); mAccountCreator.setUsername(identity.getUsername());

View file

@ -27,6 +27,7 @@ import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager; import android.content.pm.ShortcutManager;
import java.util.ArrayList; import java.util.ArrayList;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.R;
import org.linphone.contacts.ContactsManager; import org.linphone.contacts.ContactsManager;
import org.linphone.contacts.LinphoneContact; import org.linphone.contacts.LinphoneContact;
import org.linphone.core.Address; import org.linphone.core.Address;
@ -70,17 +71,32 @@ class ApiTwentyFivePlus {
ContactsManager.getInstance().findContactFromAddress(participantAddress); ContactsManager.getInstance().findContactFromAddress(participantAddress);
if (contact != null && !contacts.contains(contact)) { if (contact != null && !contacts.contains(contact)) {
String peerAddress = room.getPeerAddress().asStringUriOnly(); if (context.getResources().getBoolean(R.bool.shortcut_to_contact)) {
ShortcutInfo shortcut = manager.createChatRoomShortcutInfo(contact, peerAddress); ShortcutInfo shortcut = manager.createContactShortcutInfo(contact);
if (shortcut != null) { if (shortcut != null) {
Log.i( Log.i(
"[Shortcut] Creating launcher shortcut " "[Shortcut] Creating launcher shortcut "
+ shortcut.getShortLabel() + shortcut.getShortLabel()
+ " for room " + " for contact "
+ shortcut.getId()); + shortcut.getShortLabel());
shortcuts.add(shortcut); shortcuts.add(shortcut);
contacts.add(contact); contacts.add(contact);
i += 1; i += 1;
}
} else if (context.getResources().getBoolean(R.bool.shortcut_to_chatroom)) {
String peerAddress = room.getPeerAddress().asStringUriOnly();
ShortcutInfo shortcut =
manager.createChatRoomShortcutInfo(contact, peerAddress);
if (shortcut != null) {
Log.i(
"[Shortcut] Creating launcher shortcut "
+ shortcut.getShortLabel()
+ " for room "
+ shortcut.getId());
shortcuts.add(shortcut);
contacts.add(contact);
i += 1;
}
} }
} }
} }

View file

@ -138,14 +138,19 @@ public class ContactsActivity extends MainActivity {
showContactsList(); showContactsList();
} }
if (extras.containsKey("ContactUri")) { if (extras.containsKey("ContactUri") || extras.containsKey("ContactId")) {
String uri = extras.getString("ContactUri"); String contactId = extras.getString("ContactId");
Log.i("[Contacts Activity] Found ContactUri " + uri); if (contactId == null) {
Uri contactUri = Uri.parse(uri); String uri = extras.getString("ContactUri");
String id = ContactsManager.getInstance().getAndroidContactIdFromUri(contactUri); Log.i("[Contacts Activity] Found Contact URI " + uri);
Uri contactUri = Uri.parse(uri);
contactId = ContactsManager.getInstance().getAndroidContactIdFromUri(contactUri);
} else {
Log.i("[Contacts Activity] Found Contact ID " + contactId);
}
LinphoneContact linphoneContact = LinphoneContact linphoneContact =
ContactsManager.getInstance().findContactFromAndroidId(id); ContactsManager.getInstance().findContactFromAndroidId(contactId);
if (linphoneContact != null) { if (linphoneContact != null) {
showContactDetails(linphoneContact); showContactDetails(linphoneContact);
} }

View file

@ -76,6 +76,15 @@ public class LinphoneContact extends AndroidContact
return contact; return contact;
} }
public String getContactId() {
if (isAndroidContact()) {
return getAndroidId();
} else {
// TODO
}
return null;
}
@Override @Override
public int compareTo(LinphoneContact contact) { public int compareTo(LinphoneContact contact) {
String fullName = getFullName() != null ? getFullName() : ""; String fullName = getFullName() != null ? getFullName() : "";

View file

@ -82,7 +82,7 @@ public class ContactSettingsFragment extends SettingsFragment {
} }
if (Version.sdkAboveOrEqual(Version.API25_NOUGAT_71) if (Version.sdkAboveOrEqual(Version.API25_NOUGAT_71)
&& getResources().getBoolean(R.bool.create_most_recent_chat_rooms_shortcuts)) { && getResources().getBoolean(R.bool.create_shortcuts)) {
mCreateShortcuts.setChecked(mPrefs.shortcutsCreationEnabled()); mCreateShortcuts.setChecked(mPrefs.shortcutsCreationEnabled());
} else { } else {
mCreateShortcuts.setVisibility(View.GONE); mCreateShortcuts.setVisibility(View.GONE);

View file

@ -29,6 +29,7 @@ import android.util.ArraySet;
import java.util.Set; import java.util.Set;
import org.linphone.R; import org.linphone.R;
import org.linphone.chat.ChatActivity; import org.linphone.chat.ChatActivity;
import org.linphone.contacts.ContactsActivity;
import org.linphone.contacts.LinphoneContact; import org.linphone.contacts.LinphoneContact;
import org.linphone.core.tools.Log; import org.linphone.core.tools.Log;
@ -79,4 +80,36 @@ public class LinphoneShortcutManager {
return null; return null;
} }
public ShortcutInfo createContactShortcutInfo(LinphoneContact contact) {
if (contact == null) return null;
Bitmap bm = null;
if (contact.getThumbnailUri() != null) {
bm = ImageUtils.getRoundBitmapFromUri(mContext, contact.getThumbnailUri());
}
Icon icon =
bm == null
? Icon.createWithResource(mContext, R.drawable.avatar)
: Icon.createWithBitmap(bm);
try {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(mContext, ContactsActivity.class);
intent.addFlags(
Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra("ContactId", contact.getContactId());
return new ShortcutInfo.Builder(mContext, contact.getContactId())
.setShortLabel(contact.getFullName())
.setIcon(icon)
.setCategories(mCategories)
.setIntent(intent)
.build();
} catch (Exception e) {
Log.e("[Shortcuts Manager] ShortcutInfo.Builder exception: " + e);
}
return null;
}
} }

View file

@ -93,9 +93,14 @@
<bool name="send_multiple_images_as_different_messages">true</bool> <bool name="send_multiple_images_as_different_messages">true</bool>
<bool name="use_big_pictures_to_preview_images_file_transfers">true</bool> <bool name="use_big_pictures_to_preview_images_file_transfers">true</bool>
<bool name="show_sip_uri_in_chat">false</bool> <bool name="show_sip_uri_in_chat">false</bool>
<bool name="create_most_recent_chat_rooms_shortcuts">true</bool>
<bool name="force_end_to_end_encryption_in_chat">false</bool> <bool name="force_end_to_end_encryption_in_chat">false</bool>
<!-- Shortcuts -->
<bool name="create_shortcuts">true</bool>
<!-- The below two settings are mutually exclusive -->
<bool name="shortcut_to_contact">true</bool>
<bool name="shortcut_to_chatroom">false</bool>
<!-- Contacts --> <!-- Contacts -->
<bool name="hide_contact_phone_numbers">false</bool> <bool name="hide_contact_phone_numbers">false</bool>
<bool name="hide_contact_sip_addresses">false</bool> <bool name="hide_contact_sip_addresses">false</bool>