move up when tapping webxdc info messages (#2194)

* add DcMsg.getParent() api

* factor out scrollSmoothToMsgId() and use that for both, quotes and webxdc-info-messages
This commit is contained in:
bjoern 2022-01-20 00:53:50 +01:00 committed by GitHub
parent 56cce4b977
commit a9a99047da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 18 deletions

View file

@ -1694,6 +1694,12 @@ JNIEXPORT jlong Java_com_b44t_messenger_DcMsg_getQuotedMsgCPtr(JNIEnv *env, jobj
}
JNIEXPORT jlong Java_com_b44t_messenger_DcMsg_getParentCPtr(JNIEnv *env, jobject obj)
{
return (jlong)dc_msg_get_parent(get_dc_msg(env, obj));
}
JNIEXPORT jstring Java_com_b44t_messenger_DcMsg_getError(JNIEnv *env, jobject obj)
{
char* temp = dc_msg_get_error(get_dc_msg(env, obj));

View file

@ -156,6 +156,11 @@ public class DcMsg {
return cPtr != 0 ? new DcMsg(cPtr) : null;
}
public DcMsg getParent() {
long cPtr = getParentCPtr();
return cPtr != 0 ? new DcMsg(cPtr) : null;
}
public File getFileAsFile() {
if(getFile()==null)
throw new AssertionError("expected a file to be present.");
@ -220,5 +225,6 @@ public class DcMsg {
private native long getSummaryCPtr (long chatCPtr);
private native void setQuoteCPtr (long quoteCPtr);
private native long getQuotedMsgCPtr ();
private native long getParentCPtr ();
private native String getWebxdcInfoJson ();
};

View file

@ -556,6 +556,27 @@ public class ConversationFragment extends MessageSelectorFragment
Log.e(TAG, "msgId {} not found for scrolling");
}
}
private void scrollMaybeSmoothToMsgId(final int msgId) {
LinearLayoutManager layout = ((LinearLayoutManager) list.getLayoutManager());
boolean smooth = false;
ConversationAdapter adapter = (ConversationAdapter) list.getAdapter();
if (adapter == null) return;
int position = adapter.msgIdToPosition(msgId);
if (layout != null) {
int distance1 = Math.abs(position - layout.findFirstVisibleItemPosition());
int distance2 = Math.abs(position - layout.findLastVisibleItemPosition());
int distance = Math.min(distance1, distance2);
smooth = distance < 15;
Log.i(TAG, "Scrolling to destMsg, smoth: " + smooth + ", distance: " + distance);
}
if (position != -1) {
scrollAndHighlight(position, smooth);
} else {
Log.e(TAG, "msgId not found for scrolling: " + msgId);
}
}
public interface ConversationFragmentListener {
void handleReplyMessage(DcMsg messageRecord);
@ -758,6 +779,9 @@ public class ConversationFragment extends MessageSelectorFragment
else if(DozeReminder.isDozeReminderMsg(getContext(), messageRecord)) {
DozeReminder.dozeReminderTapped(getContext());
}
else if(messageRecord.isInfo() && messageRecord.getParent() != null) {
scrollMaybeSmoothToMsgId(messageRecord.getParent().getId());
}
else {
String self_mail = dcContext.getConfig("configured_mail_user");
if (self_mail != null && !self_mail.isEmpty()
@ -802,24 +826,7 @@ public class ConversationFragment extends MessageSelectorFragment
Log.e(TAG, "Activity was null");
}
} else {
LinearLayoutManager layout = ((LinearLayoutManager) list.getLayoutManager());
boolean smooth = false;
ConversationAdapter adapter = (ConversationAdapter) list.getAdapter();
if (adapter == null) return;
int position = adapter.msgIdToPosition(quoted.getId());
if (layout != null) {
int distance1 = Math.abs(position - layout.findFirstVisibleItemPosition());
int distance2 = Math.abs(position - layout.findLastVisibleItemPosition());
int distance = Math.min(distance1, distance2);
smooth = distance < 15;
Log.i(TAG, "Scrolling to quote, smoth: " + smooth + ", distance: " + distance);
}
if (position != -1) {
scrollAndHighlight(position, smooth);
} else {
Log.e(TAG, "msgId not found for scrolling: " + quoted.getId());
}
scrollMaybeSmoothToMsgId(quoted.getId());
}
}