mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Recreate the chatlist on updates.
This commit is contained in:
@@ -59,7 +59,7 @@ static void s_log_callback_(int type, const char* msg)
|
||||
|
||||
/* globl stuff */
|
||||
|
||||
static JNIEnv* s_env = NULL;
|
||||
static JavaVM* s_jvm = NULL;
|
||||
static jclass s_MrMailbox_class = NULL;
|
||||
static jmethodID s_MrCallback_methodID = NULL;
|
||||
|
||||
@@ -73,11 +73,11 @@ static void s_init_globals(JNIEnv *env, jclass MrMailbox_class)
|
||||
/* init global callback */
|
||||
mrlog_set_handler(s_log_callback_);
|
||||
|
||||
/* get a global pointer to the MrMailbox class and to the MrCallback method; note that this may _not_ work from other-than-java-main threads */
|
||||
s_env = env;
|
||||
/* prepare calling back a Java function */
|
||||
(*env)->GetJavaVM(env, &s_jvm); /* JNIEnv cannot be shared between threads, so we share the JavaVM object */
|
||||
s_MrMailbox_class = (*env)->NewGlobalRef(env, MrMailbox_class);
|
||||
s_MrCallback_methodID = (*env)->GetStaticMethodID(env, MrMailbox_class, "MrCallback","(IJJ)J" /*signature as "(param)ret" with I=int, J=long*/ );
|
||||
|
||||
|
||||
/* system-specific backend initialisations */
|
||||
mrosnative_init_android(env); /*this should be called before any other "important" routine is called*/
|
||||
}
|
||||
@@ -92,14 +92,21 @@ static void s_init_globals(JNIEnv *env, jclass MrMailbox_class)
|
||||
|
||||
static uintptr_t s_mailbox_callback_(mrmailbox_t* mailbox, int event, uintptr_t data1, uintptr_t data2)
|
||||
{
|
||||
jlong l;
|
||||
jlong l;
|
||||
JNIEnv* env;
|
||||
|
||||
if( s_env==NULL || s_MrMailbox_class==NULL || s_MrCallback_methodID==NULL ) {
|
||||
s_log_callback_('e', "Callback called but JNI not ready.");
|
||||
if( s_jvm==NULL || s_MrMailbox_class==NULL || s_MrCallback_methodID==NULL ) {
|
||||
s_log_callback_('e', "Callback called but JavaVM not ready.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
l = (*s_env)->CallStaticLongMethod(s_env, s_MrMailbox_class, s_MrCallback_methodID, (jint)event, (jlong)data1, (jlong)data2);
|
||||
(*s_jvm)->GetEnv(s_jvm, &env, JNI_VERSION_1_6); /* as this function may be called from _any_ thread, we cannot use a static pointer to JNIEnv */
|
||||
if( env==NULL ) {
|
||||
s_log_callback_('e', "Callback called but cannot get JNIEnv.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
l = (*env)->CallStaticLongMethod(env, s_MrMailbox_class, s_MrCallback_methodID, (jint)event, (jlong)data1, (jlong)data2);
|
||||
return (uintptr_t)l;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,12 +30,15 @@
|
||||
package org.telegram.messenger;
|
||||
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.telegram.tgnet.TLRPC;
|
||||
|
||||
public class MrMailbox {
|
||||
|
||||
public static long hMailbox = 0;
|
||||
public static long hCurrChatlist = 0;
|
||||
private static final String TAG = "LibreChat";
|
||||
|
||||
|
||||
// tools
|
||||
@@ -83,8 +86,22 @@ public class MrMailbox {
|
||||
}
|
||||
|
||||
// this function is called from within the C-wrapper
|
||||
public final static int MR_EVENT_MSGS_UPDATED = 2000;
|
||||
public static long MrCallback(int event, long data1, long data2)
|
||||
{
|
||||
switch(event) {
|
||||
case MR_EVENT_MSGS_UPDATED:
|
||||
Log.i(TAG, "Received MR_EVENT_MSGS_UPDATED!");
|
||||
AndroidUtilities.runOnUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MrChatlistUnref(hCurrChatlist); // it's not optimal running this on the UI thread, maybe we should lock it and run it in a separate thread
|
||||
hCurrChatlist = MrMailboxGetChatlist(hMailbox);
|
||||
NotificationCenter.getInstance().postNotificationName(NotificationCenter.dialogsNeedReload);
|
||||
}
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
private DialogsAdapter dialogsAdapter;
|
||||
private DialogsSearchAdapter dialogsSearchAdapter;
|
||||
private EmptyTextProgressView searchEmptyView;
|
||||
//private ProgressBar progressView;
|
||||
//private ProgressBar progressView; // EDIT BY MR
|
||||
private LinearLayout emptyView;
|
||||
private ActionBarMenuItem passcodeItem;
|
||||
private ImageView floatingButton;
|
||||
@@ -208,7 +208,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
if (listView != null) {
|
||||
if (searchString != null) {
|
||||
listView.setEmptyView(searchEmptyView);
|
||||
//progressView.setVisibility(View.GONE);
|
||||
//progressView.setVisibility(View.GONE); // EDIT BY MR
|
||||
emptyView.setVisibility(View.GONE);
|
||||
}
|
||||
if (!onlySelect) {
|
||||
@@ -233,14 +233,14 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
searchWas = false;
|
||||
if (listView != null) {
|
||||
searchEmptyView.setVisibility(View.GONE);
|
||||
/*)
|
||||
/* EDIT BY MR
|
||||
if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
|
||||
emptyView.setVisibility(View.GONE);
|
||||
listView.setEmptyView(progressView);
|
||||
} else
|
||||
*/
|
||||
{
|
||||
//progressView.setVisibility(View.GONE);
|
||||
//progressView.setVisibility(View.GONE); // EDIT BY MR
|
||||
listView.setEmptyView(emptyView);
|
||||
}
|
||||
if (!onlySelect) {
|
||||
@@ -271,7 +271,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
}
|
||||
if (searchEmptyView != null && listView.getEmptyView() != searchEmptyView) {
|
||||
emptyView.setVisibility(View.GONE);
|
||||
//progressView.setVisibility(View.GONE);
|
||||
//progressView.setVisibility(View.GONE); // EDIT BY MR
|
||||
searchEmptyView.showTextView();
|
||||
listView.setEmptyView(searchEmptyView);
|
||||
}
|
||||
@@ -404,7 +404,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
didSelectResult(dialog_id, true, false);
|
||||
} else {
|
||||
Bundle args = new Bundle();
|
||||
/*
|
||||
/* EDIT BY MR
|
||||
int lower_part = (int) dialog_id;
|
||||
int high_id = (int) (dialog_id >> 32);
|
||||
if (lower_part != 0) {
|
||||
@@ -490,7 +490,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
}
|
||||
return false;
|
||||
}
|
||||
TLRPC.TL_dialog dialog; // TODO BY MR - handle long clicks
|
||||
TLRPC.TL_dialog dialog;
|
||||
ArrayList<TLRPC.TL_dialog> dialogs = getDialogsArray();
|
||||
if (position < 0 || position >= dialogs.size()) {
|
||||
return false;
|
||||
@@ -652,7 +652,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
textView.setLineSpacing(AndroidUtilities.dp(2), 1);
|
||||
emptyView.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
|
||||
|
||||
/*
|
||||
/* EDIT BY MR
|
||||
progressView = new ProgressBar(context);
|
||||
progressView.setVisibility(View.GONE);
|
||||
frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
|
||||
@@ -698,11 +698,11 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
||||
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
|
||||
int visibleItemCount = Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
|
||||
int totalItemCount = recyclerView.getAdapter().getItemCount(); // TODO BY MR - recyclerView.adapter muss angepasst werden? ja -> das ist DialogsAdapter.java
|
||||
int totalItemCount = recyclerView.getAdapter().getItemCount();
|
||||
|
||||
if (searching && searchWas) {
|
||||
if (visibleItemCount > 0 && layoutManager.findLastVisibleItemPosition() == totalItemCount - 1 && !dialogsSearchAdapter.isMessagesSearchEndReached()) {
|
||||
dialogsSearchAdapter.loadMoreSearchMessages(); // TODO BY MR - what about this issue?
|
||||
dialogsSearchAdapter.loadMoreSearchMessages(); // TODO BY MR - implement searching
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -828,7 +828,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
*/
|
||||
{
|
||||
searchEmptyView.setVisibility(View.GONE);
|
||||
//progressView.setVisibility(View.GONE);
|
||||
//progressView.setVisibility(View.GONE); // EDIT BY MR
|
||||
listView.setEmptyView(emptyView);
|
||||
}
|
||||
if (searchString != null) {
|
||||
@@ -952,7 +952,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
if (dialogsAdapter.isDataSetChanged()) {
|
||||
dialogsAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
updateVisibleRows(MessagesController.UPDATE_MASK_NEW_MESSAGE); // TODO BY MR?
|
||||
updateVisibleRows(MessagesController.UPDATE_MASK_NEW_MESSAGE); // TODO BY MR
|
||||
}
|
||||
}
|
||||
if (dialogsSearchAdapter != null) {
|
||||
@@ -960,7 +960,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
}
|
||||
if (listView != null) {
|
||||
try {
|
||||
/*
|
||||
/* EDIT BY MR
|
||||
if (MessagesController.getInstance().loadingDialogs && MessagesController.getInstance().dialogs.isEmpty()) {
|
||||
searchEmptyView.setVisibility(View.GONE);
|
||||
emptyView.setVisibility(View.GONE);
|
||||
@@ -968,7 +968,7 @@ public class DialogsActivity extends BaseFragment implements NotificationCenter.
|
||||
} else
|
||||
*/
|
||||
{
|
||||
//progressView.setVisibility(View.GONE);
|
||||
//progressView.setVisibility(View.GONE); -- EDIT BY MR
|
||||
if (searching && searchWas) {
|
||||
emptyView.setVisibility(View.GONE);
|
||||
listView.setEmptyView(searchEmptyView);
|
||||
|
||||
Reference in New Issue
Block a user