Skip to content
Snippets Groups Projects
Commit 54cf69be authored by Aline Bonnet's avatar Aline Bonnet
Browse files

contacts: add block function


With a long click on the contact in the smartlist or a click on the
option in the conversation, it is possible to block a contact. This
contact is added in the blocked contacts list but it is not removed
to the smartlist for now.

Change-Id: I82d691d1f16c8436673acd3cddbf7daae9b5e504
Reviewed-by: default avatarHadrien De Sousa <hadrien.desousa@savoirfairelinux.com>
Tuleap: #1500
parent b0572ce3
No related branches found
No related tags found
No related merge requests found
......@@ -500,11 +500,34 @@ public class ConversationFragment extends Fragment implements
this.mConversation.getContact(),
this);
return true;
case R.id.menuitem_block:
blockContact();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void blockContact() {
Pair<Account, Uri> guess = guess();
if (guess.first == null || guess.second == null || !guess.first.isRing() || !guess.second.isRingId()) {
return;
}
String accountId = guess.first.getAccountID();
String contactId = guess.second.getRawUriString();
String[] split = contactId.split(":");
if (split.length > 1) {
contactId = split[1];
}
mContactService.removeContact(accountId, contactId);
if (getActivity() instanceof ConversationActivity) {
getActivity().finish();
}
}
/**
* Guess account and number to use to initiate a call
*/
......
......@@ -483,6 +483,9 @@ public class SmartListFragment extends BaseFragment<SmartListPresenter> implemen
case 1:
ActionHelper.launchDeleteAction(getActivity(), conversation, SmartListFragment.this);
break;
case 2:
presenter.removeContact(conversation.getLastAccountUsed(), conversation.getContact().getDisplayName());
break;
}
}
});
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM4,12c0,-4.42 3.58,-8 8,-8 1.85,0 3.55,0.63 4.9,1.69L5.69,16.9C4.63,15.55 4,13.85 4,12zM12,20c-1.85,0 -3.55,-0.63 -4.9,-1.69L18.31,7.1C19.37,8.45 20,10.15 20,12c0,4.42 -3.58,8 -8,8z"
android:fillColor="#FFFFFF"/>
</vector>
......@@ -32,4 +32,10 @@
android:title="@string/conversation_action_delete_this"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menuitem_block"
android:icon="@drawable/ic_block_white"
android:title="@string/conversation_action_block_this"
app:showAsAction="ifRoom" />
</menu>
\ No newline at end of file
......@@ -28,6 +28,7 @@ along with this program; if not, write to the Free Software
<string-array name="conversation_actions">
<item>@string/conversation_action_copy_peer_number</item>
<item>@string/conversation_action_delete_this</item>
<item>@string/conversation_action_block_this</item>
</string-array>
</resources>
......@@ -161,6 +161,7 @@ along with this program; if not, write to the Free Software
<string name="conversation_action_copy_peer_number">Copy number</string>
<string name="conversation_action_copied_peer_number_clipboard">%1$s copied to clipboard</string>
<string name="conversation_action_select_peer_number">Select a number</string>
<string name="conversation_action_block_this">Block this contact</string>
<!-- Contacts -->
<string name="add_call_contact_number_to_contacts">Add %1$s ?</string>
......
......@@ -251,7 +251,7 @@ public class SmartListPresenter extends RootPresenter<SmartListView> implements
if (smartListViewModel == null || i >= mSmartListViewModels.size()) {
if(conversation.getContact().isFromSystem()) {
if (conversation.getContact().isFromSystem()) {
Tuple<String, String> tuple = mContactService.loadContactDataFromSystem(conversation.getContact());
smartListViewModel = new SmartListViewModel(conversation, tuple.first, tuple.second, null);
} else {
......@@ -261,7 +261,7 @@ public class SmartListPresenter extends RootPresenter<SmartListView> implements
mSmartListViewModels.add(smartListViewModel);
} else {
if(conversation.getContact().isFromSystem()) {
if (conversation.getContact().isFromSystem()) {
Tuple<String, String> tuple = mContactService.loadContactDataFromSystem(conversation.getContact());
smartListViewModel.update(conversation, tuple.first, tuple.second, null);
} else {
......@@ -289,11 +289,11 @@ public class SmartListPresenter extends RootPresenter<SmartListView> implements
private ArrayList<SmartListViewModel> filter(ArrayList<SmartListViewModel> list, String query) {
ArrayList<SmartListViewModel> filteredList = new ArrayList<>();
if(list == null || list.size() == 0) {
if (list == null || list.size() == 0) {
return filteredList;
}
for(SmartListViewModel smartListViewModel : list) {
if(smartListViewModel.getContactName().toLowerCase().contains(query.toLowerCase())) {
for (SmartListViewModel smartListViewModel : list) {
if (smartListViewModel.getContactName().toLowerCase().contains(query.toLowerCase())) {
filteredList.add(smartListViewModel);
}
}
......@@ -359,6 +359,12 @@ public class SmartListPresenter extends RootPresenter<SmartListView> implements
}
}
public void removeContact(String accountId, String contactId) {
String[] split = contactId.split(":");
if (split.length > 1 && split[0].equals("ring")) {
mContactService.removeContact(accountId, split[1]);
}
}
@Override
public void update(Observable observable, ServiceEvent event) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment