aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/ui/SearchActivity.java42
-rw-r--r--src/main/java/de/pixart/messenger/ui/util/ChangeWatcher.java3
-rw-r--r--src/main/java/de/pixart/messenger/utils/FtsUtils.java11
3 files changed, 51 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/SearchActivity.java b/src/main/java/de/pixart/messenger/ui/SearchActivity.java
index 7ce4ddc98..f7e9ccd68 100644
--- a/src/main/java/de/pixart/messenger/ui/SearchActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/SearchActivity.java
@@ -60,6 +60,7 @@ import de.pixart.messenger.ui.util.Color;
import de.pixart.messenger.ui.util.DateSeparator;
import de.pixart.messenger.ui.util.Drawable;
import de.pixart.messenger.ui.util.ListViewUtils;
+import de.pixart.messenger.ui.util.PendingItem;
import de.pixart.messenger.ui.util.ShareUtil;
import de.pixart.messenger.utils.FtsUtils;
import de.pixart.messenger.utils.MessageUtils;
@@ -69,15 +70,22 @@ import static de.pixart.messenger.ui.util.SoftKeyboardUtils.showKeyboard;
public class SearchActivity extends XmppActivity implements TextWatcher, OnSearchResultsAvailable, MessageAdapter.OnContactPictureClicked {
+ private static final String EXTRA_SEARCH_TERM = "search-term";
private ActivitySearchBinding binding;
private MessageAdapter messageListAdapter;
private final List<Message> messages = new ArrayList<>();
private WeakReference<Message> selectedMessageReference = new WeakReference<>(null);
private final ChangeWatcher<List<String>> currentSearch = new ChangeWatcher<>();
+ private final PendingItem<String> pendingSearchTerm = new PendingItem<>();
+ private final PendingItem<List<String>> pendingSearch = new PendingItem<>();
@Override
- public void onCreate(final Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ public void onCreate(final Bundle bundle) {
+ final String searchTerm = bundle == null ? null : bundle.getString(EXTRA_SEARCH_TERM);
+ if (searchTerm != null) {
+ pendingSearchTerm.push(searchTerm);
+ }
+ super.onCreate(bundle);
this.binding = DataBindingUtil.setContentView(this, R.layout.activity_search);
setSupportActionBar((Toolbar) this.binding.toolbar);
configureActionBar(getSupportActionBar());
@@ -90,8 +98,20 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc
@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);
+ final MenuItem searchActionMenuItem = menu.findItem(R.id.action_search);
+ final EditText searchField = searchActionMenuItem.getActionView().findViewById(R.id.search_field);
+ final String term = pendingSearchTerm.pop();
+ if (term != null) {
+ searchField.append(term);
+ List<String> searchTerm = FtsUtils.parse(term);
+ if (xmppConnectionService != null) {
+ if (currentSearch.watch(searchTerm)) {
+ xmppConnectionService.search(searchTerm, this);
+ }
+ } else {
+ pendingSearch.push(searchTerm);
+ }
+ }
searchField.addTextChangedListener(this);
searchField.setHint(R.string.search_messages);
searchField.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
@@ -150,6 +170,15 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc
return super.onContextItemSelected(item);
}
+ @Override
+ public void onSaveInstanceState(Bundle bundle) {
+ List<String> term = currentSearch.get();
+ if (term != null && term.size() > 0) {
+ bundle.putString(EXTRA_SEARCH_TERM, FtsUtils.toUserEnteredString(term));
+ }
+ super.onSaveInstanceState(bundle);
+ }
+
private void quote(Message message) {
switchToConversationAndQuote(wrap(message.getConversation()), MessageUtils.prepareQuote(message));
}
@@ -173,7 +202,10 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc
@Override
void onBackendConnected() {
-
+ final List<String> searchTerm = pendingSearch.pop();
+ if (searchTerm != null && currentSearch.watch(searchTerm)) {
+ xmppConnectionService.search(searchTerm, this);
+ }
}
private void changeBackground(boolean hasSearch, boolean hasResults) {
diff --git a/src/main/java/de/pixart/messenger/ui/util/ChangeWatcher.java b/src/main/java/de/pixart/messenger/ui/util/ChangeWatcher.java
index c21c2fbb7..5277a42bf 100644
--- a/src/main/java/de/pixart/messenger/ui/util/ChangeWatcher.java
+++ b/src/main/java/de/pixart/messenger/ui/util/ChangeWatcher.java
@@ -44,4 +44,7 @@ public class ChangeWatcher<T> {
}
}
+ public T get() {
+ return object;
+ }
} \ No newline at end of file
diff --git a/src/main/java/de/pixart/messenger/utils/FtsUtils.java b/src/main/java/de/pixart/messenger/utils/FtsUtils.java
index ee4f10da5..3a00ac7fd 100644
--- a/src/main/java/de/pixart/messenger/utils/FtsUtils.java
+++ b/src/main/java/de/pixart/messenger/utils/FtsUtils.java
@@ -107,4 +107,15 @@ public class FtsUtils {
return input.substring(begin, end + 1);
}
}
+
+ public static String toUserEnteredString(List<String> term) {
+ final StringBuilder builder = new StringBuilder();
+ for (String part : term) {
+ if (builder.length() != 0) {
+ builder.append(' ');
+ }
+ builder.append(part);
+ }
+ return builder.toString();
+ }
} \ No newline at end of file