2013-10-25 15:19:00 +00:00
|
|
|
/*
|
2013-12-20 19:25:49 +00:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 15:19:00 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
2014-10-07 20:14:27 +00:00
|
|
|
import android.view.MotionEvent;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.Surface;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.AbsListView;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.GridView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
|
|
|
import org.telegram.android.LocaleController;
|
2014-09-25 03:54:35 +00:00
|
|
|
import org.telegram.messenger.FileLoader;
|
2014-02-28 22:28:25 +00:00
|
|
|
import org.telegram.messenger.TLRPC;
|
2014-08-22 14:24:33 +00:00
|
|
|
import org.telegram.android.MessageObject;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.MessagesController;
|
2014-08-22 14:24:33 +00:00
|
|
|
import org.telegram.android.NotificationCenter;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.R;
|
2014-06-20 00:18:13 +00:00
|
|
|
import org.telegram.ui.Adapters.BaseFragmentAdapter;
|
2014-11-13 20:10:14 +00:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.ui.Views.BackupImageView;
|
2014-11-13 20:10:14 +00:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
public class MediaActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, PhotoViewer.PhotoViewerProvider {
|
2014-11-17 02:44:57 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
private GridView listView;
|
|
|
|
private ListAdapter listAdapter;
|
|
|
|
private ArrayList<MessageObject> messages = new ArrayList<MessageObject>();
|
|
|
|
private HashMap<Integer, MessageObject> messagesDict = new HashMap<Integer, MessageObject>();
|
|
|
|
private long dialog_id;
|
|
|
|
private int totalCount = 0;
|
|
|
|
private int itemWidth = 100;
|
|
|
|
private boolean loading = false;
|
|
|
|
private boolean endReached = false;
|
|
|
|
private boolean cacheEndReached = false;
|
2014-03-22 22:31:55 +00:00
|
|
|
private int max_id = Integer.MAX_VALUE;
|
2013-10-25 15:19:00 +00:00
|
|
|
private View progressView;
|
2014-03-22 22:31:55 +00:00
|
|
|
private TextView emptyView;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
public MediaActivity(Bundle args) {
|
|
|
|
super(args);
|
|
|
|
}
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
super.onFragmentCreate();
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.mediaDidLoaded);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messagesDeleted);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.didReceivedNewMessages);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageReceivedByServer);
|
2013-10-25 15:19:00 +00:00
|
|
|
dialog_id = getArguments().getLong("dialog_id", 0);
|
2014-03-22 22:31:55 +00:00
|
|
|
if (((int)dialog_id) == 0) {
|
|
|
|
max_id = Integer.MIN_VALUE;
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
loading = true;
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().loadMedia(dialog_id, 0, 50, 0, true, classGuid);
|
2013-10-25 15:19:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.mediaDidLoaded);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didReceivedNewMessages);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messagesDeleted);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageReceivedByServer);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-03 23:31:48 +00:00
|
|
|
public View createView(LayoutInflater inflater, ViewGroup container) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (fragmentView == null) {
|
2014-11-11 22:16:17 +00:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setBackOverlay(R.layout.updating_state_layout);
|
|
|
|
actionBar.setTitle(LocaleController.getString("SharedMedia", R.string.SharedMedia));
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
2014-06-03 23:31:48 +00:00
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
2014-10-11 11:30:32 +00:00
|
|
|
if (Build.VERSION.SDK_INT < 11 && listView != null) {
|
2014-06-03 23:31:48 +00:00
|
|
|
listView.setAdapter(null);
|
|
|
|
listView = null;
|
|
|
|
listAdapter = null;
|
|
|
|
}
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
fragmentView = inflater.inflate(R.layout.media_layout, container, false);
|
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
emptyView = (TextView)fragmentView.findViewById(R.id.searchEmptyView);
|
|
|
|
emptyView.setText(LocaleController.getString("NoMedia", R.string.NoMedia));
|
2014-10-07 20:14:27 +00:00
|
|
|
emptyView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2013-10-25 15:19:00 +00:00
|
|
|
listView = (GridView)fragmentView.findViewById(R.id.media_grid);
|
|
|
|
progressView = fragmentView.findViewById(R.id.progressLayout);
|
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
listView.setAdapter(listAdapter = new ListAdapter(getParentActivity()));
|
2013-10-25 15:19:00 +00:00
|
|
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
2014-07-03 14:55:04 +00:00
|
|
|
PhotoViewer.getInstance().setParentActivity(getParentActivity());
|
2014-06-10 23:05:54 +00:00
|
|
|
PhotoViewer.getInstance().openPhoto(messages, i, MediaActivity.this);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
if (loading && messages.isEmpty()) {
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
listView.setEmptyView(null);
|
|
|
|
} else {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
listView.setEmptyView(emptyView);
|
|
|
|
}
|
|
|
|
|
|
|
|
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrollStateChanged(AbsListView absListView, int i) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
|
if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2 && !loading && !endReached) {
|
|
|
|
loading = true;
|
2014-03-22 22:31:55 +00:00
|
|
|
MessagesController.getInstance().loadMedia(dialog_id, 0, 50, max_id, !cacheEndReached, classGuid);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 14:24:33 +00:00
|
|
|
if (id == NotificationCenter.mediaDidLoaded) {
|
2013-10-25 15:19:00 +00:00
|
|
|
long uid = (Long)args[0];
|
|
|
|
int guid = (Integer)args[4];
|
|
|
|
if (uid == dialog_id && guid == classGuid) {
|
|
|
|
loading = false;
|
|
|
|
totalCount = (Integer)args[1];
|
|
|
|
@SuppressWarnings("uchecked")
|
|
|
|
ArrayList<MessageObject> arr = (ArrayList<MessageObject>)args[2];
|
|
|
|
boolean added = false;
|
2014-03-22 22:31:55 +00:00
|
|
|
boolean enc = ((int)dialog_id) == 0;
|
2013-10-25 15:19:00 +00:00
|
|
|
for (MessageObject message : arr) {
|
2013-12-20 19:25:49 +00:00
|
|
|
if (!messagesDict.containsKey(message.messageOwner.id)) {
|
2014-03-22 22:31:55 +00:00
|
|
|
if (!enc) {
|
|
|
|
if (message.messageOwner.id > 0) {
|
|
|
|
max_id = Math.min(message.messageOwner.id, max_id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
max_id = Math.max(message.messageOwner.id, max_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
messagesDict.put(message.messageOwner.id, message);
|
|
|
|
messages.add(message);
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!added) {
|
|
|
|
endReached = true;
|
|
|
|
}
|
|
|
|
cacheEndReached = !(Boolean)args[3];
|
|
|
|
if (progressView != null) {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (listView != null) {
|
|
|
|
if (listView.getEmptyView() == null) {
|
|
|
|
listView.setEmptyView(emptyView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.messagesDeleted) {
|
2013-10-25 15:19:00 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
ArrayList<Integer> markAsDeletedMessages = (ArrayList<Integer>)args[0];
|
|
|
|
boolean updated = false;
|
|
|
|
for (Integer ids : markAsDeletedMessages) {
|
|
|
|
MessageObject obj = messagesDict.get(ids);
|
|
|
|
if (obj != null) {
|
|
|
|
messages.remove(obj);
|
|
|
|
messagesDict.remove(ids);
|
|
|
|
totalCount--;
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updated && listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.didReceivedNewMessages) {
|
2013-10-25 15:19:00 +00:00
|
|
|
long uid = (Long)args[0];
|
|
|
|
if (uid == dialog_id) {
|
|
|
|
boolean markAsRead = false;
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
ArrayList<MessageObject> arr = (ArrayList<MessageObject>)args[1];
|
|
|
|
|
|
|
|
for (MessageObject obj : arr) {
|
|
|
|
if (obj.messageOwner.media == null || !(obj.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) && !(obj.messageOwner.media instanceof TLRPC.TL_messageMediaVideo)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (messagesDict.containsKey(obj.messageOwner.id)) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-03-22 22:31:55 +00:00
|
|
|
boolean enc = ((int)dialog_id) == 0;
|
|
|
|
if (!enc) {
|
|
|
|
if (obj.messageOwner.id > 0) {
|
|
|
|
max_id = Math.min(obj.messageOwner.id, max_id);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
max_id = Math.max(obj.messageOwner.id, max_id);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
messagesDict.put(obj.messageOwner.id, obj);
|
|
|
|
messages.add(0, obj);
|
|
|
|
}
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.messageReceivedByServer) {
|
2013-10-25 15:19:00 +00:00
|
|
|
Integer msgId = (Integer)args[0];
|
|
|
|
MessageObject obj = messagesDict.get(msgId);
|
|
|
|
if (obj != null) {
|
|
|
|
Integer newMsgId = (Integer)args[1];
|
|
|
|
messagesDict.remove(msgId);
|
|
|
|
messagesDict.put(newMsgId, obj);
|
|
|
|
obj.messageOwner.id = newMsgId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2014-06-04 16:00:42 +00:00
|
|
|
super.onResume();
|
2014-06-03 23:31:48 +00:00
|
|
|
if (listAdapter != null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
fixLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
fixLayout();
|
|
|
|
}
|
|
|
|
|
2014-06-10 23:05:54 +00:00
|
|
|
@Override
|
2014-06-12 01:13:15 +00:00
|
|
|
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
2014-08-22 14:24:33 +00:00
|
|
|
if (messageObject == null || listView == null) {
|
2014-06-10 23:05:54 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = listView.getChildAt(a);
|
|
|
|
BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image);
|
|
|
|
if (imageView != null) {
|
|
|
|
int num = (Integer)imageView.getTag();
|
|
|
|
if (num < 0 || num >= messages.size()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MessageObject message = messages.get(num);
|
|
|
|
if (message != null && message.messageOwner.id == messageObject.messageOwner.id) {
|
|
|
|
int coords[] = new int[2];
|
|
|
|
imageView.getLocationInWindow(coords);
|
|
|
|
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
|
|
|
|
object.viewX = coords[0];
|
2014-07-02 22:39:05 +00:00
|
|
|
object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
|
2014-06-10 23:05:54 +00:00
|
|
|
object.parentView = listView;
|
|
|
|
object.imageReceiver = imageView.imageReceiver;
|
|
|
|
object.thumb = object.imageReceiver.getBitmap();
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2014-06-11 00:22:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-12 01:13:15 +00:00
|
|
|
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) { }
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
@Override
|
|
|
|
public void willHidePhotoViewer() { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPhotoChecked(int index) { return false; }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPhotoChecked(int index) { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void cancelButtonPressed() { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendButtonPressed(int index) { }
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSelectedCount() { return 0; }
|
2014-06-10 23:05:54 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
private void fixLayout() {
|
|
|
|
if (listView != null) {
|
|
|
|
ViewTreeObserver obs = listView.getViewTreeObserver();
|
|
|
|
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
2014-06-03 23:31:48 +00:00
|
|
|
WindowManager manager = (WindowManager)ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
|
|
|
|
2014-09-24 02:17:27 +00:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
2014-06-03 23:31:48 +00:00
|
|
|
listView.setNumColumns(4);
|
2014-09-24 02:17:27 +00:00
|
|
|
itemWidth = AndroidUtilities.dp(490) / 4 - AndroidUtilities.dp(2) * 3;
|
2014-06-03 23:31:48 +00:00
|
|
|
listView.setColumnWidth(itemWidth);
|
2014-09-24 02:17:27 +00:00
|
|
|
} else {
|
|
|
|
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
|
|
|
|
listView.setNumColumns(6);
|
|
|
|
itemWidth = AndroidUtilities.displaySize.x / 6 - AndroidUtilities.dp(2) * 5;
|
|
|
|
listView.setColumnWidth(itemWidth);
|
|
|
|
} else {
|
|
|
|
listView.setNumColumns(4);
|
|
|
|
itemWidth = AndroidUtilities.displaySize.x / 4 - AndroidUtilities.dp(2) * 3;
|
|
|
|
listView.setColumnWidth(itemWidth);
|
|
|
|
}
|
2014-02-28 22:28:25 +00:00
|
|
|
}
|
2014-07-02 22:39:05 +00:00
|
|
|
listView.setPadding(listView.getPaddingLeft(), AndroidUtilities.dp(4), listView.getPaddingRight(), listView.getPaddingBottom());
|
2014-06-03 23:31:48 +00:00
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
|
2014-02-28 22:28:25 +00:00
|
|
|
if (listView != null) {
|
|
|
|
listView.getViewTreeObserver().removeOnPreDrawListener(this);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 00:18:13 +00:00
|
|
|
private class ListAdapter extends BaseFragmentAdapter {
|
2013-10-25 15:19:00 +00:00
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areAllItemsEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled(int i) {
|
|
|
|
return i != messages.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
|
|
|
return messages.size() + (messages.isEmpty() || endReached ? 0 : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int i) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasStableIds() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
|
|
|
int type = getItemViewType(i);
|
|
|
|
if (type == 0) {
|
|
|
|
MessageObject message = messages.get(i);
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.media_photo_layout, viewGroup, false);
|
|
|
|
}
|
|
|
|
ViewGroup.LayoutParams params = view.getLayoutParams();
|
|
|
|
params.width = itemWidth;
|
|
|
|
params.height = itemWidth;
|
|
|
|
view.setLayoutParams(params);
|
|
|
|
|
|
|
|
BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image);
|
2014-06-10 23:05:54 +00:00
|
|
|
imageView.setTag(i);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2013-12-26 11:43:37 +00:00
|
|
|
if (message.messageOwner.media != null && message.messageOwner.media.photo != null && !message.messageOwner.media.photo.sizes.isEmpty()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
ArrayList<TLRPC.PhotoSize> sizes = message.messageOwner.media.photo.sizes;
|
2014-06-10 23:05:54 +00:00
|
|
|
if (message.imagePreview != null) {
|
|
|
|
imageView.setImageBitmap(message.imagePreview);
|
|
|
|
} else {
|
2014-10-01 19:55:24 +00:00
|
|
|
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(message.messageOwner.media.photo.sizes, 80);
|
2014-11-06 21:34:47 +00:00
|
|
|
imageView.setImage(photoSize.location, null, mContext.getResources().getDrawable(R.drawable.photo_placeholder_in));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-12-20 19:25:49 +00:00
|
|
|
imageView.setImageResource(R.drawable.photo_placeholder_in);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
imageView.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(message), false);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (type == 1) {
|
|
|
|
MessageObject message = messages.get(i);
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.media_video_layout, viewGroup, false);
|
|
|
|
}
|
|
|
|
ViewGroup.LayoutParams params = view.getLayoutParams();
|
|
|
|
params.width = itemWidth;
|
|
|
|
params.height = itemWidth;
|
|
|
|
view.setLayoutParams(params);
|
|
|
|
|
|
|
|
TextView textView = (TextView)view.findViewById(R.id.chat_video_time);
|
|
|
|
BackupImageView imageView = (BackupImageView)view.findViewById(R.id.media_photo_image);
|
2014-06-10 23:05:54 +00:00
|
|
|
imageView.setTag(i);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
if (message.messageOwner.media.video != null && message.messageOwner.media.video.thumb != null) {
|
|
|
|
int duration = message.messageOwner.media.video.duration;
|
|
|
|
int minutes = duration / 60;
|
|
|
|
int seconds = duration - minutes * 60;
|
|
|
|
textView.setText(String.format("%d:%02d", minutes, seconds));
|
|
|
|
if (message.imagePreview != null) {
|
|
|
|
imageView.setImageBitmap(message.imagePreview);
|
|
|
|
} else {
|
2014-11-06 21:34:47 +00:00
|
|
|
imageView.setImage(message.messageOwner.media.video.thumb.location, null, mContext.getResources().getDrawable(R.drawable.photo_placeholder_in));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
textView.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
textView.setVisibility(View.GONE);
|
2013-12-20 19:25:49 +00:00
|
|
|
imageView.setImageResource(R.drawable.photo_placeholder_in);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-06-10 23:05:54 +00:00
|
|
|
imageView.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(message), false);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (type == 2) {
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
view = li.inflate(R.layout.media_loading_layout, viewGroup, false);
|
|
|
|
}
|
|
|
|
ViewGroup.LayoutParams params = view.getLayoutParams();
|
|
|
|
params.width = itemWidth;
|
|
|
|
params.height = itemWidth;
|
|
|
|
view.setLayoutParams(params);
|
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
|
|
|
if (i == messages.size()) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
MessageObject message = messages.get(i);
|
|
|
|
if (message.messageOwner.media instanceof TLRPC.TL_messageMediaVideo) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEmpty() {
|
|
|
|
return messages.isEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|