ShortcutActivity.java

 1package eu.siacs.conversations.ui;
 2
 3import android.content.Context;
 4import android.content.Intent;
 5import android.os.Bundle;
 6import android.support.v7.app.ActionBar;
 7import android.view.View;
 8import android.view.inputmethod.InputMethodManager;
 9
10import java.util.Collections;
11
12import eu.siacs.conversations.R;
13import eu.siacs.conversations.entities.Account;
14import eu.siacs.conversations.entities.Contact;
15import eu.siacs.conversations.entities.ListItem;
16
17public class ShortcutActivity extends AbstractSearchableListItemActivity{
18
19    @Override
20    protected void refreshUiReal() {
21
22    }
23
24    @Override
25    public void onCreate(Bundle savedInstanceState) {
26        super.onCreate(savedInstanceState);
27        getListView().setOnItemClickListener((parent, view, position, id) -> {
28            final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
29            imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
30
31            ListItem listItem = getListItems().get(position);
32            Intent shortcut = xmppConnectionService.getShortcutService().createShortcut(((Contact) listItem));
33            setResult(RESULT_OK,shortcut);
34            finish();
35        });
36        binding.fab.setVisibility(View.GONE);
37    }
38
39    @Override
40    protected void onStart() {
41        super.onStart();
42        ActionBar bar = getSupportActionBar();
43        if(bar != null){
44            bar.setTitle(R.string.create_shortcut);
45        }
46    }
47
48    @Override
49    protected void filterContacts(String needle) {
50        getListItems().clear();
51        if (xmppConnectionService == null) {
52            getListItemAdapter().notifyDataSetChanged();
53            return;
54        }
55        for (final Account account : xmppConnectionService.getAccounts()) {
56            if (account.getStatus() != Account.State.DISABLED) {
57                for (final Contact contact : account.getRoster().getContacts()) {
58                    if (contact.showInContactList()
59                            && contact.match(this, needle)) {
60                        getListItems().add(contact);
61                    }
62                }
63            }
64        }
65        Collections.sort(getListItems());
66        getListItemAdapter().notifyDataSetChanged();
67    }
68}