Remove DraftQuery, StickersQuery, SharedMediaQuery & Co.

This commit is contained in:
B. Petersen
2016-12-05 12:20:26 +01:00
parent a87049e443
commit db112b226e
17 changed files with 121 additions and 1183 deletions
@@ -51,7 +51,6 @@ import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import com.b44t.messenger.audioinfo.AudioInfo;
import com.b44t.messenger.query.SharedMediaQuery;
import com.b44t.messenger.video.InputSurface;
import com.b44t.messenger.video.MP4Builder;
import com.b44t.messenger.video.Mp4Movie;
@@ -1990,7 +1989,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener,
currentPlaylistNum = 0;
}
if (loadMusic) {
SharedMediaQuery.loadMusic(current.getDialogId(), playlist.get(0).getId());
//SharedMediaQuery.loadMusic(current.getDialogId(), playlist.get(0).getId());
}
}
return playAudio(current);
@@ -11,12 +11,9 @@ package com.b44t.messenger;
import android.app.Activity;
import android.content.SharedPreferences;
import com.b44t.messenger.query.DraftQuery;
import com.b44t.ui.ActionBar.BaseFragment;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
@@ -95,7 +92,6 @@ public class MessagesController implements NotificationCenter.NotificationCenter
} else {
inputUser = new TLRPC.TL_inputUser();
inputUser.user_id = user.id;
inputUser.access_hash = user.access_hash;
}
return inputUser;
}
@@ -108,12 +104,8 @@ public class MessagesController implements NotificationCenter.NotificationCenter
public static TLRPC.InputPeer getInputPeer(int id) {
TLRPC.InputPeer inputPeer;
{
TLRPC.User user = getInstance().getUser(id);
inputPeer = new TLRPC.TL_inputPeerUser();
inputPeer.user_id = id;
if (user != null) {
inputPeer.access_hash = user.access_hash;
}
}
return inputPeer;
}
@@ -27,6 +27,8 @@
package com.b44t.messenger;
import android.text.TextUtils;
public class MrChat {
public final static int MR_CHAT_UNDEFINED = 0;
@@ -131,4 +133,32 @@ public class MrChat {
public long GetCPtr() {
return m_hChat;
}
public TLRPC.DraftMessage getDraftMessageObj() {
if( getId() == 0 ) {
return null;
}
TLRPC.DraftMessage ret = new TLRPC.DraftMessage();
ret.message = getDraft();
if( ret.message==null || ret.message.isEmpty() ) {
return null;
}
ret.date = (int)getDraftTimestamp();
ret.reply_to_msg_id = getDraftReplyToMsgId();
return ret;
}
public void saveDraft(CharSequence message, TLRPC.Message replyToMessage) {
if( message == null || TextUtils.isEmpty(message) ) {
setDraft(null, 0);
}
else {
setDraft(message.toString(), 0);
}
}
public void cleanDraft()
{
setDraft(null, 0);
}
}
@@ -279,4 +279,22 @@ public class MrMailbox {
{
m_currChatlist = getChatlist();
}
public final static int MEDIA_PHOTOVIDEO = 0;
public static void getMediaCount(final long uid, final int type, final int classGuid, boolean fromCache) {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public void run() {
int[] media = new int[0];
if( type == MEDIA_PHOTOVIDEO ) {
media = MrMailbox.getChatMedia((int)uid, MrMsg.MR_MSG_IMAGE, MrMsg.MR_MSG_VIDEO);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.mediaCountDidLoaded,
uid, media.length, false /*not from cache*/, type, media);
}
});
}
}
@@ -19,7 +19,6 @@ import android.webkit.MimeTypeMap;
import android.widget.Toast;
import com.b44t.messenger.audioinfo.AudioInfo;
import com.b44t.messenger.query.DraftQuery;
import java.io.File;
import java.io.RandomAccessFile;
@@ -755,7 +754,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
if (type == 0 /*|| type == 9 && message != null && encryptedChat != null*/ )
{
newMsg.id = mrChat.sendText(newMsg.message);
DraftQuery.cleanDraft(peer);
mrChat.cleanDraft();
MrMailbox.reloadMainChatlist();
}
@@ -147,7 +147,6 @@ public class TLRPC {
public static class TL_messages_stickerSet extends TLObject {
public StickerSet set;
public ArrayList<TL_stickerPack> packs = new ArrayList<>();
public ArrayList<Document> documents = new ArrayList<>();
}
@@ -180,7 +179,6 @@ public class TLRPC {
public static class InputUser extends TLObject {
public int user_id;
public long access_hash;
}
public static class TL_inputUserEmpty extends InputUser {
@@ -236,7 +234,6 @@ public class TLRPC {
public String first_name;
public String last_name;
public String username;
public final long access_hash = 0;
public String phone;
public UserProfilePhoto photo;
public UserStatus status;
@@ -380,7 +377,6 @@ public class TLRPC {
public static class InputStickerSet extends TLObject {
public long id;
public long access_hash;
public String short_name;
}
@@ -466,7 +462,6 @@ public class TLRPC {
public static class StickerSet extends TLObject {
public long id;
public long access_hash;
public String title;
public int flags;
public boolean installed;
@@ -476,27 +471,6 @@ public class TLRPC {
public int hash;
}
public static class MessagesFilter extends TLObject {
}
public static class TL_inputMessagesFilterDocument extends MessagesFilter {
}
public static class TL_inputMessagesFilterMusic extends MessagesFilter {
}
public static class TL_inputMessagesFilterUrl extends MessagesFilter {
}
public static class TL_inputMessagesFilterVoice extends MessagesFilter {
}
public static class TL_inputMessagesFilterEmpty extends MessagesFilter {
}
public static class TL_inputMessagesFilterPhotoVideo extends MessagesFilter {
}
public static class TL_messageFwdHeader extends TLObject {
public int flags;
public int from_id;
@@ -559,10 +533,6 @@ public class TLRPC {
public static class TL_wallPaperSolid extends WallPaper {
}
public static class TL_stickerPack extends TLObject {
public ArrayList<Long> documents = new ArrayList<>();
}
public static class InputPhoto extends TLObject {
public long id;
public long access_hash;
@@ -573,7 +543,6 @@ public class TLRPC {
public static class InputPeer extends TLObject {
public int user_id;
public long access_hash;
public int chat_id;
public int channel_id;
}
@@ -584,16 +553,6 @@ public class TLRPC {
public static class TL_inputPeerEmpty extends InputPeer {
}
public static class TL_messages_search extends TLObject {
public int flags;
public InputPeer peer;
public String q;
public MessagesFilter filter;
public int offset;
public int max_id;
public int limit;
}
public static class TL_messages_searchGlobal extends TLObject {
public String q;
public int offset_date;
@@ -1,51 +0,0 @@
/*
* This is the source code of Telegram for Android v. 3.x.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013-2016.
*/
package com.b44t.messenger.query;
import android.text.TextUtils;
import com.b44t.messenger.MrChat;
import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.TLRPC;
import java.util.ArrayList;
public class DraftQuery {
public static TLRPC.DraftMessage getDraft(long did) { // returns null for "no draft"
MrChat mrChat = MrMailbox.getChat((int)did);
if( mrChat.getId() == 0 ) {
return null;
}
TLRPC.DraftMessage ret = new TLRPC.DraftMessage();
ret.message = mrChat.getDraft();
ret.date = (int)mrChat.getDraftTimestamp();
ret.reply_to_msg_id = mrChat.getDraftReplyToMsgId();
return ret;
}
private static void saveDraft__(long did, String message, long replyToMessageId) // message may be null
{
MrChat mrChat = MrMailbox.getChat((int)did);
mrChat.setDraft(message, replyToMessageId);
}
public static void saveDraft(long did, CharSequence message, TLRPC.Message replyToMessage) {
if( message == null || TextUtils.isEmpty(message) ) {
saveDraft__(did, null, 0);
}
else {
saveDraft__(did, message.toString(), 0);
}
}
public static void cleanDraft(long did) {
saveDraft__(did, null, 0);
}
}
@@ -1,438 +0,0 @@
/*
* This is the source code of Telegram for Android v. 2.0.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013-2016.
*/
package com.b44t.messenger.query;
import com.b44t.messenger.MessagesController;
import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.MrMsg;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.Utilities;
import com.b44t.messenger.TLRPC;
public class SharedMediaQuery {
public final static int MEDIA_PHOTOVIDEO = 0;
public final static int MEDIA_FILE = 1;
public final static int MEDIA_AUDIO = 2;
public final static int MEDIA_URL = 3;
public final static int MEDIA_MUSIC = 4;
public final static int MEDIA_TYPES_COUNT = 5;
public static void loadMedia(final long uid, final int offset, final int count, final int max_id, final int type, final boolean fromCache, final int classGuid) {
final boolean isChannel = false;//(int) uid < 0 && ChatObject.isChannel(-(int) uid);
int lower_part = (int)uid;
if (fromCache || lower_part == 0) {
loadMediaDatabase(uid, offset, count, max_id, type, classGuid, isChannel);
} else {
TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
req.offset = offset;
req.limit = count + 1;
req.max_id = max_id;
if (type == MEDIA_PHOTOVIDEO) {
req.filter = new TLRPC.TL_inputMessagesFilterPhotoVideo();
} else if (type == MEDIA_FILE) {
req.filter = new TLRPC.TL_inputMessagesFilterDocument();
} else if (type == MEDIA_AUDIO) {
req.filter = new TLRPC.TL_inputMessagesFilterVoice();
} else if (type == MEDIA_URL) {
req.filter = new TLRPC.TL_inputMessagesFilterUrl();
} else if (type == MEDIA_MUSIC) {
req.filter = new TLRPC.TL_inputMessagesFilterMusic();
}
req.q = "";
req.peer = MessagesController.getInputPeer(lower_part);
if (req.peer == null) {
return;
}
/*int reqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
final TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
boolean topReached;
if (res.messages.size() > count) {
topReached = false;
res.messages.remove(res.messages.size() - 1);
} else {
topReached = true;
}
processLoadedMedia(res, uid, offset, count, max_id, type, false, classGuid, isChannel, topReached);
}
}
});
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);*/
}
}
public static void getMediaCount(final long uid, final int type, final int classGuid, boolean fromCache) {
Utilities.globalQueue.postRunnable(new Runnable() {
@Override
public void run() {
int[] media = new int[0];
if( type == SharedMediaQuery.MEDIA_PHOTOVIDEO ) {
media = MrMailbox.getChatMedia((int)uid, MrMsg.MR_MSG_IMAGE, MrMsg.MR_MSG_VIDEO);
}
NotificationCenter.getInstance().postNotificationName(NotificationCenter.mediaCountDidLoaded,
uid, media.length, false /*not from cache*/, type, media);
}
});
/*
int lower_part = (int)uid;
if (fromCache || lower_part == 0) {
getMediaCountDatabase(uid, type, classGuid);
} else {
TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
req.offset = 0;
req.limit = 1;
req.max_id = 0;
if (type == MEDIA_PHOTOVIDEO) {
req.filter = new TLRPC.TL_inputMessagesFilterPhotoVideo();
} else if (type == MEDIA_FILE) {
req.filter = new TLRPC.TL_inputMessagesFilterDocument();
} else if (type == MEDIA_AUDIO) {
req.filter = new TLRPC.TL_inputMessagesFilterVoice();
} else if (type == MEDIA_URL) {
req.filter = new TLRPC.TL_inputMessagesFilterUrl();
} else if (type == MEDIA_MUSIC) {
req.filter = new TLRPC.TL_inputMessagesFilterMusic();
}
req.q = "";
req.peer = MessagesController.getInputPeer(lower_part);
if (req.peer == null) {
return;
}
int reqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(TLObject response, TLRPC.TL_error error) {
if (error == null) {
final TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
//MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
int count;
if (res instanceof TLRPC.TL_messages_messages) {
count = res.messages.size();
} else {
count = res.count;
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
MessagesController.getInstance().putUsers(res.users, false);
MessagesController.getInstance().putChats(res.chats, false);
}
});
processLoadedMediaCount(count, uid, type, classGuid, false);
}
}
});
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
}
*/
}
/*
public static int getMediaType(TLRPC.Message message) {
if (message == null) {
return -1;
}
if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
return MEDIA_PHOTOVIDEO;
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
if (MessageObject.isVoiceMessage(message)) {
return MEDIA_AUDIO;
} else if (MessageObject.isVideoMessage(message)) {
return MEDIA_PHOTOVIDEO;
} else if (MessageObject.isStickerMessage(message)) {
return -1;
} else if (MessageObject.isMusicMessage(message)) {
return MEDIA_MUSIC;
} else {
return MEDIA_FILE;
}
} else if (!message.entities.isEmpty()) {
for (int a = 0; a < message.entities.size(); a++) {
TLRPC.MessageEntity entity = message.entities.get(a);
if (entity instanceof TLRPC.TL_messageEntityUrl || entity instanceof TLRPC.TL_messageEntityTextUrl || entity instanceof TLRPC.TL_messageEntityEmail) {
return MEDIA_URL;
}
}
}
return -1;
}
*/
/*
private static void processLoadedMedia(final TLRPC.messages_Messages res, final long uid, int offset, int count, int max_id, final int type, final boolean fromCache, final int classGuid, final boolean isChannel, final boolean topReached) {
int lower_part = (int)uid;
if (fromCache && res.messages.isEmpty() && lower_part != 0) {
loadMedia(uid, offset, count, max_id, type, false, classGuid);
} else {
if (!fromCache) {
ImageLoader.saveMessagesThumbs(res.messages);
//MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
putMediaDatabase(uid, type, res.messages, max_id, topReached);
}
final HashMap<Integer, TLRPC.User> usersDict = new HashMap<>();
for (int a = 0; a < res.users.size(); a++) {
TLRPC.User u = res.users.get(a);
usersDict.put(u.id, u);
}
final ArrayList<MessageObject> objects = new ArrayList<>();
for (int a = 0; a < res.messages.size(); a++) {
TLRPC.Message message = res.messages.get(a);
objects.add(new MessageObject(message, usersDict, true));
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
int totalCount = res.count;
MessagesController.getInstance().putUsers(res.users, fromCache);
MessagesController.getInstance().putChats(res.chats, fromCache);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.mediaDidLoaded, uid, totalCount, objects, classGuid, type, topReached);
}
});
}
}
*/
private static void loadMediaDatabase(final long uid, final int offset, final int count, final int max_id, final int type, final int classGuid, final boolean isChannel) {
/*
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
boolean topReached = false;
TLRPC.TL_messages_messages res = new TLRPC.TL_messages_messages();
try {
ArrayList<Integer> usersToLoad = new ArrayList<>();
ArrayList<Integer> chatsToLoad = new ArrayList<>();
int countToLoad = count + 1;
SQLiteCursor cursor;
SQLiteDatabase database = MessagesStorage.getInstance().getDatabase();
boolean isEnd = false;
if ((int) uid != 0) {
int channelId = 0;
long messageMaxId = max_id;
if (isChannel) {
channelId = -(int) uid;
}
if (messageMaxId != 0 && channelId != 0) {
messageMaxId |= ((long) channelId) << 32;
}
cursor = database.queryFinalized(String.format(Locale.US, "SELECT start FROM media_holes_v2 WHERE uid = %d AND type = %d AND start IN (0, 1)", uid, type));
if (cursor.next()) {
isEnd = cursor.intValue(0) == 1;
cursor.dispose();
} else {
cursor.dispose();
cursor = database.queryFinalized(String.format(Locale.US, "SELECT min(mid) FROM media_v2 WHERE uid = %d AND type = %d AND mid > 0", uid, type));
if (cursor.next()) {
int mid = cursor.intValue(0);
if (mid != 0) {
SQLitePreparedStatement state = database.executeFast("REPLACE INTO media_holes_v2 VALUES(?, ?, ?, ?)");
state.requery();
state.bindLong(1, uid);
state.bindInteger(2, type);
state.bindInteger(3, 0);
state.bindInteger(4, mid);
state.step();
state.dispose();
}
}
cursor.dispose();
}
if (messageMaxId != 0) {
long holeMessageId = 0;
cursor = database.queryFinalized(String.format(Locale.US, "SELECT end FROM media_holes_v2 WHERE uid = %d AND type = %d AND end <= %d ORDER BY end DESC LIMIT 1", uid, type, max_id));
if (cursor.next()) {
holeMessageId = cursor.intValue(0);
if (channelId != 0) {
holeMessageId |= ((long) channelId) << 32;
}
}
cursor.dispose();
if (holeMessageId > 1) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media_v2 WHERE uid = %d AND mid > 0 AND mid < %d AND mid >= %d AND type = %d ORDER BY date DESC, mid DESC LIMIT %d", uid, messageMaxId, holeMessageId, type, countToLoad));
} else {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media_v2 WHERE uid = %d AND mid > 0 AND mid < %d AND type = %d ORDER BY date DESC, mid DESC LIMIT %d", uid, messageMaxId, type, countToLoad));
}
} else {
long holeMessageId = 0;
cursor = database.queryFinalized(String.format(Locale.US, "SELECT max(end) FROM media_holes_v2 WHERE uid = %d AND type = %d", uid, type));
if (cursor.next()) {
holeMessageId = cursor.intValue(0);
if (channelId != 0) {
holeMessageId |= ((long) channelId) << 32;
}
}
cursor.dispose();
if (holeMessageId > 1) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media_v2 WHERE uid = %d AND mid >= %d AND type = %d ORDER BY date DESC, mid DESC LIMIT %d,%d", uid, holeMessageId, type, offset, countToLoad));
} else {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media_v2 WHERE uid = %d AND mid > 0 AND type = %d ORDER BY date DESC, mid DESC LIMIT %d,%d", uid, type, offset, countToLoad));
}
}
} else {
isEnd = true;
if (max_id != 0) {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.data, m.mid, r.random_id FROM media_v2 as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND m.mid > %d AND type = %d ORDER BY m.mid ASC LIMIT %d", uid, max_id, type, countToLoad));
} else {
cursor = database.queryFinalized(String.format(Locale.US, "SELECT m.data, m.mid, r.random_id FROM media_v2 as m LEFT JOIN randoms as r ON r.mid = m.mid WHERE m.uid = %d AND type = %d ORDER BY m.mid ASC LIMIT %d,%d", uid, type, offset, countToLoad));
}
}
while (cursor.next()) {
NativeByteBuffer data = cursor.byteBufferValue(0);
if (data != null) {
TLRPC.Message message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
data.reuse();
message.id = cursor.intValue(1);
message.dialog_id = uid;
if ((int) uid == 0) {
message.random_id = cursor.longValue(2);
}
res.messages.add(message);
if (message.from_id > 0) {
if (!usersToLoad.contains(message.from_id)) {
usersToLoad.add(message.from_id);
}
} else {
if (!chatsToLoad.contains(-message.from_id)) {
chatsToLoad.add(-message.from_id);
}
}
}
}
cursor.dispose();
if (!usersToLoad.isEmpty()) {
//MessagesStorage.getInstance().getUsersInternal(TextUtils.join(",", usersToLoad), res.users);
}
if (!chatsToLoad.isEmpty()) {
//MessagesStorage.getInstance().getChatsInternal(TextUtils.join(",", chatsToLoad), res.chats);
}
if (res.messages.size() > count) {
topReached = false;
res.messages.remove(res.messages.size() - 1);
} else {
topReached = isEnd;
}
} catch (Exception e) {
res.messages.clear();
res.chats.clear();
res.users.clear();
FileLog.e("messenger", e);
} finally {
processLoadedMedia(res, uid, offset, count, max_id, type, true, classGuid, isChannel, topReached);
}
}
});
*/
}
/*
private static void putMediaDatabase(final long uid, final int type, final ArrayList<TLRPC.Message> messages, final int max_id, final boolean topReached) {
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
try {
if (messages.isEmpty() || topReached) {
MessagesStorage.getInstance().doneHolesInMedia(uid, max_id, type);
if (messages.isEmpty()) {
return;
}
}
MessagesStorage.getInstance().getDatabase().beginTransaction();
SQLitePreparedStatement state2 = MessagesStorage.getInstance().getDatabase().executeFast("REPLACE INTO media_v2 VALUES(?, ?, ?, ?, ?)");
for (TLRPC.Message message : messages) {
if (canAddMessageToMedia(message)) {
long messageId = message.id;
if (message.to_id.channel_id != 0) {
messageId |= ((long) message.to_id.channel_id) << 32;
}
state2.requery();
NativeByteBuffer data = new NativeByteBuffer(message.getObjectSize());
message.serializeToStream(data);
state2.bindLong(1, messageId);
state2.bindLong(2, uid);
state2.bindInteger(3, message.date);
state2.bindInteger(4, type);
state2.bindByteBuffer(5, data);
state2.step();
data.reuse();
}
}
state2.dispose();
if (!topReached || max_id != 0) {
int minId = topReached ? 1 : messages.get(messages.size() - 1).id;
if (max_id != 0) {
MessagesStorage.getInstance().closeHolesInMedia(uid, minId, max_id, type);
} else {
MessagesStorage.getInstance().closeHolesInMedia(uid, minId, Integer.MAX_VALUE, type);
}
}
MessagesStorage.getInstance().getDatabase().commitTransaction();
} catch (Exception e) {
FileLog.e("messenger", e);
}
}
});
}
*/
public static void loadMusic(final long uid, final int max_id) {
/*
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
final ArrayList<MessageObject> arrayList = new ArrayList<>();
try {
SQLiteCursor cursor = MessagesStorage.getInstance().getDatabase().queryFinalized(String.format(Locale.US, "SELECT data, mid FROM media_v2 WHERE uid = %d AND mid < %d AND type = %d ORDER BY date DESC, mid DESC LIMIT 1000", uid, max_id, MEDIA_MUSIC));
while (cursor.next()) {
NativeByteBuffer data = cursor.byteBufferValue(0);
if (data != null) {
TLRPC.Message message = TLRPC.Message.TLdeserialize(data, data.readInt32(false), false);
data.reuse();
if (MessageObject.isMusicMessage(message)) {
message.id = cursor.intValue(1);
message.dialog_id = uid;
arrayList.add(0, new MessageObject(mess age, null, false));
}
}
}
cursor.dispose();
} catch (Exception e) {
FileLog.e("messenger", e);
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
NotificationCenter.getInstance().postNotificationName(NotificationCenter.musicDidLoaded, uid, arrayList);
}
});
}
});
*/
}
}
@@ -1,519 +0,0 @@
/*
* This is the source code of Telegram for Android v. 3.x.x
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013-2016.
*/
package com.b44t.messenger.query;
import android.content.Context;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.TLRPC;
import java.util.ArrayList;
import java.util.HashMap;
public class StickersQuery {
private static int loadHash;
private static int loadDate;
private static ArrayList<TLRPC.TL_messages_stickerSet> stickerSets = new ArrayList<>();
private static HashMap<Long, TLRPC.TL_messages_stickerSet> stickerSetsById = new HashMap<>();
private static HashMap<String, TLRPC.TL_messages_stickerSet> stickerSetsByName = new HashMap<>();
private static HashMap<Long, String> stickersByEmoji = new HashMap<>();
private static HashMap<Long, TLRPC.Document> stickersById = new HashMap<>();
private static HashMap<String, ArrayList<TLRPC.Document>> allStickers = new HashMap<>();
private static boolean loadingStickers;
private static boolean stickersLoaded;
public static void cleanup() {
loadHash = 0;
loadDate = 0;
allStickers.clear();
stickerSets.clear();
stickersByEmoji.clear();
stickerSetsById.clear();
stickerSetsByName.clear();
loadingStickers = false;
stickersLoaded = false;
}
public static void checkStickers() {
if (!loadingStickers && (!stickersLoaded || Math.abs(System.currentTimeMillis() / 1000 - loadDate) >= 60 * 60)) {
loadStickers(true, false);
}
}
/*
public static boolean isLoadingStickers() {
return loadingStickers;
}
*/
public static TLRPC.Document getStickerById(long id) {
TLRPC.Document document = stickersById.get(id);
if (document != null) {
long setId = getStickerSetId(document);
TLRPC.TL_messages_stickerSet stickerSet = stickerSetsById.get(setId);
if (stickerSet != null && stickerSet.set.disabled) {
return null;
}
}
return document;
}
public static TLRPC.TL_messages_stickerSet getStickerSetByName(String name) {
return stickerSetsByName.get(name);
}
public static TLRPC.TL_messages_stickerSet getStickerSetById(Long id) {
return stickerSetsById.get(id);
}
public static HashMap<String, ArrayList<TLRPC.Document>> getAllStickers() {
return allStickers;
}
public static ArrayList<TLRPC.TL_messages_stickerSet> getStickerSets() {
return stickerSets;
}
public static boolean isStickerPackInstalled(long id) {
return stickerSetsById.containsKey(id);
}
public static boolean isStickerPackInstalled(String name) {
return stickerSetsByName.containsKey(name);
}
public static String getEmojiForSticker(long id) {
String value = stickersByEmoji.get(id);
return value != null ? value : "";
}
/*
public static void reorderStickers(final ArrayList<Long> order) {
Collections.sort(stickerSets, new Comparator<TLRPC.TL_messages_stickerSet>() {
@Override
public int compare(TLRPC.TL_messages_stickerSet lhs, TLRPC.TL_messages_stickerSet rhs) {
int index1 = order.indexOf(lhs.set.id);
int index2 = order.indexOf(rhs.set.id);
if (index1 > index2) {
return 1;
} else if (index1 < index2) {
return -1;
}
return 0;
}
});
loadHash = calcStickersHash(stickerSets);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.stickersDidLoaded);
StickersQuery.loadStickers(false, true);
}
*/
/*
public static void calcNewHash() {
loadHash = calcStickersHash(stickerSets);
}
*/
/*
public static void addNewStickerSet(final TLRPC.TL_messages_stickerSet set) {
if (stickerSetsById.containsKey(set.set.id) || stickerSetsByName.containsKey(set.set.short_name)) {
return;
}
stickerSets.add(0, set);
stickerSetsById.put(set.set.id, set);
stickerSetsByName.put(set.set.short_name, set);
for (int a = 0; a < set.documents.size(); a++) {
TLRPC.Document document = set.documents.get(a);
stickersById.put(document.id, document);
}
for (int a = 0; a < set.packs.size(); a++) {
TLRPC.TL_stickerPack stickerPack = set.packs.get(a);
stickerPack.emoticon = stickerPack.emoticon.replace("\uFE0F", "");
ArrayList<TLRPC.Document> arrayList = allStickers.get(stickerPack.emoticon);
if (arrayList == null) {
arrayList = new ArrayList<>();
allStickers.put(stickerPack.emoticon, arrayList);
}
for (int c = 0; c < stickerPack.documents.size(); c++) {
Long id = stickerPack.documents.get(c);
if (!stickersByEmoji.containsKey(id)) {
stickersByEmoji.put(id, stickerPack.emoticon);
}
TLRPC.Document sticker = stickersById.get(id);
if (sticker != null) {
arrayList.add(sticker);
}
}
}
loadHash = calcStickersHash(stickerSets);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.stickersDidLoaded);
StickersQuery.loadStickers(false, true);
}
*/
public static void loadStickers(boolean cache, boolean force) {
if (loadingStickers) {
return;
}
loadingStickers = true;
if (cache) {
/*
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
ArrayList<TLRPC.TL_messages_stickerSet> newStickerArray = null;
int date = 0;
int hash = 0;
SQLiteCursor cursor = null;
try {
cursor = MessagesStorage.getInstance().getDatabase().queryFinalized("SELECT data, date, hash FROM stickers_v2 WHERE 1");
if (cursor.next()) {
NativeByteBuffer data = cursor.byteBufferValue(0);
if (data != null) {
newStickerArray = new ArrayList<>();
int count = data.readInt32(false);
for (int a = 0; a < count; a++) {
TLRPC.TL_messages_stickerSet stickerSet = TLRPC.TL_messages_stickerSet.TLdeserialize(data, data.readInt32(false), false);
newStickerArray.add(stickerSet);
}
data.reuse();
}
date = cursor.intValue(1);
hash = calcStickersHash(newStickerArray);
}
} catch (Throwable e) {
FileLog.e("messenger", e);
} finally {
if (cursor != null) {
cursor.dispose();
}
}
processLoadedStickers(newStickerArray, true, date, hash);
}
});
*/
} else {
/*final TLRPC.TL_messages_getAllStickers req = new TLRPC.TL_messages_getAllStickers();
req.hash = force ? 0 : loadHash;
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(final TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (response instanceof TLRPC.TL_messages_allStickers) {
final HashMap<Long, TLRPC.TL_messages_stickerSet> newStickerSets = new HashMap<>();
final ArrayList<TLRPC.TL_messages_stickerSet> newStickerArray = new ArrayList<>();
final TLRPC.TL_messages_allStickers res = (TLRPC.TL_messages_allStickers) response;
for (int a = 0; a < res.sets.size(); a++) {
final TLRPC.StickerSet stickerSet = res.sets.get(a);
TLRPC.TL_messages_stickerSet oldSet = stickerSetsById.get(stickerSet.id);
if (oldSet != null && oldSet.set.hash == stickerSet.hash) {
oldSet.set.disabled = stickerSet.disabled;
oldSet.set.installed = stickerSet.installed;
oldSet.set.official = stickerSet.official;
newStickerSets.put(oldSet.set.id, oldSet);
newStickerArray.add(oldSet);
if (newStickerSets.size() == res.sets.size()) {
processLoadedStickers(newStickerArray, false, (int) (System.currentTimeMillis() / 1000), res.hash);
}
continue;
}
newStickerArray.add(null);
final int index = a;
TLRPC.TL_messages_getStickerSet req = new TLRPC.TL_messages_getStickerSet();
req.stickerset = new TLRPC.TL_inputStickerSetID();
req.stickerset.id = stickerSet.id;
req.stickerset.access_hash = stickerSet.access_hash;
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(final TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
TLRPC.TL_messages_stickerSet res1 = (TLRPC.TL_messages_stickerSet) response;
newStickerArray.set(index, res1);
newStickerSets.put(stickerSet.id, res1);
if (newStickerSets.size() == res.sets.size()) {
processLoadedStickers(newStickerArray, false, (int) (System.currentTimeMillis() / 1000), res.hash);
}
}
});
}
});
}
} else {
processLoadedStickers(null, false, (int) (System.currentTimeMillis() / 1000), req.hash);
}
}
});
}
});*/
}
}
private static void putStickersToCache(ArrayList<TLRPC.TL_messages_stickerSet> stickers, final int date, final int hash) {
final ArrayList<TLRPC.TL_messages_stickerSet> stickersFinal = stickers != null ? new ArrayList<>(stickers) : null;
/*
MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
@Override
public void run() {
try {
if (stickersFinal != null) {
SQLitePreparedStatement state = MessagesStorage.getInstance().getDatabase().executeFast("REPLACE INTO stickers_v2 VALUES(?, ?, ?, ?)");
state.requery();
int size = 4;
for (int a = 0; a < stickersFinal.size(); a++) {
size += stickersFinal.get(a).getObjectSize();
}
NativeByteBuffer data = new NativeByteBuffer(size);
data.writeInt32(stickersFinal.size());
for (int a = 0; a < stickersFinal.size(); a++) {
stickersFinal.get(a).serializeToStream(data);
}
state.bindInteger(1, 1);
state.bindByteBuffer(2, data);
state.bindInteger(3, date);
state.bindInteger(4, hash);
state.step();
data.reuse();
state.dispose();
} else {
SQLitePreparedStatement state = MessagesStorage.getInstance().getDatabase().executeFast("UPDATE stickers_v2 SET date = ?");
state.requery();
state.bindInteger(1, date);
state.step();
state.dispose();
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
}
});
*/
}
/*
public static String getStickerSetName(long setId) {
TLRPC.TL_messages_stickerSet stickerSet = stickerSetsById.get(setId);
return stickerSet != null ? stickerSet.set.short_name : null;
}
*/
public static long getStickerSetId(TLRPC.Document document) {
for (int a = 0; a < document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
if (attribute.stickerset instanceof TLRPC.TL_inputStickerSetID) {
return attribute.stickerset.id;
}
break;
}
}
return -1;
}
private static int calcStickersHash(ArrayList<TLRPC.TL_messages_stickerSet> sets) {
long acc = 0;
for (int a = 0; a < sets.size(); a++) {
TLRPC.StickerSet set = sets.get(a).set;
if (set.disabled) {
continue;
}
acc = ((acc * 20261) + 0x80000000L + set.hash) % 0x80000000L;
}
return (int) acc;
}
/*
private static void processLoadedStickers(final ArrayList<TLRPC.TL_messages_stickerSet> res, final boolean cache, final int date, final int hash) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
loadingStickers = false;
stickersLoaded = true;
}
});
Utilities.stageQueue.postRunnable(new Runnable() {
@Override
public void run() {
if (cache && (res == null || Math.abs(System.currentTimeMillis() / 1000 - date) >= 60 * 60) || !cache && res == null && hash == 0) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (res != null && hash != 0) {
loadHash = hash;
}
loadStickers(false, false);
}
}, res == null && !cache ? 1000 : 0);
if (res == null) {
return;
}
}
if (res != null) {
try {
final ArrayList<TLRPC.TL_messages_stickerSet> stickerSetsNew = new ArrayList<>();
final HashMap<Long, TLRPC.TL_messages_stickerSet> stickerSetsByIdNew = new HashMap<>();
final HashMap<String, TLRPC.TL_messages_stickerSet> stickerSetsByNameNew = new HashMap<>();
final HashMap<Long, String> stickersByEmojiNew = new HashMap<>();
final HashMap<Long, TLRPC.Document> stickersByIdNew = new HashMap<>();
final HashMap<String, ArrayList<TLRPC.Document>> allStickersNew = new HashMap<>();
for (int a = 0; a < res.size(); a++) {
TLRPC.TL_messages_stickerSet stickerSet = res.get(a);
if (stickerSet == null) {
continue;
}
stickerSetsNew.add(stickerSet);
stickerSetsByIdNew.put(stickerSet.set.id, stickerSet);
stickerSetsByNameNew.put(stickerSet.set.short_name, stickerSet);
for (int b = 0; b < stickerSet.documents.size(); b++) {
TLRPC.Document document = stickerSet.documents.get(b);
if (document == null || document instanceof TLRPC.TL_documentEmpty) {
continue;
}
stickersByIdNew.put(document.id, document);
}
if (!stickerSet.set.disabled) {
for (int b = 0; b < stickerSet.packs.size(); b++) {
TLRPC.TL_stickerPack stickerPack = stickerSet.packs.get(b);
if (stickerPack == null || stickerPack.emoticon == null) {
continue;
}
stickerPack.emoticon = stickerPack.emoticon.replace("\uFE0F", "");
ArrayList<TLRPC.Document> arrayList = allStickersNew.get(stickerPack.emoticon);
if (arrayList == null) {
arrayList = new ArrayList<>();
allStickersNew.put(stickerPack.emoticon, arrayList);
}
for (int c = 0; c < stickerPack.documents.size(); c++) {
Long id = stickerPack.documents.get(c);
if (!stickersByEmojiNew.containsKey(id)) {
stickersByEmojiNew.put(id, stickerPack.emoticon);
}
TLRPC.Document sticker = stickersByIdNew.get(id);
if (sticker != null) {
arrayList.add(sticker);
}
}
}
}
}
if (!cache) {
putStickersToCache(stickerSetsNew, date, hash);
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
stickersById = stickersByIdNew;
stickerSetsById = stickerSetsByIdNew;
stickerSetsByName = stickerSetsByNameNew;
stickerSets = stickerSetsNew;
allStickers = allStickersNew;
stickersByEmoji = stickersByEmojiNew;
loadHash = hash;
loadDate = date;
NotificationCenter.getInstance().postNotificationName(NotificationCenter.stickersDidLoaded);
}
});
} catch (Throwable e) {
FileLog.e("messenger", e);
}
} else if (!cache) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
loadDate = date;
}
});
putStickersToCache(null, date, 0);
}
}
});
}
*/
public static void removeStickersSet(final Context context, TLRPC.StickerSet stickerSet, int hide) {
TLRPC.TL_inputStickerSetID stickerSetID = new TLRPC.TL_inputStickerSetID();
stickerSetID.access_hash = stickerSet.access_hash;
stickerSetID.id = stickerSet.id;
if (hide != 0) {
stickerSet.disabled = hide == 1;
for (int a = 0; a < stickerSets.size(); a++) {
TLRPC.TL_messages_stickerSet set = stickerSets.get(a);
if (set.set.id == stickerSet.id) {
stickerSets.remove(a);
if (hide == 2) {
stickerSets.add(0, set);
} else {
for (int b = stickerSets.size() - 1; b >= 0; b--) {
if (stickerSets.get(b).set.disabled) {
continue;
}
stickerSets.add(b + 1, set);
break;
}
}
break;
}
}
loadHash = calcStickersHash(stickerSets);
putStickersToCache(stickerSets, loadDate, loadHash);
NotificationCenter.getInstance().postNotificationName(NotificationCenter.stickersDidLoaded);
/*TLRPC.TL_messages_installStickerSet req = new TLRPC.TL_messages_installStickerSet();
req.stickerset = stickerSetID;
req.disabled = hide == 1;
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
loadStickers(false, false);
}
}, 1000);
}
});*/
} else {
/*TLRPC.TL_messages_uninstallStickerSet req = new TLRPC.TL_messages_uninstallStickerSet();
req.stickerset = stickerSetID;
ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
@Override
public void run(TLObject response, final TLRPC.TL_error error) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
try {
if (error == null) {
Toast.makeText(context, LocaleController.getString("StickersRemoved", R.string.StickersRemoved), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, LocaleController.getString("ErrorOccurred", R.string.ErrorOccurred), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
loadStickers(false, true);
}
});
}
});*/
}
}
}
@@ -17,7 +17,6 @@ import android.view.ViewGroup;
import com.b44t.messenger.FileLog;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.Utilities;
import com.b44t.messenger.query.StickersQuery;
import com.b44t.messenger.support.widget.RecyclerView;
import com.b44t.messenger.FileLoader;
import com.b44t.messenger.TLRPC;
@@ -54,7 +53,7 @@ public class StickersAdapter extends RecyclerView.Adapter implements Notificatio
public StickersAdapter(Context context, StickersAdapterDelegate delegate) {
mContext = context;
this.delegate = delegate;
StickersQuery.checkStickers();
//StickersQuery.checkStickers();
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.FileDidFailedLoad);
}
@@ -108,7 +107,7 @@ public class StickersAdapter extends RecyclerView.Adapter implements Notificatio
}
}
lastSticker = emoji.toString();
HashMap<String, ArrayList<TLRPC.Document>> allStickers = StickersQuery.getAllStickers();
HashMap<String, ArrayList<TLRPC.Document>> allStickers = getAllStickers();
if (allStickers != null) {
ArrayList<TLRPC.Document> newStickers = allStickers.get(lastSticker);
if (stickers != null && newStickers == null) {
@@ -209,4 +208,35 @@ public class StickersAdapter extends RecyclerView.Adapter implements Notificatio
}
((StickerCell) viewHolder.itemView).setSticker(stickers.get(i), side);
}
////////////////////////////////////////////////////////////////////////////////////////////////
// was: StickersQuery
public static TLRPC.Document getStickerById(long id) {
return null;
}
public static TLRPC.TL_messages_stickerSet getStickerSetByName(String name) {
return null;
}
public static TLRPC.TL_messages_stickerSet getStickerSetById(Long id) {
return null;
}
public static HashMap<String, ArrayList<TLRPC.Document>> getAllStickers() {
return null;
}
public static ArrayList<TLRPC.TL_messages_stickerSet> getStickerSets() {
return new ArrayList<>();
}
public static boolean isStickerPackInstalled(long id) {
return false;
}
public static boolean isStickerPackInstalled(String name) {
return false;
}
}
@@ -28,12 +28,10 @@ import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MessageObject;
import com.b44t.messenger.MrChat;
import com.b44t.messenger.MrChatlist;
import com.b44t.messenger.MrMailbox; // EDIT BY MR
import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.FileLog;
import com.b44t.messenger.MrMsg;
import com.b44t.messenger.MrPoortext;
import com.b44t.messenger.query.DraftQuery;
import com.b44t.messenger.TLRPC;
import com.b44t.messenger.Emoji;
import com.b44t.messenger.MessagesController;
@@ -82,7 +80,6 @@ public class DialogCell extends BaseCell {
private TLRPC.User user = null;
private TLRPC.Chat chat = null;
private CharSequence lastPrintString = null;
private TLRPC.DraftMessage draftMessage;
public boolean useSeparator = false;
@@ -551,13 +548,12 @@ public class DialogCell extends BaseCell {
public void checkCurrentDialogIndex() {
if (index < MrMailbox.m_currChatlist.getCnt()) { // EDIT BY MR - was: index < getDialogsArray().size()
TLRPC.TL_dialog dialog = MrMailbox.m_currChatlist.get_TLRPC_TL_dialog(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 ||
message != null && message.getId() != dialog.top_message ||
unreadCount != dialog.unread_count ||
message != newMessageObject ||
message == null && newMessageObject != null || newDraftMessage != draftMessage) {
message == null && newMessageObject != null ) {
currentDialogId = dialog.id;
update(0);
}
@@ -19,8 +19,8 @@ import android.widget.TextView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.Emoji;
import com.b44t.messenger.query.StickersQuery;
import com.b44t.messenger.TLRPC;
import com.b44t.ui.Adapters.StickersAdapter;
import com.b44t.ui.Components.BackupImageView;
import com.b44t.ui.Components.LayoutHelper;
@@ -28,7 +28,6 @@ public class StickerEmojiCell extends FrameLayout {
private BackupImageView imageView;
private TLRPC.Document sticker;
private TextView emojiTextView;
private float alpha = 1;
private boolean changingAlpha;
private long lastUpdateTime;
@@ -43,10 +42,6 @@ public class StickerEmojiCell extends FrameLayout {
imageView = new BackupImageView(context);
imageView.setAspectFit(true);
addView(imageView, LayoutHelper.createFrame(66, 66, Gravity.CENTER));
emojiTextView = new TextView(context);
emojiTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
addView(emojiTextView, LayoutHelper.createFrame(28, 28, Gravity.BOTTOM | Gravity.RIGHT));
}
public TLRPC.Document getSticker() {
@@ -59,26 +54,6 @@ public class StickerEmojiCell extends FrameLayout {
if (document.thumb != null) {
imageView.setImage(document.thumb.location, null, "webp", null);
}
if (showEmoji) {
boolean set = false;
for (int a = 0; a < document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
if (attribute.alt != null && attribute.alt.length() > 0) {
emojiTextView.setText(Emoji.replaceEmoji(attribute.alt, emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
set = true;
}
break;
}
}
if (!set) {
emojiTextView.setText(Emoji.replaceEmoji(StickersQuery.getEmojiForSticker(sticker.id), emojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
}
emojiTextView.setVisibility(VISIBLE);
} else {
emojiTextView.setVisibility(INVISIBLE);
}
}
}
@@ -68,8 +68,6 @@ import com.b44t.messenger.SendMessagesHelper;
import com.b44t.messenger.Utilities;
import com.b44t.messenger.VideoEditedInfo;
import com.b44t.messenger.browser.Browser;
import com.b44t.messenger.query.DraftQuery;
import com.b44t.messenger.query.StickersQuery;
import com.b44t.messenger.support.widget.GridLayoutManager;
import com.b44t.messenger.support.widget.LinearLayoutManager;
import com.b44t.messenger.support.widget.RecyclerView;
@@ -2038,7 +2036,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id, replyingMessageObject, captions);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
}
return;
} else if (chatAttachAlert != null) {
@@ -2288,7 +2286,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id, replyingMessageObject, captions);
SendMessagesHelper.prepareSendingPhotosSearch(webPhotos, dialog_id, replyingMessageObject);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
}
@Override
@@ -2317,7 +2315,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else {
SendMessagesHelper.prepareSendingVideo(path, 0, 0, 0, 0, null, dialog_id, replyingMessageObject);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
return true;
}
}
@@ -2368,7 +2366,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
activity.finishFragment();
SendMessagesHelper.prepareSendingDocuments(files, files, null, null, dialog_id, replyingMessageObject);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
}
@Override
@@ -2394,7 +2392,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
public void didSelectAudio(ArrayList<MessageObject> audios) {
SendMessagesHelper.prepareSendingAudioDocuments(audios, dialog_id, replyingMessageObject);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
}
});
presentFragment(fragment);
@@ -2846,11 +2844,11 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else if (messageObject.isSticker()) {
TLRPC.InputStickerSet inputStickerSet = messageObject.getInputStickerSet();
if (inputStickerSet instanceof TLRPC.TL_inputStickerSetID) {
if (!StickersQuery.isStickerPackInstalled(inputStickerSet.id)) {
if (!StickersAdapter.isStickerPackInstalled(inputStickerSet.id)) {
return 7;
}
} else if (inputStickerSet instanceof TLRPC.TL_inputStickerSetShortName) {
if (!StickersQuery.isStickerPackInstalled(inputStickerSet.short_name)) {
if (!StickersAdapter.isStickerPackInstalled(inputStickerSet.short_name)) {
return 7;
}
}
@@ -3027,14 +3025,14 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
videoEditedInfo.originalPath = videoPath;
SendMessagesHelper.prepareSendingVideo(videoPath, estimatedSize, estimatedDuration, resultWidth, resultHeight, videoEditedInfo, dialog_id, replyingMessageObject);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
}
});
if (parentLayout == null || !fragment.onFragmentCreate()) {
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id, replyingMessageObject);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
return false;
}
parentLayout.presentFragment(fragment, removeLast, !animated, true);
@@ -3112,7 +3110,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
SendMessagesHelper.prepareSendingPhoto(null, uri, dialog_id, replyingMessageObject, null);
}
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
} else if (requestCode == 2) {
String videoPath = null;
FileLog.d("messenger", "pic path " + currentPicturePath);
@@ -3152,7 +3150,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else {
SendMessagesHelper.prepareSendingVideo(videoPath, 0, 0, 0, 0, null, dialog_id, replyingMessageObject);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
}
} else if (requestCode == 21) {
if (data == null || data.getData() == null) {
@@ -3187,7 +3185,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
SendMessagesHelper.prepareSendingDocument(tempPath, originalPath, null, null, dialog_id, replyingMessageObject);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
} else if (requestCode == 31) {
if (data == null || data.getData() == null) {
showAttachmentError();
@@ -3211,7 +3209,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
if (sent) {
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
}
}
} finally {
@@ -4416,7 +4414,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
}
chatActivityEnterView.setFieldFocused(false);
}
DraftQuery.saveDraft(dialog_id, draftMessage, replyingMessageObject != null ? replyingMessageObject.messageOwner : null);
m_mrChat.saveDraft(draftMessage, replyingMessageObject != null ? replyingMessageObject.messageOwner : null);
MessagesController.getInstance().cancelTyping(0, dialog_id);
}
@@ -4425,30 +4423,12 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (chatActivityEnterView == null) {
return;
}
TLRPC.DraftMessage draftMessage = DraftQuery.getDraft(dialog_id);
TLRPC.DraftMessage draftMessage = m_mrChat.getDraftMessageObj();
if (chatActivityEnterView.getFieldText() == null) {
if (draftMessage != null) {
chatActivityEnterView.setWebPage(null, !draftMessage.no_webpage);
CharSequence message;
/*if (!draftMessage.entities.isEmpty()) {
SpannableStringBuilder stringBuilder = SpannableStringBuilder.valueOf(draftMessage.message);
for (int a = 0; a < draftMessage.entities.size(); a++) {
TLRPC.MessageEntity entity = draftMessage.entities.get(a);
if (entity instanceof TLRPC.TL_inputMessageEntityMentionName || entity instanceof TLRPC.TL_messageEntityMentionName) {
int user_id;
if (entity instanceof TLRPC.TL_inputMessageEntityMentionName) {
user_id = ((TLRPC.TL_inputMessageEntityMentionName) entity).user_id.user_id;
} else {
user_id = ((TLRPC.TL_messageEntityMentionName) entity).user_id;
}
if (entity.offset + entity.length < stringBuilder.length() && stringBuilder.charAt(entity.offset + entity.length) == ' ') {
entity.length++;
}
stringBuilder.setSpan(new URLSpanUserMention("" + user_id), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
message = stringBuilder;
} else*/ {
{
message = draftMessage.message;
}
chatActivityEnterView.setFieldText(message);
@@ -5151,11 +5131,11 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if (photoEntry.imagePath != null) {
SendMessagesHelper.prepareSendingPhoto(photoEntry.imagePath, null, dialog_id, replyingMessageObject, photoEntry.caption);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
} else if (photoEntry.path != null) {
SendMessagesHelper.prepareSendingPhoto(photoEntry.path, null, dialog_id, replyingMessageObject, photoEntry.caption);
showReplyPanel(false, null, null, null, false, true);
DraftQuery.cleanDraft(dialog_id);
m_mrChat.cleanDraft();
}
}
@@ -47,12 +47,12 @@ import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MediaController;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.Utilities;
import com.b44t.messenger.query.StickersQuery;
import com.b44t.messenger.FileLog;
import com.b44t.messenger.R;
import com.b44t.messenger.support.widget.GridLayoutManager;
import com.b44t.messenger.support.widget.RecyclerView;
import com.b44t.messenger.TLRPC;
import com.b44t.ui.Adapters.StickersAdapter;
import com.b44t.ui.Cells.ContextLinkCell;
import com.b44t.ui.Cells.EmptyCell;
import com.b44t.ui.Cells.StickerEmojiCell;
@@ -582,7 +582,7 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
}
if (showStickers) {
StickersQuery.checkStickers();
//StickersQuery.checkStickers();
stickersGridView = new GridView(context) {
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
@@ -1162,13 +1162,13 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
}
private void sortStickers() {
if (StickersQuery.getStickerSets().isEmpty()) {
if (StickersAdapter.getStickerSets().isEmpty()) {
recentStickers.clear();
return;
}
recentStickers.clear();
for (int a = 0; a < newRecentStickers.size(); a++) {
TLRPC.Document sticker = StickersQuery.getStickerById(newRecentStickers.get(a));
TLRPC.Document sticker = StickersAdapter.getStickerById(newRecentStickers.get(a));
if (sticker != null) {
recentStickers.add(sticker);
}
@@ -1210,7 +1210,7 @@ public class EmojiView extends FrameLayout implements NotificationCenter.Notific
}
stickerSets.clear();
ArrayList<TLRPC.TL_messages_stickerSet> packs = StickersQuery.getStickerSets();
ArrayList<TLRPC.TL_messages_stickerSet> packs = StickersAdapter.getStickerSets();
for (int a = 0; a < packs.size(); a++) {
TLRPC.TL_messages_stickerSet pack = packs.get(a);
if (pack.set.disabled || pack.documents == null || pack.documents.isEmpty()) {
@@ -34,13 +34,13 @@ import com.b44t.messenger.Emoji;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.R;
import com.b44t.messenger.query.StickersQuery;
import com.b44t.messenger.support.widget.GridLayoutManager;
import com.b44t.messenger.support.widget.RecyclerView;
import com.b44t.messenger.ConnectionsManager;
import com.b44t.messenger.TLRPC;
import com.b44t.ui.ActionBar.BottomSheet;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.ui.Adapters.StickersAdapter;
import com.b44t.ui.Cells.StickerEmojiCell;
import com.b44t.ui.StickerPreviewViewer;
@@ -59,7 +59,6 @@ public class StickersAlert extends BottomSheet implements NotificationCenter.Not
private TextView previewSendButton;
private View previewSendButtonShadow;
private BackupImageView stickerImageView;
private TextView stickerEmojiTextView;
private RecyclerListView.OnItemClickListener stickersOnItemClickListener;
private Drawable shadowDrawable;
private AnimatorSet shadowAnimation[] = new AnimatorSet[2];
@@ -221,21 +220,6 @@ public class StickersAlert extends BottomSheet implements NotificationCenter.Not
}
selectedSticker = stickerSet.documents.get(position);
boolean set = false;
for (int a = 0; a < selectedSticker.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = selectedSticker.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
if (attribute.alt != null && attribute.alt.length() > 0) {
stickerEmojiTextView.setText(Emoji.replaceEmoji(attribute.alt, stickerEmojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(30), false));
set = true;
}
break;
}
}
if (!set) {
stickerEmojiTextView.setText(Emoji.replaceEmoji(StickersQuery.getEmojiForSticker(selectedSticker.id), stickerEmojiTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(30), false));
}
stickerImageView.getImageReceiver().setImage(selectedSticker, null, selectedSticker.thumb.location, null, "webp", true);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) stickerPreviewLayout.getLayoutParams();
layoutParams.topMargin = scrollOffsetY;
@@ -320,11 +304,6 @@ public class StickersAlert extends BottomSheet implements NotificationCenter.Not
int size = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) / 2 / AndroidUtilities.density);
stickerPreviewLayout.addView(stickerImageView, LayoutHelper.createFrame(size, size, Gravity.CENTER));
stickerEmojiTextView = new TextView(context);
stickerEmojiTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 30);
stickerEmojiTextView.setGravity(Gravity.BOTTOM | Gravity.RIGHT);
stickerPreviewLayout.addView(stickerEmojiTextView, LayoutHelper.createFrame(size, size, Gravity.CENTER));
previewSendButton = new TextView(context);
previewSendButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
previewSendButton.setTextColor(Theme.STICKERS_SHEET_SEND_TEXT_COLOR);
@@ -351,16 +330,15 @@ public class StickersAlert extends BottomSheet implements NotificationCenter.Not
if (delegate != null) {
previewSendButton.setText(LocaleController.getString("SendSticker", R.string.SendSticker).toUpperCase());
stickerImageView.setLayoutParams(LayoutHelper.createFrame(size, size, Gravity.CENTER, 0, 0, 0, 30));
stickerEmojiTextView.setLayoutParams(LayoutHelper.createFrame(size, size, Gravity.CENTER, 0, 0, 0, 30));
previewSendButton.setVisibility(View.VISIBLE);
previewSendButtonShadow.setVisibility(View.VISIBLE);
}
if (stickerSet == null && inputStickerSet.short_name != null) {
stickerSet = StickersQuery.getStickerSetByName(inputStickerSet.short_name);
stickerSet = StickersAdapter.getStickerSetByName(inputStickerSet.short_name);
}
if (stickerSet == null) {
stickerSet = StickersQuery.getStickerSetById(inputStickerSet.id);
stickerSet = StickersAdapter.getStickerSetById(inputStickerSet.id);
}
if (stickerSet == null) {
/*TLRPC.TL_messages_getStickerSet req = new TLRPC.TL_messages_getStickerSet();
@@ -396,7 +374,7 @@ public class StickersAlert extends BottomSheet implements NotificationCenter.Not
if (stickerSet != null) {
titleTextView.setText(stickerSet.set.title);
if (stickerSet.set == null || !StickersQuery.isStickerPackInstalled(stickerSet.set.id)) {
if (stickerSet.set == null || !StickersAdapter.isStickerPackInstalled(stickerSet.set.id)) {
setRightButton(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -437,7 +415,7 @@ public class StickersAlert extends BottomSheet implements NotificationCenter.Not
@Override
public void onClick(View v) {
dismiss();
StickersQuery.removeStickersSet(getContext(), stickerSet.set, 0);
//StickersQuery.removeStickersSet(getContext(), stickerSet.set, 0);
}
}, LocaleController.getString("StickersRemove", R.string.StickersRemove), Theme.STICKERS_SHEET_REMOVE_TEXT_COLOR, false);
}
@@ -60,7 +60,6 @@ import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.exoplayer.AspectRatioFrameLayout;
import com.b44t.messenger.exoplayer.ExoPlayer;
import com.b44t.messenger.exoplayer.util.PlayerControl;
import com.b44t.messenger.query.SharedMediaQuery;
import com.b44t.messenger.ApplicationLoader;
import com.b44t.messenger.FileLoader;
import com.b44t.messenger.FileLog;
@@ -798,7 +797,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (needSearchImageInArr && isFirstLoading) {
isFirstLoading = false;
loadingMoreImages = true;
SharedMediaQuery.loadMedia(currentDialogId, 0, 80, 0, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
//SharedMediaQuery.loadMedia(currentDialogId, 0, 80, 0, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
} else if (!imagesArr.isEmpty()) {
if (opennedFromMedia) {
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, totalImagesCount + totalImagesCountMerge));
@@ -887,9 +886,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (!endReached[loadIndex]) {
loadingMoreImages = true;
if (opennedFromMedia) {
SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 0, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
//SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 0, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
} else {
SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 0, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
//SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 0, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
}
}
}
@@ -2639,9 +2638,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (currentAnimation == null) {
if (currentDialogId != 0 && totalImagesCount == 0) {
SharedMediaQuery.getMediaCount(currentDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
MrMailbox.getMediaCount(currentDialogId, MrMailbox.MEDIA_PHOTOVIDEO, classGuid, true);
if (mergeDialogId != 0) {
SharedMediaQuery.getMediaCount(mergeDialogId, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
MrMailbox.getMediaCount(mergeDialogId, MrMailbox.MEDIA_PHOTOVIDEO, classGuid, true);
}
} else if (avatarsDialogId != 0) {
//MessagesController.getInstance().loadDialogPhotos(avatarsDialogId, 0, 80, 0, true, classGuid);
@@ -2757,7 +2756,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 0, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
//SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 0, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
loadingMoreImages = true;
}
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, totalImagesCount + totalImagesCountMerge));
@@ -2772,7 +2771,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 0, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
//SharedMediaQuery.loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 0, 80, loadFromMaxId, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
loadingMoreImages = true;
}
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, (totalImagesCount + totalImagesCountMerge - imagesArr.size()) + currentIndex + 1, totalImagesCount + totalImagesCountMerge));
@@ -50,7 +50,6 @@ import com.b44t.messenger.MrContact;
import com.b44t.messenger.MrMailbox;
import com.b44t.messenger.SendMessagesHelper;
import com.b44t.messenger.UserObject;
import com.b44t.messenger.query.SharedMediaQuery;
import com.b44t.messenger.ApplicationLoader;
import com.b44t.messenger.support.widget.LinearLayoutManager;
import com.b44t.messenger.support.widget.RecyclerView;
@@ -206,14 +205,6 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
return false;
}
if (dialog_id != 0) {
SharedMediaQuery.getMediaCount(dialog_id, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
} else if (user_id != 0) {
SharedMediaQuery.getMediaCount(user_id, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
} else if (chat_id > 0) {
SharedMediaQuery.getMediaCount(-chat_id, SharedMediaQuery.MEDIA_PHOTOVIDEO, classGuid, true);
}
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
updateRowsIds();