#10 Scrolling through images in chat, works mostly, displays wrong buttons, though.

This commit is contained in:
Angelo Fuchs - Der Mor
2018-06-06 13:06:03 +02:00
parent 631959ba63
commit e1ac76bbfd
2 changed files with 50 additions and 4 deletions
@@ -48,6 +48,7 @@ import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.style.ClickableSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.util.SparseIntArray;
import android.util.TypedValue;
import android.view.Gravity;
@@ -82,6 +83,7 @@ import com.b44t.messenger.Components.RecyclerListView;
import com.b44t.messenger.Components.SizeNotifierFrameLayout;
import com.b44t.messenger.ActionBar.Theme;
import java.io.Console;
import java.io.File;
import java.net.URLDecoder;
import java.util.ArrayList;
@@ -2806,7 +2808,11 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
if( /*(Build.VERSION.SDK_INT >= 16 && message.isVideo()) ||*/ message.type == MessageObject.MO_TYPE1_PHOTO || message.isGif()) {
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhoto(message, message.type != MessageObject.MO_TYPE0_TEXT ? dialog_id : 0, ChatActivity.this);
//PhotoViewer.getInstance().openPhoto(message, message.type != MessageObject.MO_TYPE0_TEXT ? dialog_id : 0,
// ChatActivity.this, getPhotosInChat());
ArrayList<Object> photos = getPhotosInChat();
int index = getIndexOfCellPhoto(cell);
PhotoViewer.getInstance().openPhoto(null, 0, ChatActivity.this, photos, index);
} else if (message.type == MessageObject.MO_TYPE9_FILE || message.type == MessageObject.MO_TYPE3_VIDEO ) {
AndroidUtilities.openForViewOrShare(getParentActivity(), message.getId(), Intent.ACTION_VIEW);
}
@@ -2826,7 +2832,47 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
return new Holder(view);
}
@Override
private ArrayList<Object> getPhotosInChat() {
ArrayList<Object> photos = new ArrayList<>();
for(int msg_index = 0; msg_index < m_msglist.length; msg_index ++) {
MrMsg msg = MrMailbox.getMsg(m_msglist[msg_index]);
switch (msg.getType()) {
case MrMsg.MR_MSG_IMAGE:
case MrMsg.MR_MSG_GIF:
{
TLRPC.Message tlrpcMsg = msg.get_TLRPC_Message();
MediaController.PhotoEntry entry = new MediaController.PhotoEntry(0, tlrpcMsg.id,
msg.getTimestamp(), tlrpcMsg.attachPath, 0, false);
photos.add(entry);
}
case MrMsg.MR_MSG_TEXT:
Log.d(TAG, "getPhotosInChat: a message: " + msg.getText());
}
msg.get_TLRPC_Message();
}
return photos;
}
private int getIndexOfCellPhoto(ChatMessageCell callingCell) {
int photoCount = 0;
for(int msg_index = 0; msg_index < m_msglist.length; msg_index ++) {
MrMsg msg = MrMailbox.getMsg(m_msglist[msg_index]);
switch (msg.getType()) {
case MrMsg.MR_MSG_IMAGE:
case MrMsg.MR_MSG_GIF:
{
if(callingCell.getMessageObject().getId() == msg.getId())
return photoCount; // count up until now.
photoCount ++;
}
}
msg.get_TLRPC_Message();
}
return 0; // didn't find the matching photo.
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int i) {
if (i >= 0 && i < m_msglist.length) {
View view = holder.itemView;
@@ -2693,8 +2693,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
return isVisible && !disableShowCheck && object != null && currentPathObject != null && object.equals(currentPathObject);
}
public void openPhoto(final MessageObject messageObject, long dialogId, final PhotoViewerProvider provider) {
openPhoto(messageObject, null, null, null, 0, provider, null, dialogId);
public void openPhoto(final MessageObject messageObject, long dialogId, final PhotoViewerProvider provider, ArrayList<Object> photos, int index) {
openPhoto(messageObject, null, null, photos, index, provider, null, dialogId);
}
public void openPhoto(final TLRPC.FileLocation fileLocation, final PhotoViewerProvider provider) {