mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 17:59:39 +02:00
implement in-chat-search
This commit is contained in:
parent
2ae7e8896b
commit
0a3dee4573
3 changed files with 54 additions and 2 deletions
|
@ -1534,8 +1534,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
|
|
||||||
// in-chat search
|
// in-chat search
|
||||||
|
|
||||||
int beforeSearchComposeVisibility = View.VISIBLE;
|
private int beforeSearchComposeVisibility = View.VISIBLE;
|
||||||
int beforeSearchAttachVisibility = View.GONE;
|
private int beforeSearchAttachVisibility = View.GONE;
|
||||||
|
|
||||||
|
private int[] searchResult = {};
|
||||||
|
private int searchResultPosition = -1;
|
||||||
|
|
||||||
|
private Toast lastToast = null;
|
||||||
|
|
||||||
private void searchExpand(final Menu menu, final MenuItem searchItem) {
|
private void searchExpand(final Menu menu, final MenuItem searchItem) {
|
||||||
beforeSearchComposeVisibility = composePanel.getVisibility();
|
beforeSearchComposeVisibility = composePanel.getVisibility();
|
||||||
|
@ -1555,6 +1560,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleMenuSearchNext(boolean searchNext) {
|
private void handleMenuSearchNext(boolean searchNext) {
|
||||||
|
if(searchResult.length>0) {
|
||||||
|
searchResultPosition += searchNext? 1 : -1;
|
||||||
|
if(searchResultPosition<0) searchResultPosition = searchResult.length-1;
|
||||||
|
if(searchResultPosition>=searchResult.length) searchResultPosition = 0;
|
||||||
|
fragment.scrollToMsgId(searchResult[searchResultPosition]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1564,6 +1575,30 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onQueryTextChange(String query) {
|
public boolean onQueryTextChange(String query) {
|
||||||
|
if (lastToast!=null) {
|
||||||
|
lastToast.cancel();
|
||||||
|
lastToast = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String normQuery = query.trim();
|
||||||
|
searchResult = dcContext.searchMsgs(chatId, normQuery);
|
||||||
|
|
||||||
|
if(searchResult.length>0) {
|
||||||
|
searchResultPosition = 0;
|
||||||
|
fragment.scrollToMsgId(searchResult[searchResultPosition]);
|
||||||
|
} else {
|
||||||
|
searchResultPosition = -1;
|
||||||
|
if (!normQuery.isEmpty()) {
|
||||||
|
String msg = getString(R.string.search_no_result_for_x, normQuery);
|
||||||
|
if (lastToast != null) {
|
||||||
|
lastToast.cancel();
|
||||||
|
}
|
||||||
|
lastToast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
|
||||||
|
lastToast.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
return true; // action handled by listener
|
return true; // action handled by listener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,6 +170,14 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||||
return fromDb;
|
return fromDb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int msgIdToPosition(int msgId) {
|
||||||
|
for(int i=0; i<dcMsgList.length; i++ ) {
|
||||||
|
if(dcMsgList[i]==msgId) {
|
||||||
|
return dcMsgList.length - 1 - i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static class HeaderViewHolder extends RecyclerView.ViewHolder {
|
static class HeaderViewHolder extends RecyclerView.ViewHolder {
|
||||||
TextView textView;
|
TextView textView;
|
||||||
|
|
|
@ -512,6 +512,15 @@ public class ConversationFragment extends Fragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void scrollToMsgId(final int msgId) {
|
||||||
|
ConversationAdapter adapter = (ConversationAdapter)list.getAdapter();
|
||||||
|
int position = adapter.msgIdToPosition(msgId);
|
||||||
|
if (position!=-1) {
|
||||||
|
scrollToStartingPosition(position);
|
||||||
|
Log.i("Delta Chat", String.format(">>>>>>>>>>>>>>>>>>> %d", position));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public interface ConversationFragmentListener {
|
public interface ConversationFragmentListener {
|
||||||
void setChatId(int threadId);
|
void setChatId(int threadId);
|
||||||
void handleReplyMessage(DcMsg messageRecord);
|
void handleReplyMessage(DcMsg messageRecord);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue