aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-03 21:14:17 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-03 21:14:17 +0200
commit035f2ce97395d60448be7e751f586080e39d4c31 (patch)
tree9e4669954701a24ae656bd5653a43a466846c03f /src
parenta311e0912f9bb6d45b43ed61031f7470546c32b6 (diff)
use fab in choose contact activity. scan qr not yet working
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/pixart/messenger/ui/AbstractSearchableListItemActivity.java13
-rw-r--r--src/main/java/de/pixart/messenger/ui/BlocklistActivity.java48
-rw-r--r--src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java129
-rw-r--r--src/main/res/layout/activity_choose_contact.xml30
-rw-r--r--src/main/res/menu/choose_contact.xml20
5 files changed, 102 insertions, 138 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/AbstractSearchableListItemActivity.java b/src/main/java/de/pixart/messenger/ui/AbstractSearchableListItemActivity.java
index a3536a368..059df9bb8 100644
--- a/src/main/java/de/pixart/messenger/ui/AbstractSearchableListItemActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/AbstractSearchableListItemActivity.java
@@ -1,6 +1,7 @@
package de.pixart.messenger.ui;
import android.content.Context;
+import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
@@ -16,11 +17,12 @@ import java.util.ArrayList;
import java.util.List;
import de.pixart.messenger.R;
+import de.pixart.messenger.databinding.ActivityChooseContactBinding;
import de.pixart.messenger.entities.ListItem;
import de.pixart.messenger.ui.adapter.ListItemAdapter;
public abstract class AbstractSearchableListItemActivity extends XmppActivity {
- private ListView mListView;
+ protected ActivityChooseContactBinding binding;
private final List<ListItem> listItems = new ArrayList<>();
private ArrayAdapter<ListItem> mListItemsAdapter;
@@ -74,7 +76,7 @@ public abstract class AbstractSearchableListItemActivity extends XmppActivity {
};
public ListView getListView() {
- return mListView;
+ return binding.chooseContactList;
}
public List<ListItem> getListItems() {
@@ -92,11 +94,10 @@ public abstract class AbstractSearchableListItemActivity extends XmppActivity {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_choose_contact);
- mListView = findViewById(R.id.choose_contact_list);
- mListView.setFastScrollEnabled(true);
+ this.binding = DataBindingUtil.setContentView(this, R.layout.activity_choose_contact);
+ this.binding.chooseContactList.setFastScrollEnabled(true);
mListItemsAdapter = new ListItemAdapter(this, listItems);
- mListView.setAdapter(mListItemsAdapter);
+ this.binding.chooseContactList.setAdapter(mListItemsAdapter);
}
@Override
diff --git a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
index 84d2ab24b..7fb1dd349 100644
--- a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
@@ -2,10 +2,6 @@ package de.pixart.messenger.ui;
import android.os.Bundle;
import android.text.Editable;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.widget.AdapterView;
import android.widget.Toast;
import java.util.ArrayList;
@@ -25,17 +21,11 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
-
- @Override
- 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;
- }
+ getListView().setOnItemLongClickListener((parent, view, position, id) -> {
+ BlockContactDialog.show(BlocklistActivity.this, (Contact) getListItems().get(position));
+ return true;
});
+ this.binding.fab.setOnClickListener((v)->showEnterJidDialog());
}
@Override
@@ -65,23 +55,6 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
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() {
EnterJidDialog dialog = new EnterJidDialog(
this, mKnownHosts, null,
@@ -89,15 +62,12 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
null, account.getJid().asBareJid().toString(), true, xmppConnectionService.multipleAccounts()
);
- dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() {
- @Override
- public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError {
- Contact contact = account.getRoster().getContact(contactJid);
- if (xmppConnectionService.sendBlockRequest(contact, false)) {
- Toast.makeText(BlocklistActivity.this, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show();
- }
- return true;
+ dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
+ Contact contact = account.getRoster().getContact(contactJid);
+ if (xmppConnectionService.sendBlockRequest(contact, false)) {
+ Toast.makeText(BlocklistActivity.this, R.string.corresponding_conversations_closed, Toast.LENGTH_SHORT).show();
}
+ return true;
});
dialog.show();
}
diff --git a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
index 4450c8759..647330c71 100644
--- a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
@@ -13,7 +13,6 @@ 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 java.util.ArrayList;
@@ -32,12 +31,32 @@ import de.pixart.messenger.entities.MucOptions;
import rocks.xmpp.addr.Jid;
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> mKnownHosts;
-
private Set<Contact> selected;
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
public void onCreate(final Bundle savedInstanceState) {
@@ -60,8 +79,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(),
- InputMethodManager.HIDE_IMPLICIT_ONLY);
+ imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.select_multiple, menu);
selected = new HashSet<>();
@@ -109,32 +127,32 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
});
}
- getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(final AdapterView<?> parent, final View view,
- final int position, final long id) {
- 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("conversation",
- request.getStringExtra("conversation"));
- data.putExtra("multiple", false);
- data.putExtra("subject", request.getStringExtra("subject"));
- setResult(RESULT_OK, data);
- finish();
+ getListView().setOnItemClickListener((parent, view, position, id) -> {
+ 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("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
@@ -158,7 +176,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
super.onCreateOptionsMenu(menu);
final Intent i = getIntent();
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;
}
@@ -191,7 +209,6 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
return result.toArray(new String[result.size()]);
}
-
public void refreshUiReal() {
//nothing to do. This Activity doesn't implement any listeners
}
@@ -199,8 +216,8 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.action_create_contact:
- showEnterJidDialog();
+ case R.id.action_scan_qr_code:
+ ScanActivity.scan(this);
return true;
}
return super.onOptionsItemSelected(item);
@@ -213,22 +230,19 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
null, getIntent().getStringExtra(EXTRA_ACCOUNT), true, xmppConnectionService.multipleAccounts()
);
- dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() {
- @Override
- public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError {
- final Intent request = getIntent();
- final Intent data = new Intent();
- data.putExtra("contact", contactJid.toString());
- data.putExtra(EXTRA_ACCOUNT, accountJid.toString());
- data.putExtra("conversation",
- request.getStringExtra("conversation"));
- data.putExtra("multiple", false);
- data.putExtra("subject", request.getStringExtra("subject"));
- setResult(RESULT_OK, data);
- finish();
+ dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
+ final Intent request = getIntent();
+ final Intent data = new Intent();
+ data.putExtra("contact", contactJid.toString());
+ data.putExtra(EXTRA_ACCOUNT, accountJid.toString());
+ data.putExtra("conversation",
+ request.getStringExtra("conversation"));
+ data.putExtra("multiple", false);
+ data.putExtra("subject", request.getStringExtra("subject"));
+ setResult(RESULT_OK, data);
+ finish();
- return true;
- }
+ return true;
});
dialog.show();
@@ -250,25 +264,4 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
}
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;
- }
}
diff --git a/src/main/res/layout/activity_choose_contact.xml b/src/main/res/layout/activity_choose_contact.xml
index c5158510b..5767def46 100644
--- a/src/main/res/layout/activity_choose_contact.xml
+++ b/src/main/res/layout/activity_choose_contact.xml
@@ -1,16 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout 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">
+<layout xmlns:android="http://schemas.android.com/apk/res/android">
- <ListView
- android:id="@+id/choose_contact_list"
+ <FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:divider="@android:color/transparent"
- android:dividerHeight="0dp"
- tools:listitem="@layout/contact" />
+ android:background="?attr/color_background_primary">
-</LinearLayout> \ No newline at end of file
+ <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> \ No newline at end of file
diff --git a/src/main/res/menu/choose_contact.xml b/src/main/res/menu/choose_contact.xml
index b0f907ffd..4602d0e53 100644
--- a/src/main/res/menu/choose_contact.xml
+++ b/src/main/res/menu/choose_contact.xml
@@ -7,19 +7,11 @@
app:actionLayout="@layout/actionview_search"
android:icon="?attr/icon_search"
app:showAsAction="collapseActionView|always"
- android:title="@string/search" />
-
- <item
- android:id="@+id/action_create_contact"
- android:icon="?attr/icon_add_person"
- app:showAsAction="always"
- android:title="@string/create_contact"
- android:visible="false" />
-
+ android:title="@string/search"/>
<item
- android:id="@+id/action_block_jid"
- android:icon="?attr/icon_add_person"
+ android:id="@+id/action_scan_qr_code"
+ android:title="@string/scan_qr_code"
+ android:icon="?attr/icon_scan_qr_code"
app:showAsAction="always"
- android:title="@string/block_jabber_id"
- android:visible="false" />
-</menu>
+ android:visible="false"/>
+</menu> \ No newline at end of file