mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Add MrChatlist class.
This commit is contained in:
@@ -376,24 +376,30 @@ JNIEXPORT jint Java_com_b44t_messenger_MrMailbox_MrMailboxAddAddressBook(JNIEnv
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
JNIEXPORT void Java_com_b44t_messenger_MrMailbox_MrChatlistUnref(JNIEnv *env, jclass c, jlong hChatlist)
|
||||
JNIEXPORT void Java_com_b44t_messenger_MrChatlist_MrChatlistUnref(JNIEnv *env, jclass c, jlong hChatlist)
|
||||
{
|
||||
mrchatlist_unref((mrchatlist_t*)hChatlist);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint Java_com_b44t_messenger_MrMailbox_MrChatlistGetCnt(JNIEnv *env, jclass c, jlong hChatlist)
|
||||
JNIEXPORT jint Java_com_b44t_messenger_MrChatlist_MrChatlistGetCnt(JNIEnv *env, jclass c, jlong hChatlist)
|
||||
{
|
||||
return mrchatlist_get_cnt((mrchatlist_t*)hChatlist);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jlong Java_com_b44t_messenger_MrMailbox_MrChatlistGetChatByIndex(JNIEnv *env, jclass c, jlong hChatlist, jint index)
|
||||
JNIEXPORT jlong Java_com_b44t_messenger_MrChatlist_MrChatlistGetChatByIndex(JNIEnv *env, jclass c, jlong hChatlist, jint index)
|
||||
{
|
||||
return (jlong)mrchatlist_get_chat_by_index((mrchatlist_t*)hChatlist, index);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jlong Java_com_b44t_messenger_MrChatlist_MrChatlistGetSummaryByIndex(JNIEnv *env, jclass c, jlong hChatlist, jint index, jlong hChat)
|
||||
{
|
||||
return (jlong)mrchatlist_get_summary_by_index((mrchatlist_t*)hChatlist, index, (mrchat_t*)hChat);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* MrChat
|
||||
******************************************************************************/
|
||||
@@ -471,12 +477,6 @@ JNIEXPORT jint Java_com_b44t_messenger_MrChat_MrChatGetUnseenCount(JNIEnv *env,
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jlong Java_com_b44t_messenger_MrChat_MrChatGetSummary(JNIEnv *env, jclass c, jlong hChat)
|
||||
{
|
||||
return (jlong)mrchat_get_summary((mrchat_t*)hChat);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint Java_com_b44t_messenger_MrChat_MrChatSetDraft(JNIEnv *env, jclass c, jlong hChat, jstring draft /* NULL=delete */, jint replyToMsgId)
|
||||
{
|
||||
CHAR_REF(draft);
|
||||
|
||||
@@ -82,10 +82,6 @@ public class MrChat {
|
||||
return MrChatGetTotalMsgCount(m_hChat);
|
||||
}
|
||||
|
||||
public MrPoortext getSummary() {
|
||||
return new MrPoortext(MrChatGetSummary(m_hChat));
|
||||
}
|
||||
|
||||
public int sendText(String text) {
|
||||
return MrChatSendText(m_hChat, text);
|
||||
}
|
||||
@@ -123,4 +119,8 @@ public class MrChat {
|
||||
ret.id = mrChat.getId();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public long GetCPtr() {
|
||||
return m_hChat;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
* Messenger Android Frontend
|
||||
* Copyright (C) 2016 Björn Petersen Software Design and Development
|
||||
* Contact: r10s@b44t.com, http://b44t.com
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later
|
||||
* version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see http://www.gnu.org/licenses/ .
|
||||
*
|
||||
*******************************************************************************
|
||||
*
|
||||
* File: MrChatlist.java
|
||||
* Authors: Björn Petersen
|
||||
* Purpose: Wrap around mrchatlist_t
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
package com.b44t.messenger;
|
||||
|
||||
|
||||
public class MrChatlist {
|
||||
public MrChatlist(long hChatlist) {
|
||||
m_hChatlist = hChatlist;
|
||||
}
|
||||
|
||||
@Override protected void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
MrChatlistUnref(m_hChatlist);
|
||||
}
|
||||
|
||||
public int getCnt() {
|
||||
return MrChatlistGetCnt(m_hChatlist);
|
||||
}
|
||||
|
||||
public MrChat getChatByIndex(int index) {
|
||||
return new MrChat(MrChatlistGetChatByIndex(m_hChatlist, index));
|
||||
}
|
||||
|
||||
public MrPoortext getSummaryByIndex(int index, MrChat chat) {
|
||||
return new MrPoortext(MrChatlistGetSummaryByIndex(m_hChatlist, index, chat.GetCPtr()));
|
||||
}
|
||||
|
||||
private long m_hChatlist;
|
||||
private native static void MrChatlistUnref (long hChatlist);
|
||||
private native static int MrChatlistGetCnt (long hChatlist);
|
||||
private native static long MrChatlistGetChatByIndex (long hChatlist, int index); // returns hChat which must be unref'd after usage
|
||||
private native static long MrChatlistGetSummaryByIndex(long hChatlist, int index, long hChat);
|
||||
}
|
||||
@@ -32,17 +32,16 @@ package com.b44t.messenger;
|
||||
public class MrMailbox {
|
||||
|
||||
public static long hMailbox = 0;
|
||||
public static long hCurrChatlist = 0;
|
||||
public static MrChatlist mrCurrChatlist = new MrChatlist(0);
|
||||
private static final String TAG = "LibreChat"; // TAG is an Android convention
|
||||
|
||||
|
||||
// tools
|
||||
|
||||
public static TLRPC.TL_dialog hChatlist2dialog(long hChatlist, int index)
|
||||
public static TLRPC.TL_dialog mrChatlist2dialog(MrChatlist mrChatlist, int index)
|
||||
{
|
||||
MrChat mrChat = MrMailbox.getChatByIndex(hChatlist, index);
|
||||
MrChat mrChat = mrChatlist.getChatByIndex(index);
|
||||
TLRPC.TL_dialog dlg = MrChat.MrChat2dialog(mrChat);
|
||||
|
||||
return dlg;
|
||||
}
|
||||
|
||||
@@ -62,8 +61,7 @@ public class MrMailbox {
|
||||
|
||||
public static void reloadMainChatlist()
|
||||
{
|
||||
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);
|
||||
mrCurrChatlist = getChatlist(hMailbox);
|
||||
}
|
||||
|
||||
// this function is called from within the C-wrapper
|
||||
@@ -127,6 +125,10 @@ public class MrMailbox {
|
||||
return new MrChat(MrMailboxGetChat(hMailbox, contact_id));
|
||||
}
|
||||
|
||||
public static MrChatlist getChatlist(long hMailbox) {
|
||||
return new MrChatlist(MrMailboxGetChatlist(hMailbox));
|
||||
}
|
||||
|
||||
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)
|
||||
public native static int MrMailboxOpen (long hMailbox, String dbfile, String blobdir);
|
||||
public native static void MrMailboxClose (long hMailbox);
|
||||
@@ -144,7 +146,7 @@ public class MrMailbox {
|
||||
public native static int MrMailboxDeleteContact (long hMailbox, int id); // returns 0 if the contact could not be deleted (eg. it is in use, maybe by deaddrop)
|
||||
public native static int MrMailboxAddAddressBook (long hMailbox, String adrbook);
|
||||
|
||||
public native static long MrMailboxGetChatlist (long hMailbox); // returns hChatlist which must be unref'd after usage
|
||||
private native static long MrMailboxGetChatlist (long hMailbox); // returns hChatlist which must be unref'd after usage
|
||||
private native static long MrMailboxGetChat (long hMailbox, int chat_id); // return hChat which must be unref'd after usage
|
||||
public native static int MrMailboxMarkseenChat (long hMailbox, int id);
|
||||
public native static int MrMailboxGetChatIdByContactId (long hMailbox, int chat_id);
|
||||
@@ -163,15 +165,6 @@ public class MrMailbox {
|
||||
public native static String MrMailboxGetInfo (long hMailbox);
|
||||
public native static String MrMailboxExecute (long hMailbox, String cmd);
|
||||
|
||||
// MrChatlist objects
|
||||
public static MrChat getChatByIndex(long hChatlist, int index)
|
||||
{
|
||||
return new MrChat(MrChatlistGetChatByIndex(hChatlist, index));
|
||||
}
|
||||
public native static void MrChatlistUnref (long hChatlist);
|
||||
public native static int MrChatlistGetCnt (long hChatlist);
|
||||
private native static long MrChatlistGetChatByIndex (long hChatlist, int index); // returns hChat which must be unref'd after usage
|
||||
|
||||
// Tools
|
||||
public native static void MrStockAddStr (int id, String str);
|
||||
public native static String MrGetVersionStr ();
|
||||
|
||||
@@ -38,8 +38,7 @@ public class DialogsAdapter extends RecyclerView.Adapter {
|
||||
mContext = context;
|
||||
dialogsType = type;
|
||||
|
||||
MrMailbox.MrChatlistUnref(MrMailbox.hCurrChatlist);
|
||||
MrMailbox.hCurrChatlist = MrMailbox.MrMailboxGetChatlist(MrMailbox.hMailbox);
|
||||
MrMailbox.reloadMainChatlist();
|
||||
}
|
||||
|
||||
public void setOpenedDialogId(long id) {
|
||||
@@ -48,11 +47,11 @@ public class DialogsAdapter extends RecyclerView.Adapter {
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return MrMailbox.MrChatlistGetCnt(MrMailbox.hCurrChatlist);
|
||||
return MrMailbox.mrCurrChatlist.getCnt();
|
||||
}
|
||||
|
||||
public TLRPC.TL_dialog getItem(int i) {
|
||||
return MrMailbox.hChatlist2dialog(MrMailbox.hCurrChatlist, i);
|
||||
return MrMailbox.mrChatlist2dialog(MrMailbox.mrCurrChatlist, i);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -126,6 +126,7 @@ public class DialogCell extends BaseCell {
|
||||
private boolean isSelected;
|
||||
|
||||
private MrChat m_mrChat = new MrChat(0);
|
||||
private MrPoortext m_summary = new MrPoortext(0);
|
||||
|
||||
public DialogCell(Context context) {
|
||||
super(context);
|
||||
@@ -184,7 +185,8 @@ public class DialogCell extends BaseCell {
|
||||
isDialogCell = true;
|
||||
index = i;
|
||||
|
||||
m_mrChat = MrMailbox.getChatByIndex(MrMailbox.hCurrChatlist, i);
|
||||
m_mrChat = MrMailbox.mrCurrChatlist.getChatByIndex(i);
|
||||
m_summary = MrMailbox.mrCurrChatlist.getSummaryByIndex(i, m_mrChat);
|
||||
|
||||
update(0);
|
||||
}
|
||||
@@ -307,17 +309,15 @@ public class DialogCell extends BaseCell {
|
||||
}
|
||||
|
||||
{
|
||||
MrPoortext mrPoortext = m_mrChat.getSummary();
|
||||
|
||||
checkMessage = false;
|
||||
String mess = mrPoortext.getText();
|
||||
String mess = m_summary.getText();
|
||||
if (mess.length() > 150) {
|
||||
mess = mess.substring(0, 150);
|
||||
}
|
||||
String title = mrPoortext.getTitle();
|
||||
String title = m_summary.getTitle();
|
||||
if( !title.isEmpty() )
|
||||
{
|
||||
int title_meaning = mrPoortext.getTitleMeaning();
|
||||
int title_meaning = m_summary.getTitleMeaning();
|
||||
int title_color = Theme.DIALOGS_NAME_TEXT_COLOR;
|
||||
switch( title_meaning ) {
|
||||
case MrPoortext.MR_TITLE_SELF: title_color = Theme.DIALOGS_SELF_TEXT_COLOR; break;
|
||||
@@ -332,7 +332,7 @@ public class DialogCell extends BaseCell {
|
||||
messageString = mess;
|
||||
}
|
||||
|
||||
long timestmp =mrPoortext.getTimestamp();
|
||||
long timestmp =m_summary.getTimestamp();
|
||||
if( timestmp!=0 ) {
|
||||
timeString = LocaleController.stringForMessageListDate(timestmp);
|
||||
}
|
||||
@@ -345,7 +345,7 @@ public class DialogCell extends BaseCell {
|
||||
drawClock = false;
|
||||
drawCount = false;
|
||||
drawError = false;
|
||||
switch( mrPoortext.getState() ) {
|
||||
switch( m_summary.getState() ) {
|
||||
case MrMsg.MR_OUT_ERROR: drawError = true; break;
|
||||
case MrMsg.MR_OUT_PENDING: drawClock = true; break;
|
||||
case MrMsg.MR_OUT_DELIVERED: drawCheck2 = true; break;
|
||||
@@ -564,8 +564,8 @@ public class DialogCell extends BaseCell {
|
||||
*/
|
||||
|
||||
public void checkCurrentDialogIndex() {
|
||||
if (index < MrMailbox.MrChatlistGetCnt(MrMailbox.hCurrChatlist)) { // EDIT BY MR - was: index < getDialogsArray().size()
|
||||
TLRPC.TL_dialog dialog = MrMailbox.hChatlist2dialog(MrMailbox.hCurrChatlist, index); // EDIT BY MR - was: getDialogsArray().get(index);
|
||||
if (index < MrMailbox.mrCurrChatlist.getCnt()) { // EDIT BY MR - was: index < getDialogsArray().size()
|
||||
TLRPC.TL_dialog dialog = MrMailbox.mrChatlist2dialog(MrMailbox.mrCurrChatlist, index); // EDIT BY MR - was: getDialogsArray().get(index);
|
||||
TLRPC.DraftMessage newDraftMessage = DraftQuery.getDraft(currentDialogId);
|
||||
MessageObject newMessageObject = MessagesController.getInstance().dialogMessage.get(dialog.id);
|
||||
if (currentDialogId != dialog.id ||
|
||||
|
||||
Reference in New Issue
Block a user