aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-29 23:54:21 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-29 23:54:21 +0200
commitc49894c6667f1853337a3a5fc95ad84047c694c4 (patch)
tree90912935a26d2e4b353335cb200f9189035c0d4d /src/main/java
parentca556ec916c2bb034d0edc8f1a02ffc0b10c3457 (diff)
mock (non functional) search activity
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java9
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java31
-rw-r--r--src/main/java/de/pixart/messenger/ui/EditAccountActivity.java3
-rw-r--r--src/main/java/de/pixart/messenger/ui/SearchActivity.java114
-rw-r--r--src/main/java/de/pixart/messenger/ui/StartConversationActivity.java7
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java11
-rw-r--r--src/main/java/de/pixart/messenger/ui/util/SoftKeyboardUtils.java58
7 files changed, 209 insertions, 24 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index def3c00f6..371bdb5e5 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -118,6 +118,7 @@ import rocks.xmpp.addr.Jid;
import static de.pixart.messenger.ui.XmppActivity.EXTRA_ACCOUNT;
import static de.pixart.messenger.ui.XmppActivity.REQUEST_INVITE_TO_CONVERSATION;
+import static de.pixart.messenger.ui.util.SoftKeyboardUtils.hideSoftKeyboard;
import static de.pixart.messenger.xmpp.Patches.ENCRYPTION_EXCEPTIONS;
public class ConversationFragment extends XmppFragment implements EditMessage.KeyboardListener {
@@ -612,14 +613,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
return null;
}
- private static void hideSoftKeyboard(final Activity activity) {
- InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
- View view = activity.getCurrentFocus();
- if (view != null && imm != null) {
- imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
- }
- }
-
private static boolean scrolledToBottom(AbsListView listView) {
final int count = listView.getCount();
if (count == 0) {
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java
index 6c478e92f..63dc9b699 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationsOverviewFragment.java
@@ -31,11 +31,15 @@ package de.pixart.messenger.ui;
import android.app.Activity;
import android.app.Fragment;
+import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
@@ -51,6 +55,7 @@ import de.pixart.messenger.ui.interfaces.OnConversationSelected;
import de.pixart.messenger.ui.util.PendingActionHelper;
import de.pixart.messenger.ui.util.PendingItem;
import de.pixart.messenger.ui.util.ScrollState;
+import de.pixart.messenger.utils.MenuDoubleTabUtil;
public class ConversationsOverviewFragment extends XmppFragment {
@@ -127,11 +132,15 @@ public class ConversationsOverviewFragment extends XmppFragment {
}
@Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setHasOptionsMenu(true);
+ }
+
+ @Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- Log.d(Config.LOGTAG, "onCreateView");
this.binding = DataBindingUtil.inflate(inflater, R.layout.fragment_conversations_overview, container, false);
this.binding.fab.setOnClickListener((view) -> StartConversationActivity.launch(getActivity()));
-
this.conversationsAdapter = new ConversationAdapter(this.activity, this.conversations);
this.conversationsAdapter.setConversationClickListener((view, conversation) -> {
if (activity instanceof OnConversationSelected) {
@@ -147,6 +156,11 @@ public class ConversationsOverviewFragment extends XmppFragment {
}
@Override
+ public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
+ menuInflater.inflate(R.menu.fragment_conversations_overview, menu);
+ }
+
+ @Override
public void onBackendConnected() {
refresh();
}
@@ -190,6 +204,19 @@ public class ConversationsOverviewFragment extends XmppFragment {
}
@Override
+ public boolean onOptionsItemSelected(final MenuItem item) {
+ if (MenuDoubleTabUtil.shouldIgnoreTap()) {
+ return false;
+ }
+ switch (item.getItemId()) {
+ case R.id.action_search:
+ startActivity(new Intent(getActivity(), SearchActivity.class));
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
void refresh() {
if (this.binding == null || this.activity == null) {
Log.d(Config.LOGTAG, "ConversationsOverviewFragment.refresh() skipped updated because view binding or activity was null");
diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
index 7aa352342..407a967a7 100644
--- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
@@ -64,6 +64,7 @@ import de.pixart.messenger.services.XmppConnectionService.OnCaptchaRequested;
import de.pixart.messenger.ui.adapter.KnownHostsAdapter;
import de.pixart.messenger.ui.adapter.PresenceTemplateAdapter;
import de.pixart.messenger.ui.util.PendingItem;
+import de.pixart.messenger.ui.util.SoftKeyboardUtils;
import de.pixart.messenger.utils.CryptoHelper;
import de.pixart.messenger.utils.MenuDoubleTabUtil;
import de.pixart.messenger.utils.UIHelper;
@@ -401,7 +402,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
protected void finishInitialSetup(final Avatar avatar) {
runOnUiThread(() -> {
- hideKeyboard();
+ SoftKeyboardUtils.hideSoftKeyboard(EditAccountActivity.this);
final Intent intent;
final XmppConnection connection = mAccount.getXmppConnection();
final boolean wasFirstAccount = xmppConnectionService != null && xmppConnectionService.getAccounts().size() == 1;
diff --git a/src/main/java/de/pixart/messenger/ui/SearchActivity.java b/src/main/java/de/pixart/messenger/ui/SearchActivity.java
new file mode 100644
index 000000000..152544c7e
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/ui/SearchActivity.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2018, Daniel Gultsch All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package de.pixart.messenger.ui;
+
+import android.databinding.DataBindingUtil;
+import android.os.Bundle;
+import android.support.v7.widget.Toolbar;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.widget.EditText;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import de.pixart.messenger.Config;
+import de.pixart.messenger.R;
+import de.pixart.messenger.databinding.ActivitySearchBinding;
+import de.pixart.messenger.entities.Message;
+import de.pixart.messenger.ui.adapter.MessageAdapter;
+
+import static de.pixart.messenger.ui.util.SoftKeyboardUtils.hideSoftKeyboard;
+import static de.pixart.messenger.ui.util.SoftKeyboardUtils.showKeyboard;
+
+public class SearchActivity extends XmppActivity implements TextWatcher {
+
+ private final List<Message> messages = new ArrayList<>();
+ private ActivitySearchBinding binding;
+ private MessageAdapter messageListAdapter;
+
+ @Override
+ public void onCreate(final Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ this.binding = DataBindingUtil.setContentView(this, R.layout.activity_search);
+ setSupportActionBar((Toolbar) this.binding.toolbar);
+ configureActionBar(getSupportActionBar());
+ this.messageListAdapter = new MessageAdapter(this, this.messages);
+ this.binding.searchResults.setAdapter(messageListAdapter);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(final Menu menu) {
+ getMenuInflater().inflate(R.menu.activity_search, menu);
+ MenuItem searchActionMenuItem = menu.findItem(R.id.action_search);
+ EditText searchField = searchActionMenuItem.getActionView().findViewById(R.id.search_field);
+ searchField.addTextChangedListener(this);
+ searchField.setHint(R.string.search_messages);
+ showKeyboard(searchField);
+ return super.onCreateOptionsMenu(menu);
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ hideSoftKeyboard(this);
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ protected void refreshUiReal() {
+
+ }
+
+ @Override
+ void onBackendConnected() {
+
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ Log.d(Config.LOGTAG, "searching for " + s);
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
index 70995e8d2..8f153be6f 100644
--- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
@@ -71,6 +71,7 @@ import de.pixart.messenger.services.XmppConnectionService.OnRosterUpdate;
import de.pixart.messenger.ui.adapter.ListItemAdapter;
import de.pixart.messenger.ui.interfaces.OnBackendConnected;
import de.pixart.messenger.ui.util.PendingItem;
+import de.pixart.messenger.ui.util.SoftKeyboardUtils;
import de.pixart.messenger.utils.MenuDoubleTabUtil;
import de.pixart.messenger.utils.XmppUri;
import de.pixart.messenger.xmpp.OnUpdateBlocklist;
@@ -118,7 +119,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
- hideKeyboard();
+ SoftKeyboardUtils.hideSoftKeyboard(StartConversationActivity.this);
mSearchEditText.setText("");
filter(null);
return true;
@@ -188,7 +189,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
return true;
}
}
- hideKeyboard();
+ SoftKeyboardUtils.hideSoftKeyboard(StartConversationActivity.this);
mListPagerAdapter.requestFocus(pos);
return true;
}
@@ -345,6 +346,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
protected void openConversationForContact(Contact contact) {
Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false, true);
+ SoftKeyboardUtils.hideSoftKeyboard(this);
switchToConversation(conversation);
}
@@ -386,6 +388,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
bookmark.setAutojoin(true);
xmppConnectionService.pushBookmarks(bookmark.getAccount());
}
+ SoftKeyboardUtils.hideSoftKeyboard(this);
switchToConversation(conversation);
}
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index 0b425c0d8..991111634 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -45,7 +45,6 @@ import android.util.Pair;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
@@ -266,16 +265,6 @@ public abstract class XmppActivity extends ActionBarActivity {
}
}
- protected void hideKeyboard() {
- final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
-
- View focus = getCurrentFocus();
-
- if (focus != null && inputManager != null) {
- inputManager.hideSoftInputFromWindow(focus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
- }
- }
-
public boolean hasPgp() {
return xmppConnectionService.getPgpEngine() != null;
}
diff --git a/src/main/java/de/pixart/messenger/ui/util/SoftKeyboardUtils.java b/src/main/java/de/pixart/messenger/ui/util/SoftKeyboardUtils.java
new file mode 100644
index 000000000..b92a020b0
--- /dev/null
+++ b/src/main/java/de/pixart/messenger/ui/util/SoftKeyboardUtils.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2018, Daniel Gultsch All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation and/or
+ * other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its contributors
+ * may be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package de.pixart.messenger.ui.util;
+
+import android.app.Activity;
+import android.content.Context;
+import android.view.View;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+
+public class SoftKeyboardUtils {
+
+ public static void hideSoftKeyboard(final Activity activity) {
+ InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (imm == null) {
+ return;
+ }
+ View view = activity.getCurrentFocus();
+ if (view == null) {
+ view = new View(activity);
+ }
+ imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
+ }
+
+ public static void showKeyboard(EditText editText) {
+ editText.requestFocus();
+ InputMethodManager inputMethodManager = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+ if (inputMethodManager != null) {
+ inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
+ }
+ }
+} \ No newline at end of file