2013-10-25 17:19:00 +02:00
|
|
|
|
/*
|
2015-10-29 18:10:07 +01:00
|
|
|
|
* This is the source code of Telegram for Android v. 3.x.x.
|
2013-10-25 17:19:00 +02: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).
|
|
|
|
|
*
|
2017-03-31 01:58:05 +02:00
|
|
|
|
* Copyright Nikolai Kudashov, 2013-2017.
|
2013-10-25 17:19:00 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
|
import android.animation.Animator;
|
|
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
|
import android.animation.ObjectAnimator;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.content.Context;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.res.Configuration;
|
2015-01-02 23:15:07 +01:00
|
|
|
|
import android.graphics.Bitmap;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
|
|
|
|
import android.graphics.drawable.Drawable;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
import android.net.Uri;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
import android.support.v4.content.FileProvider;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.TypedValue;
|
|
|
|
|
import android.view.Gravity;
|
2014-10-07 22:14:27 +02:00
|
|
|
|
import android.view.MotionEvent;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
import android.view.Surface;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
|
import android.view.WindowManager;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
import android.webkit.MimeTypeMap;
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.LinearLayout;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2016-10-11 13:57:01 +02:00
|
|
|
|
import org.telegram.messenger.BuildConfig;
|
2015-09-24 22:52:02 +02:00
|
|
|
|
import org.telegram.messenger.ChatObject;
|
|
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
|
import org.telegram.messenger.MediaController;
|
|
|
|
|
import org.telegram.messenger.MessagesController;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
import org.telegram.messenger.UserConfig;
|
|
|
|
|
import org.telegram.messenger.UserObject;
|
|
|
|
|
import org.telegram.messenger.VideoEditedInfo;
|
2016-04-22 15:49:00 +02:00
|
|
|
|
import org.telegram.messenger.browser.Browser;
|
2015-09-24 22:52:02 +02:00
|
|
|
|
import org.telegram.messenger.query.SharedMediaQuery;
|
2014-12-01 18:56:31 +01:00
|
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2014-09-25 05:54:35 +02:00
|
|
|
|
import org.telegram.messenger.FileLoader;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
import org.telegram.messenger.FileLog;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
import org.telegram.messenger.support.widget.LinearLayoutManager;
|
|
|
|
|
import org.telegram.messenger.support.widget.RecyclerView;
|
2015-09-24 22:52:02 +02:00
|
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
|
import org.telegram.tgnet.RequestDelegate;
|
|
|
|
|
import org.telegram.tgnet.TLObject;
|
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
|
|
|
|
import org.telegram.messenger.MessageObject;
|
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
import org.telegram.messenger.R;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
import org.telegram.messenger.Utilities;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarPopupWindow;
|
2014-11-13 21:10:14 +01:00
|
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2015-10-29 18:10:07 +01:00
|
|
|
|
import org.telegram.ui.ActionBar.BackDrawable;
|
2016-04-22 15:49:00 +02:00
|
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
import org.telegram.ui.ActionBar.ThemeDescription;
|
|
|
|
|
import org.telegram.ui.Cells.CheckBoxCell;
|
|
|
|
|
import org.telegram.ui.Cells.GraySectionCell;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
import org.telegram.ui.Cells.LoadingCell;
|
|
|
|
|
import org.telegram.ui.Cells.SharedDocumentCell;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
import org.telegram.ui.Cells.SharedLinkCell;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
import org.telegram.ui.Cells.SharedMediaSectionCell;
|
|
|
|
|
import org.telegram.ui.Cells.SharedPhotoVideoCell;
|
2014-12-01 18:56:31 +01:00
|
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
2014-11-13 21:10:14 +01:00
|
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
import org.telegram.ui.Components.EmbedBottomSheet;
|
2015-05-03 13:48:36 +02:00
|
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2015-10-29 18:10:07 +01:00
|
|
|
|
import org.telegram.ui.Components.NumberTextView;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
import org.telegram.ui.Components.FragmentContextView;
|
|
|
|
|
import org.telegram.ui.Components.RadialProgressView;
|
|
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
|
import java.io.File;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
import java.util.ArrayList;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
import java.util.Collections;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
import java.util.HashMap;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
import java.util.Timer;
|
|
|
|
|
import java.util.TimerTask;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
|
@SuppressWarnings("unchecked")
|
2014-06-11 01:05:54 +02:00
|
|
|
|
public class MediaActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, PhotoViewer.PhotoViewerProvider {
|
2014-11-17 03:44:57 +01:00
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
|
private SharedPhotoVideoAdapter photoVideoAdapter;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
private SharedLinksAdapter linksAdapter;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
private SharedDocumentsAdapter documentsAdapter;
|
2015-10-29 18:10:07 +01:00
|
|
|
|
private SharedDocumentsAdapter audioAdapter;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
private MediaSearchAdapter documentsSearchAdapter;
|
2015-10-29 18:10:07 +01:00
|
|
|
|
private MediaSearchAdapter audioSearchAdapter;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
private MediaSearchAdapter linksSearchAdapter;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
private RecyclerListView listView;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
private LinearLayout progressView;
|
|
|
|
|
private TextView emptyTextView;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
private LinearLayoutManager layoutManager;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
private ImageView emptyImageView;
|
|
|
|
|
private LinearLayout emptyView;
|
|
|
|
|
private TextView dropDown;
|
2017-03-31 01:58:05 +02:00
|
|
|
|
private Drawable dropDownDrawable;
|
|
|
|
|
private RadialProgressView progressBar;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
private ActionBarMenuItem dropDownContainer;
|
|
|
|
|
private ActionBarMenuItem searchItem;
|
2015-10-29 18:10:07 +01:00
|
|
|
|
private NumberTextView selectedMessagesCountTextView;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
private ActionBarPopupWindow.ActionBarPopupWindowLayout popupLayout;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
private ArrayList<SharedPhotoVideoCell> cellCache = new ArrayList<>(6);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
private FragmentContextView fragmentContextView;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
|
|
|
|
|
private boolean searchWas;
|
|
|
|
|
private boolean searching;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
|
private HashMap<Integer, MessageObject>[] selectedFiles = new HashMap[] {new HashMap<>(), new HashMap<>()};
|
2015-09-24 22:52:02 +02:00
|
|
|
|
private int cantDeleteMessagesCount;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
private ArrayList<View> actionModeViews = new ArrayList<>();
|
|
|
|
|
private boolean scrolling;
|
2015-11-26 22:04:02 +01:00
|
|
|
|
private long mergeDialogId;
|
|
|
|
|
protected TLRPC.ChatFull info = null;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
|
private long dialog_id;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
private int selectedMode;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
private int columnsCount = 4;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
|
|
|
|
private class SharedMediaData {
|
|
|
|
|
private ArrayList<MessageObject> messages = new ArrayList<>();
|
2015-11-26 22:04:02 +01:00
|
|
|
|
private HashMap<Integer, MessageObject>[] messagesDict = new HashMap[] {new HashMap<>(), new HashMap<>()};
|
2015-02-26 02:32:51 +01:00
|
|
|
|
private ArrayList<String> sections = new ArrayList<>();
|
|
|
|
|
private HashMap<String, ArrayList<MessageObject>> sectionArrays = new HashMap<>();
|
2015-02-01 19:51:02 +01:00
|
|
|
|
private int totalCount;
|
|
|
|
|
private boolean loading;
|
2015-11-26 22:04:02 +01:00
|
|
|
|
private boolean endReached[] = new boolean[] {false, true};
|
|
|
|
|
private int max_id[] = new int[] {0, 0};
|
2015-02-26 02:32:51 +01:00
|
|
|
|
|
|
|
|
|
public boolean addMessage(MessageObject messageObject, boolean isNew, boolean enc) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
int loadIndex = messageObject.getDialogId() == dialog_id ? 0 : 1;
|
|
|
|
|
if (messagesDict[loadIndex].containsKey(messageObject.getId())) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
ArrayList<MessageObject> messageObjects = sectionArrays.get(messageObject.monthKey);
|
|
|
|
|
if (messageObjects == null) {
|
|
|
|
|
messageObjects = new ArrayList<>();
|
|
|
|
|
sectionArrays.put(messageObject.monthKey, messageObjects);
|
|
|
|
|
if (isNew) {
|
|
|
|
|
sections.add(0, messageObject.monthKey);
|
|
|
|
|
} else {
|
|
|
|
|
sections.add(messageObject.monthKey);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (isNew) {
|
|
|
|
|
messageObjects.add(0, messageObject);
|
|
|
|
|
messages.add(0, messageObject);
|
|
|
|
|
} else {
|
|
|
|
|
messageObjects.add(messageObject);
|
|
|
|
|
messages.add(messageObject);
|
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
|
messagesDict[loadIndex].put(messageObject.getId(), messageObject);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (!enc) {
|
2015-03-19 00:09:45 +01:00
|
|
|
|
if (messageObject.getId() > 0) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
max_id[loadIndex] = Math.min(messageObject.getId(), max_id[loadIndex]);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
max_id[loadIndex] = Math.max(messageObject.getId(), max_id[loadIndex]);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
|
public boolean deleteMessage(int mid, int loadIndex) {
|
|
|
|
|
MessageObject messageObject = messagesDict[loadIndex].get(mid);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (messageObject == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
ArrayList<MessageObject> messageObjects = sectionArrays.get(messageObject.monthKey);
|
|
|
|
|
if (messageObjects == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
messageObjects.remove(messageObject);
|
|
|
|
|
messages.remove(messageObject);
|
2015-11-26 22:04:02 +01:00
|
|
|
|
messagesDict[loadIndex].remove(messageObject.getId());
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (messageObjects.isEmpty()) {
|
|
|
|
|
sectionArrays.remove(messageObject.monthKey);
|
|
|
|
|
sections.remove(messageObject.monthKey);
|
|
|
|
|
}
|
|
|
|
|
totalCount--;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void replaceMid(int oldMid, int newMid) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
MessageObject obj = messagesDict[0].get(oldMid);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (obj != null) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
messagesDict[0].remove(oldMid);
|
|
|
|
|
messagesDict[0].put(newMid, obj);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
obj.messageOwner.id = newMid;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
|
private SharedMediaData sharedMediaData[] = new SharedMediaData[5];
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
|
|
|
|
private final static int shared_media_item = 1;
|
|
|
|
|
private final static int files_item = 2;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
private final static int links_item = 5;
|
2015-10-29 18:10:07 +01:00
|
|
|
|
private final static int music_item = 6;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
private final static int forward = 3;
|
|
|
|
|
private final static int delete = 4;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
2014-06-04 01:31:48 +02:00
|
|
|
|
public MediaActivity(Bundle args) {
|
|
|
|
|
super(args);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
|
@Override
|
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
|
super.onFragmentCreate();
|
2014-08-22 16:24:33 +02: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 17:19:00 +02:00
|
|
|
|
dialog_id = getArguments().getLong("dialog_id", 0);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
for (int a = 0; a < sharedMediaData.length; a++) {
|
|
|
|
|
sharedMediaData[a] = new SharedMediaData();
|
2015-11-26 22:04:02 +01:00
|
|
|
|
sharedMediaData[a].max_id[0] = ((int)dialog_id) == 0 ? Integer.MIN_VALUE : Integer.MAX_VALUE;
|
|
|
|
|
if (mergeDialogId != 0 && info != null) {
|
|
|
|
|
sharedMediaData[a].max_id[1] = info.migrated_from_max_id;
|
|
|
|
|
sharedMediaData[a].endReached[1] = false;
|
|
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
sharedMediaData[0].loading = true;
|
|
|
|
|
SharedMediaQuery.loadMedia(dialog_id, 0, 50, 0, SharedMediaQuery.MEDIA_PHOTOVIDEO, true, classGuid);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
|
super.onFragmentDestroy();
|
2014-08-22 16:24:33 +02: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 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
|
public View createView(Context context) {
|
2015-10-29 18:10:07 +01:00
|
|
|
|
actionBar.setBackButtonDrawable(new BackDrawable(false));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
actionBar.setTitle("");
|
|
|
|
|
actionBar.setAllowOverlayTitle(false);
|
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
|
if (id == -1) {
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
for (int a = 1; a >= 0; a--) {
|
|
|
|
|
selectedFiles[a].clear();
|
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
cantDeleteMessagesCount = 0;
|
|
|
|
|
actionBar.hideActionMode();
|
2017-03-31 01:58:05 +02:00
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
|
View child = listView.getChildAt(a);
|
|
|
|
|
if (child instanceof SharedDocumentCell) {
|
|
|
|
|
((SharedDocumentCell) child).setChecked(false, true);
|
|
|
|
|
} else if (child instanceof SharedPhotoVideoCell) {
|
|
|
|
|
for (int b = 0; b < 6; b++) {
|
|
|
|
|
((SharedPhotoVideoCell) child).setChecked(b, false, true);
|
|
|
|
|
}
|
|
|
|
|
} else if (child instanceof SharedLinkCell) {
|
|
|
|
|
((SharedLinkCell) child).setChecked(false, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
} else {
|
|
|
|
|
finishFragment();
|
2015-04-09 20:00:14 +02:00
|
|
|
|
}
|
|
|
|
|
} else if (id == shared_media_item) {
|
|
|
|
|
if (selectedMode == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
selectedMode = 0;
|
|
|
|
|
switchToCurrentSelectedMode();
|
|
|
|
|
} else if (id == files_item) {
|
|
|
|
|
if (selectedMode == 1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
selectedMode = 1;
|
|
|
|
|
switchToCurrentSelectedMode();
|
2015-08-13 11:23:31 +02:00
|
|
|
|
} else if (id == links_item) {
|
|
|
|
|
if (selectedMode == 3) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
selectedMode = 3;
|
|
|
|
|
switchToCurrentSelectedMode();
|
2015-10-29 18:10:07 +01:00
|
|
|
|
} else if (id == music_item) {
|
|
|
|
|
if (selectedMode == 4) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
selectedMode = 4;
|
|
|
|
|
switchToCurrentSelectedMode();
|
2015-04-09 20:00:14 +02:00
|
|
|
|
} else if (id == delete) {
|
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2015-11-26 22:04:02 +01:00
|
|
|
|
builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages", R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("items", selectedFiles[0].size() + selectedFiles[1].size())));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
|
|
final boolean deleteForAll[] = new boolean[1];
|
|
|
|
|
int lower_id = (int) dialog_id;
|
|
|
|
|
if (lower_id != 0) {
|
|
|
|
|
TLRPC.Chat currentChat;
|
|
|
|
|
TLRPC.User currentUser;
|
|
|
|
|
if (lower_id > 0) {
|
|
|
|
|
currentUser = MessagesController.getInstance().getUser(lower_id);
|
|
|
|
|
currentChat = null;
|
|
|
|
|
} else {
|
|
|
|
|
currentUser = null;
|
|
|
|
|
currentChat = MessagesController.getInstance().getChat(-lower_id);
|
|
|
|
|
}
|
|
|
|
|
if (currentUser != null || !ChatObject.isChannel(currentChat)) {
|
|
|
|
|
int currentDate = ConnectionsManager.getInstance().getCurrentTime();
|
|
|
|
|
if (currentUser != null && currentUser.id != UserConfig.getClientUserId() || currentChat != null) {
|
|
|
|
|
boolean hasOutgoing = false;
|
|
|
|
|
for (int a = 1; a >= 0; a--) {
|
|
|
|
|
int channelId = 0;
|
|
|
|
|
for (HashMap.Entry<Integer, MessageObject> entry : selectedFiles[a].entrySet()) {
|
|
|
|
|
MessageObject msg = entry.getValue();
|
|
|
|
|
if (msg.messageOwner.action != null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (msg.isOut()) {
|
|
|
|
|
if ((currentDate - msg.messageOwner.date) <= 2 * 24 * 60 * 60) {
|
|
|
|
|
hasOutgoing = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
hasOutgoing = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (hasOutgoing) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hasOutgoing) {
|
|
|
|
|
FrameLayout frameLayout = new FrameLayout(getParentActivity());
|
|
|
|
|
CheckBoxCell cell = new CheckBoxCell(getParentActivity(), true);
|
|
|
|
|
cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
|
|
|
|
|
if (currentChat != null) {
|
|
|
|
|
cell.setText(LocaleController.getString("DeleteForAll", R.string.DeleteForAll), "", false, false);
|
|
|
|
|
} else {
|
|
|
|
|
cell.setText(LocaleController.formatString("DeleteForUser", R.string.DeleteForUser, UserObject.getFirstName(currentUser)), "", false, false);
|
|
|
|
|
}
|
|
|
|
|
cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16) : AndroidUtilities.dp(8), 0, LocaleController.isRTL ? AndroidUtilities.dp(8) : AndroidUtilities.dp(16), 0);
|
|
|
|
|
frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 0, 0, 0, 0));
|
|
|
|
|
cell.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
CheckBoxCell cell = (CheckBoxCell) v;
|
|
|
|
|
deleteForAll[0] = !deleteForAll[0];
|
|
|
|
|
cell.setChecked(deleteForAll[0], true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
builder.setView(frameLayout);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
for (int a = 1; a >= 0; a--) {
|
|
|
|
|
ArrayList<Integer> ids = new ArrayList<>(selectedFiles[a].keySet());
|
|
|
|
|
ArrayList<Long> random_ids = null;
|
|
|
|
|
TLRPC.EncryptedChat currentEncryptedChat = null;
|
|
|
|
|
int channelId = 0;
|
|
|
|
|
if (!ids.isEmpty()) {
|
|
|
|
|
MessageObject msg = selectedFiles[a].get(ids.get(0));
|
|
|
|
|
if (channelId == 0 && msg.messageOwner.to_id.channel_id != 0) {
|
|
|
|
|
channelId = msg.messageOwner.to_id.channel_id;
|
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
|
if ((int) dialog_id == 0) {
|
|
|
|
|
currentEncryptedChat = MessagesController.getInstance().getEncryptedChat((int) (dialog_id >> 32));
|
|
|
|
|
}
|
|
|
|
|
if (currentEncryptedChat != null) {
|
|
|
|
|
random_ids = new ArrayList<>();
|
|
|
|
|
for (HashMap.Entry<Integer, MessageObject> entry : selectedFiles[a].entrySet()) {
|
|
|
|
|
MessageObject msg = entry.getValue();
|
|
|
|
|
if (msg.messageOwner.random_id != 0 && msg.type != 10) {
|
|
|
|
|
random_ids.add(msg.messageOwner.random_id);
|
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
MessagesController.getInstance().deleteMessages(ids, random_ids, currentEncryptedChat, channelId, deleteForAll[0]);
|
2015-11-26 22:04:02 +01:00
|
|
|
|
selectedFiles[a].clear();
|
2015-04-09 20:00:14 +02:00
|
|
|
|
}
|
|
|
|
|
actionBar.hideActionMode();
|
2015-09-02 00:14:21 +02:00
|
|
|
|
actionBar.closeSearchField();
|
2015-09-24 22:52:02 +02:00
|
|
|
|
cantDeleteMessagesCount = 0;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
});
|
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2015-05-21 23:27:27 +02:00
|
|
|
|
showDialog(builder.create());
|
2015-04-09 20:00:14 +02:00
|
|
|
|
} else if (id == forward) {
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putBoolean("onlySelect", true);
|
2015-06-29 19:12:11 +02:00
|
|
|
|
args.putInt("dialogsType", 1);
|
2015-07-22 20:56:37 +02:00
|
|
|
|
DialogsActivity fragment = new DialogsActivity(args);
|
2016-04-22 15:49:00 +02:00
|
|
|
|
fragment.setDelegate(new DialogsActivity.DialogsActivityDelegate() {
|
2015-04-09 20:00:14 +02:00
|
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
|
public void didSelectDialog(DialogsActivity fragment, long did, boolean param) {
|
2015-04-09 20:00:14 +02:00
|
|
|
|
int lower_part = (int) did;
|
|
|
|
|
if (lower_part != 0) {
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
|
args.putBoolean("scrollToTopOnResume", true);
|
|
|
|
|
if (lower_part > 0) {
|
|
|
|
|
args.putInt("user_id", lower_part);
|
|
|
|
|
} else if (lower_part < 0) {
|
|
|
|
|
args.putInt("chat_id", -lower_part);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2016-03-16 13:26:32 +01:00
|
|
|
|
if (!MessagesController.checkCanOpenChat(args, fragment)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
|
|
ArrayList<MessageObject> fmessages = new ArrayList<>();
|
2015-11-26 22:04:02 +01:00
|
|
|
|
for (int a = 1; a >= 0; a--) {
|
|
|
|
|
ArrayList<Integer> ids = new ArrayList<>(selectedFiles[a].keySet());
|
|
|
|
|
Collections.sort(ids);
|
|
|
|
|
for (Integer id : ids) {
|
|
|
|
|
if (id > 0) {
|
|
|
|
|
fmessages.add(selectedFiles[a].get(id));
|
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
|
selectedFiles[a].clear();
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
|
cantDeleteMessagesCount = 0;
|
2015-04-09 20:00:14 +02:00
|
|
|
|
actionBar.hideActionMode();
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
|
NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats);
|
2016-03-16 13:26:32 +01:00
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
|
ChatActivity chatActivity = new ChatActivity(args);
|
|
|
|
|
presentFragment(chatActivity, true);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
chatActivity.showReplyPanel(true, null, fmessages, null, false);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
|
removeSelfFromStack();
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
} else {
|
|
|
|
|
fragment.finishFragment();
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
presentFragment(fragment);
|
2014-06-04 01:31:48 +02:00
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
2014-06-04 01:31:48 +02:00
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
|
for (int a = 1; a >= 0; a--) {
|
|
|
|
|
selectedFiles[a].clear();
|
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
|
cantDeleteMessagesCount = 0;
|
2015-04-09 20:00:14 +02:00
|
|
|
|
actionModeViews.clear();
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
|
final ActionBarMenu menu = actionBar.createMenu();
|
|
|
|
|
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onSearchExpand() {
|
|
|
|
|
dropDownContainer.setVisibility(View.GONE);
|
|
|
|
|
searching = true;
|
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
|
@Override
|
2015-06-29 19:12:11 +02:00
|
|
|
|
public void onSearchCollapse() {
|
2015-04-09 20:00:14 +02:00
|
|
|
|
dropDownContainer.setVisibility(View.VISIBLE);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
if (selectedMode == 1) {
|
|
|
|
|
documentsSearchAdapter.search(null);
|
|
|
|
|
} else if (selectedMode == 3) {
|
|
|
|
|
linksSearchAdapter.search(null);
|
2015-10-29 18:10:07 +01:00
|
|
|
|
} else if (selectedMode == 4) {
|
|
|
|
|
audioSearchAdapter.search(null);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
searching = false;
|
|
|
|
|
searchWas = false;
|
|
|
|
|
switchToCurrentSelectedMode();
|
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void onTextChanged(EditText editText) {
|
|
|
|
|
String text = editText.getText().toString();
|
|
|
|
|
if (text.length() != 0) {
|
|
|
|
|
searchWas = true;
|
|
|
|
|
switchToCurrentSelectedMode();
|
2014-10-07 22:14:27 +02:00
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
|
if (selectedMode == 1) {
|
|
|
|
|
if (documentsSearchAdapter == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
documentsSearchAdapter.search(text);
|
|
|
|
|
} else if (selectedMode == 3) {
|
|
|
|
|
if (linksSearchAdapter == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
linksSearchAdapter.search(text);
|
2015-10-29 18:10:07 +01:00
|
|
|
|
} else if (selectedMode == 4) {
|
|
|
|
|
if (audioSearchAdapter == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
audioSearchAdapter.search(text);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
});
|
|
|
|
|
searchItem.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
|
|
|
|
|
searchItem.setVisibility(View.GONE);
|
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
dropDownContainer = new ActionBarMenuItem(context, menu, 0, 0);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
dropDownContainer.setSubMenuOpenSide(1);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
dropDownContainer.addSubItem(shared_media_item, LocaleController.getString("SharedMediaTitle", R.string.SharedMediaTitle));
|
|
|
|
|
dropDownContainer.addSubItem(files_item, LocaleController.getString("DocumentsTitle", R.string.DocumentsTitle));
|
2015-09-02 00:14:21 +02:00
|
|
|
|
if ((int) dialog_id != 0) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
dropDownContainer.addSubItem(links_item, LocaleController.getString("LinksTitle", R.string.LinksTitle));
|
|
|
|
|
dropDownContainer.addSubItem(music_item, LocaleController.getString("AudioTitle", R.string.AudioTitle));
|
2016-03-06 02:49:31 +01:00
|
|
|
|
} else {
|
|
|
|
|
TLRPC.EncryptedChat currentEncryptedChat = MessagesController.getInstance().getEncryptedChat((int) (dialog_id >> 32));
|
|
|
|
|
if (currentEncryptedChat != null && AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
dropDownContainer.addSubItem(music_item, LocaleController.getString("AudioTitle", R.string.AudioTitle));
|
2016-03-06 02:49:31 +01:00
|
|
|
|
}
|
2015-09-02 00:14:21 +02:00
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
actionBar.addView(dropDownContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 64 : 56, 0, 40, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
dropDownContainer.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
dropDownContainer.toggleSubMenu();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dropDown = new TextView(context);
|
|
|
|
|
dropDown.setGravity(Gravity.LEFT);
|
|
|
|
|
dropDown.setSingleLine(true);
|
|
|
|
|
dropDown.setLines(1);
|
|
|
|
|
dropDown.setMaxLines(1);
|
|
|
|
|
dropDown.setEllipsize(TextUtils.TruncateAt.END);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
dropDown.setTextColor(Theme.getColor(Theme.key_actionBarDefaultTitle));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
2017-03-31 01:58:05 +02:00
|
|
|
|
dropDownDrawable = context.getResources().getDrawable(R.drawable.ic_arrow_drop_down).mutate();
|
|
|
|
|
dropDownDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_actionBarDefaultTitle), PorterDuff.Mode.MULTIPLY));
|
|
|
|
|
dropDown.setCompoundDrawablesWithIntrinsicBounds(null, null, dropDownDrawable, null);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
|
|
|
|
|
dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
|
2015-07-22 20:56:37 +02:00
|
|
|
|
dropDownContainer.addView(dropDown, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 16, 0, 0, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
|
|
final ActionBarMenu actionMode = actionBar.createActionMode();
|
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
|
selectedMessagesCountTextView = new NumberTextView(actionMode.getContext());
|
2015-04-09 20:00:14 +02:00
|
|
|
|
selectedMessagesCountTextView.setTextSize(18);
|
|
|
|
|
selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
2017-03-31 01:58:05 +02:00
|
|
|
|
selectedMessagesCountTextView.setTextColor(Theme.getColor(Theme.key_actionBarActionModeDefaultIcon));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
2015-10-29 18:10:07 +01:00
|
|
|
|
actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
|
|
if ((int) dialog_id != 0) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
actionModeViews.add(actionMode.addItemWithWidth(forward, R.drawable.ic_ab_forward, AndroidUtilities.dp(54)));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
actionModeViews.add(actionMode.addItemWithWidth(delete, R.drawable.ic_ab_delete, AndroidUtilities.dp(54)));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
|
|
photoVideoAdapter = new SharedPhotoVideoAdapter(context);
|
2015-10-29 18:10:07 +01:00
|
|
|
|
documentsAdapter = new SharedDocumentsAdapter(context, 1);
|
|
|
|
|
audioAdapter = new SharedDocumentsAdapter(context, 4);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
documentsSearchAdapter = new MediaSearchAdapter(context, 1);
|
2015-10-29 18:10:07 +01:00
|
|
|
|
audioSearchAdapter = new MediaSearchAdapter(context, 4);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
linksSearchAdapter = new MediaSearchAdapter(context, 3);
|
|
|
|
|
linksAdapter = new SharedLinksAdapter(context);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
|
|
FrameLayout frameLayout;
|
|
|
|
|
fragmentView = frameLayout = new FrameLayout(context);
|
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
int scrollToPositionOnRecreate = -1;
|
|
|
|
|
int scrollToOffsetOnRecreate = 0;
|
|
|
|
|
if (layoutManager != null) {
|
|
|
|
|
scrollToPositionOnRecreate = layoutManager.findFirstVisibleItemPosition();
|
|
|
|
|
if (scrollToPositionOnRecreate != layoutManager.getItemCount() - 1) {
|
|
|
|
|
RecyclerListView.Holder holder = (RecyclerListView.Holder) listView.findViewHolderForAdapterPosition(scrollToPositionOnRecreate);
|
|
|
|
|
if (holder != null) {
|
|
|
|
|
scrollToOffsetOnRecreate = holder.itemView.getTop();
|
|
|
|
|
} else {
|
|
|
|
|
scrollToPositionOnRecreate = -1;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
scrollToPositionOnRecreate = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listView = new RecyclerListView(context);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
listView.setClipToPadding(false);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
listView.setSectionsType(2);
|
|
|
|
|
listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
|
2015-07-22 20:56:37 +02:00
|
|
|
|
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2017-03-31 01:58:05 +02:00
|
|
|
|
listView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
|
2015-04-09 20:00:14 +02:00
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public void onItemClick(View view, int position) {
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if ((selectedMode == 1 || selectedMode == 4) && view instanceof SharedDocumentCell) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
MediaActivity.this.onItemClick(position, view, ((SharedDocumentCell) view).getMessage(), 0);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
} else if (selectedMode == 3 && view instanceof SharedLinkCell) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
MediaActivity.this.onItemClick(position, view, ((SharedLinkCell) view).getMessage(), 0);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
}
|
|
|
|
|
});
|
2017-03-31 01:58:05 +02:00
|
|
|
|
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
2015-04-09 20:00:14 +02:00
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
|
|
|
|
if (newState == RecyclerView.SCROLL_STATE_DRAGGING && searching && searchWas) {
|
2015-04-09 20:00:14 +02:00
|
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
scrolling = newState != RecyclerView.SCROLL_STATE_IDLE;
|
2015-04-09 20:00:14 +02:00
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
2015-04-09 20:00:14 +02:00
|
|
|
|
if (searching && searchWas) {
|
|
|
|
|
return;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
|
|
|
|
|
int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
|
|
|
|
|
int totalItemCount = recyclerView.getAdapter().getItemCount();
|
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
|
if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2 && !sharedMediaData[selectedMode].loading) {
|
2015-04-09 20:00:14 +02:00
|
|
|
|
int type;
|
|
|
|
|
if (selectedMode == 0) {
|
|
|
|
|
type = SharedMediaQuery.MEDIA_PHOTOVIDEO;
|
|
|
|
|
} else if (selectedMode == 1) {
|
|
|
|
|
type = SharedMediaQuery.MEDIA_FILE;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
} else if (selectedMode == 2) {
|
2015-04-09 20:00:14 +02:00
|
|
|
|
type = SharedMediaQuery.MEDIA_AUDIO;
|
2015-10-29 18:10:07 +01:00
|
|
|
|
} else if (selectedMode == 4) {
|
|
|
|
|
type = SharedMediaQuery.MEDIA_MUSIC;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
} else {
|
|
|
|
|
type = SharedMediaQuery.MEDIA_URL;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
|
if (!sharedMediaData[selectedMode].endReached[0]) {
|
|
|
|
|
sharedMediaData[selectedMode].loading = true;
|
|
|
|
|
SharedMediaQuery.loadMedia(dialog_id, 0, 50, sharedMediaData[selectedMode].max_id[0], type, true, classGuid);
|
|
|
|
|
} else if (mergeDialogId != 0 && !sharedMediaData[selectedMode].endReached[1]) {
|
|
|
|
|
sharedMediaData[selectedMode].loading = true;
|
|
|
|
|
SharedMediaQuery.loadMedia(mergeDialogId, 0, 50, sharedMediaData[selectedMode].max_id[1], type, true, classGuid);
|
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
});
|
2017-03-31 01:58:05 +02:00
|
|
|
|
listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
|
2015-04-09 20:00:14 +02:00
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public boolean onItemClick(View view, int position) {
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if ((selectedMode == 1 || selectedMode == 4) && view instanceof SharedDocumentCell) {
|
2015-04-09 20:00:14 +02:00
|
|
|
|
SharedDocumentCell cell = (SharedDocumentCell) view;
|
2016-04-22 15:49:00 +02:00
|
|
|
|
MessageObject message = cell.getMessage();
|
2015-04-09 20:00:14 +02:00
|
|
|
|
return MediaActivity.this.onItemLongClick(message, view, 0);
|
2015-09-02 00:14:21 +02:00
|
|
|
|
} else if (selectedMode == 3 && view instanceof SharedLinkCell) {
|
|
|
|
|
SharedLinkCell cell = (SharedLinkCell) view;
|
|
|
|
|
MessageObject message = cell.getMessage();
|
|
|
|
|
return MediaActivity.this.onItemLongClick(message, view, 0);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
return false;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
});
|
2017-03-31 01:58:05 +02:00
|
|
|
|
if (scrollToPositionOnRecreate != -1) {
|
|
|
|
|
layoutManager.scrollToPositionWithOffset(scrollToPositionOnRecreate, scrollToOffsetOnRecreate);
|
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
|
|
for (int a = 0; a < 6; a++) {
|
|
|
|
|
cellCache.add(new SharedPhotoVideoCell(context));
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
|
|
emptyView = new LinearLayout(context);
|
|
|
|
|
emptyView.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
emptyView.setGravity(Gravity.CENTER);
|
|
|
|
|
emptyView.setVisibility(View.GONE);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
emptyView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
|
2015-07-22 20:56:37 +02:00
|
|
|
|
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
emptyView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
emptyImageView = new ImageView(context);
|
2015-07-22 20:56:37 +02:00
|
|
|
|
emptyView.addView(emptyImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
|
|
emptyTextView = new TextView(context);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
emptyTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
emptyTextView.setGravity(Gravity.CENTER);
|
|
|
|
|
emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
|
|
|
|
|
emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), AndroidUtilities.dp(128));
|
2015-07-22 20:56:37 +02:00
|
|
|
|
emptyView.addView(emptyTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 24, 0, 0));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
|
|
progressView = new LinearLayout(context);
|
|
|
|
|
progressView.setGravity(Gravity.CENTER);
|
|
|
|
|
progressView.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
progressView.setVisibility(View.GONE);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
progressView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
|
2015-07-22 20:56:37 +02:00
|
|
|
|
frameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
progressBar = new RadialProgressView(context);
|
2015-07-22 20:56:37 +02:00
|
|
|
|
progressView.addView(progressBar, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
|
|
switchToCurrentSelectedMode();
|
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if (!AndroidUtilities.isTablet()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
frameLayout.addView(fragmentContextView = new FragmentContextView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0));
|
2015-10-29 18:10:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
|
return fragmentView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 16:24:33 +02:00
|
|
|
|
if (id == NotificationCenter.mediaDidLoaded) {
|
2015-02-01 19:51:02 +01:00
|
|
|
|
long uid = (Long) args[0];
|
2015-09-24 22:52:02 +02:00
|
|
|
|
int guid = (Integer) args[3];
|
2015-11-26 22:04:02 +01:00
|
|
|
|
if (guid == classGuid) {
|
2015-09-24 22:52:02 +02:00
|
|
|
|
int type = (Integer) args[4];
|
2015-02-01 19:51:02 +01:00
|
|
|
|
sharedMediaData[type].loading = false;
|
|
|
|
|
sharedMediaData[type].totalCount = (Integer) args[1];
|
|
|
|
|
ArrayList<MessageObject> arr = (ArrayList<MessageObject>) args[2];
|
|
|
|
|
boolean enc = ((int) dialog_id) == 0;
|
2015-11-26 22:04:02 +01:00
|
|
|
|
int loadIndex = uid == dialog_id ? 0 : 1;
|
|
|
|
|
for (int a = 0; a < arr.size(); a++) {
|
|
|
|
|
MessageObject message = arr.get(a);
|
2015-09-24 22:52:02 +02:00
|
|
|
|
sharedMediaData[type].addMessage(message, false, enc);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
|
sharedMediaData[type].endReached[loadIndex] = (Boolean) args[5];
|
2017-07-08 18:32:04 +02:00
|
|
|
|
if (loadIndex == 0 && sharedMediaData[type].endReached[loadIndex] && mergeDialogId != 0) {
|
|
|
|
|
sharedMediaData[type].loading = true;
|
|
|
|
|
SharedMediaQuery.loadMedia(mergeDialogId, 0, 50, sharedMediaData[type].max_id[1], type, true, classGuid);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
|
if (!sharedMediaData[type].loading) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
if (progressView != null) {
|
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
if (selectedMode == type && listView != null) {
|
|
|
|
|
if (listView.getEmptyView() == null) {
|
|
|
|
|
listView.setEmptyView(emptyView);
|
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
scrolling = true;
|
|
|
|
|
if (selectedMode == 0 && type == 0) {
|
|
|
|
|
if (photoVideoAdapter != null) {
|
|
|
|
|
photoVideoAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
} else if (selectedMode == 1 && type == 1) {
|
|
|
|
|
if (documentsAdapter != null) {
|
|
|
|
|
documentsAdapter.notifyDataSetChanged();
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
} else if (selectedMode == 3 && type == 3) {
|
2015-08-13 11:23:31 +02:00
|
|
|
|
if (linksAdapter != null) {
|
|
|
|
|
linksAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
} else if (selectedMode == 4 && type == 4) {
|
|
|
|
|
if (audioAdapter != null) {
|
|
|
|
|
audioAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if (selectedMode == 1 || selectedMode == 3 || selectedMode == 4) {
|
2017-07-08 18:32:04 +02:00
|
|
|
|
searchItem.setVisibility(!sharedMediaData[type].messages.isEmpty() && !searching ? View.VISIBLE : View.GONE);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
|
} else if (id == NotificationCenter.messagesDeleted) {
|
2015-09-24 22:52:02 +02:00
|
|
|
|
TLRPC.Chat currentChat = null;
|
|
|
|
|
if ((int) dialog_id < 0) {
|
|
|
|
|
currentChat = MessagesController.getInstance().getChat(-(int) dialog_id);
|
|
|
|
|
}
|
|
|
|
|
int channelId = (Integer) args[1];
|
2015-11-26 22:04:02 +01:00
|
|
|
|
int loadIndex = 0;
|
2015-09-24 22:52:02 +02:00
|
|
|
|
if (ChatObject.isChannel(currentChat)) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
if (channelId == 0 && mergeDialogId != 0) {
|
|
|
|
|
loadIndex = 1;
|
|
|
|
|
} else if (channelId == currentChat.id) {
|
|
|
|
|
loadIndex = 0;
|
|
|
|
|
} else {
|
2015-09-24 22:52:02 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} else if (channelId != 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
ArrayList<Integer> markAsDeletedMessages = (ArrayList<Integer>) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
|
boolean updated = false;
|
|
|
|
|
for (Integer ids : markAsDeletedMessages) {
|
2015-02-01 19:51:02 +01:00
|
|
|
|
for (SharedMediaData data : sharedMediaData) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
if (data.deleteMessage(ids, loadIndex)) {
|
2015-02-01 19:51:02 +01:00
|
|
|
|
updated = true;
|
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (updated) {
|
2015-02-01 19:51:02 +01:00
|
|
|
|
scrolling = true;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (photoVideoAdapter != null) {
|
|
|
|
|
photoVideoAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
if (documentsAdapter != null) {
|
|
|
|
|
documentsAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
|
if (linksAdapter != null) {
|
|
|
|
|
linksAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if (audioAdapter != null) {
|
|
|
|
|
audioAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
if (selectedMode == 1 || selectedMode == 3 || selectedMode == 4) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
searchItem.setVisibility(!sharedMediaData[selectedMode].messages.isEmpty() && !searching ? View.VISIBLE : View.GONE);
|
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
|
} else if (id == NotificationCenter.didReceivedNewMessages) {
|
2015-02-01 19:51:02 +01:00
|
|
|
|
long uid = (Long) args[0];
|
2013-10-25 17:19:00 +02:00
|
|
|
|
if (uid == dialog_id) {
|
2015-02-01 19:51:02 +01:00
|
|
|
|
ArrayList<MessageObject> arr = (ArrayList<MessageObject>) args[1];
|
2015-02-26 02:32:51 +01:00
|
|
|
|
boolean enc = ((int) dialog_id) == 0;
|
|
|
|
|
boolean updated = false;
|
2017-07-23 14:56:38 +02:00
|
|
|
|
for (int a = 0; a < arr.size(); a++) {
|
|
|
|
|
MessageObject obj = arr.get(a);
|
|
|
|
|
if (obj.messageOwner.media == null || obj.isSecretPhoto()) {
|
2013-10-25 17:19:00 +02:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
int type = SharedMediaQuery.getMediaType(obj.messageOwner);
|
|
|
|
|
if (type == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (sharedMediaData[type].addMessage(obj, true, enc)) {
|
|
|
|
|
updated = true;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (updated) {
|
2015-02-01 19:51:02 +01:00
|
|
|
|
scrolling = true;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (photoVideoAdapter != null) {
|
|
|
|
|
photoVideoAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
if (documentsAdapter != null) {
|
|
|
|
|
documentsAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
|
if (linksAdapter != null) {
|
|
|
|
|
linksAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if (audioAdapter != null) {
|
|
|
|
|
audioAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
if (selectedMode == 1 || selectedMode == 3 || selectedMode == 4) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
searchItem.setVisibility(!sharedMediaData[selectedMode].messages.isEmpty() && !searching ? View.VISIBLE : View.GONE);
|
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
|
} else if (id == NotificationCenter.messageReceivedByServer) {
|
2015-02-01 19:51:02 +01:00
|
|
|
|
Integer msgId = (Integer) args[0];
|
2015-02-26 02:32:51 +01:00
|
|
|
|
Integer newMsgId = (Integer) args[1];
|
2015-02-01 19:51:02 +01:00
|
|
|
|
for (SharedMediaData data : sharedMediaData) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
data.replaceMid(msgId, newMsgId);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 00:14:21 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void onPause() {
|
|
|
|
|
super.onPause();
|
|
|
|
|
if (dropDownContainer != null) {
|
|
|
|
|
dropDownContainer.closeSubMenu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void onResume() {
|
2014-06-04 18:00:42 +02:00
|
|
|
|
super.onResume();
|
2015-02-26 02:32:51 +01:00
|
|
|
|
scrolling = true;
|
|
|
|
|
if (photoVideoAdapter != null) {
|
|
|
|
|
photoVideoAdapter.notifyDataSetChanged();
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
if (documentsAdapter != null) {
|
|
|
|
|
documentsAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
|
if (linksAdapter != null) {
|
|
|
|
|
linksAdapter.notifyDataSetChanged();
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
fixLayoutInternal();
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
|
super.onConfigurationChanged(newConfig);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (listView != null) {
|
|
|
|
|
ViewTreeObserver obs = listView.getViewTreeObserver();
|
|
|
|
|
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onPreDraw() {
|
|
|
|
|
listView.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
|
|
fixLayoutInternal();
|
2015-06-29 19:12:11 +02:00
|
|
|
|
return true;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updatePhotoAtIndex(int index) {
|
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
|
@Override
|
|
|
|
|
public boolean scaleToFill() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
|
@Override
|
2014-06-12 03:13:15 +02:00
|
|
|
|
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (messageObject == null || listView == null || selectedMode != 0) {
|
2014-06-11 01:05:54 +02:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
|
|
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
|
View view = listView.getChildAt(a);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (view instanceof SharedPhotoVideoCell) {
|
|
|
|
|
SharedPhotoVideoCell cell = (SharedPhotoVideoCell) view;
|
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
|
MessageObject message = cell.getMessageObject(i);
|
|
|
|
|
if (message == null) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
BackupImageView imageView = cell.getImageView(i);
|
2015-03-19 00:09:45 +01:00
|
|
|
|
if (message.getId() == messageObject.getId()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
int coords[] = new int[2];
|
|
|
|
|
imageView.getLocationInWindow(coords);
|
|
|
|
|
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
|
|
|
|
|
object.viewX = coords[0];
|
2016-10-11 13:57:01 +02:00
|
|
|
|
object.viewY = coords[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
object.parentView = listView;
|
2015-04-09 20:00:14 +02:00
|
|
|
|
object.imageReceiver = imageView.getImageReceiver();
|
2015-02-26 02:32:51 +01:00
|
|
|
|
object.thumb = object.imageReceiver.getBitmap();
|
2015-11-26 22:04:02 +01:00
|
|
|
|
object.parentView.getLocationInWindow(coords);
|
|
|
|
|
object.clipTopAddition = AndroidUtilities.dp(40);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
return object;
|
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
2014-06-11 02:22:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
|
@Override
|
|
|
|
|
public Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
|
@Override
|
|
|
|
|
public boolean allowCaption() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-11 02:22:42 +02:00
|
|
|
|
@Override
|
2014-06-12 03:13:15 +02:00
|
|
|
|
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) { }
|
2014-06-11 01:05:54 +02:00
|
|
|
|
|
2014-06-12 03:13:15 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void willHidePhotoViewer() { }
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isPhotoChecked(int index) { return false; }
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-07-08 18:32:04 +02:00
|
|
|
|
public void setPhotoChecked(int index, VideoEditedInfo videoEditedInfo) { }
|
2014-06-12 03:13:15 +02:00
|
|
|
|
|
|
|
|
|
@Override
|
2015-10-29 18:10:07 +01:00
|
|
|
|
public boolean cancelButtonPressed() { return true; }
|
2014-06-12 03:13:15 +02:00
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo) { }
|
2014-06-12 03:13:15 +02:00
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getSelectedCount() { return 0; }
|
2014-06-11 01:05:54 +02:00
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
|
public void setChatInfo(TLRPC.ChatFull chatInfo) {
|
|
|
|
|
info = chatInfo;
|
|
|
|
|
if (info != null && info.migrated_from_chat_id != 0) {
|
|
|
|
|
mergeDialogId = -info.migrated_from_chat_id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
|
public void setMergeDialogId(long did) {
|
|
|
|
|
mergeDialogId = did;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
|
private void switchToCurrentSelectedMode() {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (searching && searchWas) {
|
|
|
|
|
if (listView != null) {
|
2015-08-13 11:23:31 +02:00
|
|
|
|
if (selectedMode == 1) {
|
|
|
|
|
listView.setAdapter(documentsSearchAdapter);
|
|
|
|
|
documentsSearchAdapter.notifyDataSetChanged();
|
|
|
|
|
} else if (selectedMode == 3) {
|
|
|
|
|
listView.setAdapter(linksSearchAdapter);
|
|
|
|
|
linksSearchAdapter.notifyDataSetChanged();
|
2015-10-29 18:10:07 +01:00
|
|
|
|
} else if (selectedMode == 4) {
|
|
|
|
|
listView.setAdapter(audioSearchAdapter);
|
|
|
|
|
audioSearchAdapter.notifyDataSetChanged();
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (emptyTextView != null) {
|
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
|
|
|
|
|
emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
|
|
|
|
emptyImageView.setVisibility(View.GONE);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
} else {
|
|
|
|
|
emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
|
|
|
|
|
emptyImageView.setVisibility(View.VISIBLE);
|
|
|
|
|
if (selectedMode == 0) {
|
|
|
|
|
listView.setAdapter(photoVideoAdapter);
|
2015-02-27 20:57:58 +01:00
|
|
|
|
dropDown.setText(LocaleController.getString("SharedMediaTitle", R.string.SharedMediaTitle));
|
2015-02-26 02:32:51 +01:00
|
|
|
|
emptyImageView.setImageResource(R.drawable.tip1);
|
2016-03-16 13:26:32 +01:00
|
|
|
|
if ((int) dialog_id == 0) {
|
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoMediaSecret", R.string.NoMediaSecret));
|
|
|
|
|
} else {
|
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoMedia", R.string.NoMedia));
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
searchItem.setVisibility(View.GONE);
|
|
|
|
|
if (sharedMediaData[selectedMode].loading && sharedMediaData[selectedMode].messages.isEmpty()) {
|
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
|
listView.setEmptyView(null);
|
|
|
|
|
emptyView.setVisibility(View.GONE);
|
|
|
|
|
} else {
|
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
|
listView.setEmptyView(emptyView);
|
|
|
|
|
}
|
|
|
|
|
listView.setVisibility(View.VISIBLE);
|
|
|
|
|
listView.setPadding(0, 0, 0, AndroidUtilities.dp(4));
|
2015-10-29 18:10:07 +01:00
|
|
|
|
} else if (selectedMode == 1 || selectedMode == 4) {
|
|
|
|
|
if (selectedMode == 1) {
|
|
|
|
|
listView.setAdapter(documentsAdapter);
|
|
|
|
|
dropDown.setText(LocaleController.getString("DocumentsTitle", R.string.DocumentsTitle));
|
|
|
|
|
emptyImageView.setImageResource(R.drawable.tip2);
|
2016-03-16 13:26:32 +01:00
|
|
|
|
if ((int) dialog_id == 0) {
|
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoSharedFilesSecret", R.string.NoSharedFilesSecret));
|
|
|
|
|
} else {
|
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoSharedFiles", R.string.NoSharedFiles));
|
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
} else if (selectedMode == 4) {
|
|
|
|
|
listView.setAdapter(audioAdapter);
|
|
|
|
|
dropDown.setText(LocaleController.getString("AudioTitle", R.string.AudioTitle));
|
|
|
|
|
emptyImageView.setImageResource(R.drawable.tip4);
|
2016-03-16 13:26:32 +01:00
|
|
|
|
if ((int) dialog_id == 0) {
|
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoSharedAudioSecret", R.string.NoSharedAudioSecret));
|
|
|
|
|
} else {
|
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoSharedAudio", R.string.NoSharedAudio));
|
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
|
searchItem.setVisibility(!sharedMediaData[selectedMode].messages.isEmpty() ? View.VISIBLE : View.GONE);
|
2015-11-26 22:04:02 +01:00
|
|
|
|
if (!sharedMediaData[selectedMode].loading && !sharedMediaData[selectedMode].endReached[0] && sharedMediaData[selectedMode].messages.isEmpty()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
sharedMediaData[selectedMode].loading = true;
|
2015-10-29 18:10:07 +01:00
|
|
|
|
SharedMediaQuery.loadMedia(dialog_id, 0, 50, 0, selectedMode == 1 ? SharedMediaQuery.MEDIA_FILE : SharedMediaQuery.MEDIA_MUSIC, true, classGuid);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
listView.setVisibility(View.VISIBLE);
|
|
|
|
|
if (sharedMediaData[selectedMode].loading && sharedMediaData[selectedMode].messages.isEmpty()) {
|
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
|
listView.setEmptyView(null);
|
|
|
|
|
emptyView.setVisibility(View.GONE);
|
|
|
|
|
} else {
|
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
|
listView.setEmptyView(emptyView);
|
|
|
|
|
}
|
|
|
|
|
listView.setPadding(0, 0, 0, AndroidUtilities.dp(4));
|
2015-08-13 11:23:31 +02:00
|
|
|
|
} else if (selectedMode == 3) {
|
|
|
|
|
listView.setAdapter(linksAdapter);
|
|
|
|
|
dropDown.setText(LocaleController.getString("LinksTitle", R.string.LinksTitle));
|
2015-09-02 00:14:21 +02:00
|
|
|
|
emptyImageView.setImageResource(R.drawable.tip3);
|
2016-03-16 13:26:32 +01:00
|
|
|
|
if ((int) dialog_id == 0) {
|
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoSharedLinksSecret", R.string.NoSharedLinksSecret));
|
|
|
|
|
} else {
|
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoSharedLinks", R.string.NoSharedLinks));
|
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
|
searchItem.setVisibility(!sharedMediaData[3].messages.isEmpty() ? View.VISIBLE : View.GONE);
|
2015-11-26 22:04:02 +01:00
|
|
|
|
if (!sharedMediaData[selectedMode].loading && !sharedMediaData[selectedMode].endReached[0] && sharedMediaData[selectedMode].messages.isEmpty()) {
|
2015-08-13 11:23:31 +02:00
|
|
|
|
sharedMediaData[selectedMode].loading = true;
|
2015-09-02 00:14:21 +02:00
|
|
|
|
SharedMediaQuery.loadMedia(dialog_id, 0, 50, 0, SharedMediaQuery.MEDIA_URL, true, classGuid);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
|
|
|
|
listView.setVisibility(View.VISIBLE);
|
|
|
|
|
if (sharedMediaData[selectedMode].loading && sharedMediaData[selectedMode].messages.isEmpty()) {
|
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
|
listView.setEmptyView(null);
|
|
|
|
|
emptyView.setVisibility(View.GONE);
|
|
|
|
|
} else {
|
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
|
listView.setEmptyView(emptyView);
|
|
|
|
|
}
|
|
|
|
|
listView.setPadding(0, 0, 0, AndroidUtilities.dp(4));
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
|
private boolean onItemLongClick(MessageObject item, View view, int a) {
|
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
|
|
|
|
selectedFiles[item.getDialogId() == dialog_id ? 0 : 1].put(item.getId(), item);
|
2015-09-24 22:52:02 +02:00
|
|
|
|
if (!item.canDeleteMessage(null)) {
|
|
|
|
|
cantDeleteMessagesCount++;
|
|
|
|
|
}
|
|
|
|
|
actionBar.createActionMode().getItem(delete).setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
|
2015-10-29 18:10:07 +01:00
|
|
|
|
selectedMessagesCountTextView.setNumber(1, false);
|
2016-06-24 12:27:15 +02:00
|
|
|
|
AnimatorSet animatorSet = new AnimatorSet();
|
|
|
|
|
ArrayList<Animator> animators = new ArrayList<>();
|
|
|
|
|
for (int i = 0; i < actionModeViews.size(); i++) {
|
|
|
|
|
View view2 = actionModeViews.get(i);
|
|
|
|
|
AndroidUtilities.clearDrawableAnimation(view2);
|
|
|
|
|
animators.add(ObjectAnimator.ofFloat(view2, "scaleY", 0.1f, 1.0f));
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
|
animatorSet.playTogether(animators);
|
|
|
|
|
animatorSet.setDuration(250);
|
|
|
|
|
animatorSet.start();
|
2015-02-26 02:32:51 +01:00
|
|
|
|
scrolling = false;
|
|
|
|
|
if (view instanceof SharedDocumentCell) {
|
|
|
|
|
((SharedDocumentCell) view).setChecked(true, true);
|
|
|
|
|
} else if (view instanceof SharedPhotoVideoCell) {
|
|
|
|
|
((SharedPhotoVideoCell) view).setChecked(a, true, true);
|
2015-09-02 00:14:21 +02:00
|
|
|
|
} else if (view instanceof SharedLinkCell) {
|
|
|
|
|
((SharedLinkCell) view).setChecked(true, true);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
actionBar.showActionMode();
|
|
|
|
|
return true;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
|
private void onItemClick(int index, View view, MessageObject message, int a) {
|
|
|
|
|
if (message == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
int loadIndex = message.getDialogId() == dialog_id ? 0 : 1;
|
|
|
|
|
if (selectedFiles[loadIndex].containsKey(message.getId())) {
|
|
|
|
|
selectedFiles[loadIndex].remove(message.getId());
|
2015-09-24 22:52:02 +02:00
|
|
|
|
if (!message.canDeleteMessage(null)) {
|
|
|
|
|
cantDeleteMessagesCount--;
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
if (selectedFiles[0].size() + selectedFiles[1].size() >= 100) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
|
selectedFiles[loadIndex].put(message.getId(), message);
|
2015-09-24 22:52:02 +02:00
|
|
|
|
if (!message.canDeleteMessage(null)) {
|
|
|
|
|
cantDeleteMessagesCount++;
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
|
if (selectedFiles[0].isEmpty() && selectedFiles[1].isEmpty()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
actionBar.hideActionMode();
|
|
|
|
|
} else {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
selectedMessagesCountTextView.setNumber(selectedFiles[0].size() + selectedFiles[1].size(), true);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
|
actionBar.createActionMode().getItem(delete).setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
scrolling = false;
|
|
|
|
|
if (view instanceof SharedDocumentCell) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
((SharedDocumentCell) view).setChecked(selectedFiles[loadIndex].containsKey(message.getId()), true);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
} else if (view instanceof SharedPhotoVideoCell) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
((SharedPhotoVideoCell) view).setChecked(a, selectedFiles[loadIndex].containsKey(message.getId()), true);
|
2015-09-02 00:14:21 +02:00
|
|
|
|
} else if (view instanceof SharedLinkCell) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
((SharedLinkCell) view).setChecked(selectedFiles[loadIndex].containsKey(message.getId()), true);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (selectedMode == 0) {
|
|
|
|
|
PhotoViewer.getInstance().setParentActivity(getParentActivity());
|
2015-11-26 22:04:02 +01:00
|
|
|
|
PhotoViewer.getInstance().openPhoto(sharedMediaData[selectedMode].messages, index, dialog_id, mergeDialogId, this);
|
2015-10-29 18:10:07 +01:00
|
|
|
|
} else if (selectedMode == 1 || selectedMode == 4) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (view instanceof SharedDocumentCell) {
|
|
|
|
|
SharedDocumentCell cell = (SharedDocumentCell) view;
|
|
|
|
|
if (cell.isLoaded()) {
|
2015-07-22 20:56:37 +02:00
|
|
|
|
if (message.isMusic()) {
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if (MediaController.getInstance().setPlaylist(sharedMediaData[selectedMode].messages, message)) {
|
2015-07-22 20:56:37 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
File f = null;
|
2016-04-22 15:49:00 +02:00
|
|
|
|
String fileName = message.messageOwner.media != null ? FileLoader.getAttachFileName(message.getDocument()) : "";
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (message.messageOwner.attachPath != null && message.messageOwner.attachPath.length() != 0) {
|
|
|
|
|
f = new File(message.messageOwner.attachPath);
|
2014-09-24 04:17:27 +02:00
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (f == null || f != null && !f.exists()) {
|
|
|
|
|
f = FileLoader.getPathToMessage(message.messageOwner);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (f != null && f.exists()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
if (f.getName().endsWith("attheme")) {
|
|
|
|
|
Theme.ThemeInfo themeInfo = Theme.applyThemeFile(f, message.getDocumentName(), true);
|
|
|
|
|
if (themeInfo != null) {
|
|
|
|
|
presentFragment(new ThemePreviewActivity(f, themeInfo));
|
2015-02-26 02:32:51 +01:00
|
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
|
builder.setMessage(LocaleController.getString("IncorrectTheme", R.string.IncorrectTheme));
|
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
|
showDialog(builder.create());
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
} else {
|
|
|
|
|
String realMimeType = null;
|
|
|
|
|
try {
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
|
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
|
|
|
MimeTypeMap myMime = MimeTypeMap.getSingleton();
|
|
|
|
|
int idx = fileName.lastIndexOf('.');
|
|
|
|
|
if (idx != -1) {
|
|
|
|
|
String ext = fileName.substring(idx + 1);
|
|
|
|
|
realMimeType = myMime.getMimeTypeFromExtension(ext.toLowerCase());
|
|
|
|
|
if (realMimeType == null) {
|
|
|
|
|
realMimeType = message.getDocument().mime_type;
|
|
|
|
|
if (realMimeType == null || realMimeType.length() == 0) {
|
|
|
|
|
realMimeType = null;
|
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
}
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
|
|
|
intent.setDataAndType(FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", f), realMimeType != null ? realMimeType : "text/plain");
|
|
|
|
|
} else {
|
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), realMimeType != null ? realMimeType : "text/plain");
|
|
|
|
|
}
|
|
|
|
|
if (realMimeType != null) {
|
|
|
|
|
try {
|
|
|
|
|
getParentActivity().startActivityForResult(intent, 500);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 24) {
|
|
|
|
|
intent.setDataAndType(FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", f), "text/plain");
|
|
|
|
|
} else {
|
|
|
|
|
intent.setDataAndType(Uri.fromFile(f), "text/plain");
|
|
|
|
|
}
|
|
|
|
|
getParentActivity().startActivityForResult(intent, 500);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
getParentActivity().startActivityForResult(intent, 500);
|
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
|
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
|
|
|
|
|
builder.setMessage(LocaleController.formatString("NoHandleAppInstalled", R.string.NoHandleAppInstalled, message.getDocument().mime_type));
|
|
|
|
|
showDialog(builder.create());
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
} else if (!cell.isLoading()) {
|
2017-07-23 14:56:38 +02:00
|
|
|
|
FileLoader.getInstance().loadFile(cell.getMessage().getDocument(), false, 0);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
cell.updateFileExistIcon();
|
|
|
|
|
} else {
|
2016-04-22 15:49:00 +02:00
|
|
|
|
FileLoader.getInstance().cancelLoadFile(cell.getMessage().getDocument());
|
2015-02-26 02:32:51 +01:00
|
|
|
|
cell.updateFileExistIcon();
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
|
} else if (selectedMode == 3) {
|
|
|
|
|
try {
|
|
|
|
|
TLRPC.WebPage webPage = message.messageOwner.media.webpage;
|
2015-09-02 00:14:21 +02:00
|
|
|
|
String link = null;
|
|
|
|
|
if (webPage != null && !(webPage instanceof TLRPC.TL_webPageEmpty)) {
|
2017-07-23 14:56:38 +02:00
|
|
|
|
if (webPage.embed_url != null && webPage.embed_url.length() != 0) {
|
2015-09-02 00:14:21 +02:00
|
|
|
|
openWebView(webPage);
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
link = webPage.url;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (link == null) {
|
|
|
|
|
link = ((SharedLinkCell) view).getLink(0);
|
|
|
|
|
}
|
|
|
|
|
if (link != null) {
|
2016-04-22 15:49:00 +02:00
|
|
|
|
Browser.openUrl(getParentActivity(), link);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
FileLog.e(e);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 00:14:21 +02:00
|
|
|
|
private void openWebView(TLRPC.WebPage webPage) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
EmbedBottomSheet.show(getParentActivity(), webPage.site_name, webPage.description, webPage.url, webPage.embed_url, webPage.embed_width, webPage.embed_height);
|
2015-09-02 00:14:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
|
private void fixLayoutInternal() {
|
|
|
|
|
if (listView == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
|
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if (!AndroidUtilities.isTablet() && ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
|
selectedMessagesCountTextView.setTextSize(18);
|
|
|
|
|
} else {
|
|
|
|
|
selectedMessagesCountTextView.setTextSize(20);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
|
columnsCount = 4;
|
|
|
|
|
emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), AndroidUtilities.dp(128));
|
|
|
|
|
} else {
|
|
|
|
|
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
|
|
|
|
|
columnsCount = 6;
|
|
|
|
|
emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), 0);
|
|
|
|
|
} else {
|
|
|
|
|
columnsCount = 4;
|
|
|
|
|
emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), AndroidUtilities.dp(128));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
photoVideoAdapter.notifyDataSetChanged();
|
|
|
|
|
|
|
|
|
|
if (dropDownContainer != null) {
|
|
|
|
|
if (!AndroidUtilities.isTablet()) {
|
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
|
|
|
|
|
layoutParams.topMargin = (Build.VERSION.SDK_INT >= 21 ? AndroidUtilities.statusBarHeight : 0);
|
|
|
|
|
dropDownContainer.setLayoutParams(layoutParams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!AndroidUtilities.isTablet() && ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
|
dropDown.setTextSize(18);
|
|
|
|
|
} else {
|
|
|
|
|
dropDown.setTextSize(20);
|
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
private class SharedLinksAdapter extends RecyclerListView.SectionsAdapter {
|
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
|
|
public SharedLinksAdapter(Context context) {
|
|
|
|
|
mContext = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Object getItem(int section, int position) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public boolean isEnabled(int section, int row) {
|
2015-08-13 11:23:31 +02:00
|
|
|
|
return row != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getSectionCount() {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
return sharedMediaData[3].sections.size() + (sharedMediaData[3].sections.isEmpty() || sharedMediaData[3].endReached[0] && sharedMediaData[3].endReached[1] ? 0 : 1);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getCountForSection(int section) {
|
|
|
|
|
if (section < sharedMediaData[3].sections.size()) {
|
|
|
|
|
return sharedMediaData[3].sectionArrays.get(sharedMediaData[3].sections.get(section)).size() + 1;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public View getSectionHeaderView(int section, View view) {
|
|
|
|
|
if (view == null) {
|
|
|
|
|
view = new GraySectionCell(mContext);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
|
|
|
|
if (section < sharedMediaData[3].sections.size()) {
|
|
|
|
|
String name = sharedMediaData[3].sections.get(section);
|
|
|
|
|
ArrayList<MessageObject> messageObjects = sharedMediaData[3].sectionArrays.get(name);
|
|
|
|
|
MessageObject messageObject = messageObjects.get(0);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
((GraySectionCell) view).setText(LocaleController.getInstance().formatterMonthYear.format((long) messageObject.messageOwner.date * 1000).toUpperCase());
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
return view;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
|
View view;
|
|
|
|
|
switch (viewType) {
|
|
|
|
|
case 0:
|
|
|
|
|
view = new GraySectionCell(mContext);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
view = new SharedLinkCell(mContext);
|
|
|
|
|
((SharedLinkCell) view).setDelegate(new SharedLinkCell.SharedLinkCellDelegate() {
|
|
|
|
|
@Override
|
|
|
|
|
public void needOpenWebView(TLRPC.WebPage webPage) {
|
|
|
|
|
MediaActivity.this.openWebView(webPage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canPerformActions() {
|
|
|
|
|
return !actionBar.isActionModeShowed();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
default:
|
|
|
|
|
view = new LoadingCell(mContext);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return new RecyclerListView.Holder(view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(int section, int position, RecyclerView.ViewHolder holder) {
|
|
|
|
|
if (holder.getItemViewType() != 2) {
|
2015-08-13 11:23:31 +02:00
|
|
|
|
String name = sharedMediaData[3].sections.get(section);
|
|
|
|
|
ArrayList<MessageObject> messageObjects = sharedMediaData[3].sectionArrays.get(name);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
switch (holder.getItemViewType()) {
|
|
|
|
|
case 0: {
|
|
|
|
|
MessageObject messageObject = messageObjects.get(0);
|
|
|
|
|
((GraySectionCell) holder.itemView).setText(LocaleController.getInstance().formatterMonthYear.format((long) messageObject.messageOwner.date * 1000).toUpperCase());
|
|
|
|
|
break;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
case 1: {
|
|
|
|
|
SharedLinkCell sharedLinkCell = (SharedLinkCell) holder.itemView;
|
|
|
|
|
MessageObject messageObject = messageObjects.get(position - 1);
|
|
|
|
|
sharedLinkCell.setLink(messageObject, position != messageObjects.size() || section == sharedMediaData[3].sections.size() - 1 && sharedMediaData[3].loading);
|
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
|
|
|
|
sharedLinkCell.setChecked(selectedFiles[messageObject.getDialogId() == dialog_id ? 0 : 1].containsKey(messageObject.getId()), !scrolling);
|
|
|
|
|
} else {
|
|
|
|
|
sharedLinkCell.setChecked(false, !scrolling);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2015-09-02 00:14:21 +02:00
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemViewType(int section, int position) {
|
|
|
|
|
if (section < sharedMediaData[3].sections.size()) {
|
|
|
|
|
if (position == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public String getLetter(int position) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getPositionForScrollProgress(float progress) {
|
|
|
|
|
return 0;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
private class SharedDocumentsAdapter extends RecyclerListView.SectionsAdapter {
|
2015-10-29 18:10:07 +01:00
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
|
private Context mContext;
|
2015-10-29 18:10:07 +01:00
|
|
|
|
private int currentType;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
|
public SharedDocumentsAdapter(Context context, int type) {
|
2015-02-01 19:51:02 +01:00
|
|
|
|
mContext = context;
|
2015-10-29 18:10:07 +01:00
|
|
|
|
currentType = type;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public boolean isEnabled(int section, int row) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
return row != 0;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-02-26 02:32:51 +01:00
|
|
|
|
public int getSectionCount() {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
return sharedMediaData[currentType].sections.size() + (sharedMediaData[currentType].sections.isEmpty() || sharedMediaData[currentType].endReached[0] && sharedMediaData[currentType].endReached[1] ? 0 : 1);
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
@Override
|
|
|
|
|
public Object getItem(int section, int position) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
|
@Override
|
2015-02-26 02:32:51 +01:00
|
|
|
|
public int getCountForSection(int section) {
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if (section < sharedMediaData[currentType].sections.size()) {
|
|
|
|
|
return sharedMediaData[currentType].sectionArrays.get(sharedMediaData[currentType].sections.get(section)).size() + 1;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
return 1;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public View getSectionHeaderView(int section, View view) {
|
|
|
|
|
if (view == null) {
|
|
|
|
|
view = new GraySectionCell(mContext);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if (section < sharedMediaData[currentType].sections.size()) {
|
|
|
|
|
String name = sharedMediaData[currentType].sections.get(section);
|
|
|
|
|
ArrayList<MessageObject> messageObjects = sharedMediaData[currentType].sectionArrays.get(name);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
MessageObject messageObject = messageObjects.get(0);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
((GraySectionCell) view).setText(LocaleController.getInstance().formatterMonthYear.format((long) messageObject.messageOwner.date * 1000).toUpperCase());
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
return view;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
|
View view;
|
|
|
|
|
switch (viewType) {
|
|
|
|
|
case 0:
|
|
|
|
|
view = new GraySectionCell(mContext);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
view = new SharedDocumentCell(mContext);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
default:
|
|
|
|
|
view = new LoadingCell(mContext);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return new RecyclerListView.Holder(view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(int section, int position, RecyclerView.ViewHolder holder) {
|
|
|
|
|
if (holder.getItemViewType() != 2) {
|
2015-10-29 18:10:07 +01:00
|
|
|
|
String name = sharedMediaData[currentType].sections.get(section);
|
|
|
|
|
ArrayList<MessageObject> messageObjects = sharedMediaData[currentType].sectionArrays.get(name);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
switch (holder.getItemViewType()) {
|
|
|
|
|
case 0: {
|
|
|
|
|
MessageObject messageObject = messageObjects.get(0);
|
|
|
|
|
((GraySectionCell) holder.itemView).setText(LocaleController.getInstance().formatterMonthYear.format((long) messageObject.messageOwner.date * 1000).toUpperCase());
|
|
|
|
|
break;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
case 1: {
|
|
|
|
|
SharedDocumentCell sharedDocumentCell = (SharedDocumentCell) holder.itemView;
|
|
|
|
|
MessageObject messageObject = messageObjects.get(position - 1);
|
|
|
|
|
sharedDocumentCell.setDocument(messageObject, position != messageObjects.size() || section == sharedMediaData[currentType].sections.size() - 1 && sharedMediaData[currentType].loading);
|
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
|
|
|
|
sharedDocumentCell.setChecked(selectedFiles[messageObject.getDialogId() == dialog_id ? 0 : 1].containsKey(messageObject.getId()), !scrolling);
|
|
|
|
|
} else {
|
|
|
|
|
sharedDocumentCell.setChecked(false, !scrolling);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-02-26 02:32:51 +01:00
|
|
|
|
public int getItemViewType(int section, int position) {
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if (section < sharedMediaData[currentType].sections.size()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (position == 0) {
|
|
|
|
|
return 0;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
} else {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
return 1;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
return 2;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public String getLetter(int position) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getPositionForScrollProgress(float progress) {
|
|
|
|
|
return 0;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
private class SharedPhotoVideoAdapter extends RecyclerListView.SectionsAdapter {
|
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
|
|
public SharedPhotoVideoAdapter(Context context) {
|
|
|
|
|
mContext = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Object getItem(int section, int position) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public boolean isEnabled(int section, int row) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getSectionCount() {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
return sharedMediaData[0].sections.size() + (sharedMediaData[0].sections.isEmpty() || sharedMediaData[0].endReached[0] && sharedMediaData[0].endReached[1] ? 0 : 1);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getCountForSection(int section) {
|
|
|
|
|
if (section < sharedMediaData[0].sections.size()) {
|
|
|
|
|
return (int) Math.ceil(sharedMediaData[0].sectionArrays.get(sharedMediaData[0].sections.get(section)).size() / (float)columnsCount) + 1;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
return 1;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public View getSectionHeaderView(int section, View view) {
|
|
|
|
|
if (view == null) {
|
|
|
|
|
view = new SharedMediaSectionCell(mContext);
|
|
|
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
if (section < sharedMediaData[0].sections.size()) {
|
|
|
|
|
String name = sharedMediaData[0].sections.get(section);
|
|
|
|
|
ArrayList<MessageObject> messageObjects = sharedMediaData[0].sectionArrays.get(name);
|
|
|
|
|
MessageObject messageObject = messageObjects.get(0);
|
2017-03-31 01:58:05 +02:00
|
|
|
|
((SharedMediaSectionCell) view).setText(LocaleController.getInstance().formatterMonthYear.format((long) messageObject.messageOwner.date * 1000).toUpperCase());
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
return view;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
|
View view;
|
|
|
|
|
switch (viewType) {
|
|
|
|
|
case 0:
|
|
|
|
|
view = new SharedMediaSectionCell(mContext);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
if (!cellCache.isEmpty()) {
|
|
|
|
|
view = cellCache.get(0);
|
|
|
|
|
cellCache.remove(0);
|
|
|
|
|
} else {
|
|
|
|
|
view = new SharedPhotoVideoCell(mContext);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
SharedPhotoVideoCell cell = (SharedPhotoVideoCell) view;
|
|
|
|
|
cell.setDelegate(new SharedPhotoVideoCell.SharedPhotoVideoCellDelegate() {
|
|
|
|
|
@Override
|
|
|
|
|
public void didClickItem(SharedPhotoVideoCell cell, int index, MessageObject messageObject, int a) {
|
|
|
|
|
onItemClick(index, cell, messageObject, a);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
@Override
|
|
|
|
|
public boolean didLongClickItem(SharedPhotoVideoCell cell, int index, MessageObject messageObject, int a) {
|
|
|
|
|
return onItemLongClick(messageObject, cell, a);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
default:
|
|
|
|
|
view = new LoadingCell(mContext);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return new RecyclerListView.Holder(view);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(int section, int position, RecyclerView.ViewHolder holder) {
|
|
|
|
|
if (holder.getItemViewType() != 2) {
|
|
|
|
|
String name = sharedMediaData[0].sections.get(section);
|
|
|
|
|
ArrayList<MessageObject> messageObjects = sharedMediaData[0].sectionArrays.get(name);
|
|
|
|
|
switch (holder.getItemViewType()) {
|
|
|
|
|
case 0: {
|
|
|
|
|
MessageObject messageObject = messageObjects.get(0);
|
|
|
|
|
((SharedMediaSectionCell) holder.itemView).setText(LocaleController.getInstance().formatterMonthYear.format((long) messageObject.messageOwner.date * 1000).toUpperCase());
|
|
|
|
|
break;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
case 1: {
|
|
|
|
|
SharedPhotoVideoCell cell = (SharedPhotoVideoCell) holder.itemView;
|
|
|
|
|
cell.setItemsCount(columnsCount);
|
|
|
|
|
for (int a = 0; a < columnsCount; a++) {
|
|
|
|
|
int index = (position - 1) * columnsCount + a;
|
|
|
|
|
if (index < messageObjects.size()) {
|
|
|
|
|
MessageObject messageObject = messageObjects.get(index);
|
|
|
|
|
cell.setIsFirst(position == 1);
|
|
|
|
|
cell.setItem(a, sharedMediaData[0].messages.indexOf(messageObject), messageObject);
|
|
|
|
|
|
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
|
|
|
|
cell.setChecked(a, selectedFiles[messageObject.getDialogId() == dialog_id ? 0 : 1].containsKey(messageObject.getId()), !scrolling);
|
|
|
|
|
} else {
|
|
|
|
|
cell.setChecked(a, false, !scrolling);
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
cell.setItem(a, index, null);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
cell.requestLayout();
|
|
|
|
|
break;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemViewType(int section, int position) {
|
|
|
|
|
if (section < sharedMediaData[0].sections.size()) {
|
|
|
|
|
if (position == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public String getLetter(int position) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getPositionForScrollProgress(float progress) {
|
|
|
|
|
return 0;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public class MediaSearchAdapter extends RecyclerListView.SelectionAdapter {
|
2013-10-25 17:19:00 +02:00
|
|
|
|
private Context mContext;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
private ArrayList<MessageObject> searchResult = new ArrayList<>();
|
|
|
|
|
private Timer searchTimer;
|
|
|
|
|
protected ArrayList<MessageObject> globalSearch = new ArrayList<>();
|
2015-09-24 22:52:02 +02:00
|
|
|
|
private int reqId = 0;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
private int lastReqId;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
private int currentType;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
|
public MediaSearchAdapter(Context context, int type) {
|
2013-10-25 17:19:00 +02:00
|
|
|
|
mContext = context;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
currentType = type;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
|
public void queryServerSearch(final String query, final int max_id, long did) {
|
|
|
|
|
int uid = (int) did;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
if (uid == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (reqId != 0) {
|
2015-09-24 22:52:02 +02:00
|
|
|
|
ConnectionsManager.getInstance().cancelRequest(reqId, true);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
reqId = 0;
|
|
|
|
|
}
|
|
|
|
|
if (query == null || query.length() == 0) {
|
|
|
|
|
globalSearch.clear();
|
|
|
|
|
lastReqId = 0;
|
|
|
|
|
notifyDataSetChanged();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
|
|
|
|
|
req.offset = 0;
|
|
|
|
|
req.limit = 50;
|
|
|
|
|
req.max_id = max_id;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
if (currentType == 1) {
|
|
|
|
|
req.filter = new TLRPC.TL_inputMessagesFilterDocument();
|
|
|
|
|
} else if (currentType == 3) {
|
|
|
|
|
req.filter = new TLRPC.TL_inputMessagesFilterUrl();
|
2015-10-29 18:10:07 +01:00
|
|
|
|
} else if (currentType == 4) {
|
2016-03-06 02:49:31 +01:00
|
|
|
|
req.filter = new TLRPC.TL_inputMessagesFilterMusic();
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
req.q = query;
|
2015-09-24 22:52:02 +02:00
|
|
|
|
req.peer = MessagesController.getInputPeer(uid);
|
|
|
|
|
if (req.peer == null) {
|
|
|
|
|
return;
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
final int currentReqId = ++lastReqId;
|
2015-09-24 22:52:02 +02:00
|
|
|
|
reqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
@Override
|
|
|
|
|
public void run(TLObject response, TLRPC.TL_error error) {
|
|
|
|
|
final ArrayList<MessageObject> messageObjects = new ArrayList<>();
|
|
|
|
|
if (error == null) {
|
|
|
|
|
TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
|
2015-11-26 22:04:02 +01:00
|
|
|
|
for (int a = 0; a < res.messages.size(); a++) {
|
|
|
|
|
TLRPC.Message message = res.messages.get(a);
|
2016-01-11 18:19:48 +01:00
|
|
|
|
if (max_id != 0 && message.id > max_id) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
messageObjects.add(new MessageObject(message, null, false));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
if (currentReqId == lastReqId) {
|
|
|
|
|
globalSearch = messageObjects;
|
|
|
|
|
notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
reqId = 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
|
}, ConnectionsManager.RequestFlagFailOnServerErrors);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
|
public void search(final String query) {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
try {
|
|
|
|
|
if (searchTimer != null) {
|
|
|
|
|
searchTimer.cancel();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
FileLog.e(e);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
if (query == null) {
|
|
|
|
|
searchResult.clear();
|
|
|
|
|
notifyDataSetChanged();
|
|
|
|
|
} else {
|
|
|
|
|
searchTimer = new Timer();
|
|
|
|
|
searchTimer.schedule(new TimerTask() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
searchTimer.cancel();
|
|
|
|
|
searchTimer = null;
|
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
FileLog.e(e);
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
processSearch(query);
|
|
|
|
|
}
|
|
|
|
|
}, 200, 300);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void processSearch(final String query) {
|
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
2015-08-13 11:23:31 +02:00
|
|
|
|
if (!sharedMediaData[currentType].messages.isEmpty()) {
|
2016-04-22 15:49:00 +02:00
|
|
|
|
if (currentType == 1 || currentType == 4) {
|
2015-08-13 11:23:31 +02:00
|
|
|
|
MessageObject messageObject = sharedMediaData[currentType].messages.get(sharedMediaData[currentType].messages.size() - 1);
|
2015-11-26 22:04:02 +01:00
|
|
|
|
queryServerSearch(query, messageObject.getId(), messageObject.getDialogId());
|
2016-04-22 15:49:00 +02:00
|
|
|
|
} else if (currentType == 3) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
queryServerSearch(query, 0, dialog_id);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
|
if (currentType == 1 || currentType == 4) {
|
2015-08-13 11:23:31 +02:00
|
|
|
|
final ArrayList<MessageObject> copy = new ArrayList<>();
|
2015-10-29 18:10:07 +01:00
|
|
|
|
copy.addAll(sharedMediaData[currentType].messages);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
Utilities.searchQueue.postRunnable(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
String search1 = query.trim().toLowerCase();
|
|
|
|
|
if (search1.length() == 0) {
|
|
|
|
|
updateSearchResults(new ArrayList<MessageObject>());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String search2 = LocaleController.getInstance().getTranslitString(search1);
|
|
|
|
|
if (search1.equals(search2) || search2.length() == 0) {
|
|
|
|
|
search2 = null;
|
|
|
|
|
}
|
|
|
|
|
String search[] = new String[1 + (search2 != null ? 1 : 0)];
|
|
|
|
|
search[0] = search1;
|
|
|
|
|
if (search2 != null) {
|
2016-10-11 13:57:01 +02:00
|
|
|
|
search[1] = search2;
|
2015-08-13 11:23:31 +02:00
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
|
ArrayList<MessageObject> resultArray = new ArrayList<>();
|
2015-02-26 02:32:51 +01:00
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
|
for (int a = 0; a < copy.size(); a++) {
|
|
|
|
|
MessageObject messageObject = copy.get(a);
|
2016-04-22 15:49:00 +02:00
|
|
|
|
for (int b = 0; b < search.length; b++) {
|
|
|
|
|
String q = search[b];
|
2015-08-13 11:23:31 +02:00
|
|
|
|
String name = messageObject.getDocumentName();
|
|
|
|
|
if (name == null || name.length() == 0) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
name = name.toLowerCase();
|
|
|
|
|
if (name.contains(q)) {
|
|
|
|
|
resultArray.add(messageObject);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
|
if (currentType == 4) {
|
|
|
|
|
TLRPC.Document document;
|
|
|
|
|
if (messageObject.type == 0) {
|
|
|
|
|
document = messageObject.messageOwner.media.webpage.document;
|
|
|
|
|
} else {
|
|
|
|
|
document = messageObject.messageOwner.media.document;
|
|
|
|
|
}
|
|
|
|
|
boolean ok = false;
|
|
|
|
|
for (int c = 0; c < document.attributes.size(); c++) {
|
|
|
|
|
TLRPC.DocumentAttribute attribute = document.attributes.get(c);
|
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
|
|
|
|
|
if (attribute.performer != null) {
|
|
|
|
|
ok = attribute.performer.toLowerCase().contains(q);
|
|
|
|
|
}
|
|
|
|
|
if (!ok && attribute.title != null) {
|
|
|
|
|
ok = attribute.title.toLowerCase().contains(q);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (ok) {
|
|
|
|
|
resultArray.add(messageObject);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
|
updateSearchResults(resultArray);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateSearchResults(final ArrayList<MessageObject> documents) {
|
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
searchResult = documents;
|
|
|
|
|
notifyDataSetChanged();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
|
return holder.getItemViewType() != searchResult.size() + globalSearch.size();
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public int getItemCount() {
|
2015-02-26 02:32:51 +01:00
|
|
|
|
int count = searchResult.size();
|
|
|
|
|
int globalCount = globalSearch.size();
|
|
|
|
|
if (globalCount != 0) {
|
|
|
|
|
count += globalCount;
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isGlobalSearch(int i) {
|
|
|
|
|
int localCount = searchResult.size();
|
|
|
|
|
int globalCount = globalSearch.size();
|
|
|
|
|
if (i >= 0 && i < localCount) {
|
|
|
|
|
return false;
|
|
|
|
|
} else if (i > localCount && i <= globalCount + localCount) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
|
public MessageObject getItem(int i) {
|
|
|
|
|
if (i < searchResult.size()) {
|
|
|
|
|
return searchResult.get(i);
|
|
|
|
|
} else {
|
|
|
|
|
return globalSearch.get(i - searchResult.size());
|
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
|
View view;
|
|
|
|
|
if (currentType == 1 || currentType == 4) {
|
|
|
|
|
view = new SharedDocumentCell(mContext);
|
|
|
|
|
} else {
|
|
|
|
|
view = new SharedLinkCell(mContext);
|
|
|
|
|
((SharedLinkCell) view).setDelegate(new SharedLinkCell.SharedLinkCellDelegate() {
|
|
|
|
|
@Override
|
|
|
|
|
public void needOpenWebView(TLRPC.WebPage webPage) {
|
|
|
|
|
MediaActivity.this.openWebView(webPage);
|
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
@Override
|
|
|
|
|
public boolean canPerformActions() {
|
|
|
|
|
return !actionBar.isActionModeShowed();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return new RecyclerListView.Holder(view);
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
2015-10-29 18:10:07 +01:00
|
|
|
|
if (currentType == 1 || currentType == 4) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
SharedDocumentCell sharedDocumentCell = (SharedDocumentCell) holder.itemView;
|
|
|
|
|
MessageObject messageObject = getItem(position);
|
|
|
|
|
sharedDocumentCell.setDocument(messageObject, position != getItemCount() - 1);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
sharedDocumentCell.setChecked(selectedFiles[messageObject.getDialogId() == dialog_id ? 0 : 1].containsKey(messageObject.getId()), !scrolling);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
} else {
|
|
|
|
|
sharedDocumentCell.setChecked(false, !scrolling);
|
|
|
|
|
}
|
|
|
|
|
} else if (currentType == 3) {
|
2017-03-31 01:58:05 +02:00
|
|
|
|
SharedLinkCell sharedLinkCell = (SharedLinkCell) holder.itemView;
|
|
|
|
|
MessageObject messageObject = getItem(position);
|
|
|
|
|
sharedLinkCell.setLink(messageObject, position != getItemCount() - 1);
|
2015-09-02 00:14:21 +02:00
|
|
|
|
if (actionBar.isActionModeShowed()) {
|
2015-11-26 22:04:02 +01:00
|
|
|
|
sharedLinkCell.setChecked(selectedFiles[messageObject.getDialogId() == dialog_id ? 0 : 1].containsKey(messageObject.getId()), !scrolling);
|
2015-08-13 11:23:31 +02:00
|
|
|
|
} else {
|
2015-09-02 00:14:21 +02:00
|
|
|
|
sharedLinkCell.setChecked(false, !scrolling);
|
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemViewType(int i) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
|
@Override
|
|
|
|
|
public ThemeDescription[] getThemeDescriptions() {
|
|
|
|
|
ThemeDescription.ThemeDescriptionDelegate сellDelegate = new ThemeDescription.ThemeDescriptionDelegate() {
|
|
|
|
|
@Override
|
|
|
|
|
public void didSetColor(int color) {
|
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
|
View child = listView.getChildAt(a);
|
|
|
|
|
if (child instanceof SharedPhotoVideoCell) {
|
|
|
|
|
((SharedPhotoVideoCell) child).updateCheckboxColor();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return new ThemeDescription[]{
|
|
|
|
|
new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite),
|
|
|
|
|
new ThemeDescription(emptyView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray),
|
|
|
|
|
new ThemeDescription(progressView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_actionBarDefault),
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarDefaultIcon),
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle),
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarDefaultSelector),
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUBACKGROUND, null, null, null, null, Theme.key_actionBarDefaultSubmenuBackground),
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SUBMENUITEM, null, null, null, null, Theme.key_actionBarDefaultSubmenuItem),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(dropDown, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle),
|
|
|
|
|
new ThemeDescription(dropDown, 0, null, null, new Drawable[]{dropDownDrawable}, null, Theme.key_actionBarDefaultTitle),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(emptyView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_emptyListPlaceholder),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_AM_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarActionModeDefaultIcon),
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_AM_BACKGROUND, null, null, null, null, Theme.key_actionBarActionModeDefault),
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_AM_TOPBACKGROUND, null, null, null, null, Theme.key_actionBarActionModeDefaultTop),
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_AM_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarActionModeDefaultSelector),
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SEARCH, null, null, null, null, Theme.key_actionBarDefaultSearch),
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SEARCHPLACEHOLDER, null, null, null, null, Theme.key_actionBarDefaultSearchPlaceholder),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(selectedMessagesCountTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_actionBarActionModeDefaultIcon),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(progressBar, ThemeDescription.FLAG_PROGRESSBAR, null, null, null, null, Theme.key_progressCircle),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(emptyTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText2),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{GraySectionCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{GraySectionCell.class}, null, null, null, Theme.key_graySection),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR, new Class[]{SharedDocumentCell.class}, new String[]{"nameTextView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR, new Class[]{SharedDocumentCell.class}, new String[]{"dateTextView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText3),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_PROGRESSBAR, new Class[]{SharedDocumentCell.class}, new String[]{"progressView"}, null, null, null, Theme.key_sharedMedia_startStopLoadIcon),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_IMAGECOLOR, new Class[]{SharedDocumentCell.class}, new String[]{"statusImageView"}, null, null, null, Theme.key_sharedMedia_startStopLoadIcon),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKBOX, new Class[]{SharedDocumentCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_checkbox),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKBOXCHECK, new Class[]{SharedDocumentCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_checkboxCheck),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_IMAGECOLOR, new Class[]{SharedDocumentCell.class}, new String[]{"thumbImageView"}, null, null, null, Theme.key_files_folderIcon),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_TEXTCOLOR, new Class[]{SharedDocumentCell.class}, new String[]{"extTextView"}, null, null, null, Theme.key_files_iconText),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{GraySectionCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText2),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{GraySectionCell.class}, null, null, null, Theme.key_graySection),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{LoadingCell.class}, new String[]{"progressBar"}, null, null, null, Theme.key_progressCircle),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKBOX, new Class[]{SharedLinkCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_checkbox),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKBOXCHECK, new Class[]{SharedLinkCell.class}, new String[]{"checkBox"}, null, null, null, Theme.key_checkboxCheck),
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{SharedLinkCell.class}, new String[]{"titleTextPaint"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{SharedLinkCell.class}, null, null, null, Theme.key_windowBackgroundWhiteLinkText),
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{SharedLinkCell.class}, Theme.linkSelectionPaint, null, null, Theme.key_windowBackgroundWhiteLinkSelection),
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{SharedLinkCell.class}, new String[]{"letterDrawable"}, null, null, null, Theme.key_sharedMedia_linkPlaceholderText),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{SharedLinkCell.class}, new String[]{"letterDrawable"}, null, null, null, Theme.key_sharedMedia_linkPlaceholder),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{SharedMediaSectionCell.class}, null, null, null, Theme.key_windowBackgroundWhite),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_SECTIONS, new Class[]{SharedMediaSectionCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{SharedMediaSectionCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKBOX, new Class[]{SharedPhotoVideoCell.class}, null, null, сellDelegate, Theme.key_checkbox),
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKBOXCHECK, new Class[]{SharedPhotoVideoCell.class}, null, null, сellDelegate, Theme.key_checkboxCheck),
|
|
|
|
|
|
|
|
|
|
new ThemeDescription(fragmentContextView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{FragmentContextView.class}, new String[]{"frameLayout"}, null, null, null, Theme.key_inappPlayerBackground),
|
|
|
|
|
new ThemeDescription(fragmentContextView, 0, new Class[]{FragmentContextView.class}, new String[]{"playButton"}, null, null, null, Theme.key_inappPlayerPlayPause),
|
|
|
|
|
new ThemeDescription(fragmentContextView, ThemeDescription.FLAG_TEXTCOLOR, new Class[]{FragmentContextView.class}, new String[]{"titleTextView"}, null, null, null, Theme.key_inappPlayerTitle),
|
|
|
|
|
new ThemeDescription(fragmentContextView, ThemeDescription.FLAG_TEXTCOLOR, new Class[]{FragmentContextView.class}, new String[]{"frameLayout"}, null, null, null, Theme.key_inappPlayerPerformer),
|
|
|
|
|
new ThemeDescription(fragmentContextView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{FragmentContextView.class}, new String[]{"closeButton"}, null, null, null, Theme.key_inappPlayerClose),
|
|
|
|
|
};
|
2013-10-25 17:19:00 +02:00
|
|
|
|
}
|
|
|
|
|
}
|