diff --git a/res/anim/fade_in.xml b/res/anim/fade_in.xml new file mode 100644 index 000000000..8c8557d88 --- /dev/null +++ b/res/anim/fade_in.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/res/anim/fade_out.xml b/res/anim/fade_out.xml new file mode 100644 index 000000000..09beb8382 --- /dev/null +++ b/res/anim/fade_out.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/res/menu/profile_chat.xml b/res/menu/profile_chat.xml new file mode 100644 index 000000000..0fcaa467e --- /dev/null +++ b/res/menu/profile_chat.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + diff --git a/res/menu/profile_contact.xml b/res/menu/profile_contact.xml new file mode 100644 index 000000000..bd7d92a5a --- /dev/null +++ b/res/menu/profile_contact.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/res/values/strings.xml b/res/values/strings.xml index 6e3658612..c54b2dea0 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -184,6 +184,8 @@ Delete contacts? This will permanently delete the selected contacts.\n\nContacts with ongoing chats and contacts from the system\'s address book cannot be deleted permanently. Cannot delete contacts with ongoing chats. Chat with %1$s? + + Remove %1$s from group? @@ -249,6 +251,7 @@ Shared chats Contact Group + Members Gallery Docs Links diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 17d3ead42..4fb479510 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -542,6 +542,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity Intent intent = new Intent(this, ProfileActivity.class); intent.putExtra(ProfileActivity.CHAT_ID_EXTRA, chatId); startActivity(intent); + overridePendingTransition(R.anim.fade_in, R.anim.fade_out); } } diff --git a/src/org/thoughtcrime/securesms/ProfileActivity.java b/src/org/thoughtcrime/securesms/ProfileActivity.java index bd89813c9..9be7722f6 100644 --- a/src/org/thoughtcrime/securesms/ProfileActivity.java +++ b/src/org/thoughtcrime/securesms/ProfileActivity.java @@ -1,29 +1,42 @@ package org.thoughtcrime.securesms; +import android.app.Activity; +import android.content.Intent; +import android.media.RingtoneManager; +import android.net.Uri; import android.os.Bundle; -import android.support.annotation.Nullable; +import android.provider.Settings; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; +import android.support.v7.app.AlertDialog; import android.support.v7.widget.Toolbar; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; +import android.widget.EditText; import com.b44t.messenger.DcChat; import com.b44t.messenger.DcContact; +import com.b44t.messenger.DcContext; +import com.b44t.messenger.DcEventCenter; import org.thoughtcrime.securesms.connect.ApplicationDcContext; import org.thoughtcrime.securesms.connect.DcHelper; -import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme; import org.thoughtcrime.securesms.util.DynamicTheme; +import org.thoughtcrime.securesms.util.Prefs; import org.thoughtcrime.securesms.util.ViewUtil; import java.util.ArrayList; +import java.util.List; -public class ProfileActivity extends PassphraseRequiredActionBarActivity { +public class ProfileActivity extends PassphraseRequiredActionBarActivity + implements DcEventCenter.DcEventDelegate +{ @SuppressWarnings("unused") private final static String TAG = ProfileActivity.class.getSimpleName(); @@ -38,14 +51,15 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity { public static final int TAB_LINKS = 40; public static final int TAB_MAP = 50; + private static final int REQUEST_CODE_PICK_RINGTONE = 1; + private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme(); private final DynamicLanguage dynamicLanguage = new DynamicLanguage(); private ApplicationDcContext dcContext; private int chatId; - private @Nullable DcChat dcChat; + private boolean chatIsGroup; private int contactId; - private @Nullable DcContact dcContact; private ArrayList tabs = new ArrayList<>(); private Toolbar toolbar; @@ -68,6 +82,27 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity { this.tabLayout.setupWithViewPager(viewPager); this.viewPager.setAdapter(new ProfilePagerAdapter(getSupportFragmentManager())); + dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CHAT_MODIFIED, this); + dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + + if (chatId!=0) { + inflater.inflate(R.menu.profile_chat, menu); + if(!chatIsGroup) { + menu.findItem(R.id.edit_group_name_and_image).setVisible(false); + } + } + + if (isContactProfile()) { + inflater.inflate(R.menu.profile_contact, menu); + } + + super.onCreateOptionsMenu(menu); + return true; } @Override @@ -78,35 +113,30 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity { } @Override - public boolean onOptionsItemSelected(MenuItem item) { - super.onOptionsItemSelected(item); + public void onDestroy() { + dcContext.eventCenter.removeObservers(this); + super.onDestroy(); + } - switch (item.getItemId()) { - case android.R.id.home: finish(); return true; - } - - return false; + @Override + public void handleEvent(int eventId, Object data1, Object data2) { + updateToolbar(); } private void initializeResources() { - chatId = getIntent().getIntExtra(CHAT_ID_EXTRA, 0); - contactId = getIntent().getIntExtra(CONTACT_ID_EXTRA, 0); + chatId = getIntent().getIntExtra(CHAT_ID_EXTRA, 0); + contactId = getIntent().getIntExtra(CONTACT_ID_EXTRA, 0); + chatIsGroup = false; if (contactId!=0) { - dcContact = dcContext.getContact(contactId); chatId = dcContext.getChatIdByContactId(contactId); - if (chatId!=0) { - dcChat = dcContext.getChat(chatId); - } } else if(chatId!=0) { - dcChat = dcContext.getChat(chatId); - if(!dcChat.isGroup()) { + DcChat dcChat = dcContext.getChat(chatId); + chatIsGroup = dcChat.isGroup(); + if(!chatIsGroup) { final int[] members = dcContext.getChatContacts(chatId); contactId = members.length>=1? members[0] : 0; - if (contactId!=0) { - dcContact = dcContext.getContact(contactId); - } } } @@ -137,10 +167,10 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity { getSupportActionBar().setTitle(R.string.menu_all_media); } else if (isContactProfile()){ - getSupportActionBar().setTitle(dcContact.getName()); + getSupportActionBar().setTitle(dcContext.getContact(contactId).getName()); } - else if (dcChat != null) { - getSupportActionBar().setTitle(dcChat.getName()); + else if (chatId >= 0) { + getSupportActionBar().setTitle(dcContext.getChat(chatId).getName()); } } @@ -150,25 +180,13 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity { private boolean isContactProfile() { // there may still be a single-chat lined to the contact profile - return dcContact!=null && (dcChat==null || !dcChat.isGroup()); + return contactId!=0 && (chatId==0 || !chatIsGroup); } private boolean isSelfProfile() { return isContactProfile() && contactId==DcContact.DC_CONTACT_ID_SELF; } - private Recipient getRecipient() { - if(dcChat!=null) { - return dcContext.getRecipient(dcChat); - } - else if(dcContact!=null) { - return dcContext.getRecipient(dcContact); - } - else { - return dcContext.getRecipient(dcContext.getContact(0)); - } - } - private class ProfilePagerAdapter extends FragmentStatePagerAdapter { ProfilePagerAdapter(FragmentManager fragmentManager) { @@ -184,20 +202,20 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity { switch(tabId) { case TAB_SETTINGS: fragment = new ProfileSettingsFragment(); - args.putInt(ProfileSettingsFragment.CHAT_ID_EXTRA, dcChat==null? -1 : chatId); - args.putInt(ProfileSettingsFragment.CONTACT_ID_EXTRA, dcContact==null? -1 : contactId); + args.putInt(ProfileSettingsFragment.CHAT_ID_EXTRA, (chatId==0&&!isGlobalProfile())? -1 : chatId); + args.putInt(ProfileSettingsFragment.CONTACT_ID_EXTRA, (contactId==0&&!isGlobalProfile())? -1 : contactId); args.putSerializable(ProfileSettingsFragment.LOCALE_EXTRA, dynamicLanguage.getCurrentLocale()); break; case TAB_GALLERY: fragment = new ProfileGalleryFragment(); - args.putInt(ProfileGalleryFragment.CHAT_ID_EXTRA, dcChat==null? -1 : chatId); + args.putInt(ProfileGalleryFragment.CHAT_ID_EXTRA, (chatId==0&&!isGlobalProfile())? -1 : chatId); args.putSerializable(ProfileGalleryFragment.LOCALE_EXTRA, dynamicLanguage.getCurrentLocale()); break; default: fragment = new ProfileDocumentsFragment(); - args.putInt(ProfileGalleryFragment.CHAT_ID_EXTRA, dcChat==null? -1 : chatId); + args.putInt(ProfileGalleryFragment.CHAT_ID_EXTRA, (chatId==0&&!isGlobalProfile())? -1 : chatId); args.putSerializable(ProfileDocumentsFragment.LOCALE_EXTRA, dynamicLanguage.getCurrentLocale()); break; } @@ -220,7 +238,7 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity { return getString(contactId==DcContact.DC_CONTACT_ID_SELF? R.string.self : R.string.tab_contact); } else { - return getString(R.string.tab_group); + return getString(R.string.tab_members); } case TAB_GALLERY: @@ -240,4 +258,152 @@ public class ProfileActivity extends PassphraseRequiredActionBarActivity { } } } + + + // handle events + // ========================================================================= + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + super.onOptionsItemSelected(item); + + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + case R.id.menu_mute_notifications: + onNotifyOnOff(); + break; + case R.id.menu_sound: + onSoundSettings(); + break; + case R.id.menu_vibrate: + onVibrateSettings(); + break; + case R.id.edit_group_name_and_image: + onEditGroupNameAndImage(); + break; + case R.id.edit_contact_name: + onEditContactName(); + break; + case R.id.show_encr_info: + onEncrInfo(); + break; + case R.id.block_contact: + onBlockContact(); + break; + } + + return false; + } + + public void onNotifyOnOff() { + if (Prefs.isChatMuted(this, chatId)) { + setMuted(0); + } + else { + MuteDialog.show(this, until -> setMuted(until)); + } + } + + private void setMuted(final long until) { + if(chatId!=0) { + Prefs.setChatMutedUntil(this, chatId, until); + } + } + + public void onSoundSettings() { + Uri current = dcContext.getRecipient(dcContext.getChat(chatId)).getMessageRingtone(); + Uri defaultUri = Prefs.getNotificationRingtone(this); + + if (current == null) current = Settings.System.DEFAULT_NOTIFICATION_URI; + else if (current.toString().isEmpty()) current = null; + + Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, defaultUri); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, current); + + startActivityForResult(intent, REQUEST_CODE_PICK_RINGTONE); + } + + public void onVibrateSettings() { + new AlertDialog.Builder(this) + .setTitle(R.string.pref_vibrate) + .setItems(R.array.recipient_vibrate_entries, (dialog, which) -> { + Prefs.setChatVibrate(this, chatId, Prefs.VibrateState.fromId(which)); + }) + .show(); + } + + public void onEditGroupNameAndImage() { + Intent intent = new Intent(this, GroupCreateActivity.class); + intent.putExtra(GroupCreateActivity.EDIT_GROUP_CHAT_ID, chatId); + if (dcContext.getChat(chatId).isVerified()) { + intent.putExtra(GroupCreateActivity.GROUP_CREATE_VERIFIED_EXTRA, true); + } + startActivity(intent); + } + + public void onEditContactName() { + DcContact dcContact = dcContext.getContact(contactId); + final EditText txt = new EditText(this); + txt.setText(dcContact.getName()); + new AlertDialog.Builder(this) + .setTitle(R.string.menu_edit_name) + .setView(txt) + .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { + String newName = txt.getText().toString(); + dcContext.createContact(newName, dcContact.getAddr()); + }) + .setNegativeButton(android.R.string.cancel, null) + .show(); + } + + public void onEncrInfo() { + String info_str = dcContext.getContactEncrInfo(contactId); + new AlertDialog.Builder(this) + .setMessage(info_str) + .setPositiveButton(android.R.string.ok, null) + .show(); + } + + public void onBlockContact() { + DcContact dcContact = dcContext.getContact(contactId); + if(dcContact.isBlocked()) { + new AlertDialog.Builder(this) + .setMessage(R.string.ask_unblock_contact) + .setCancelable(true) + .setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(R.string.menu_unblock_contact, (dialog, which) -> { + dcContext.blockContact(contactId, 0); + }).show(); + } + else { + new AlertDialog.Builder(this) + .setMessage(R.string.ask_block_contact) + .setCancelable(true) + .setNegativeButton(android.R.string.cancel, null) + .setPositiveButton(R.string.menu_block_contact, (dialog, which) -> { + dcContext.blockContact(contactId, 1); + }).show(); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode==REQUEST_CODE_PICK_RINGTONE && resultCode== Activity.RESULT_OK && data!=null) { + Uri value = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI); + Uri defaultValue = Prefs.getNotificationRingtone(this); + + if (defaultValue.equals(value)) value = null; + else if (value == null) value = Uri.EMPTY; + + Prefs.setChatRingtone(this, chatId, value); + } + } + } diff --git a/src/org/thoughtcrime/securesms/ProfileDocumentsAdapter.java b/src/org/thoughtcrime/securesms/ProfileDocumentsAdapter.java index 270644ddf..6dea8e7ef 100644 --- a/src/org/thoughtcrime/securesms/ProfileDocumentsAdapter.java +++ b/src/org/thoughtcrime/securesms/ProfileDocumentsAdapter.java @@ -1,7 +1,6 @@ package org.thoughtcrime.securesms; import android.content.Context; -import android.content.Intent; import android.support.annotation.NonNull; import android.view.LayoutInflater; import android.view.View; @@ -13,8 +12,6 @@ import com.codewaves.stickyheadergrid.StickyHeaderGridAdapter; import org.thoughtcrime.securesms.components.AudioView; import org.thoughtcrime.securesms.components.DocumentView; -import org.thoughtcrime.securesms.connect.ApplicationDcContext; -import org.thoughtcrime.securesms.connect.DcHelper; import org.thoughtcrime.securesms.database.loaders.BucketedThreadMediaLoader.BucketedThreadMedia; import org.thoughtcrime.securesms.mms.AudioSlide; import org.thoughtcrime.securesms.mms.DocumentSlide; diff --git a/src/org/thoughtcrime/securesms/ProfileDocumentsFragment.java b/src/org/thoughtcrime/securesms/ProfileDocumentsFragment.java index 1414c233b..3aef6f5b4 100644 --- a/src/org/thoughtcrime/securesms/ProfileDocumentsFragment.java +++ b/src/org/thoughtcrime/securesms/ProfileDocumentsFragment.java @@ -24,6 +24,7 @@ import android.view.Window; import android.widget.TextView; import com.b44t.messenger.DcContext; +import com.b44t.messenger.DcEventCenter; import com.b44t.messenger.DcMsg; import com.codewaves.stickyheadergrid.StickyHeaderGridLayoutManager; @@ -37,7 +38,9 @@ import java.util.Collection; import java.util.Locale; public class ProfileDocumentsFragment - extends Fragment implements LoaderManager.LoaderCallbacks, ProfileDocumentsAdapter.ItemClickListener + extends Fragment + implements LoaderManager.LoaderCallbacks, + ProfileDocumentsAdapter.ItemClickListener, DcEventCenter.DcEventDelegate { public static final String LOCALE_EXTRA = "locale_extra"; public static final String CHAT_ID_EXTRA = "chat_id"; @@ -48,13 +51,15 @@ public class ProfileDocumentsFragment private ActionMode actionMode; private ActionModeCallback actionModeCallback = new ActionModeCallback(); - protected int chatId; - protected Locale locale; + private ApplicationDcContext dcContext; + protected int chatId; + protected Locale locale; @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); + dcContext = DcHelper.getContext(getContext()); chatId = getArguments().getInt(CHAT_ID_EXTRA, -1); locale = (Locale)getArguments().getSerializable(LOCALE_EXTRA); if (locale == null) throw new AssertionError(); @@ -77,9 +82,22 @@ public class ProfileDocumentsFragment this.recyclerView.setLayoutManager(gridManager); this.recyclerView.setHasFixedSize(true); + dcContext.eventCenter.addObserver(DcContext.DC_EVENT_MSGS_CHANGED, this); + dcContext.eventCenter.addObserver(DcContext.DC_EVENT_INCOMING_MSG, this); return view; } + @Override + public void onDestroyView() { + dcContext.eventCenter.removeObservers(this); + super.onDestroyView(); + } + + @Override + public void handleEvent(int eventId, Object data1, Object data2) { + getLoaderManager().restartLoader(0, null, this); + } + @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); @@ -130,7 +148,7 @@ public class ProfileDocumentsFragment } private void handleMediaPreviewClick(@NonNull DcMsg dcMsg) { - // audio is stated by the play-button + // audio is started by the play-button if (dcMsg.getType()==DcMsg.DC_MSG_AUDIO || dcMsg.getType()==DcMsg.DC_MSG_VOICE) { return; } @@ -140,7 +158,6 @@ public class ProfileDocumentsFragment return; } - ApplicationDcContext dcContext = DcHelper.getContext(context); dcContext.openForViewOrShare(dcMsg.getId(), Intent.ACTION_VIEW); } @@ -165,7 +182,6 @@ public class ProfileDocumentsFragment AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setMessage(confirmMessage); builder.setCancelable(true); - final DcContext dcContext = DcHelper.getContext(getContext()); builder.setPositiveButton(R.string.delete, (dialogInterface, i) -> { new ProgressDialogAsyncTask(getContext(), diff --git a/src/org/thoughtcrime/securesms/ProfileGalleryFragment.java b/src/org/thoughtcrime/securesms/ProfileGalleryFragment.java index 04b19b68d..0529557c4 100644 --- a/src/org/thoughtcrime/securesms/ProfileGalleryFragment.java +++ b/src/org/thoughtcrime/securesms/ProfileGalleryFragment.java @@ -24,9 +24,11 @@ import android.view.Window; import android.widget.TextView; import com.b44t.messenger.DcContext; +import com.b44t.messenger.DcEventCenter; import com.b44t.messenger.DcMsg; import com.codewaves.stickyheadergrid.StickyHeaderGridLayoutManager; +import org.thoughtcrime.securesms.connect.ApplicationDcContext; import org.thoughtcrime.securesms.connect.DcHelper; import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.loaders.BucketedThreadMediaLoader; @@ -38,7 +40,9 @@ import java.util.Collection; import java.util.Locale; public class ProfileGalleryFragment - extends Fragment implements LoaderManager.LoaderCallbacks, ProfileGalleryAdapter.ItemClickListener + extends Fragment + implements LoaderManager.LoaderCallbacks, + ProfileGalleryAdapter.ItemClickListener, DcEventCenter.DcEventDelegate { public static final String LOCALE_EXTRA = "locale_extra"; public static final String CHAT_ID_EXTRA = "chat_id"; @@ -49,13 +53,15 @@ public class ProfileGalleryFragment private ActionMode actionMode; private ActionModeCallback actionModeCallback = new ActionModeCallback(); - protected int chatId; - protected Locale locale; + private ApplicationDcContext dcContext; + private int chatId; + private Locale locale; @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); + dcContext = DcHelper.getContext(getContext()); chatId = getArguments().getInt(CHAT_ID_EXTRA, -1); locale = (Locale)getArguments().getSerializable(LOCALE_EXTRA); if (locale == null) throw new AssertionError(); @@ -79,9 +85,22 @@ public class ProfileGalleryFragment this.recyclerView.setLayoutManager(gridManager); this.recyclerView.setHasFixedSize(true); + dcContext.eventCenter.addObserver(DcContext.DC_EVENT_MSGS_CHANGED, this); + dcContext.eventCenter.addObserver(DcContext.DC_EVENT_INCOMING_MSG, this); return view; } + @Override + public void onDestroyView() { + dcContext.eventCenter.removeObservers(this); + super.onDestroyView(); + } + + @Override + public void handleEvent(int eventId, Object data1, Object data2) { + getLoaderManager().restartLoader(0, null, this); + } + private int getCols() { return getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE? 5 : 3; } @@ -174,7 +193,6 @@ public class ProfileGalleryFragment AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setMessage(confirmMessage); builder.setCancelable(true); - final DcContext dcContext = DcHelper.getContext(getContext()); builder.setPositiveButton(R.string.delete, (dialogInterface, i) -> { new ProgressDialogAsyncTask(getContext(), diff --git a/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java b/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java index d4ff029df..95774a30a 100644 --- a/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java +++ b/src/org/thoughtcrime/securesms/ProfileSettingsAdapter.java @@ -18,14 +18,15 @@ import org.thoughtcrime.securesms.connect.ApplicationDcContext; import org.thoughtcrime.securesms.connect.DcHelper; import org.thoughtcrime.securesms.contacts.ContactSelectionListItem; import org.thoughtcrime.securesms.mms.GlideRequests; -import org.thoughtcrime.securesms.util.LRUCache; +import org.thoughtcrime.securesms.util.Prefs; import org.thoughtcrime.securesms.util.StickyHeaderDecoration.StickyHeaderAdapter; -import java.lang.ref.SoftReference; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.Locale; -import java.util.Map; +import java.util.Set; public class ProfileSettingsAdapter extends RecyclerView.Adapter implements StickyHeaderAdapter @@ -42,10 +43,6 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter public static final int SETTING_SOUND = 320; public static final int SETTING_VIBRATE = 330; - private static final int MAX_CACHE_SIZE = 100; - private final Map> recordCache = - Collections.synchronizedMap(new LRUCache<>(MAX_CACHE_SIZE)); - private final @NonNull Context context; private final @NonNull Locale locale; private final @NonNull ApplicationDcContext dcContext; @@ -54,6 +51,7 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter private int itemDataMemberCount; private DcChatlist itemDataSharedChats; private DcContact itemDataContact; + private final Set selectedMembers; private final LayoutInflater layoutInflater; private final ItemClickListener clickListener; @@ -99,6 +97,7 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter this.clickListener = clickListener; this.dcContext = DcHelper.getContext(context); this.layoutInflater = LayoutInflater.from(context); + this.selectedMembers= new HashSet<>(); } @Override @@ -106,24 +105,6 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter return itemData.size(); } - private @NonNull DcContact getContact(int position) { - if(position<0 || position>=itemData.size() || itemData.get(position).type!=ItemData.TYPE_MEMBER) { - return new DcContact(0); - } - - final SoftReference reference = recordCache.get(position); - if (reference != null) { - final DcContact fromCache = reference.get(); - if (fromCache != null) { - return fromCache; - } - } - - final DcContact fromDb = dcContext.getContact(itemData.get(position).contactId); - recordCache.put(position, new SoftReference<>(fromDb)); - return fromDb; - } - public static class ViewHolder extends RecyclerView.ViewHolder { public ViewHolder(View itemView) { super(itemView); @@ -162,36 +143,42 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter if (holder.itemView instanceof ContactSelectionListItem) { ContactSelectionListItem contactItem = (ContactSelectionListItem) holder.itemView; - int id = itemData.get(i).contactId; + int contactId = itemData.get(i).contactId; DcContact dcContact = null; String label = null; String name; String addr = null; - if (id == DcContact.DC_CONTACT_ID_ADD_MEMBER) { + if (contactId == DcContact.DC_CONTACT_ID_ADD_MEMBER) { name = context.getString(R.string.group_add_members); } - else if (id == DcContact.DC_CONTACT_ID_QR_INVITE) { + else if (contactId == DcContact.DC_CONTACT_ID_QR_INVITE) { name = context.getString(R.string.qrshow_title); } else { - dcContact = getContact(i); + dcContact = dcContext.getContact(contactId); name = dcContact.getDisplayName(); addr = dcContact.getAddr(); } - contactItem.set(glideRequests, id, dcContact, name, addr, label, false, true); + contactItem.unbind(glideRequests); + contactItem.set(glideRequests, contactId, dcContact, name, addr, label, false, true); + contactItem.setSelected(selectedMembers.contains(contactId)); + contactItem.setOnClickListener(view -> clickListener.onMemberClicked(contactId)); + contactItem.setOnLongClickListener(view -> {clickListener.onMemberLongClicked(contactId); return true;}); } else if (holder.itemView instanceof ConversationListItem) { ConversationListItem conversationListItem = (ConversationListItem) holder.itemView; int chatlistIndex = itemData.get(i).chatlistIndex; - DcChat chat = dcContext.getChat(itemDataSharedChats.getChatId(chatlistIndex)); + int chatId = itemDataSharedChats.getChatId(chatlistIndex); + DcChat chat = dcContext.getChat(chatId); DcLot summary = itemDataSharedChats.getSummary(chatlistIndex, chat); conversationListItem.bind(dcContext.getThreadRecord(summary, chat), itemDataSharedChats.getMsgId(chatlistIndex), summary, glideRequests, locale, Collections.emptySet(), false); + conversationListItem.setOnClickListener(view -> clickListener.onSharedChatClicked(chatId)); } else if(holder.itemView instanceof ProfileSettingsItem) { int settingsId = itemData.get(i).settingsId; @@ -208,6 +195,9 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter public interface ItemClickListener { void onSettingsClicked(int settingsId); + void onSharedChatClicked(int chatId); + void onMemberClicked(int contactId); + void onMemberLongClicked(int contactId); } @Override @@ -245,6 +235,26 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter viewHolder.textView.setText(txt); } + public void toggleMemberSelection(int contactId) { + if (!selectedMembers.remove(contactId)) { + selectedMembers.add(contactId); + } + notifyDataSetChanged(); + } + + @NonNull + public Collection getSelectedMembers() { + return new HashSet<>(selectedMembers); + } + + public int getSelectedMembersCount() { + return selectedMembers.size(); + } + + public void clearSelection() { + selectedMembers.clear(); + notifyDataSetChanged(); + } public void changeData(@Nullable int[] memberList, @Nullable DcContact dcContact, @Nullable DcChatlist sharedChats, @Nullable DcChat dcChat) { itemData.clear(); @@ -259,13 +269,13 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter for (int i = 0; i < memberList.length; i++) { itemData.add(new ItemData(ItemData.TYPE_MEMBER, memberList[i], 0)); } - itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_GROUP_NAME_N_IMAGE, context.getString(R.string.menu_group_name_and_image))); +// itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_GROUP_NAME_N_IMAGE, context.getString(R.string.menu_group_name_and_image))); } else if (sharedChats!=null && dcContact!=null) { itemDataContact = dcContact; itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_CONTACT_ADDR,dcContact.getAddr())); - itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_CONTACT_NAME, context.getString(R.string.menu_edit_name))); - itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_ENCRYPTION, context.getString(R.string.profile_encryption))); +// itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_CONTACT_NAME, context.getString(R.string.menu_edit_name))); +// itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_ENCRYPTION, context.getString(R.string.profile_encryption))); itemData.add(new ItemData(ItemData.TYPE_PRIMARY_SETTING, SETTING_NEW_CHAT, context.getString(R.string.menu_new_chat))); itemDataSharedChats = sharedChats; int sharedChatsCnt = sharedChats.getCnt(); @@ -274,17 +284,18 @@ public class ProfileSettingsAdapter extends RecyclerView.Adapter } } - if(dcChat!=null) { - itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_NOTIFY, context.getString(R.string.pref_notifications))); - itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_SOUND, context.getString(R.string.pref_sound))); - itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_VIBRATE, context.getString(R.string.pref_vibrate))); - } +// if(dcChat!=null) { +// itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_NOTIFY, +// context.getString(Prefs.isChatMuted(context, dcChat.getId())? R.string.menu_unmute : R.string.menu_mute))); +// itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_SOUND, context.getString(R.string.pref_sound))); +// itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_VIBRATE, context.getString(R.string.pref_vibrate))); +// } - if (dcContact!=null) { - itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_BLOCK_CONTACT, context.getString(R.string.menu_block_contact))); - } +// if (dcContact!=null) { +// itemData.add(new ItemData(ItemData.TYPE_SECONDARY_SETTING, SETTING_BLOCK_CONTACT, +// context.getString(dcContact.isBlocked()? R.string.menu_unblock_contact : R.string.menu_block_contact))); +// } - recordCache.clear(); notifyDataSetChanged(); } } diff --git a/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java b/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java index 918716602..6acdc79fb 100644 --- a/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java +++ b/src/org/thoughtcrime/securesms/ProfileSettingsFragment.java @@ -1,45 +1,66 @@ package org.thoughtcrime.securesms; +import android.app.Activity; +import android.content.Intent; +import android.media.RingtoneManager; +import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.view.ActionMode; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.Window; import android.widget.EditText; import android.widget.Toast; import com.b44t.messenger.DcChat; import com.b44t.messenger.DcChatlist; import com.b44t.messenger.DcContact; +import com.b44t.messenger.DcContext; +import com.b44t.messenger.DcEventCenter; import org.thoughtcrime.securesms.connect.ApplicationDcContext; import org.thoughtcrime.securesms.connect.DcHelper; import org.thoughtcrime.securesms.mms.GlideApp; +import org.thoughtcrime.securesms.util.Prefs; import org.thoughtcrime.securesms.util.StickyHeaderDecoration; import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.ViewUtil; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; import java.util.Locale; -public class ProfileSettingsFragment extends Fragment implements ProfileSettingsAdapter.ItemClickListener { +public class ProfileSettingsFragment extends Fragment + implements ProfileSettingsAdapter.ItemClickListener, DcEventCenter.DcEventDelegate { public static final String LOCALE_EXTRA = "locale_extra"; public static final String CHAT_ID_EXTRA = "chat_id"; public static final String CONTACT_ID_EXTRA = "contact_id"; - private RecyclerView recyclerView; + private static final int REQUEST_CODE_PICK_CONTACT = 2; + + private RecyclerView list; + private StickyHeaderDecoration listDecoration; private ProfileSettingsAdapter adapter; + private ActionMode actionMode; + private ActionModeCallback actionModeCallback = new ActionModeCallback(); + private Locale locale; private ApplicationDcContext dcContext; protected int chatId; - private DcChat dcChat; private int contactId; - private DcContact dcContact; @Override public void onCreate(Bundle bundle) { @@ -50,10 +71,6 @@ public class ProfileSettingsFragment extends Fragment implements ProfileSettings chatId = getArguments().getInt(CHAT_ID_EXTRA, -1); contactId = getArguments().getInt(CONTACT_ID_EXTRA, -1); dcContext = DcHelper.getContext(getContext()); - - // if given, the ids really belong together, this is checked in ProfileActivity - if (contactId>0) { dcContact = dcContext.getContact(contactId); } - if (chatId>0) { dcChat = dcContext.getChat(chatId); } } @Override @@ -61,21 +78,42 @@ public class ProfileSettingsFragment extends Fragment implements ProfileSettings View view = inflater.inflate(R.layout.profile_settings_fragment, container, false); adapter = new ProfileSettingsAdapter(getContext(), GlideApp.with(this), locale,this); - recyclerView = ViewUtil.findById(view, R.id.recycler_view); - recyclerView.setAdapter(adapter); - recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false)); - recyclerView.addItemDecoration(new StickyHeaderDecoration(adapter, false, true)); + list = ViewUtil.findById(view, R.id.recycler_view); + list.setAdapter(adapter); + list.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false)); + listDecoration = new StickyHeaderDecoration(adapter, false, true); + list.addItemDecoration(listDecoration); update(); + dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CHAT_MODIFIED, this); + dcContext.eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this); + dcContext.eventCenter.addObserver(DcContext.DC_EVENT_MSGS_CHANGED, this); + dcContext.eventCenter.addObserver(DcContext.DC_EVENT_INCOMING_MSG, this); return view; } + @Override + public void onDestroyView() { + dcContext.eventCenter.removeObservers(this); + super.onDestroyView(); + } + + @Override + public void handleEvent(int eventId, Object data1, Object data2) { + update(); + } + private void update() { int[] memberList = null; DcChatlist sharedChats = null; + DcChat dcChat = null; + DcContact dcContact = null; + if (contactId>0) { dcContact = dcContext.getContact(contactId); } + if (chatId>0) { dcChat = dcContext.getChat(chatId); } + if(dcChat!=null && dcChat.isGroup()) { memberList = dcContext.getChatContacts(chatId); } @@ -84,25 +122,120 @@ public class ProfileSettingsFragment extends Fragment implements ProfileSettings } adapter.changeData(memberList, dcContact, sharedChats, dcChat); + listDecoration.invalidateLayouts(); } + + // handle events + // ========================================================================= + @Override public void onSettingsClicked(int settingsId) { switch(settingsId) { case ProfileSettingsAdapter.SETTING_CONTACT_ADDR: onContactAddrClicked(); break; + case ProfileSettingsAdapter.SETTING_NEW_CHAT: + onNewChat(); + break; case ProfileSettingsAdapter.SETTING_CONTACT_NAME: - onEditContactName(); + ((ProfileActivity)getActivity()).onEditContactName(); break; case ProfileSettingsAdapter.SETTING_ENCRYPTION: - onEncrInfo(); + ((ProfileActivity)getActivity()).onEncrInfo(); + break; + case ProfileSettingsAdapter.SETTING_BLOCK_CONTACT: + ((ProfileActivity)getActivity()).onBlockContact(); + break; + case ProfileSettingsAdapter.SETTING_NOTIFY: + ((ProfileActivity)getActivity()).onNotifyOnOff(); + break; + case ProfileSettingsAdapter.SETTING_SOUND: + ((ProfileActivity)getActivity()).onSoundSettings(); + break; + case ProfileSettingsAdapter.SETTING_VIBRATE: + ((ProfileActivity)getActivity()).onVibrateSettings(); break; } } + @Override + public void onMemberLongClicked(int contactId) { + if (contactId>DcContact.DC_CONTACT_ID_LAST_SPECIAL || contactId==DcContact.DC_CONTACT_ID_SELF) { + if (actionMode==null) { + adapter.toggleMemberSelection(contactId); + actionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(actionModeCallback); + } else { + onMemberClicked(contactId); + } + } + } + + @Override + public void onMemberClicked(int contactId) { + if (actionMode!=null) { + if (contactId>DcContact.DC_CONTACT_ID_LAST_SPECIAL || contactId==DcContact.DC_CONTACT_ID_SELF) { + adapter.toggleMemberSelection(contactId); + if (adapter.getSelectedMembersCount() == 0) { + actionMode.finish(); + actionMode = null; + } else { + actionMode.setTitle(String.valueOf(adapter.getSelectedMembersCount())); + } + } + } + else if(contactId==DcContact.DC_CONTACT_ID_ADD_MEMBER) { + onAddMember(); + } + else if(contactId==DcContact.DC_CONTACT_ID_QR_INVITE) { + onQrInvite(); + } + else if(contactId>DcContact.DC_CONTACT_ID_LAST_SPECIAL) { + new AlertDialog.Builder(getContext()) + .setPositiveButton(android.R.string.ok, (dialog, which) -> { + int chatId = dcContext.createChatByContactId(contactId); + if( chatId != 0 ) { + Intent intent = new Intent(getContext(), ConversationActivity.class); + intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId); + getContext().startActivity(intent); + getActivity().finish(); + } + }) + .setNegativeButton(android.R.string.cancel, null) + .setMessage(getString(R.string.ask_start_chat_with, dcContext.getContact(contactId).getDisplayName())) + .show(); + } + } + + public void onAddMember() { + DcChat dcChat = dcContext.getChat(chatId); + Intent intent = new Intent(getContext(), ContactMultiSelectionActivity.class); + intent.putExtra(ContactSelectionListFragment.SELECT_VERIFIED_EXTRA, dcChat.isVerified()); + ArrayList preselectedContacts = new ArrayList<>(); + int[] memberIds = dcContext.getChatContacts(chatId); + for (int memberId : memberIds) { + preselectedContacts.add(dcContext.getContact(memberId).getAddr()); + } + intent.putExtra(ContactSelectionListFragment.PRESELECTED_CONTACTS, preselectedContacts); + startActivityForResult(intent, REQUEST_CODE_PICK_CONTACT); + } + + public void onQrInvite() { + Intent qrIntent = new Intent(getContext(), QrShowActivity.class); + qrIntent.putExtra(QrShowActivity.CHAT_ID, chatId); + startActivity(qrIntent); + } + + @Override + public void onSharedChatClicked(int chatId) { + Intent intent = new Intent(getContext(), ConversationActivity.class); + intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId); + getContext().startActivity(intent); + getActivity().finish(); + } + private void onContactAddrClicked() { - String address = dcContact.getAddr(); + String address = dcContext.getContact(contactId).getAddr(); new AlertDialog.Builder(getContext()) .setTitle(address) .setItems(new CharSequence[]{ @@ -116,25 +249,93 @@ public class ProfileSettingsFragment extends Fragment implements ProfileSettings .show(); } - private void onEncrInfo() { - String info_str = dcContext.getContactEncrInfo(contactId); + private void onNewChat() { + DcContact dcContact = dcContext.getContact(contactId); new AlertDialog.Builder(getActivity()) - .setMessage(info_str) - .setPositiveButton(android.R.string.ok, null) + .setMessage(getActivity().getString(R.string.ask_start_chat_with, dcContact.getNameNAddr())) + .setPositiveButton(android.R.string.ok, (dialog, which) -> { + int chatId = dcContext.createChatByContactId(dcContact.getId()); + if (chatId != 0) { + Intent intent = new Intent(getActivity(), ConversationActivity.class); + intent.putExtra(ConversationActivity.CHAT_ID_EXTRA, chatId); + getActivity().startActivity(intent); + getActivity().finish(); + } + }) + .setNegativeButton(R.string.cancel, null) .show(); } - private void onEditContactName() { - final EditText txt = new EditText(getActivity()); - txt.setText(dcContact.getName()); - new AlertDialog.Builder(getActivity()) - .setTitle(R.string.menu_edit_name) - .setView(txt) - .setPositiveButton(android.R.string.ok, (dialog, whichButton) -> { - String newName = txt.getText().toString(); - dcContext.createContact(newName, dcContact.getAddr()); - }) - .setNegativeButton(android.R.string.cancel, null) - .show(); + private class ActionModeCallback implements ActionMode.Callback { + + private int originalStatusBarColor; + + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + mode.getMenuInflater().inflate(R.menu.profile_context, menu); + mode.setTitle("1"); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Window window = getActivity().getWindow(); + originalStatusBarColor = window.getStatusBarColor(); + window.setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar)); + } + return true; + } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return false; + } + + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem menuItem) { + switch (menuItem.getItemId()) { + case R.id.delete: + final Collection toDelIds = adapter.getSelectedMembers(); + StringBuilder readableToDelList = new StringBuilder(); + for (Integer toDelId : toDelIds) { + if(readableToDelList.length()>0) { + readableToDelList.append(", "); + } + readableToDelList.append(dcContext.getContact(toDelId).getDisplayName()); + } + new AlertDialog.Builder(getContext()) + .setPositiveButton(android.R.string.ok, (dialog, which) -> { + for (Integer toDelId : toDelIds) { + dcContext.removeContactFromChat(chatId, toDelId); + } + mode.finish(); + }) + .setNegativeButton(android.R.string.cancel, null) + .setMessage(getString(R.string.ask_remove_members, readableToDelList)) + .show(); + return true; + } + return false; + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + actionMode = null; + adapter.clearSelection(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + getActivity().getWindow().setStatusBarColor(originalStatusBarColor); + } + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode==REQUEST_CODE_PICK_CONTACT && resultCode==Activity.RESULT_OK && data!=null) { + List selected = data.getStringArrayListExtra("contacts"); + for (String addr : selected) { + if (addr!=null) { + int toAddId = dcContext.createContact(null, addr); + dcContext.addContactToChat(chatId, toAddId); + } + } + } } } diff --git a/src/org/thoughtcrime/securesms/components/AvatarImageView.java b/src/org/thoughtcrime/securesms/components/AvatarImageView.java index 03c7a622a..0757b25b3 100644 --- a/src/org/thoughtcrime/securesms/components/AvatarImageView.java +++ b/src/org/thoughtcrime/securesms/components/AvatarImageView.java @@ -59,7 +59,7 @@ public class AvatarImageView extends AppCompatImageView { setAvatarClickHandler(recipient, quickContactEnabled); } } else { - setImageDrawable(new GeneratedContactPhoto("+").asDrawable(getContext(), ThemeUtil.getDummyContactColor(getContext()), false)); + setImageDrawable(new GeneratedContactPhoto("+").asDrawable(getContext(), ThemeUtil.getDummyContactColor(getContext()))); super.setOnClickListener(listener); } } diff --git a/src/org/thoughtcrime/securesms/contacts/ContactSelectionListItem.java b/src/org/thoughtcrime/securesms/contacts/ContactSelectionListItem.java index 742955498..f3f823dc3 100644 --- a/src/org/thoughtcrime/securesms/contacts/ContactSelectionListItem.java +++ b/src/org/thoughtcrime/securesms/contacts/ContactSelectionListItem.java @@ -68,7 +68,6 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM if (specialId==DcContact.DC_CONTACT_ID_NEW_CONTACT || specialId==DcContact.DC_CONTACT_ID_NEW_GROUP || specialId==DcContact.DC_CONTACT_ID_NEW_VERIFIED_GROUP || specialId==DcContact.DC_CONTACT_ID_ADD_MEMBER || specialId==DcContact.DC_CONTACT_ID_QR_INVITE) { this.recipient = null; - this.contactPhotoImage.setAvatar(glideRequests, Recipient.from(getContext(), Address.UNKNOWN), false); } else { this.recipient = DcHelper.getContext(getContext()).getRecipient(contact); diff --git a/src/org/thoughtcrime/securesms/contacts/avatars/FallbackContactPhoto.java b/src/org/thoughtcrime/securesms/contacts/avatars/FallbackContactPhoto.java index 8d8bf0ed8..d33323098 100644 --- a/src/org/thoughtcrime/securesms/contacts/avatars/FallbackContactPhoto.java +++ b/src/org/thoughtcrime/securesms/contacts/avatars/FallbackContactPhoto.java @@ -6,7 +6,6 @@ import android.graphics.drawable.Drawable; public interface FallbackContactPhoto { public Drawable asDrawable(Context context, int color); - public Drawable asDrawable(Context context, int color, boolean inverted); public Drawable asCallCard(Context context); } diff --git a/src/org/thoughtcrime/securesms/contacts/avatars/GeneratedContactPhoto.java b/src/org/thoughtcrime/securesms/contacts/avatars/GeneratedContactPhoto.java index 61e6f06f6..374711074 100644 --- a/src/org/thoughtcrime/securesms/contacts/avatars/GeneratedContactPhoto.java +++ b/src/org/thoughtcrime/securesms/contacts/avatars/GeneratedContactPhoto.java @@ -25,20 +25,15 @@ public class GeneratedContactPhoto implements FallbackContactPhoto { @Override public Drawable asDrawable(Context context, int color) { - return asDrawable(context, color, false); - } - - @Override - public Drawable asDrawable(Context context, int color, boolean inverted) { int targetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size); return TextDrawable.builder() .beginConfig() .width(targetSize) .height(targetSize) - .textColor(inverted ? color : Color.WHITE) + .textColor(Color.WHITE) .endConfig() - .buildRound(getCharacter(name), inverted ? Color.WHITE : color); + .buildRound(getCharacter(name), color); } private String getCharacter(String name) { diff --git a/src/org/thoughtcrime/securesms/contacts/avatars/ResourceContactPhoto.java b/src/org/thoughtcrime/securesms/contacts/avatars/ResourceContactPhoto.java index edb902c35..690b24d49 100644 --- a/src/org/thoughtcrime/securesms/contacts/avatars/ResourceContactPhoto.java +++ b/src/org/thoughtcrime/securesms/contacts/avatars/ResourceContactPhoto.java @@ -28,20 +28,11 @@ public class ResourceContactPhoto implements FallbackContactPhoto { @Override public Drawable asDrawable(Context context, int color) { - return asDrawable(context, color, false); - } - - @Override - public Drawable asDrawable(Context context, int color, boolean inverted) { - Drawable background = TextDrawable.builder().buildRound(" ", inverted ? Color.WHITE : color); + Drawable background = TextDrawable.builder().buildRound(" ", color); RoundedDrawable foreground = (RoundedDrawable) RoundedDrawable.fromDrawable(context.getResources().getDrawable(resourceId)); foreground.setScaleType(ImageView.ScaleType.CENTER); - if (inverted) { - foreground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); - } - return new ExpandingLayerDrawable(new Drawable[] {background, foreground}); } diff --git a/src/org/thoughtcrime/securesms/contacts/avatars/TransparentContactPhoto.java b/src/org/thoughtcrime/securesms/contacts/avatars/TransparentContactPhoto.java deleted file mode 100644 index 33c2064b1..000000000 --- a/src/org/thoughtcrime/securesms/contacts/avatars/TransparentContactPhoto.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.thoughtcrime.securesms.contacts.avatars; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.support.v4.content.ContextCompat; - -import com.makeramen.roundedimageview.RoundedDrawable; - -import org.thoughtcrime.securesms.R; - -public class TransparentContactPhoto implements FallbackContactPhoto { - - public TransparentContactPhoto() {} - - @Override - public Drawable asDrawable(Context context, int color) { - return asDrawable(context, color, false); - } - - @Override - public Drawable asDrawable(Context context, int color, boolean inverted) { - return RoundedDrawable.fromDrawable(context.getResources().getDrawable(android.R.color.transparent)); - } - - @Override - public Drawable asCallCard(Context context) { - return ContextCompat.getDrawable(context, R.drawable.ic_contact_picture_large); - } - -} diff --git a/src/org/thoughtcrime/securesms/recipients/Recipient.java b/src/org/thoughtcrime/securesms/recipients/Recipient.java index ce2a402fc..4eaa4d89e 100644 --- a/src/org/thoughtcrime/securesms/recipients/Recipient.java +++ b/src/org/thoughtcrime/securesms/recipients/Recipient.java @@ -203,7 +203,7 @@ public class Recipient { } public synchronized @NonNull Drawable getFallbackAvatarDrawable(Context context) { - return getFallbackContactPhoto().asDrawable(context, getFallbackAvatarColor(context), false); + return getFallbackContactPhoto().asDrawable(context, getFallbackAvatarColor(context)); } public synchronized @NonNull FallbackContactPhoto getFallbackContactPhoto() {