mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Read number of chats from MrMailbox.
This commit is contained in:
@@ -149,6 +149,12 @@ JNIEXPORT jstring Java_org_telegram_messenger_MrMailbox_MrMailboxGetConfig(JNIEn
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
JNIEXPORT void Java_org_telegram_messenger_MrMailbox_MrChatlistUnref(JNIEnv *env, jclass c, jlong hChatlist)
|
||||
{
|
||||
return mrchatlist_unref((mrchatlist_t*)hChatlist);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT int Java_org_telegram_messenger_MrMailbox_MrChatlistGetCnt(JNIEnv *env, jclass c, jlong hChatlist)
|
||||
{
|
||||
return mrchatlist_get_cnt((mrchatlist_t*)hChatlist);
|
||||
@@ -166,6 +172,12 @@ JNIEXPORT jlong Java_org_telegram_messenger_MrMailbox_MrChatlistGetChat(JNIEnv *
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
JNIEXPORT void Java_org_telegram_messenger_MrMailbox_MrChatUnref(JNIEnv *env, jclass c, jlong hChat)
|
||||
{
|
||||
return mrchat_unref((mrchat_t*)hChat);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT int Java_org_telegram_messenger_MrMailbox_MrChatGetId(JNIEnv *env, jclass c, jlong hChat)
|
||||
{
|
||||
mrchat_t* ths = (mrchat_t*)hChat;
|
||||
@@ -194,6 +206,27 @@ JNIEXPORT jlong Java_org_telegram_messenger_MrMailbox_MrChatGetLastMsg(JNIEnv *e
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* MrMsglist
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
JNIEXPORT void Java_org_telegram_messenger_MrMailbox_MrMsglistUnref(JNIEnv *env, jclass c, jlong hMsglist)
|
||||
{
|
||||
return mrmsglist_unref((mrmsglist_t*)hMsglist);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* MrMsg
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
JNIEXPORT void Java_org_telegram_messenger_MrMailbox_MrMsgUnref(JNIEnv *env, jclass c, jlong hMsg)
|
||||
{
|
||||
return mrmsg_unref((mrmsg_t*)hMsg);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
* Tools
|
||||
******************************************************************************/
|
||||
|
||||
@@ -53,8 +53,6 @@ public class ApplicationLoader extends Application {
|
||||
public static volatile boolean isScreenOn = false;
|
||||
public static volatile boolean mainInterfacePaused = true;
|
||||
|
||||
public static long hMailbox = 0; // EDIT BY MR
|
||||
|
||||
public static boolean isCustomTheme() {
|
||||
return isCustomTheme;
|
||||
}
|
||||
@@ -283,7 +281,7 @@ public class ApplicationLoader extends Application {
|
||||
|
||||
// EDIT BY MR - open my sqlite file (you can inspect the file eg. with "Tools / Android Device Monitor / File Explorer")
|
||||
File dbfile = new File(getFilesDirFixed(), "mrmailbox.db");
|
||||
MrMailbox.MrMailboxOpen(ApplicationLoader.hMailbox, dbfile.getAbsolutePath());
|
||||
MrMailbox.MrMailboxOpen(MrMailbox.hMailbox, dbfile.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -297,7 +295,7 @@ public class ApplicationLoader extends Application {
|
||||
|
||||
// EDIT BY MR - create a MrMailbox object; as android stops the App by just killing it, we do never call MrMailboxUnref()
|
||||
// however, we may want to to have a look at onPause() eg. of activities (eg. for flushing data, if needed)
|
||||
hMailbox = MrMailbox.MrMailboxNew();
|
||||
MrMailbox.hMailbox = MrMailbox.MrMailboxNew();
|
||||
|
||||
applicationHandler = new Handler(applicationContext.getMainLooper());
|
||||
|
||||
|
||||
@@ -26,12 +26,13 @@
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
// EDIT BY MR
|
||||
package org.telegram.messenger;
|
||||
|
||||
|
||||
public class MrMailbox {
|
||||
|
||||
int dummy = 4; // just a counter that can be increased to force recompiling
|
||||
public static long hMailbox = 0;
|
||||
|
||||
// MrMailbox objects
|
||||
public native static long MrMailboxNew (); // returns hMailbox which must be unref'd after usage (Names as mrmailbox_new don't work due to the additional underscore)
|
||||
@@ -49,14 +50,23 @@ public class MrMailbox {
|
||||
public native static long MrMailboxGetChats (long hMailbox); // returns hChatlist which must be unref'd after usage
|
||||
|
||||
// MrChatlist objects
|
||||
public native static void MrChatlistUnref (long hChatlist);
|
||||
public native static int MrChatlistGetCnt (long hChatlist);
|
||||
public native static int MrChatlistGetChat (long hChatlist, int index); // returns hChat which must be unref'd after usage
|
||||
|
||||
// MrChat objects
|
||||
public native static void MrChatUnref (long hChat);
|
||||
public native static int MrChatGetId (long hChat);
|
||||
public native static int MrChatGetType (long hChat);
|
||||
public native static String MrChatGetName (long hChat);
|
||||
|
||||
// MrMsglist objects
|
||||
public native static void MrMsglistUnref (long hMsglist);
|
||||
|
||||
// MrMsg objects
|
||||
public native static void MrMsgUnref (long hMsg);
|
||||
|
||||
// Tools
|
||||
public native static String MrGetVersionStr ();
|
||||
}
|
||||
// /EDIT BY MR
|
||||
@@ -15,6 +15,7 @@ import android.view.ViewGroup;
|
||||
import org.telegram.messenger.AndroidUtilities;
|
||||
import org.telegram.messenger.MessagesController;
|
||||
import org.telegram.messenger.support.widget.RecyclerView;
|
||||
import org.telegram.messenger.MrMailbox;
|
||||
import org.telegram.tgnet.TLRPC;
|
||||
import org.telegram.ui.Cells.DialogCell;
|
||||
import org.telegram.ui.Cells.LoadingCell;
|
||||
@@ -27,6 +28,7 @@ public class DialogsAdapter extends RecyclerView.Adapter {
|
||||
private int dialogsType;
|
||||
private long openedDialogId;
|
||||
private int currentCount;
|
||||
private long hChatlist = 0; // EDIT BY MR
|
||||
|
||||
private class Holder extends RecyclerView.ViewHolder {
|
||||
|
||||
@@ -38,8 +40,33 @@ public class DialogsAdapter extends RecyclerView.Adapter {
|
||||
public DialogsAdapter(Context context, int type) {
|
||||
mContext = context;
|
||||
dialogsType = type;
|
||||
|
||||
// EDIT BY MR
|
||||
hChatlist = MrMailbox.MrMailboxGetChats(MrMailbox.hMailbox);
|
||||
// /EDIT BY MR
|
||||
}
|
||||
|
||||
// EDIT BY MR
|
||||
protected void finalize()
|
||||
{
|
||||
MrMailbox.MrChatlistUnref(hChatlist);
|
||||
hChatlist = 0;
|
||||
}
|
||||
|
||||
private static TLRPC.TL_dialog chat2dialog(long hChat)
|
||||
{
|
||||
return new TLRPC.TL_dialog();
|
||||
}
|
||||
|
||||
private static TLRPC.TL_dialog chatlist2dialog(long hChatlist, int index)
|
||||
{
|
||||
long hChat = MrMailbox.MrChatlistGetChat(hChatlist, index);
|
||||
TLRPC.TL_dialog dlg = chat2dialog(hChat);
|
||||
MrMailbox.MrChatUnref(hChat);
|
||||
return dlg;
|
||||
}
|
||||
// /EDIT BY MR
|
||||
|
||||
public void setOpenedDialogId(long id) {
|
||||
openedDialogId = id;
|
||||
}
|
||||
@@ -49,6 +76,7 @@ public class DialogsAdapter extends RecyclerView.Adapter {
|
||||
return current != getItemCount() || current == 1;
|
||||
}
|
||||
|
||||
/* EDIT BY MR
|
||||
private ArrayList<TLRPC.TL_dialog> getDialogsArray() {
|
||||
if (dialogsType == 0) {
|
||||
return MessagesController.getInstance().dialogs;
|
||||
@@ -59,9 +87,13 @@ public class DialogsAdapter extends RecyclerView.Adapter {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/EDIT BY MR */
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
// EDIT BY MR
|
||||
int count = MrMailbox.MrMailboxGetChatCnt(MrMailbox.hMailbox);
|
||||
/*
|
||||
int count = getDialogsArray().size();
|
||||
if (count == 0 && MessagesController.getInstance().loadingDialogs) {
|
||||
return 0;
|
||||
@@ -69,16 +101,24 @@ public class DialogsAdapter extends RecyclerView.Adapter {
|
||||
if (!MessagesController.getInstance().dialogsEndReached) {
|
||||
count++;
|
||||
}
|
||||
*/
|
||||
// /EDIT BY MR
|
||||
currentCount = count;
|
||||
return count;
|
||||
|
||||
}
|
||||
|
||||
public TLRPC.TL_dialog getItem(int i) {
|
||||
// EDIT BY MR
|
||||
return chatlist2dialog(hChatlist, i);
|
||||
/*
|
||||
ArrayList<TLRPC.TL_dialog> arrayList = getDialogsArray();
|
||||
if (i < 0 || i >= arrayList.size()) {
|
||||
return null;
|
||||
}
|
||||
return arrayList.get(i);
|
||||
*/
|
||||
// /EDIT BY MR
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,9 +162,11 @@ public class DialogsAdapter extends RecyclerView.Adapter {
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int i) {
|
||||
/* EDIT BY MR -- 1 would be the "loading cell" that is not needed by us
|
||||
if (i == getDialogsArray().size()) {
|
||||
return 1;
|
||||
}
|
||||
/EDIT BY MR */
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user