SearchActivity.java

  1/*
  2 * Copyright (c) 2018, Daniel Gultsch All rights reserved.
  3 *
  4 * Redistribution and use in source and binary forms, with or without modification,
  5 * are permitted provided that the following conditions are met:
  6 *
  7 * 1. Redistributions of source code must retain the above copyright notice, this
  8 * list of conditions and the following disclaimer.
  9 *
 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
 11 * this list of conditions and the following disclaimer in the documentation and/or
 12 * other materials provided with the distribution.
 13 *
 14 * 3. Neither the name of the copyright holder nor the names of its contributors
 15 * may be used to endorse or promote products derived from this software without
 16 * specific prior written permission.
 17 *
 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 25 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28 */
 29
 30package eu.siacs.conversations.ui;
 31
 32import android.databinding.DataBindingUtil;
 33import android.os.Bundle;
 34import android.support.v7.widget.Toolbar;
 35import android.text.Editable;
 36import android.text.TextWatcher;
 37import android.util.Log;
 38import android.view.Menu;
 39import android.view.MenuItem;
 40import android.widget.EditText;
 41
 42import java.util.ArrayList;
 43import java.util.List;
 44
 45import eu.siacs.conversations.Config;
 46import eu.siacs.conversations.R;
 47import eu.siacs.conversations.databinding.ActivitySearchBinding;
 48import eu.siacs.conversations.entities.Message;
 49import eu.siacs.conversations.ui.adapter.MessageAdapter;
 50
 51import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.hideSoftKeyboard;
 52import static eu.siacs.conversations.ui.util.SoftKeyboardUtils.showKeyboard;
 53
 54public class SearchActivity extends XmppActivity implements TextWatcher {
 55
 56	private ActivitySearchBinding binding;
 57	private MessageAdapter messageListAdapter;
 58	private final List<Message> messages = new ArrayList<>();
 59
 60	@Override
 61	public void onCreate(final Bundle savedInstanceState) {
 62		super.onCreate(savedInstanceState);
 63		this.binding = DataBindingUtil.setContentView(this, R.layout.activity_search);
 64		setSupportActionBar((Toolbar) this.binding.toolbar);
 65		configureActionBar(getSupportActionBar());
 66		this.messageListAdapter = new MessageAdapter(this, this.messages);
 67		this.binding.searchResults.setAdapter(messageListAdapter);
 68	}
 69
 70	@Override
 71	public boolean onCreateOptionsMenu(final Menu menu) {
 72		getMenuInflater().inflate(R.menu.activity_search, menu);
 73		MenuItem searchActionMenuItem = menu.findItem(R.id.action_search);
 74		EditText searchField = searchActionMenuItem.getActionView().findViewById(R.id.search_field);
 75		searchField.addTextChangedListener(this);
 76		searchField.setHint(R.string.search_messages);
 77		showKeyboard(searchField);
 78		return super.onCreateOptionsMenu(menu);
 79	}
 80
 81	@Override
 82	public boolean onOptionsItemSelected(MenuItem item) {
 83		if (item.getItemId() == android.R.id.home) {
 84			hideSoftKeyboard(this);
 85		}
 86		return super.onOptionsItemSelected(item);
 87	}
 88
 89	@Override
 90	protected void refreshUiReal() {
 91
 92	}
 93
 94	@Override
 95	void onBackendConnected() {
 96
 97	}
 98
 99	@Override
100	public void beforeTextChanged(CharSequence s, int start, int count, int after) {
101
102	}
103
104	@Override
105	public void onTextChanged(CharSequence s, int start, int before, int count) {
106
107	}
108
109	@Override
110	public void afterTextChanged(Editable s) {
111		Log.d(Config.LOGTAG,"searching for "+s);
112	}
113
114}