2015-01-02 23:15:07 +01:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 2.0.x.
|
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2015-01-02 23:15:07 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.Surface;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MediaController;
|
|
|
|
import org.telegram.messenger.MessagesStorage;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
|
|
|
import org.telegram.messenger.R;
|
2017-12-08 18:35:59 +01:00
|
|
|
import org.telegram.messenger.SendMessagesHelper;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2016-04-22 15:49:00 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.ui.Cells.PhotoPickerAlbumsCell;
|
|
|
|
import org.telegram.ui.Cells.PhotoPickerSearchCell;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2015-07-22 20:56:37 +02:00
|
|
|
import org.telegram.ui.Components.PickerBottomLayout;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.RadialProgressView;
|
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
public class PhotoAlbumPickerActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public interface PhotoAlbumPickerActivityDelegate {
|
2017-12-08 18:35:59 +01:00
|
|
|
void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos);
|
2015-03-19 00:09:45 +01:00
|
|
|
void startPhotoSelectActivity();
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private HashMap<Object, Object> selectedPhotos = new HashMap<>();
|
|
|
|
private ArrayList<Object> selectedPhotosOrder = new ArrayList<>();
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private ArrayList<MediaController.AlbumEntry> albumsSorted = null;
|
|
|
|
private HashMap<String, MediaController.SearchImage> recentImagesWebKeys = new HashMap<>();
|
|
|
|
private HashMap<String, MediaController.SearchImage> recentImagesGifKeys = new HashMap<>();
|
|
|
|
private ArrayList<MediaController.SearchImage> recentWebImages = new ArrayList<>();
|
|
|
|
private ArrayList<MediaController.SearchImage> recentGifImages = new ArrayList<>();
|
2017-12-08 18:35:59 +01:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private boolean loading = false;
|
|
|
|
|
|
|
|
private int columnsCount = 2;
|
2017-03-31 01:58:05 +02:00
|
|
|
private RecyclerListView listView;
|
2015-01-02 23:15:07 +01:00
|
|
|
private ListAdapter listAdapter;
|
|
|
|
private FrameLayout progressView;
|
|
|
|
private TextView emptyView;
|
2015-07-22 20:56:37 +02:00
|
|
|
private PickerBottomLayout pickerBottomLayout;
|
2016-01-11 18:19:48 +01:00
|
|
|
private boolean sendPressed;
|
2019-01-23 18:03:33 +01:00
|
|
|
private int selectPhotoType;
|
2018-07-30 04:07:02 +02:00
|
|
|
private boolean allowSearchImages = true;
|
2016-01-11 18:19:48 +01:00
|
|
|
private boolean allowGifs;
|
2016-10-11 13:57:01 +02:00
|
|
|
private boolean allowCaption;
|
2015-05-03 13:48:36 +02:00
|
|
|
private ChatActivity chatActivity;
|
2019-01-23 18:03:33 +01:00
|
|
|
private int maxSelectedPhotos;
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
private PhotoAlbumPickerActivityDelegate delegate;
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public PhotoAlbumPickerActivity(int selectPhotoType, boolean allowGifs, boolean allowCaption, ChatActivity chatActivity) {
|
2015-02-26 02:32:51 +01:00
|
|
|
super();
|
2015-05-03 13:48:36 +02:00
|
|
|
this.chatActivity = chatActivity;
|
2019-01-23 18:03:33 +01:00
|
|
|
this.selectPhotoType = selectPhotoType;
|
2016-01-11 18:19:48 +01:00
|
|
|
this.allowGifs = allowGifs;
|
2016-10-11 13:57:01 +02:00
|
|
|
this.allowCaption = allowCaption;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
loading = true;
|
|
|
|
MediaController.loadGalleryPhotosAlbums(classGuid);
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.albumsDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.recentImagesDidLoad);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.closeChats);
|
2015-01-02 23:15:07 +01:00
|
|
|
return super.onFragmentCreate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
2019-01-23 18:03:33 +01:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.albumsDidLoad);
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.recentImagesDidLoad);
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.closeChats);
|
2015-01-02 23:15:07 +01:00
|
|
|
super.onFragmentDestroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public View createView(Context context) {
|
2016-04-22 15:49:00 +02:00
|
|
|
actionBar.setBackgroundColor(Theme.ACTION_BAR_MEDIA_PICKER_COLOR);
|
2017-03-31 01:58:05 +02:00
|
|
|
actionBar.setTitleColor(0xffffffff);
|
2019-06-04 12:14:50 +02:00
|
|
|
actionBar.setItemsColor(0xffffffff, false);
|
2017-03-31 01:58:05 +02:00
|
|
|
actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR, false);
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
2015-01-02 23:15:07 +01:00
|
|
|
finishFragment();
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (id == 1) {
|
|
|
|
if (delegate != null) {
|
|
|
|
finishFragment(false);
|
|
|
|
delegate.startPhotoSelectActivity();
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
2019-05-14 14:08:05 +02:00
|
|
|
menu.addItem(1, R.drawable.ic_ab_other).setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
fragmentView = new FrameLayout(context);
|
|
|
|
|
|
|
|
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
|
|
|
frameLayout.setBackgroundColor(0xff000000);
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
actionBar.setTitle(LocaleController.getString("Gallery", R.string.Gallery));
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
listView = new RecyclerListView(context);
|
2015-04-09 20:00:14 +02:00
|
|
|
listView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), AndroidUtilities.dp(4));
|
|
|
|
listView.setClipToPadding(false);
|
|
|
|
listView.setHorizontalScrollBarEnabled(false);
|
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
2017-03-31 01:58:05 +02:00
|
|
|
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
|
2015-04-09 20:00:14 +02:00
|
|
|
listView.setDrawingCacheEnabled(false);
|
|
|
|
frameLayout.addView(listView);
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
2015-04-09 20:00:14 +02:00
|
|
|
layoutParams.bottomMargin = AndroidUtilities.dp(48);
|
|
|
|
listView.setLayoutParams(layoutParams);
|
|
|
|
listView.setAdapter(listAdapter = new ListAdapter(context));
|
2017-03-31 01:58:05 +02:00
|
|
|
listView.setGlowColor(0xff333333);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
emptyView = new TextView(context);
|
|
|
|
emptyView.setTextColor(0xff808080);
|
|
|
|
emptyView.setTextSize(20);
|
|
|
|
emptyView.setGravity(Gravity.CENTER);
|
|
|
|
emptyView.setVisibility(View.GONE);
|
|
|
|
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
|
|
|
|
frameLayout.addView(emptyView);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
2015-04-09 20:00:14 +02:00
|
|
|
layoutParams.bottomMargin = AndroidUtilities.dp(48);
|
|
|
|
emptyView.setLayoutParams(layoutParams);
|
2019-01-23 18:03:33 +01:00
|
|
|
emptyView.setOnTouchListener((v, event) -> true);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
progressView = new FrameLayout(context);
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
frameLayout.addView(progressView);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
2015-04-09 20:00:14 +02:00
|
|
|
layoutParams.bottomMargin = AndroidUtilities.dp(48);
|
|
|
|
progressView.setLayoutParams(layoutParams);
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
RadialProgressView progressBar = new RadialProgressView(context);
|
2015-04-09 20:00:14 +02:00
|
|
|
progressView.addView(progressBar);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams.width = LayoutHelper.WRAP_CONTENT;
|
|
|
|
layoutParams.height = LayoutHelper.WRAP_CONTENT;
|
2015-04-09 20:00:14 +02:00
|
|
|
layoutParams.gravity = Gravity.CENTER;
|
|
|
|
progressView.setLayoutParams(layoutParams);
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
pickerBottomLayout = new PickerBottomLayout(context);
|
|
|
|
frameLayout.addView(pickerBottomLayout);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) pickerBottomLayout.getLayoutParams();
|
2015-05-03 13:48:36 +02:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
2015-04-09 20:00:14 +02:00
|
|
|
layoutParams.height = AndroidUtilities.dp(48);
|
|
|
|
layoutParams.gravity = Gravity.BOTTOM;
|
2015-07-22 20:56:37 +02:00
|
|
|
pickerBottomLayout.setLayoutParams(layoutParams);
|
2019-01-23 18:03:33 +01:00
|
|
|
pickerBottomLayout.cancelButton.setOnClickListener(view -> finishFragment());
|
|
|
|
pickerBottomLayout.doneButton.setOnClickListener(view -> {
|
|
|
|
sendSelectedPhotos(selectedPhotos, selectedPhotosOrder);
|
|
|
|
finishFragment();
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (loading && (albumsSorted == null || albumsSorted != null && albumsSorted.isEmpty())) {
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
listView.setEmptyView(null);
|
|
|
|
} else {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
listView.setEmptyView(emptyView);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
pickerBottomLayout.updateSelectedCount(selectedPhotos.size(), true);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
fixLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
fixLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
public void didReceivedNotification(int id, int account, Object... args) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (id == NotificationCenter.albumsDidLoad) {
|
2015-01-02 23:15:07 +01:00
|
|
|
int guid = (Integer) args[0];
|
|
|
|
if (classGuid == guid) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (selectPhotoType != 0 || !allowSearchImages) {
|
2017-07-08 18:32:04 +02:00
|
|
|
albumsSorted = (ArrayList<MediaController.AlbumEntry>) args[2];
|
|
|
|
} else {
|
|
|
|
albumsSorted = (ArrayList<MediaController.AlbumEntry>) args[1];
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
if (progressView != null) {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (listView != null && listView.getEmptyView() == null) {
|
|
|
|
listView.setEmptyView(emptyView);
|
|
|
|
}
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
loading = false;
|
|
|
|
}
|
|
|
|
} else if (id == NotificationCenter.closeChats) {
|
|
|
|
removeSelfFromStack();
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (id == NotificationCenter.recentImagesDidLoad) {
|
2015-01-02 23:15:07 +01:00
|
|
|
int type = (Integer) args[0];
|
|
|
|
if (type == 0) {
|
|
|
|
recentWebImages = (ArrayList<MediaController.SearchImage>) args[1];
|
|
|
|
recentImagesWebKeys.clear();
|
|
|
|
for (MediaController.SearchImage searchImage : recentWebImages) {
|
|
|
|
recentImagesWebKeys.put(searchImage.id, searchImage);
|
|
|
|
}
|
|
|
|
} else if (type == 1) {
|
|
|
|
recentGifImages = (ArrayList<MediaController.SearchImage>) args[1];
|
|
|
|
recentImagesGifKeys.clear();
|
|
|
|
for (MediaController.SearchImage searchImage : recentGifImages) {
|
|
|
|
recentImagesGifKeys.put(searchImage.id, searchImage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void setMaxSelectedPhotos(int value) {
|
|
|
|
maxSelectedPhotos = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAllowSearchImages(boolean value) {
|
|
|
|
allowSearchImages = value;
|
|
|
|
}
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
public void setDelegate(PhotoAlbumPickerActivityDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private void sendSelectedPhotos(HashMap<Object, Object> photos, ArrayList<Object> order) {
|
|
|
|
if (photos.isEmpty() || delegate == null || sendPressed) {
|
2015-01-02 23:15:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
sendPressed = true;
|
|
|
|
boolean gifChanged = false;
|
|
|
|
boolean webChange = false;
|
2017-12-08 18:35:59 +01:00
|
|
|
|
|
|
|
ArrayList<SendMessagesHelper.SendingMediaInfo> media = new ArrayList<>();
|
|
|
|
for (int a = 0; a < order.size(); a++) {
|
|
|
|
Object object = photos.get(order.get(a));
|
|
|
|
SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo();
|
|
|
|
media.add(info);
|
|
|
|
if (object instanceof MediaController.PhotoEntry) {
|
|
|
|
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) object;
|
|
|
|
if (photoEntry.isVideo) {
|
|
|
|
info.path = photoEntry.path;
|
|
|
|
info.videoEditedInfo = photoEntry.editedInfo;
|
|
|
|
} else if (photoEntry.imagePath != null) {
|
|
|
|
info.path = photoEntry.imagePath;
|
|
|
|
} else if (photoEntry.path != null) {
|
|
|
|
info.path = photoEntry.path;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
info.isVideo = photoEntry.isVideo;
|
|
|
|
info.caption = photoEntry.caption != null ? photoEntry.caption.toString() : null;
|
2018-07-30 04:07:02 +02:00
|
|
|
info.entities = photoEntry.entities;
|
2017-12-08 18:35:59 +01:00
|
|
|
info.masks = !photoEntry.stickers.isEmpty() ? new ArrayList<>(photoEntry.stickers) : null;
|
|
|
|
info.ttl = photoEntry.ttl;
|
|
|
|
} else if (object instanceof MediaController.SearchImage) {
|
|
|
|
MediaController.SearchImage searchImage = (MediaController.SearchImage) object;
|
|
|
|
if (searchImage.imagePath != null) {
|
|
|
|
info.path = searchImage.imagePath;
|
2015-01-02 23:15:07 +01:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
info.searchImage = searchImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
info.caption = searchImage.caption != null ? searchImage.caption.toString() : null;
|
2018-07-30 04:07:02 +02:00
|
|
|
info.entities = searchImage.entities;
|
2017-12-08 18:35:59 +01:00
|
|
|
info.masks = !searchImage.stickers.isEmpty() ? new ArrayList<>(searchImage.stickers) : null;
|
|
|
|
info.ttl = searchImage.ttl;
|
|
|
|
|
|
|
|
searchImage.date = (int) (System.currentTimeMillis() / 1000);
|
|
|
|
if (searchImage.type == 0) {
|
|
|
|
webChange = true;
|
|
|
|
MediaController.SearchImage recentImage = recentImagesWebKeys.get(searchImage.id);
|
|
|
|
if (recentImage != null) {
|
|
|
|
recentWebImages.remove(recentImage);
|
|
|
|
recentWebImages.add(0, recentImage);
|
|
|
|
} else {
|
|
|
|
recentWebImages.add(0, searchImage);
|
|
|
|
}
|
|
|
|
} else if (searchImage.type == 1) {
|
|
|
|
gifChanged = true;
|
|
|
|
MediaController.SearchImage recentImage = recentImagesGifKeys.get(searchImage.id);
|
|
|
|
if (recentImage != null) {
|
|
|
|
recentGifImages.remove(recentImage);
|
|
|
|
recentGifImages.add(0, recentImage);
|
|
|
|
} else {
|
|
|
|
recentGifImages.add(0, searchImage);
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
if (webChange) {
|
2018-07-30 04:07:02 +02:00
|
|
|
MessagesStorage.getInstance(currentAccount).putWebRecent(recentWebImages);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
if (gifChanged) {
|
2018-07-30 04:07:02 +02:00
|
|
|
MessagesStorage.getInstance(currentAccount).putWebRecent(recentGifImages);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
delegate.didSelectPhotos(media);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void fixLayout() {
|
|
|
|
if (listView != null) {
|
|
|
|
ViewTreeObserver obs = listView.getViewTreeObserver();
|
|
|
|
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onPreDraw() {
|
|
|
|
fixLayoutInternal();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.getViewTreeObserver().removeOnPreDrawListener(this);
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
return true;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fixLayoutInternal() {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
|
|
|
columnsCount = 2;
|
2015-03-26 18:34:47 +01:00
|
|
|
if (!AndroidUtilities.isTablet() && (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90)) {
|
2015-01-02 23:15:07 +01:00
|
|
|
columnsCount = 4;
|
|
|
|
}
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void openPhotoPicker(MediaController.AlbumEntry albumEntry, int type) {
|
|
|
|
ArrayList<MediaController.SearchImage> recentImages = null;
|
|
|
|
if (albumEntry == null) {
|
|
|
|
if (type == 0) {
|
|
|
|
recentImages = recentWebImages;
|
|
|
|
} else if (type == 1) {
|
|
|
|
recentImages = recentGifImages;
|
|
|
|
}
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
|
|
|
|
PhotoPickerActivity fragment;
|
|
|
|
if (albumEntry != null) {
|
2019-01-23 18:03:33 +01:00
|
|
|
fragment = new PhotoPickerActivity(type, albumEntry, selectedPhotos, selectedPhotosOrder, recentImages, selectPhotoType, allowCaption, chatActivity);
|
2017-12-08 18:35:59 +01:00
|
|
|
fragment.setDelegate(new PhotoPickerActivity.PhotoPickerActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void selectedPhotosChanged() {
|
|
|
|
if (pickerBottomLayout != null) {
|
|
|
|
pickerBottomLayout.updateSelectedCount(selectedPhotos.size(), true);
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
@Override
|
|
|
|
public void actionButtonPressed(boolean canceled) {
|
|
|
|
removeSelfFromStack();
|
|
|
|
if (!canceled) {
|
|
|
|
sendSelectedPhotos(selectedPhotos, selectedPhotosOrder);
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
final HashMap<Object, Object> photos = new HashMap<>();
|
|
|
|
final ArrayList<Object> order = new ArrayList<>();
|
2019-01-23 18:03:33 +01:00
|
|
|
fragment = new PhotoPickerActivity(type, albumEntry, photos, order, recentImages, selectPhotoType, allowCaption, chatActivity);
|
2017-12-08 18:35:59 +01:00
|
|
|
fragment.setDelegate(new PhotoPickerActivity.PhotoPickerActivityDelegate() {
|
|
|
|
@Override
|
|
|
|
public void selectedPhotosChanged() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void actionButtonPressed(boolean canceled) {
|
|
|
|
removeSelfFromStack();
|
|
|
|
if (!canceled) {
|
|
|
|
sendSelectedPhotos(photos, order);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
fragment.setMaxSelectedPhotos(maxSelectedPhotos);
|
2015-01-02 23:15:07 +01:00
|
|
|
presentFragment(fragment);
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class ListAdapter extends RecyclerListView.SelectionAdapter {
|
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
2015-01-02 23:15:07 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public int getItemCount() {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (!allowSearchImages) {
|
2017-07-08 18:32:04 +02:00
|
|
|
return albumsSorted != null ? (int) Math.ceil(albumsSorted.size() / (float) columnsCount) : 0;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
return 1 + (albumsSorted != null ? (int) Math.ceil(albumsSorted.size() / (float) columnsCount) : 0);
|
2015-01-02 23:15:07 +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: {
|
|
|
|
PhotoPickerAlbumsCell cell = new PhotoPickerAlbumsCell(mContext);
|
2019-01-23 18:03:33 +01:00
|
|
|
cell.setDelegate(albumEntry -> openPhotoPicker(albumEntry, 0));
|
2017-03-31 01:58:05 +02:00
|
|
|
view = cell;
|
|
|
|
break;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
case 1:
|
|
|
|
default: {
|
|
|
|
PhotoPickerSearchCell cell = new PhotoPickerSearchCell(mContext, allowGifs);
|
2019-01-23 18:03:33 +01:00
|
|
|
cell.setDelegate(index -> openPhotoPicker(null, index));
|
2017-03-31 01:58:05 +02:00
|
|
|
view = cell;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new RecyclerListView.Holder(view);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
|
|
|
if (holder.getItemViewType() == 0) {
|
|
|
|
PhotoPickerAlbumsCell photoPickerAlbumsCell = (PhotoPickerAlbumsCell) holder.itemView;
|
2015-01-02 23:15:07 +01:00
|
|
|
photoPickerAlbumsCell.setAlbumsCount(columnsCount);
|
|
|
|
for (int a = 0; a < columnsCount; a++) {
|
2015-02-26 02:32:51 +01:00
|
|
|
int index;
|
2019-01-23 18:03:33 +01:00
|
|
|
if (!allowSearchImages) {
|
2017-03-31 01:58:05 +02:00
|
|
|
index = position * columnsCount + a;
|
2015-02-26 02:32:51 +01:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
index = (position - 1) * columnsCount + a;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
if (index < albumsSorted.size()) {
|
|
|
|
MediaController.AlbumEntry albumEntry = albumsSorted.get(index);
|
|
|
|
photoPickerAlbumsCell.setAlbum(a, albumEntry);
|
2015-01-02 23:15:07 +01:00
|
|
|
} else {
|
2017-07-08 18:32:04 +02:00
|
|
|
photoPickerAlbumsCell.setAlbum(a, null);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
photoPickerAlbumsCell.requestLayout();
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (!allowSearchImages) {
|
2015-02-26 02:32:51 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
if (i == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|