mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
@@ -3,6 +3,26 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
>
|
||||
|
||||
<item android:title="@string/search"
|
||||
android:id="@+id/menu_search_chat"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:showAsAction="collapseActionView|never" />
|
||||
|
||||
<item android:title="@string/back"
|
||||
android:id="@+id/menu_search_up"
|
||||
android:icon="@drawable/ic_search_up"
|
||||
android:visible="false"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
<item android:title="@string/next"
|
||||
android:id="@+id/menu_search_down"
|
||||
android:icon="@drawable/ic_search_down"
|
||||
android:visible="false"
|
||||
app:showAsAction="always"/>
|
||||
|
||||
<item android:title="@string/menu_mute"
|
||||
android:id="@+id/menu_mute_notifications"/>
|
||||
|
||||
<item android:title="@string/menu_view_profile"
|
||||
android:id="@+id/menu_profile"/>
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:title="@string/menu_unmute"
|
||||
android:id="@+id/menu_unmute_notifications" />
|
||||
</menu>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:title="@string/menu_mute"
|
||||
android:id="@+id/menu_mute_notifications" />
|
||||
|
||||
</menu>
|
||||
@@ -34,6 +34,7 @@ import android.os.Vibrator;
|
||||
import android.provider.Browser;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.core.view.WindowCompat;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
@@ -54,6 +55,7 @@ import android.view.View.OnKeyListener;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
@@ -140,6 +142,7 @@ import static org.thoughtcrime.securesms.util.RelayUtil.isSharing;
|
||||
public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
implements ConversationFragment.ConversationFragmentListener,
|
||||
AttachmentManager.AttachmentListener,
|
||||
SearchView.OnQueryTextListener,
|
||||
DcEventCenter.DcEventDelegate,
|
||||
OnKeyboardShownListener,
|
||||
AttachmentDrawerListener,
|
||||
@@ -428,15 +431,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
return true;
|
||||
}
|
||||
|
||||
if (recipient != null && Prefs.isChatMuted(this, chatId)) {
|
||||
inflater.inflate(R.menu.conversation_muted, menu);
|
||||
}
|
||||
else {
|
||||
inflater.inflate(R.menu.conversation_unmuted, menu);
|
||||
}
|
||||
|
||||
inflater.inflate(R.menu.conversation, menu);
|
||||
|
||||
if(Prefs.isChatMuted(this, chatId)) {
|
||||
menu.findItem(R.id.menu_mute_notifications).setTitle(R.string.menu_unmute);
|
||||
}
|
||||
|
||||
if (!Prefs.isLocationStreamingEnabled(this)) {
|
||||
menu.findItem(R.id.menu_show_map).setVisible(false);
|
||||
}
|
||||
@@ -456,6 +456,43 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
|
||||
inflater.inflate(R.menu.conversation_delete, menu);
|
||||
|
||||
try {
|
||||
MenuItem searchItem = menu.findItem(R.id.menu_search_chat);
|
||||
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
||||
@Override
|
||||
public boolean onMenuItemActionExpand(final MenuItem item) {
|
||||
searchExpand(menu, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemActionCollapse(final MenuItem item) {
|
||||
searchCollapse(menu, item);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
SearchView searchView = (SearchView) searchItem.getActionView();
|
||||
searchView.setOnQueryTextListener(this);
|
||||
searchView.setQueryHint(getString(R.string.search));
|
||||
searchView.setIconifiedByDefault(true);
|
||||
|
||||
// hide the [X] beside the search field - this is too much noise, search can be aborted eg. by "back"
|
||||
ImageView closeBtn = searchView.findViewById(R.id.search_close_btn);
|
||||
if (closeBtn!=null) {
|
||||
closeBtn.setEnabled(false);
|
||||
closeBtn.setImageDrawable(null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "cannot set up in-chat-search: ", e);
|
||||
}
|
||||
|
||||
if (!dcChat.canSend()) {
|
||||
MenuItem attachItem = menu.findItem(R.id.menu_add_attachment);
|
||||
if (attachItem!=null) {
|
||||
attachItem.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
return true;
|
||||
}
|
||||
@@ -469,9 +506,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
case R.id.menu_archive_chat: handleArchiveChat(); return true;
|
||||
case R.id.menu_delete_chat: handleDeleteChat(); return true;
|
||||
case R.id.menu_mute_notifications: handleMuteNotifications(); return true;
|
||||
case R.id.menu_unmute_notifications: handleUnmuteNotifications(); return true;
|
||||
case R.id.menu_profile: handleProfile(); return true;
|
||||
case R.id.menu_show_map: handleShowMap(); return true;
|
||||
case R.id.menu_search_up: handleMenuSearchNext(false); return true;
|
||||
case R.id.menu_search_down: handleMenuSearchNext(true); return true;
|
||||
case android.R.id.home: handleReturnToConversationList(); return true;
|
||||
}
|
||||
|
||||
@@ -525,10 +563,16 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private void handleMuteNotifications() {
|
||||
MuteDialog.show(this, until -> {
|
||||
Prefs.setChatMutedUntil(this, chatId, until);
|
||||
titleView.setTitle(glideRequests, dcChat); // update title-mute-icon
|
||||
});
|
||||
if(!Prefs.isChatMuted(this, chatId)) {
|
||||
MuteDialog.show(this, until -> {
|
||||
Prefs.setChatMutedUntil(this, chatId, until);
|
||||
titleView.setTitle(glideRequests, dcChat);
|
||||
});
|
||||
} else {
|
||||
// unmute
|
||||
Prefs.setChatMutedUntil(this, chatId, 0);
|
||||
titleView.setTitle(glideRequests, dcChat);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleProfile() {
|
||||
@@ -541,11 +585,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void handleUnmuteNotifications() {
|
||||
Prefs.setChatMutedUntil(this, chatId, 0);
|
||||
titleView.setTitle(glideRequests, dcChat); // update title-mute-icon
|
||||
}
|
||||
|
||||
private void handleLeaveGroup() {
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(getString(R.string.ask_leave_group))
|
||||
@@ -1499,4 +1538,82 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// in-chat search
|
||||
|
||||
private int beforeSearchComposeVisibility = View.VISIBLE;
|
||||
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) {
|
||||
beforeSearchComposeVisibility = composePanel.getVisibility();
|
||||
composePanel.setVisibility(View.GONE);
|
||||
|
||||
beforeSearchAttachVisibility = attachmentManager.getVisibility();
|
||||
attachmentManager.setVisibility(View.GONE);
|
||||
|
||||
ConversationActivity.this.makeSearchMenuVisible(menu, searchItem, false);
|
||||
}
|
||||
|
||||
private void searchCollapse(final Menu menu, final MenuItem searchItem) {
|
||||
composePanel.setVisibility(beforeSearchComposeVisibility);
|
||||
attachmentManager.setVisibility(beforeSearchAttachVisibility);
|
||||
|
||||
ConversationActivity.this.makeSearchMenuVisible(menu, searchItem, true);
|
||||
}
|
||||
|
||||
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]);
|
||||
} else {
|
||||
// no search, scroll to first/last message
|
||||
if(searchNext) {
|
||||
fragment.scrollToBottom();
|
||||
} else {
|
||||
fragment.scrollToTop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return true; // action handled by listener
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -170,6 +170,17 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||
return fromDb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position of the message with msgId in the chat list, counted from the top
|
||||
*/
|
||||
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 {
|
||||
TextView textView;
|
||||
@@ -412,4 +423,3 @@ public class ConversationAdapter <V extends View & BindableConversationItem>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -310,6 +310,16 @@ public class ConversationFragment extends Fragment
|
||||
}
|
||||
}
|
||||
|
||||
public void scrollToTop() {
|
||||
ConversationAdapter adapter = (ConversationAdapter)list.getAdapter();
|
||||
if (adapter.getItemCount()>0) {
|
||||
final int pos = adapter.getItemCount()-1;
|
||||
list.post(() -> {
|
||||
list.getLayoutManager().scrollToPosition(pos);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void scrollToBottom() {
|
||||
if (((LinearLayoutManager) list.getLayoutManager()).findFirstVisibleItemPosition() < SCROLL_ANIMATION_THRESHOLD) {
|
||||
list.smoothScrollToPosition(0);
|
||||
@@ -512,6 +522,14 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ConversationFragmentListener {
|
||||
void setChatId(int threadId);
|
||||
void handleReplyMessage(DcMsg messageRecord);
|
||||
|
||||
@@ -281,7 +281,7 @@ public class ConversationItem extends LinearLayout
|
||||
} else if (pulseHighlight) {
|
||||
setBackgroundResource(R.drawable.conversation_item_background_animated);
|
||||
setSelected(true);
|
||||
postDelayed(() -> setSelected(false), 500);
|
||||
postDelayed(() -> setSelected(false), 1500);
|
||||
} else {
|
||||
setSelected(false);
|
||||
}
|
||||
|
||||
@@ -592,4 +592,18 @@ public class AttachmentManager {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getVisibility() {
|
||||
try {
|
||||
return attachmentViewStub.get().getVisibility();
|
||||
} catch(Exception e) {
|
||||
return View.GONE;
|
||||
}
|
||||
}
|
||||
|
||||
public void setVisibility(int vis) {
|
||||
try {
|
||||
attachmentViewStub.get().setVisibility(vis);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user