Merge pull request #921 from deltachat/simplify-profile2

tweak simplified profile
This commit is contained in:
björn petersen
2019-05-24 00:13:52 +02:00
committed by GitHub
19 changed files with 607 additions and 182 deletions
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<alpha
android:duration="150"
android:fromAlpha="0.3"
android:toAlpha="1.0" />
</set>
+9
View File
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/decelerate_interpolator">
<alpha
android:duration="150"
android:fromAlpha="1.0"
android:toAlpha="0.3" />
</set>
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="@string/menu_group_name_and_image"
android:id="@+id/edit_group_name_and_image"
android:icon="@drawable/ic_create_white_24dp"
app:showAsAction="always"/>
<item android:title="@string/menu_mute"
android:id="@+id/menu_mute_notifications"
app:showAsAction="never"/>
<item android:title="@string/pref_sound"
android:id="@+id/menu_sound"
app:showAsAction="never"/>
<item android:title="@string/pref_vibrate"
android:id="@+id/menu_vibrate"
app:showAsAction="never"/>
</menu>
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="@string/menu_edit_name"
android:id="@+id/edit_contact_name"
android:icon="@drawable/ic_create_white_24dp"
app:showAsAction="always"/>
<item android:title="@string/profile_encryption"
android:id="@+id/show_encr_info"
app:showAsAction="never"/>
<item android:title="@string/menu_block_contact"
android:id="@+id/block_contact"
app:showAsAction="never"/>
</menu>
+3
View File
@@ -184,6 +184,8 @@
<string name="ask_delete_contacts">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.</string>
<string name="cannot_delete_contacts_in_use">Cannot delete contacts with ongoing chats.</string>
<string name="ask_start_chat_with">Chat with %1$s?</string>
<!-- Translators: %1$s will be replaces by a comma separated list of names -->
<string name="ask_remove_members">Remove %1$s from group?</string>
<!-- contact list -->
@@ -249,6 +251,7 @@
<string name="profile_shared_chats">Shared chats</string>
<string name="tab_contact">Contact</string>
<string name="tab_group">Group</string>
<string name="tab_members">Members</string>
<string name="tab_gallery">Gallery</string>
<string name="tab_docs">Docs</string>
<string name="tab_links">Links</string>
@@ -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);
}
}
@@ -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<Integer> 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);
}
}
}
@@ -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;
@@ -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<BucketedThreadMediaLoader.BucketedThreadMedia>, ProfileDocumentsAdapter.ItemClickListener
extends Fragment
implements LoaderManager.LoaderCallbacks<BucketedThreadMediaLoader.BucketedThreadMedia>,
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<DcMsg, Void, Void>(getContext(),
@@ -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<BucketedThreadMediaLoader.BucketedThreadMedia>, ProfileGalleryAdapter.ItemClickListener
extends Fragment
implements LoaderManager.LoaderCallbacks<BucketedThreadMediaLoader.BucketedThreadMedia>,
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<DcMsg, Void, Void>(getContext(),
@@ -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<ProfileSettingsAdapter.HeaderViewHolder>
@@ -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<Integer,SoftReference<DcContact>> 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<Integer> 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<DcContact> 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<Integer> 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();
}
}
@@ -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<String> 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<Integer> 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<String> selected = data.getStringArrayListExtra("contacts");
for (String addr : selected) {
if (addr!=null) {
int toAddId = dcContext.createContact(null, addr);
dcContext.addContactToChat(chatId, toAddId);
}
}
}
}
}
@@ -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);
}
}
@@ -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);
@@ -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);
}
@@ -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) {
@@ -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});
}
@@ -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);
}
}
@@ -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() {