use fab in choose contact activity. scan qr not yet working

This commit is contained in:
Daniel Gultsch 2018-03-06 11:18:29 +01:00
parent ed0ba89551
commit 1efaecf745
5 changed files with 106 additions and 139 deletions

View file

@ -1,6 +1,7 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.content.Context; import android.content.Context;
import android.databinding.DataBindingUtil;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -16,11 +17,12 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.ActivityChooseContactBinding;
import eu.siacs.conversations.entities.ListItem; import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.ui.adapter.ListItemAdapter; import eu.siacs.conversations.ui.adapter.ListItemAdapter;
public abstract class AbstractSearchableListItemActivity extends XmppActivity { public abstract class AbstractSearchableListItemActivity extends XmppActivity {
private ListView mListView; protected ActivityChooseContactBinding binding;
private final List<ListItem> listItems = new ArrayList<>(); private final List<ListItem> listItems = new ArrayList<>();
private ArrayAdapter<ListItem> mListItemsAdapter; private ArrayAdapter<ListItem> mListItemsAdapter;
@ -74,7 +76,7 @@ public abstract class AbstractSearchableListItemActivity extends XmppActivity {
}; };
public ListView getListView() { public ListView getListView() {
return mListView; return binding.chooseContactList;
} }
public List<ListItem> getListItems() { public List<ListItem> getListItems() {
@ -92,11 +94,10 @@ public abstract class AbstractSearchableListItemActivity extends XmppActivity {
@Override @Override
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_choose_contact); this.binding = DataBindingUtil.setContentView(this,R.layout.activity_choose_contact);
mListView = (ListView) findViewById(R.id.choose_contact_list); this.binding.chooseContactList.setFastScrollEnabled(true);
mListView.setFastScrollEnabled(true);
mListItemsAdapter = new ListItemAdapter(this, listItems); mListItemsAdapter = new ListItemAdapter(this, listItems);
mListView.setAdapter(mListItemsAdapter); this.binding.chooseContactList.setAdapter(mListItemsAdapter);
} }
@Override @Override

View file

@ -26,17 +26,11 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
@Override @Override
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { getListView().setOnItemLongClickListener((parent, view, position, id) -> {
BlockContactDialog.show(BlocklistActivity.this, (Contact) getListItems().get(position));
@Override return true;
public boolean onItemLongClick(final AdapterView<?> parent,
final View view,
final int position,
final long id) {
BlockContactDialog.show(BlocklistActivity.this, (Contact) getListItems().get(position));
return true;
}
}); });
this.binding.fab.setOnClickListener((v)->showEnterJidDialog());
} }
@Override @Override
@ -66,23 +60,6 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
getListItemAdapter().notifyDataSetChanged(); getListItemAdapter().notifyDataSetChanged();
} }
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
super.onCreateOptionsMenu(menu);
menu.findItem(R.id.action_block_jid).setVisible(true);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_block_jid:
showEnterJidDialog();
return true;
}
return super.onOptionsItemSelected(item);
}
protected void showEnterJidDialog() { protected void showEnterJidDialog() {
EnterJidDialog dialog = new EnterJidDialog( EnterJidDialog dialog = new EnterJidDialog(
this, mKnownHosts, null, this, mKnownHosts, null,
@ -90,15 +67,12 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
null, account.getJid().asBareJid().toString(), true null, account.getJid().asBareJid().toString(), true
); );
dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() { dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
@Override Contact contact = account.getRoster().getContact(contactJid);
public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError { if (xmppConnectionService.sendBlockRequest(contact, false)) {
Contact contact = account.getRoster().getContact(contactJid); Toast.makeText(BlocklistActivity.this, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show();
if (xmppConnectionService.sendBlockRequest(contact, false)) {
Toast.makeText(BlocklistActivity.this,R.string.corresponding_conversations_closed,Toast.LENGTH_SHORT).show();
}
return true;
} }
return true;
}); });
dialog.show(); dialog.show();

View file

@ -13,7 +13,6 @@ import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView.MultiChoiceModeListener; import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,12 +31,32 @@ import eu.siacs.conversations.entities.MucOptions;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
public class ChooseContactActivity extends AbstractSearchableListItemActivity { public class ChooseContactActivity extends AbstractSearchableListItemActivity {
public static final String EXTRA_TITLE_RES_ID = "extra_title_res_id";
private List<String> mActivatedAccounts = new ArrayList<>(); private List<String> mActivatedAccounts = new ArrayList<>();
private List<String> mKnownHosts; private List<String> mKnownHosts;
private Set<Contact> selected; private Set<Contact> selected;
private Set<String> filterContacts; private Set<String> filterContacts;
public static final String EXTRA_TITLE_RES_ID = "extra_title_res_id";
public static Intent create(Activity activity, Conversation conversation) {
final Intent intent = new Intent(activity, ChooseContactActivity.class);
List<String> contacts = new ArrayList<>();
if (conversation.getMode() == Conversation.MODE_MULTI) {
for (MucOptions.User user : conversation.getMucOptions().getUsers(false)) {
Jid jid = user.getRealJid();
if (jid != null) {
contacts.add(jid.asBareJid().toString());
}
}
} else {
contacts.add(conversation.getJid().asBareJid().toString());
}
intent.putExtra("filter_contacts", contacts.toArray(new String[contacts.size()]));
intent.putExtra("conversation", conversation.getUuid());
intent.putExtra("multiple", true);
intent.putExtra("show_enter_jid", true);
intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().asBareJid().toString());
return intent;
}
@Override @Override
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
@ -53,15 +72,14 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() { getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() {
@Override @Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) { public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false; return false;
} }
@Override @Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
InputMethodManager.HIDE_IMPLICIT_ONLY);
MenuInflater inflater = getMenuInflater(); MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.select_multiple, menu); inflater.inflate(R.menu.select_multiple, menu);
selected = new HashSet<>(); selected = new HashSet<>();
@ -74,7 +92,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
@Override @Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch(item.getItemId()) { switch (item.getItemId()) {
case R.id.selection_submit: case R.id.selection_submit:
final Intent request = getIntent(); final Intent request = getIntent();
final Intent data = new Intent(); final Intent data = new Intent();
@ -83,7 +101,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
String[] selection = getSelectedContactJids(); String[] selection = getSelectedContactJids();
data.putExtra("contacts", selection); data.putExtra("contacts", selection);
data.putExtra("multiple", true); data.putExtra("multiple", true);
data.putExtra(EXTRA_ACCOUNT,request.getStringExtra(EXTRA_ACCOUNT)); data.putExtra(EXTRA_ACCOUNT, request.getStringExtra(EXTRA_ACCOUNT));
data.putExtra("subject", request.getStringExtra("subject")); data.putExtra("subject", request.getStringExtra("subject"));
setResult(RESULT_OK, data); setResult(RESULT_OK, data);
finish(); finish();
@ -109,32 +127,31 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
}); });
} }
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { getListView().setOnItemClickListener((parent, view, position, id) -> {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
@Override imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
public void onItemClick(final AdapterView<?> parent, final View view, final Intent request = getIntent();
final int position, final long id) { final Intent data = new Intent();
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); final ListItem mListItem = getListItems().get(position);
imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), data.putExtra("contact", mListItem.getJid().toString());
InputMethodManager.HIDE_IMPLICIT_ONLY); String account = request.getStringExtra(EXTRA_ACCOUNT);
final Intent request = getIntent(); if (account == null && mListItem instanceof Contact) {
final Intent data = new Intent(); account = ((Contact) mListItem).getAccount().getJid().asBareJid().toString();
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("conversation",
request.getStringExtra("conversation"));
data.putExtra("multiple", false);
data.putExtra("subject", request.getStringExtra("subject"));
setResult(RESULT_OK, data);
finish();
} }
data.putExtra(EXTRA_ACCOUNT, account);
data.putExtra("conversation", request.getStringExtra("conversation"));
data.putExtra("multiple", false);
data.putExtra("subject", request.getStringExtra("subject"));
setResult(RESULT_OK, data);
finish();
}); });
final Intent i = getIntent();
boolean showEnterJid = i != null && i.getBooleanExtra("show_enter_jid", false);
if (showEnterJid) {
this.binding.fab.setOnClickListener((v) -> showEnterJidDialog());
} else {
this.binding.fab.setVisibility(View.GONE);
}
} }
@Override @Override
@ -142,7 +159,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
super.onStart(); super.onStart();
Intent intent = getIntent(); Intent intent = getIntent();
@StringRes @StringRes
int res = intent != null ? intent.getIntExtra(EXTRA_TITLE_RES_ID,R.string.title_activity_choose_contact) : R.string.title_activity_choose_contact; int res = intent != null ? intent.getIntExtra(EXTRA_TITLE_RES_ID, R.string.title_activity_choose_contact) : R.string.title_activity_choose_contact;
ActionBar bar = getSupportActionBar(); ActionBar bar = getSupportActionBar();
if (bar != null) { if (bar != null) {
try { try {
@ -158,7 +175,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);
final Intent i = getIntent(); final Intent i = getIntent();
boolean showEnterJid = i != null && i.getBooleanExtra("show_enter_jid", false); boolean showEnterJid = i != null && i.getBooleanExtra("show_enter_jid", false);
menu.findItem(R.id.action_create_contact).setVisible(showEnterJid); menu.findItem(R.id.action_scan_qr_code).setVisible(showEnterJid);
return true; return true;
} }
@ -191,7 +208,6 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
return result.toArray(new String[result.size()]); return result.toArray(new String[result.size()]);
} }
public void refreshUiReal() { public void refreshUiReal() {
//nothing to do. This Activity doesn't implement any listeners //nothing to do. This Activity doesn't implement any listeners
} }
@ -199,8 +215,8 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.action_create_contact: case R.id.action_scan_qr_code:
showEnterJidDialog(); ScanActivity.scan(this);
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
@ -208,27 +224,24 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
protected void showEnterJidDialog() { protected void showEnterJidDialog() {
EnterJidDialog dialog = new EnterJidDialog( EnterJidDialog dialog = new EnterJidDialog(
this, mKnownHosts, mActivatedAccounts, this, mKnownHosts, mActivatedAccounts,
getString(R.string.enter_contact), getString(R.string.select), getString(R.string.enter_contact), getString(R.string.select),
null, getIntent().getStringExtra(EXTRA_ACCOUNT), true null, getIntent().getStringExtra(EXTRA_ACCOUNT), true
); );
dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() { dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
@Override final Intent request = getIntent();
public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError { final Intent data = new Intent();
final Intent request = getIntent(); data.putExtra("contact", contactJid.toString());
final Intent data = new Intent(); data.putExtra(EXTRA_ACCOUNT, accountJid.toString());
data.putExtra("contact", contactJid.toString()); data.putExtra("conversation",
data.putExtra(EXTRA_ACCOUNT, accountJid.toString()); request.getStringExtra("conversation"));
data.putExtra("conversation", data.putExtra("multiple", false);
request.getStringExtra("conversation")); data.putExtra("subject", request.getStringExtra("subject"));
data.putExtra("multiple", false); setResult(RESULT_OK, data);
data.putExtra("subject", request.getStringExtra("subject")); finish();
setResult(RESULT_OK, data);
finish();
return true; return true;
}
}); });
dialog.show(); dialog.show();
@ -249,25 +262,4 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
} }
this.mKnownHosts = xmppConnectionService.getKnownHosts(); this.mKnownHosts = xmppConnectionService.getKnownHosts();
} }
public static Intent create(Activity activity, Conversation conversation) {
final Intent intent = new Intent(activity, ChooseContactActivity.class);
List<String> contacts = new ArrayList<>();
if (conversation.getMode() == Conversation.MODE_MULTI) {
for (MucOptions.User user : conversation.getMucOptions().getUsers(false)) {
Jid jid = user.getRealJid();
if (jid != null) {
contacts.add(jid.asBareJid().toString());
}
}
} else {
contacts.add(conversation.getJid().asBareJid().toString());
}
intent.putExtra("filter_contacts", contacts.toArray(new String[contacts.size()]));
intent.putExtra("conversation", conversation.getUuid());
intent.putExtra("multiple", true);
intent.putExtra("show_enter_jid", true);
intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().asBareJid().toString());
return intent;
}
} }

View file

@ -1,16 +1,24 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <layout xmlns:android="http://schemas.android.com/apk/res/android">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/color_background_primary">
<ListView <FrameLayout
android:id="@+id/choose_contact_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:listitem="@layout/contact" android:background="?attr/color_background_primary">
android:divider="@android:color/transparent"
android:dividerHeight="0dp"/>
</LinearLayout> <ListView
android:id="@+id/choose_contact_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:src="@drawable/ic_person_add_white_24dp"/>
</FrameLayout>
</layout>

View file

@ -8,18 +8,10 @@
android:icon="?attr/icon_search" android:icon="?attr/icon_search"
app:showAsAction="collapseActionView|always" app:showAsAction="collapseActionView|always"
android:title="@string/search"/> android:title="@string/search"/>
<item <item
android:id="@+id/action_create_contact" android:id="@+id/action_scan_qr_code"
android:icon="?attr/icon_add_person" android:title="@string/scan_qr_code"
android:icon="?attr/icon_scan_qr_code"
app:showAsAction="always" app:showAsAction="always"
android:title="@string/create_contact"
android:visible="false"/>
<item
android:id="@+id/action_block_jid"
android:icon="?attr/icon_add_person"
app:showAsAction="always"
android:title="@string/block_jabber_id"
android:visible="false"/> android:visible="false"/>
</menu> </menu>