open direct search after hitting + in share with screen

This commit is contained in:
Daniel Gultsch 2018-12-01 13:27:00 +01:00
parent 846bba96f2
commit fdbed9cf58
4 changed files with 86 additions and 47 deletions

View File

@ -6,6 +6,7 @@ import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -13,6 +14,7 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
@ -22,7 +24,7 @@ import eu.siacs.conversations.databinding.ActivityChooseContactBinding;
import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.ui.adapter.ListItemAdapter;
public abstract class AbstractSearchableListItemActivity extends XmppActivity {
public abstract class AbstractSearchableListItemActivity extends XmppActivity implements TextView.OnEditorActionListener {
protected ActivityChooseContactBinding binding;
private final List<ListItem> listItems = new ArrayList<>();
private ArrayAdapter<ListItem> mListItemsAdapter;
@ -33,15 +35,10 @@ public abstract class AbstractSearchableListItemActivity extends XmppActivity {
@Override
public boolean onMenuItemActionExpand(final MenuItem item) {
mSearchEditText.post(new Runnable() {
@Override
public void run() {
mSearchEditText.post(() -> {
mSearchEditText.requestFocus();
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mSearchEditText,
InputMethodManager.SHOW_IMPLICIT);
}
imm.showSoftInput(mSearchEditText, InputMethodManager.SHOW_IMPLICIT);
});
return true;
@ -50,8 +47,7 @@ public abstract class AbstractSearchableListItemActivity extends XmppActivity {
@Override
public boolean onMenuItemActionCollapse(final MenuItem item) {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mSearchEditText.getWindowToken(),
InputMethodManager.HIDE_IMPLICIT_ONLY);
imm.hideSoftInputFromWindow(mSearchEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
mSearchEditText.setText("");
filterContacts();
return true;
@ -108,8 +104,10 @@ public abstract class AbstractSearchableListItemActivity extends XmppActivity {
getMenuInflater().inflate(R.menu.choose_contact, menu);
final MenuItem menuSearchView = menu.findItem(R.id.action_search);
final View mSearchView = menuSearchView.getActionView();
mSearchEditText = (EditText) mSearchView.findViewById(R.id.search_field);
mSearchEditText = mSearchView.findViewById(R.id.search_field);
mSearchEditText.addTextChangedListener(mSearchTextWatcher);
mSearchEditText.setHint(R.string.search_contacts);
mSearchEditText.setOnEditorActionListener(this);
menuSearchView.setOnActionExpandListener(mOnActionExpandListener);
return true;
}
@ -129,4 +127,9 @@ public abstract class AbstractSearchableListItemActivity extends XmppActivity {
void onBackendConnected() {
filterContacts();
}
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return false;
}
}

View File

@ -3,6 +3,7 @@ package eu.siacs.conversations.ui;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
@ -10,12 +11,15 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Arrays;
@ -37,7 +41,7 @@ import eu.siacs.conversations.ui.util.PendingItem;
import eu.siacs.conversations.utils.XmppUri;
import rocks.xmpp.addr.Jid;
public class ChooseContactActivity extends AbstractSearchableListItemActivity implements MultiChoiceModeListener {
public class ChooseContactActivity extends AbstractSearchableListItemActivity implements MultiChoiceModeListener, AdapterView.OnItemClickListener {
public static final String EXTRA_TITLE_RES_ID = "extra_title_res_id";
public static final String EXTRA_GROUP_CHAT_NAME = "extra_group_chat_name";
public static final String EXTRA_SELECT_MULTIPLE = "extra_select_multiple";
@ -49,6 +53,8 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im
private Set<String> filterContacts;
private boolean showEnterJid = false;
private boolean startSearching = false;
private boolean multiple = false;
private PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
@ -109,42 +115,24 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im
Intent intent = getIntent();
final boolean multiple = intent.getBooleanExtra(EXTRA_SELECT_MULTIPLE, false);
multiple = intent.getBooleanExtra(EXTRA_SELECT_MULTIPLE, false);
if (multiple) {
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
getListView().setMultiChoiceModeListener(this);
}
getListView().setOnItemClickListener((parent, view, position, id) -> {
if (multiple) {
startActionMode(this);
getListView().setItemChecked(position, true);
return;
}
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
final Intent request = getIntent();
final Intent data = new Intent();
final ListItem mListItem = getListItems().get(position);
data.putExtra("contact", mListItem.getJid().toString());
String account = request.getStringExtra(EXTRA_ACCOUNT);
if (account == null && mListItem instanceof Contact) {
account = ((Contact) mListItem).getAccount().getJid().asBareJid().toString();
}
data.putExtra(EXTRA_ACCOUNT, account);
data.putExtra(EXTRA_SELECT_MULTIPLE, false);
copy(request, data);
setResult(RESULT_OK, data);
finish();
});
final Intent i = getIntent();
this.showEnterJid = i != null && i.getBooleanExtra(EXTRA_SHOW_ENTER_JID, false);
getListView().setOnItemClickListener(this);
this.showEnterJid = intent.getBooleanExtra(EXTRA_SHOW_ENTER_JID, false);
this.binding.fab.setOnClickListener(this::onFabClicked);
if (this.showEnterJid) {
this.binding.fab.setVisibility(View.VISIBLE);
this.binding.fab.show();
} else {
this.binding.fab.setVisibility(View.GONE);
binding.fab.setImageResource(R.drawable.ic_forward_white_24dp);
}
final SharedPreferences preferences = getPreferences();
this.startSearching = intent.getBooleanExtra("direct_search", false) && preferences.getBoolean("start_searching", getResources().getBoolean(R.bool.start_searching));
}
private void onFabClicked(View v) {
@ -164,7 +152,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.setTitle(getTitleFromIntent());
binding.fab.setImageResource(R.drawable.ic_forward_white_24dp);
binding.fab.setVisibility(View.VISIBLE);
binding.fab.show();
final View view = getSearchEditText();
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (view != null && imm != null) {
@ -177,9 +165,9 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im
public void onDestroyActionMode(ActionMode mode) {
this.binding.fab.setImageResource(R.drawable.ic_person_add_white_24dp);
if (this.showEnterJid) {
this.binding.fab.setVisibility(View.VISIBLE);
this.binding.fab.show();
} else {
this.binding.fab.setVisibility(View.GONE);
this.binding.fab.hide();
}
selected.clear();
}
@ -245,6 +233,10 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im
final Intent i = getIntent();
boolean showEnterJid = i != null && i.getBooleanExtra(EXTRA_SHOW_ENTER_JID, false);
menu.findItem(R.id.action_scan_qr_code).setVisible(isCameraFeatureAvailable() && showEnterJid);
MenuItem mMenuSearchView = menu.findItem(R.id.action_search);
if (startSearching) {
mMenuSearchView.expandActionView();
}
return true;
}
@ -254,6 +246,20 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im
super.onSaveInstanceState(savedInstanceState);
}
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (multiple) {
return false;
} else {
List<ListItem> items = getListItems();
if (items.size() == 1) {
onListItemClicked(items.get(0));
return true;
}
return false;
}
}
protected void filterContacts(final String needle) {
getListItems().clear();
if (xmppConnectionService == null) {
@ -276,7 +282,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im
}
private String[] getSelectedContactJids() {
return selected.toArray(new String[selected.size()]);
return selected.toArray(new String[0]);
}
public void refreshUiReal() {
@ -364,8 +370,8 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im
if (activityResult != null) {
handleActivityResult(activityResult);
}
Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
if (fragment != null && fragment instanceof OnBackendConnected) {
final Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
if (fragment instanceof OnBackendConnected) {
((OnBackendConnected) fragment).onBackendConnected();
}
}
@ -374,4 +380,32 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
ScanActivity.onRequestPermissionResult(this, requestCode, grantResults);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (multiple) {
startActionMode(this);
getListView().setItemChecked(position, true);
return;
}
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
final ListItem mListItem = getListItems().get(position);
onListItemClicked(mListItem);
}
private void onListItemClicked(ListItem item) {
final Intent request = getIntent();
final Intent data = new Intent();
data.putExtra("contact", item.getJid().toString());
String account = request.getStringExtra(EXTRA_ACCOUNT);
if (account == null && item instanceof Contact) {
account = ((Contact) item).getAccount().getJid().asBareJid().toString();
}
data.putExtra(EXTRA_ACCOUNT, account);
data.putExtra(EXTRA_SELECT_MULTIPLE, false);
copy(request, data);
setResult(RESULT_OK, data);
finish();
}
}

View File

@ -112,6 +112,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
switch (item.getItemId()) {
case R.id.action_add:
final Intent intent = new Intent(getApplicationContext(), ChooseContactActivity.class);
intent.putExtra("direct_search",true);
startActivityForResult(intent, REQUEST_START_NEW_CONVERSATION);
return true;
}

View File

@ -24,6 +24,7 @@
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:visibility="gone"
app:backgroundTint="?colorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"