Removed unneeded image search function, cleanup gallery code.

This commit is contained in:
B. Petersen
2017-03-08 13:57:18 +01:00
parent 4d3929576d
commit 009adc09bc
23 changed files with 57 additions and 878 deletions
@@ -815,162 +815,6 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
prepareSendingPhotos(paths, uris, dialog_id, captions);
}
public static void prepareSendingPhotosSearch(final ArrayList<MediaController.SearchImage> photos, final long dialog_id) {
if (photos == null || photos.isEmpty()) {
return;
}
new Thread(new Runnable() {
@Override
public void run() {
final boolean isEncrypted = false;//(int) dialog_id == 0;
for (int a = 0; a < photos.size(); a++) {
final MediaController.SearchImage searchImage = photos.get(a);
if (searchImage.type == 1) {
final HashMap<String, String> params = new HashMap<>();
TLRPC.TL_document document = null;
File cacheFile;
if (searchImage.document instanceof TLRPC.TL_document) {
document = (TLRPC.TL_document) searchImage.document;
cacheFile = FileLoader.getPathToAttach(document, true);
} else {
/*if (!isEncrypted)*/ {
TLRPC.Document doc = null;//(TLRPC.Document) MessagesStorage.getInstance().getSentFile(searchImage.imageUrl, !isEncrypted ? 1 : 4);
if (doc instanceof TLRPC.TL_document) {
document = (TLRPC.TL_document) doc;
}
}
String md5 = Utilities.MD5(searchImage.imageUrl) + "." + ImageLoader.getHttpUrlExtension(searchImage.imageUrl, "jpg");
cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), md5);
}
if (document == null) {
if (searchImage.localUrl != null) {
params.put("url", searchImage.localUrl);
}
File thumbFile = null;
document = new TLRPC.TL_document();
document.id = 0;
document.date = ConnectionsManager.getInstance().getCurrentTime();
TLRPC.TL_documentAttributeFilename fileName = new TLRPC.TL_documentAttributeFilename();
fileName.file_name = "animation.gif";
document.attributes.add(fileName);
document.size = searchImage.size;
document.dc_id = 0;
if (cacheFile.toString().endsWith("mp4")) {
document.mime_type = "video/mp4";
document.attributes.add(new TLRPC.TL_documentAttributeAnimated());
} else {
document.mime_type = "image/gif";
}
if (cacheFile.exists()) {
thumbFile = cacheFile;
} else {
cacheFile = null;
}
if (thumbFile == null) {
String thumb = Utilities.MD5(searchImage.thumbUrl) + "." + ImageLoader.getHttpUrlExtension(searchImage.thumbUrl, "jpg");
thumbFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), thumb);
if (!thumbFile.exists()) {
thumbFile = null;
}
}
if (thumbFile != null) {
try {
Bitmap bitmap;
if (thumbFile.getAbsolutePath().endsWith("mp4")) {
bitmap = ThumbnailUtils.createVideoThumbnail(thumbFile.getAbsolutePath(), MediaStore.Video.Thumbnails.MINI_KIND);
} else {
bitmap = ImageLoader.loadBitmap(thumbFile.getAbsolutePath(), null, 90, 90, true);
}
if (bitmap != null) {
document.thumb = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, isEncrypted);
bitmap.recycle();
}
} catch (Exception e) {
FileLog.e("messenger", e);
}
}
if (document.thumb == null) {
document.thumb = new TLRPC.TL_photoSize();
document.thumb.w = searchImage.width;
document.thumb.h = searchImage.height;
document.thumb.size = 0;
document.thumb.location = new TLRPC.TL_fileLocationUnavailable();
document.thumb.type = "x";
}
}
if (searchImage.caption != null) {
document.caption = searchImage.caption.toString();
}
final TLRPC.TL_document documentFinal = document;
final String originalPathFinal = searchImage.imageUrl;
final String pathFinal = cacheFile == null ? searchImage.imageUrl : cacheFile.toString();
if (params != null && searchImage.imageUrl != null) {
params.put("originalPath", searchImage.imageUrl);
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
SendMessagesHelper.getInstance().sendMessageDocument(documentFinal, null, pathFinal, dialog_id, params);
}
});
} else {
boolean needDownloadHttp = true;
TLRPC.TL_photo photo = null;
/*if (!isEncrypted)*/ {
photo = null;//MessagesStorage.getInstance().getSentFile(searchImage.imageUrl, !isEncrypted ? 0 : 3);
}
if (photo == null) {
String md5 = Utilities.MD5(searchImage.imageUrl) + "." + ImageLoader.getHttpUrlExtension(searchImage.imageUrl, "jpg");
File cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), md5);
if (cacheFile.exists() && cacheFile.length() != 0) {
photo = SendMessagesHelper.getInstance().generatePhotoSizes(cacheFile.toString(), null);
if (photo != null) {
needDownloadHttp = false;
}
}
if (photo == null) {
md5 = Utilities.MD5(searchImage.thumbUrl) + "." + ImageLoader.getHttpUrlExtension(searchImage.thumbUrl, "jpg");
cacheFile = new File(FileLoader.getInstance().getDirectory(FileLoader.MEDIA_DIR_CACHE), md5);
if (cacheFile.exists()) {
photo = SendMessagesHelper.getInstance().generatePhotoSizes(cacheFile.toString(), null);
}
if (photo == null) {
photo = new TLRPC.TL_photo();
photo.date = ConnectionsManager.getInstance().getCurrentTime();
TLRPC.TL_photoSize photoSize = new TLRPC.TL_photoSize();
photoSize.w = searchImage.width;
photoSize.h = searchImage.height;
photoSize.size = 0;
photoSize.location = new TLRPC.TL_fileLocationUnavailable();
photoSize.type = "x";
photo.sizes.add(photoSize);
}
}
}
if (photo != null) {
if (searchImage.caption != null) {
photo.caption = searchImage.caption.toString();
}
final TLRPC.TL_photo photoFinal = photo;
final boolean needDownloadHttpFinal = needDownloadHttp;
final HashMap<String, String> params = new HashMap<>();
if (searchImage.imageUrl != null) {
params.put("originalPath", searchImage.imageUrl);
}
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
SendMessagesHelper.getInstance().sendMessagePhoto(photoFinal, needDownloadHttpFinal ? searchImage.imageUrl : null, dialog_id, params);
}
});
}
}
}
}
}).start();
}
private static String getTrimmedString(String src) {
String result = src.trim();
if (result.length() == 0) {
@@ -70,7 +70,7 @@ public class PhotoPickerAlbumsCell extends FrameLayout {
addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 28, Gravity.LEFT | Gravity.BOTTOM));
nameTextView = new TextView(context);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
nameTextView.setTextColor(0xffffffff);
nameTextView.setSingleLine(true);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
@@ -1,163 +0,0 @@
/*******************************************************************************
*
* Messenger Android Frontend
* (C) 2013-2016 Nikolai Kudashov
* (C) 2017 Björn Petersen
* Contact: r10s@b44t.com, http://b44t.com
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see http://www.gnu.org/licenses/ .
*
******************************************************************************/
package com.b44t.ui.Cells;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.R;
import com.b44t.ui.Components.LayoutHelper;
public class PhotoPickerSearchCell extends LinearLayout {
public interface PhotoPickerSearchCellDelegate {
void didPressedSearchButton(int index);
}
private class SearchButton extends FrameLayout {
private TextView textView1;
private TextView textView2;
private ImageView imageView;
private View selector;
public SearchButton(Context context) {
super(context);
setBackgroundColor(0xff1a1a1a);
selector = new View(context);
selector.setBackgroundResource(R.drawable.list_selector);
addView(selector, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER);
addView(imageView, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.TOP));
textView1 = new TextView(context);
textView1.setGravity(Gravity.CENTER_VERTICAL);
textView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView1.setTextColor(0xffffffff);
textView1.setSingleLine(true);
textView1.setEllipsize(TextUtils.TruncateAt.END);
addView(textView1, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 51, 8, 4, 0));
textView2 = new TextView(context);
textView2.setGravity(Gravity.CENTER_VERTICAL);
textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
textView2.setTextColor(0xff666666);
textView2.setSingleLine(true);
textView2.setEllipsize(TextUtils.TruncateAt.END);
addView(textView2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 51, 26, 4, 0));
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (Build.VERSION.SDK_INT >= 21) {
selector.drawableHotspotChanged(event.getX(), event.getY());
}
return super.onTouchEvent(event);
}
}
private PhotoPickerSearchCellDelegate delegate;
public PhotoPickerSearchCell(Context context, boolean allowGifs) {
super(context);
setOrientation(HORIZONTAL);
SearchButton searchButton = new SearchButton(context);
searchButton.textView1.setText(LocaleController.getString("SearchImages", R.string.SearchImages));
searchButton.textView2.setText(LocaleController.getString("SearchImagesInfo", R.string.SearchImagesInfo));
searchButton.imageView.setImageResource(R.drawable.search_web);
addView(searchButton);
LayoutParams layoutParams = (LayoutParams) searchButton.getLayoutParams();
layoutParams.weight = 0.5f;
layoutParams.topMargin = AndroidUtilities.dp(4);
layoutParams.height = AndroidUtilities.dp(48);
layoutParams.width = 0;
searchButton.setLayoutParams(layoutParams);
searchButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (delegate != null) {
delegate.didPressedSearchButton(0);
}
}
});
FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setBackgroundColor(0);
addView(frameLayout);
layoutParams = (LayoutParams) frameLayout.getLayoutParams();
layoutParams.topMargin = AndroidUtilities.dp(4);
layoutParams.height = AndroidUtilities.dp(48);
layoutParams.width = AndroidUtilities.dp(4);
frameLayout.setLayoutParams(layoutParams);
searchButton = new SearchButton(context);
searchButton.textView1.setText(LocaleController.getString("SearchGifs", R.string.SearchGifs));
searchButton.textView2.setText("GIPHY");
searchButton.imageView.setImageResource(R.drawable.search_gif);
addView(searchButton);
layoutParams = (LayoutParams) searchButton.getLayoutParams();
layoutParams.weight = 0.5f;
layoutParams.topMargin = AndroidUtilities.dp(4);
layoutParams.height = AndroidUtilities.dp(48);
layoutParams.width = 0;
searchButton.setLayoutParams(layoutParams);
if (allowGifs) {
searchButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (delegate != null) {
delegate.didPressedSearchButton(1);
}
}
});
} else {
searchButton.setAlpha(0.5f);
}
}
public void setDelegate(PhotoPickerSearchCellDelegate delegate) {
this.delegate = delegate;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(52), MeasureSpec.EXACTLY));
}
}
@@ -1205,17 +1205,17 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
getParentActivity().requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 4);
return;
}
PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(false, true, ChatActivity.this);
PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(false, ChatActivity.this);
fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {
@Override
public void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions, ArrayList<MediaController.SearchImage> webPhotos) {
public void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions) {
SendMessagesHelper.prepareSendingPhotos(photos, null, dialog_id, captions);
SendMessagesHelper.prepareSendingPhotosSearch(webPhotos, dialog_id);
m_mrChat.cleanDraft();
}
@Override
public void startPhotoSelectActivity() {
/* -- this is the fallback implementation of the gallery selection, see ID_OPEN_SYSTEM_SELECTOR
try {
Intent videoPickerIntent = new Intent();
videoPickerIntent.setType("video/*");
@@ -1230,7 +1230,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
startActivityForResult(chooserIntent, RC1_CHAT_PICK);
} catch (Exception e) {
FileLog.e("messenger", e);
}
} */
}
@Override
@@ -1717,6 +1717,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
AndroidUtilities.addMediaToGallery(currentPicturePath);
currentPicturePath = null;
} else if (requestCode == RC1_CHAT_PICK) {
/* -- this is the fallback implementation of the gallery selection, see ID_OPEN_SYSTEM_SELECTOR
if (data == null || data.getData() == null) {
showAttachmentError();
return;
@@ -1744,7 +1745,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} else {
SendMessagesHelper.prepareSendingPhoto(null, uri, dialog_id, null);
}
m_mrChat.cleanDraft();
m_mrChat.cleanDraft(); */
} else if (requestCode == RC2_CHAT_VIDEO_CAPTURE) {
String videoPath = null;
FileLog.d("messenger", "pic path " + currentPicturePath);
@@ -97,10 +97,10 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
return;
}
}
PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(true, false, null);
PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(true, null);
fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {
@Override
public void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions, ArrayList<MediaController.SearchImage> webPhotos) {
public void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions) {
if (!photos.isEmpty()) {
Bitmap bitmap = ImageLoader.loadBitmap(photos.get(0), null, 800, 800, true);
processBitmap(bitmap);
@@ -109,13 +109,14 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
@Override
public void startPhotoSelectActivity() {
/* -- this is the fallback implementation of the gallery selection, see ID_OPEN_SYSTEM_SELECTOR
try {
Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT);
photoPickerIntent.setType("image/*");
parentFragment.startActivityForResult(photoPickerIntent, BaseFragment.RC14_AVATAR_GET_CONTENT);
} catch (Exception e) {
FileLog.e("messenger", e);
}
} */
}
@Override
@@ -189,10 +190,11 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg
AndroidUtilities.addMediaToGallery(currentPicturePath);
currentPicturePath = null;
} else if (requestCode == BaseFragment.RC14_AVATAR_GET_CONTENT) {
/* -- this is the fallback implementation of the gallery selection, see ID_OPEN_SYSTEM_SELECTOR
if (data == null || data.getData() == null) {
return;
}
startCrop(null, data.getData());
startCrop(null, data.getData()); */
}
}
}
@@ -54,7 +54,6 @@ import com.b44t.ui.ActionBar.BaseFragment;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.ui.Adapters.BaseFragmentAdapter;
import com.b44t.ui.Cells.PhotoPickerAlbumsCell;
import com.b44t.ui.Cells.PhotoPickerSearchCell;
import com.b44t.ui.Components.LayoutHelper;
import com.b44t.ui.Components.PickerBottomLayout;
@@ -64,7 +63,7 @@ import java.util.HashMap;
public class PhotoAlbumPickerActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
public interface PhotoAlbumPickerActivityDelegate {
void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions, ArrayList<MediaController.SearchImage> webPhotos);
void didSelectPhotos(ArrayList<String> photos, ArrayList<String> captions);
boolean didSelectVideo(String path);
void startPhotoSelectActivity();
}
@@ -72,11 +71,6 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
private ArrayList<MediaController.AlbumEntry> albumsSorted = null;
private ArrayList<MediaController.AlbumEntry> videoAlbumsSorted = null;
private HashMap<Integer, MediaController.PhotoEntry> selectedPhotos = new HashMap<>();
private HashMap<String, MediaController.SearchImage> selectedWebPhotos = new HashMap<>();
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<>();
private boolean loading = false;
private int columnsCount = 2;
@@ -89,7 +83,6 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
private PickerBottomLayout pickerBottomLayout;
private boolean sendPressed;
private boolean singlePhoto;
private boolean allowGifs;
private final static int SELECTMODE0_PHOTOS = 0;
private final static int SELECTMODE1_VIDEOS = 1;
@@ -99,14 +92,14 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
private PhotoAlbumPickerActivityDelegate delegate;
private final static int item_photos = 2;
private final static int item_video = 3;
private final static int ID_OPEN_SYSTEM_SELECTOR = 1;
private final static int ID_ITEM_PHOTOS = 2;
private final static int ID_ITEM_VIDEO = 3;
public PhotoAlbumPickerActivity(boolean singlePhoto, boolean allowGifs, ChatActivity chatActivity) {
public PhotoAlbumPickerActivity(boolean singlePhoto, ChatActivity chatActivity) {
super();
this.chatActivity = chatActivity;
this.singlePhoto = singlePhoto;
this.allowGifs = allowGifs;
}
@Override
@@ -114,7 +107,6 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
loading = true;
MediaController.loadGalleryPhotosAlbums(classGuid);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.albumsDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recentImagesDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
return super.onFragmentCreate();
}
@@ -122,7 +114,6 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
@Override
public void onFragmentDestroy() {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.albumsDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recentImagesDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
super.onFragmentDestroy();
}
@@ -136,12 +127,12 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == 1) {
} else if (id == ID_OPEN_SYSTEM_SELECTOR) {
if (delegate != null) {
finishFragment(false);
delegate.startPhotoSelectActivity();
}
} else if (id == item_photos) {
} else if (id == ID_ITEM_PHOTOS) {
if (selectedMode == SELECTMODE0_PHOTOS) {
return;
}
@@ -149,7 +140,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
dropDown.setText(LocaleController.getString("PickerPhotos", R.string.PickerPhotos));
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
listAdapter.notifyDataSetChanged();
} else if (id == item_video) {
} else if (id == ID_ITEM_VIDEO) {
if (selectedMode == SELECTMODE1_VIDEOS) {
return;
}
@@ -162,7 +153,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(1, R.drawable.ic_ab_other);
//menu.addItem(ID_OPEN_SYSTEM_SELECTOR, R.drawable.ic_ab_other); -- fallback-selector not needed
fragmentView = new FrameLayout(context);
@@ -174,8 +165,8 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
dropDownContainer = new ActionBarMenuItem(context, menu, 0);
dropDownContainer.setSubMenuOpenSide(1);
dropDownContainer.addSubItem(item_photos, LocaleController.getString("PickerPhotos", R.string.PickerPhotos), 0);
dropDownContainer.addSubItem(item_video, LocaleController.getString("PickerVideo", R.string.PickerVideo), 0);
dropDownContainer.addSubItem(ID_ITEM_PHOTOS, LocaleController.getString("PickerPhotos", R.string.PickerPhotos), 0);
dropDownContainer.addSubItem(ID_ITEM_VIDEO, LocaleController.getString("PickerVideo", R.string.PickerVideo), 0);
actionBar.addView(dropDownContainer);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams();
layoutParams.height = LayoutHelper.MATCH_PARENT;
@@ -296,7 +287,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
progressView.setVisibility(View.GONE);
listView.setEmptyView(emptyView);
}
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
pickerBottomLayout.updateSelectedCount(selectedPhotos.size(), true);
View shadow = new View(context);
shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
@@ -349,21 +340,6 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
}
} else if (id == NotificationCenter.closeChats) {
removeSelfFromStack();
} else if (id == NotificationCenter.recentImagesDidLoaded) {
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);
}
}
}
}
@@ -372,7 +348,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
}
private void sendSelectedPhotos() {
if (selectedPhotos.isEmpty() && selectedWebPhotos.isEmpty() || delegate == null || sendPressed) {
if (selectedPhotos.isEmpty() || delegate == null || sendPressed) {
return;
}
sendPressed = true;
@@ -388,47 +364,8 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
captions.add(photoEntry.caption != null ? photoEntry.caption.toString() : null);
}
}
ArrayList<MediaController.SearchImage> webPhotos = new ArrayList<>();
boolean gifChanged = false;
boolean webChange = false;
for (HashMap.Entry<String, MediaController.SearchImage> entry : selectedWebPhotos.entrySet()) {
MediaController.SearchImage searchImage = entry.getValue();
if (searchImage.imagePath != null) {
photos.add(searchImage.imagePath);
captions.add(searchImage.caption != null ? searchImage.caption.toString() : null);
} else {
webPhotos.add(searchImage);
}
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);
}
}
}
if (webChange) {
//MessagesStorage.getInstance().putWebRecent(recentWebImages);
}
if (gifChanged) {
//MessagesStorage.getInstance().putWebRecent(recentGifImages);
}
delegate.didSelectPhotos(photos, captions, webPhotos);
delegate.didSelectPhotos(photos, captions);
}
private void fixLayout() {
@@ -475,21 +412,16 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
}
}
private void openPhotoPicker(MediaController.AlbumEntry albumEntry, int type) {
ArrayList<MediaController.SearchImage> recentImages = null;
if (albumEntry == null) {
if (type == PhotoPickerActivity.TYPE0_SEARCH_IMAGES) {
recentImages = recentWebImages;
} else if (type == PhotoPickerActivity.TYPE1_SEARCH_GIF) {
recentImages = recentGifImages;
}
private void openPhotoPicker(MediaController.AlbumEntry albumEntry) {
if( albumEntry == null ) {
return;
}
PhotoPickerActivity fragment = new PhotoPickerActivity(type, albumEntry, selectedPhotos, selectedWebPhotos, recentImages, singlePhoto, chatActivity);
PhotoPickerActivity fragment = new PhotoPickerActivity(albumEntry, selectedPhotos, singlePhoto, chatActivity);
fragment.setDelegate(new PhotoPickerActivity.PhotoPickerActivityDelegate() {
@Override
public void selectedPhotosChanged() {
if (pickerBottomLayout != null) {
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
pickerBottomLayout.updateSelectedCount(selectedPhotos.size(), true);
}
}
@@ -530,10 +462,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
@Override
public int getCount() {
if (singlePhoto || selectedMode == SELECTMODE0_PHOTOS) {
if (singlePhoto) {
return albumsSorted != null ? (int) Math.ceil(albumsSorted.size() / (float) columnsCount) : 0;
}
return 1 + (albumsSorted != null ? (int) Math.ceil(albumsSorted.size() / (float) columnsCount) : 0);
return (albumsSorted != null ? (int) Math.ceil(albumsSorted.size() / (float) columnsCount) : 0);
} else {
return (videoAlbumsSorted != null ? (int) Math.ceil(videoAlbumsSorted.size() / (float) columnsCount) : 0);
}
@@ -565,7 +494,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
photoPickerAlbumsCell.setDelegate(new PhotoPickerAlbumsCell.PhotoPickerAlbumsCellDelegate() {
@Override
public void didSelectAlbum(MediaController.AlbumEntry albumEntry) {
openPhotoPicker(albumEntry, PhotoPickerActivity.TYPE0_SEARCH_IMAGES);
openPhotoPicker(albumEntry);
}
});
} else {
@@ -573,12 +502,7 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
}
photoPickerAlbumsCell.setAlbumsCount(columnsCount);
for (int a = 0; a < columnsCount; a++) {
int index;
if (singlePhoto || selectedMode == SELECTMODE1_VIDEOS) {
index = i * columnsCount + a;
} else {
index = (i - 1) * columnsCount + a;
}
int index = i * columnsCount + a;
if (singlePhoto || selectedMode == SELECTMODE0_PHOTOS) {
if (index < albumsSorted.size()) {
MediaController.AlbumEntry albumEntry = albumsSorted.get(index);
@@ -596,37 +520,18 @@ public class PhotoAlbumPickerActivity extends BaseFragment implements Notificati
}
}
photoPickerAlbumsCell.requestLayout();
} else if (type == 1) {
if (view == null) {
view = new PhotoPickerSearchCell(mContext, allowGifs);
((PhotoPickerSearchCell) view).setDelegate(new PhotoPickerSearchCell.PhotoPickerSearchCellDelegate() {
@Override
public void didPressedSearchButton(int index) {
openPhotoPicker(null, index);
}
});
}
}
return view;
}
@Override
public int getItemViewType(int i) {
if (singlePhoto || selectedMode == SELECTMODE1_VIDEOS) {
return 0;
}
if (i == 0) {
return 1;
}
return 0;
}
@Override
public int getViewTypeCount() {
if (singlePhoto || selectedMode == SELECTMODE1_VIDEOS) {
return 1;
}
return 2;
return 1;
}
@Override
@@ -27,34 +27,25 @@ import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.b44t.messenger.AndroidUtilities;
import com.b44t.messenger.FileLoader;
import com.b44t.messenger.LocaleController;
import com.b44t.messenger.MediaController;
import com.b44t.messenger.NotificationCenter;
import com.b44t.messenger.volley.RequestQueue;
import com.b44t.messenger.volley.toolbox.Volley;
import com.b44t.messenger.ApplicationLoader;
import com.b44t.messenger.R;
import com.b44t.messenger.TLRPC;
import com.b44t.messenger.MessageObject;
import com.b44t.ui.ActionBar.ActionBarMenu;
import com.b44t.ui.ActionBar.ActionBarMenuItem;
import com.b44t.ui.ActionBar.Theme;
import com.b44t.ui.Adapters.BaseFragmentAdapter;
import com.b44t.ui.ActionBar.ActionBar;
@@ -77,37 +68,13 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
boolean didSelectVideo(String path);
}
private RequestQueue requestQueue;
public final static int TYPE0_SEARCH_IMAGES = 0;
public final static int TYPE1_SEARCH_GIF = 1;
private int type;
private HashMap<String, MediaController.SearchImage> selectedWebPhotos;
private HashMap<Integer, MediaController.PhotoEntry> selectedPhotos;
private ArrayList<MediaController.SearchImage> recentImages;
private ArrayList<MediaController.SearchImage> searchResult = new ArrayList<>();
private HashMap<String, MediaController.SearchImage> searchResultKeys = new HashMap<>();
private HashMap<String, MediaController.SearchImage> searchResultUrls = new HashMap<>();
private boolean searching;
private String nextSearchBingString;
private boolean giphySearchEndReached = true;
private String lastSearchString;
private boolean loadingRecent;
private int nextGiphySearchOffset;
private int giphyReqId;
private int lastSearchToken;
private MediaController.AlbumEntry selectedAlbum;
private GridView listView;
private ListAdapter listAdapter;
private PickerBottomLayout pickerBottomLayout;
private FrameLayout progressView;
private TextView emptyView;
private ActionBarMenuItem searchItem;
private int itemWidth = 100;
private boolean sendPressed;
private boolean singlePhoto;
@@ -115,16 +82,13 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
private PhotoPickerActivityDelegate delegate;
public PhotoPickerActivity(int type, MediaController.AlbumEntry selectedAlbum, HashMap<Integer, MediaController.PhotoEntry> selectedPhotos, HashMap<String, MediaController.SearchImage> selectedWebPhotos, ArrayList<MediaController.SearchImage> recentImages, boolean onlyOnePhoto, ChatActivity chatActivity) {
public PhotoPickerActivity(MediaController.AlbumEntry selectedAlbum, HashMap<Integer, MediaController.PhotoEntry> selectedPhotos, boolean onlyOnePhoto, ChatActivity chatActivity) {
super();
this.selectedAlbum = selectedAlbum;
this.selectedAlbum = selectedAlbum; // must never be null
this.selectedPhotos = selectedPhotos;
this.selectedWebPhotos = selectedWebPhotos;
this.type = type;
this.recentImages = recentImages;
this.singlePhoto = onlyOnePhoto;
this.chatActivity = chatActivity;
if (selectedAlbum != null && selectedAlbum.isVideo) {
if (selectedAlbum.isVideo) {
singlePhoto = true;
}
}
@@ -132,25 +96,12 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public boolean onFragmentCreate() {
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recentImagesDidLoaded);
if (selectedAlbum == null) {
requestQueue = Volley.newRequestQueue(ApplicationLoader.applicationContext);
if (recentImages.isEmpty()) {
//MessagesStorage.getInstance().loadWebRecent(type);
loadingRecent = true;
}
}
return super.onFragmentCreate();
}
@Override
public void onFragmentDestroy() {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recentImagesDidLoaded);
if (requestQueue != null) {
requestQueue.cancelAll("search");
requestQueue.stop();
}
super.onFragmentDestroy();
}
@@ -158,13 +109,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public View createView(Context context) {
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
if (selectedAlbum != null) {
actionBar.setTitle(selectedAlbum.bucketName);
} else if (type == TYPE0_SEARCH_IMAGES) {
actionBar.setTitle(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else if (type == TYPE1_SEARCH_GIF) {
actionBar.setTitle(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
actionBar.setTitle(selectedAlbum.bucketName);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
@@ -174,36 +119,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
});
if (selectedAlbum == null) {
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true, false).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
}
@Override
public boolean canCollapseSearch() {
finishFragment();
return false;
}
@Override
public void onSearchPressed(EditText editText) {
// Telegram-FOSS doesn't support searching with external engines (privacy issues)
return;
}
});
}
if (selectedAlbum == null) {
if (type == TYPE0_SEARCH_IMAGES) {
searchItem.getSearchField().setHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
} else if (type == TYPE1_SEARCH_GIF) {
searchItem.getSearchField().setHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
}
}
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
@@ -231,7 +146,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if (selectedAlbum != null && selectedAlbum.isVideo) {
if (selectedAlbum.isVideo) {
if (i < 0 || i >= selectedAlbum.photos.size()) {
return;
}
@@ -239,52 +154,23 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
finishFragment();
}
} else {
ArrayList<Object> arrayList;
if (selectedAlbum != null) {
arrayList = (ArrayList) selectedAlbum.photos;
} else {
if (searchResult.isEmpty() && lastSearchString == null) {
arrayList = (ArrayList) recentImages;
} else {
arrayList = (ArrayList) searchResult;
}
}
ArrayList<Object> arrayList = (ArrayList) selectedAlbum.photos;
if (i < 0 || i >= arrayList.size()) {
return;
}
if (searchItem != null) {
AndroidUtilities.hideKeyboard(searchItem.getSearchField());
}
PhotoViewer.getInstance().setParentActivity(getParentActivity());
PhotoViewer.getInstance().openPhotoForSelect(arrayList, i, singlePhoto ? 1 : 0, PhotoPickerActivity.this, chatActivity);
}
}
});
if (selectedAlbum == null) {
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
// Telegram-FOSS doesn't support searching with external engines (privacy issues)
return false;
}
});
}
emptyView = new TextView(context);
TextView emptyView = new TextView(context);
emptyView.setTextColor(0xff808080);
emptyView.setTextSize(20);
emptyView.setGravity(Gravity.CENTER);
emptyView.setVisibility(View.GONE);
if (selectedAlbum != null) {
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
} else {
if (type == TYPE0_SEARCH_IMAGES) {
emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
} else if (type == TYPE1_SEARCH_GIF) {
emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
}
}
emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
frameLayout.addView(emptyView);
layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
layoutParams.width = LayoutHelper.MATCH_PARENT;
@@ -298,42 +184,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
});
if (selectedAlbum == null) {
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
if (i == SCROLL_STATE_TOUCH_SCROLL) {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
}
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
// Telegram-FOSS doesn't support searching with external engines (privacy issues)
return;
}
});
progressView = new FrameLayout(context);
progressView.setVisibility(View.GONE);
frameLayout.addView(progressView);
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
layoutParams.width = LayoutHelper.MATCH_PARENT;
layoutParams.height = LayoutHelper.MATCH_PARENT;
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
progressView.setLayoutParams(layoutParams);
ProgressBar progressBar = new ProgressBar(context);
progressView.addView(progressBar);
layoutParams = (FrameLayout.LayoutParams) progressBar.getLayoutParams();
layoutParams.width = LayoutHelper.WRAP_CONTENT;
layoutParams.height = LayoutHelper.WRAP_CONTENT;
layoutParams.gravity = Gravity.CENTER;
progressBar.setLayoutParams(layoutParams);
updateSearchInterface();
}
pickerBottomLayout = new PickerBottomLayout(context, false);
frameLayout.addView(pickerBottomLayout);
layoutParams = (FrameLayout.LayoutParams) pickerBottomLayout.getLayoutParams();
@@ -359,7 +209,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
listView.setEmptyView(emptyView);
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
pickerBottomLayout.updateSelectedCount(selectedPhotos.size(), true);
View shadow = new View(context);
shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
@@ -374,10 +224,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
if (searchItem != null) {
searchItem.openSearch(true);
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
fixLayout();
}
@@ -392,12 +238,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.closeChats) {
removeSelfFromStack();
} else if (id == NotificationCenter.recentImagesDidLoaded) {
if (selectedAlbum == null && type == (Integer) args[0]) {
recentImages = (ArrayList<MediaController.SearchImage>) args[1];
loadingRecent = false;
updateSearchInterface();
}
}
}
@@ -409,21 +249,10 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
if (view instanceof PhotoPickerPhotoCell) {
PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
int num = (Integer) cell.photoImage.getTag();
if (selectedAlbum != null) {
if (num < 0 || num >= selectedAlbum.photos.size()) {
continue;
}
} else {
ArrayList<MediaController.SearchImage> array;
if (searchResult.isEmpty() && lastSearchString == null) {
array = recentImages;
} else {
array = searchResult;
}
if (num < 0 || num >= array.size()) {
continue;
}
if (num < 0 || num >= selectedAlbum.photos.size()) {
continue;
}
if (num == index) {
return cell;
}
@@ -455,7 +284,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
public void updatePhotoAtIndex(int index) {
PhotoPickerPhotoCell cell = getCellForIndex(index);
if (cell != null) {
if (selectedAlbum != null) {
cell.photoImage.setOrientation(0, true);
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
if (photoEntry.thumbPath != null) {
@@ -470,24 +298,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
} else {
cell.photoImage.setImageResource(R.drawable.nophotos);
}
} else {
ArrayList<MediaController.SearchImage> array;
if (searchResult.isEmpty() && lastSearchString == null) {
array = recentImages;
} else {
array = searchResult;
}
MediaController.SearchImage photoEntry = array.get(index);
if (photoEntry.document != null && photoEntry.document.thumb != null) {
cell.photoImage.setImage(photoEntry.document.thumb.location, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
} else if (photoEntry.thumbPath != null) {
cell.photoImage.setImage(photoEntry.thumbPath, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
} else if (photoEntry.thumbUrl != null && photoEntry.thumbUrl.length() > 0) {
cell.photoImage.setImage(photoEntry.thumbUrl, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
} else {
cell.photoImage.setImageResource(R.drawable.nophotos);
}
}
}
}
@@ -510,21 +320,9 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
int num = (Integer) view.getTag();
if (selectedAlbum != null) {
if (num < 0 || num >= selectedAlbum.photos.size()) {
continue;
}
} else {
ArrayList<MediaController.SearchImage> array;
if (searchResult.isEmpty() && lastSearchString == null) {
array = recentImages;
} else {
array = searchResult;
}
if (num < 0 || num >= array.size()) {
continue;
}
}
if (num == index) {
cell.checkBox.setVisibility(View.VISIBLE);
break;
@@ -541,23 +339,12 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public boolean isPhotoChecked(int index) {
if (selectedAlbum != null) {
return !(index < 0 || index >= selectedAlbum.photos.size()) && selectedPhotos.containsKey(selectedAlbum.photos.get(index).imageId);
} else {
ArrayList<MediaController.SearchImage> array;
if (searchResult.isEmpty() && lastSearchString == null) {
array = recentImages;
} else {
array = searchResult;
}
return !(index < 0 || index >= array.size()) && selectedWebPhotos.containsKey(array.get(index).id);
}
}
@Override
public void setPhotoChecked(int index) {
boolean add = true;
if (selectedAlbum != null) {
if (index < 0 || index >= selectedAlbum.photos.size()) {
return;
}
@@ -568,25 +355,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
} else {
selectedPhotos.put(photoEntry.imageId, photoEntry);
}
} else {
MediaController.SearchImage photoEntry;
ArrayList<MediaController.SearchImage> array;
if (searchResult.isEmpty() && lastSearchString == null) {
array = recentImages;
} else {
array = searchResult;
}
if (index < 0 || index >= array.size()) {
return;
}
photoEntry = array.get(index);
if (selectedWebPhotos.containsKey(photoEntry.id)) {
selectedWebPhotos.remove(photoEntry.id);
add = false;
} else {
selectedWebPhotos.put(photoEntry.id, photoEntry);
}
}
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View view = listView.getChildAt(a);
@@ -596,7 +364,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
break;
}
}
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
pickerBottomLayout.updateSelectedCount(selectedPhotos.size(), true);
delegate.selectedPhotosChanged();
}
@@ -609,7 +377,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public void sendButtonPressed(int index) {
if (selectedAlbum != null) {
if (selectedPhotos.isEmpty()) {
if (index < 0 || index >= selectedAlbum.photos.size()) {
return;
@@ -617,47 +384,12 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
selectedPhotos.put(photoEntry.imageId, photoEntry);
}
} else if (selectedPhotos.isEmpty()) {
ArrayList<MediaController.SearchImage> array;
if (searchResult.isEmpty() && lastSearchString == null) {
array = recentImages;
} else {
array = searchResult;
}
if (index < 0 || index >= array.size()) {
return;
}
MediaController.SearchImage photoEntry = array.get(index);
selectedWebPhotos.put(photoEntry.id, photoEntry);
}
sendSelectedPhotos();
}
@Override
public int getSelectedCount() {
return selectedPhotos.size() + selectedWebPhotos.size();
}
@Override
public void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
if (isOpen && searchItem != null) {
AndroidUtilities.showKeyboard(searchItem.getSearchField());
}
}
private void updateSearchInterface() {
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
if (searching && searchResult.isEmpty() || loadingRecent && lastSearchString == null) {
progressView.setVisibility(View.VISIBLE);
listView.setEmptyView(null);
emptyView.setVisibility(View.GONE);
} else {
progressView.setVisibility(View.GONE);
emptyView.setVisibility(View.VISIBLE);
listView.setEmptyView(emptyView);
}
return selectedPhotos.size();
}
public void setDelegate(PhotoPickerActivityDelegate delegate) {
@@ -665,7 +397,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
private void sendSelectedPhotos() {
if (selectedPhotos.isEmpty() && selectedWebPhotos.isEmpty() || delegate == null || sendPressed) {
if (selectedPhotos.isEmpty() || delegate == null || sendPressed) {
return;
}
sendPressed = true;
@@ -717,10 +449,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
listAdapter.notifyDataSetChanged();
listView.setSelection(position);
if (selectedAlbum == null) {
emptyView.setPadding(0, 0, 0, (int) ((AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight()) * 0.4f));
}
}
private class ListAdapter extends BaseFragmentAdapter {
@@ -732,32 +460,16 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public boolean areAllItemsEnabled() {
return selectedAlbum != null;
return true;
}
@Override
public boolean isEnabled(int i) {
if (selectedAlbum == null) {
if (searchResult.isEmpty() && lastSearchString == null) {
return i < recentImages.size();
} else {
return i < searchResult.size();
}
}
return true;
}
@Override
public int getCount() {
if (selectedAlbum == null) {
if (searchResult.isEmpty() && lastSearchString == null) {
return recentImages.size();
} else if (type == TYPE0_SEARCH_IMAGES) {
return searchResult.size() + (nextSearchBingString == null ? 0 : 1);
} else if (type == TYPE1_SEARCH_GIF) {
return searchResult.size() + (giphySearchEndReached ? 0 : 1);
}
}
return selectedAlbum.photos.size();
}
@@ -778,8 +490,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
int viewType = getItemViewType(i);
if (viewType == 0) {
PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
if (view == null) {
view = new PhotoPickerPhotoCell(mContext);
@@ -788,7 +498,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override
public void onClick(View v) {
int index = (Integer) ((View) v.getParent()).getTag();
if (selectedAlbum != null) {
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
if (selectedPhotos.containsKey(photoEntry.imageId)) {
selectedPhotos.remove(photoEntry.imageId);
@@ -799,25 +508,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
selectedPhotos.put(photoEntry.imageId, photoEntry);
}
((PhotoPickerPhotoCell) v.getParent()).setChecked(selectedPhotos.containsKey(photoEntry.imageId), true);
} else {
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
MediaController.SearchImage photoEntry;
if (searchResult.isEmpty() && lastSearchString == null) {
photoEntry = recentImages.get((Integer) ((View) v.getParent()).getTag());
} else {
photoEntry = searchResult.get((Integer) ((View) v.getParent()).getTag());
}
if (selectedWebPhotos.containsKey(photoEntry.id)) {
selectedWebPhotos.remove(photoEntry.id);
photoEntry.imagePath = null;
photoEntry.thumbPath = null;
updatePhotoAtIndex(index);
} else {
selectedWebPhotos.put(photoEntry.id, photoEntry);
}
((PhotoPickerPhotoCell) v.getParent()).setChecked(selectedWebPhotos.containsKey(photoEntry.id), true);
}
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
pickerBottomLayout.updateSelectedCount(selectedPhotos.size(), true);
delegate.selectedPhotosChanged();
}
});
@@ -830,7 +521,6 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
boolean showing;
imageView.setOrientation(0, true);
if (selectedAlbum != null) {
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(i);
if (photoEntry.thumbPath != null) {
imageView.setImage(photoEntry.thumbPath, null, mContext.getResources().getDrawable(R.drawable.nophotos));
@@ -846,68 +536,24 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
}
cell.setChecked(selectedPhotos.containsKey(photoEntry.imageId), false);
showing = PhotoViewer.getInstance().isShowingImage(photoEntry.path);
} else {
MediaController.SearchImage photoEntry;
if (searchResult.isEmpty() && lastSearchString == null) {
photoEntry = recentImages.get(i);
} else {
photoEntry = searchResult.get(i);
}
if (photoEntry.thumbPath != null) {
imageView.setImage(photoEntry.thumbPath, null, mContext.getResources().getDrawable(R.drawable.nophotos));
} else if (photoEntry.thumbUrl != null && photoEntry.thumbUrl.length() > 0) {
imageView.setImage(photoEntry.thumbUrl, null, mContext.getResources().getDrawable(R.drawable.nophotos));
} else if (photoEntry.document != null && photoEntry.document.thumb != null) {
imageView.setImage(photoEntry.document.thumb.location, null, mContext.getResources().getDrawable(R.drawable.nophotos));
} else {
imageView.setImageResource(R.drawable.nophotos);
}
cell.setChecked(selectedWebPhotos.containsKey(photoEntry.id), false);
if (photoEntry.document != null) {
showing = PhotoViewer.getInstance().isShowingImage(FileLoader.getPathToAttach(photoEntry.document, true).getAbsolutePath());
} else {
showing = PhotoViewer.getInstance().isShowingImage(photoEntry.imageUrl);
}
}
imageView.getImageReceiver().setVisible(!showing, true);
cell.checkBox.setVisibility(singlePhoto || showing ? View.GONE : View.VISIBLE);
} else if (viewType == 1) {
if (view == null) {
LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.media_loading_layout, viewGroup, false);
}
ViewGroup.LayoutParams params = view.getLayoutParams();
params.width = itemWidth;
params.height = itemWidth;
view.setLayoutParams(params);
}
return view;
}
@Override
public int getItemViewType(int i) {
if (selectedAlbum != null || searchResult.isEmpty() && lastSearchString == null && i < recentImages.size() || i < searchResult.size()) {
return 0;
}
return 1;
return 0;
}
@Override
public int getViewTypeCount() {
return 2;
return 1;
}
@Override
public boolean isEmpty() {
if (selectedAlbum != null) {
return selectedAlbum.photos.isEmpty();
} else {
if (searchResult.isEmpty() && lastSearchString == null) {
return recentImages.isEmpty();
} else {
return searchResult.isEmpty();
}
}
return selectedAlbum.photos.isEmpty();
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

@@ -177,13 +177,6 @@
<string name="AllVideo">Alle Videos</string>
<string name="NoPhotos">Noch keine Bilder</string>
<string name="NoVideo">Noch keine Videos</string>
<string name="NoRecentPhotos">Suchverlauf</string>
<string name="NoRecentGIFs">Suchverlauf</string>
<string name="SearchImages">BILDERSUCHE</string>
<string name="SearchImagesInfo">BILDERSUCHE</string>
<string name="SearchGifs">GIF-SUCHE</string>
<string name="SearchImagesTitle">Suche Bilder</string>
<string name="SearchGifsTitle">Suche GIFs</string>
<string name="CropImage">Bild zuschneiden</string>
<string name="EditImage">Bild bearbeiten</string>
<string name="Enhance">Verbessern</string>
@@ -174,13 +174,6 @@
<string name="AllVideo">Todos los vídeos</string>
<string name="NoPhotos">Aún sin fotos</string>
<string name="NoVideo">Sin vídeos aún</string>
<string name="NoRecentPhotos">No hay fotos recientes</string>
<string name="NoRecentGIFs">No hay GIF recientes</string>
<string name="SearchImages">BUSCA FOTOS</string>
<string name="SearchImagesInfo">BÚSQUEDA WEB</string>
<string name="SearchGifs">BUSCA GIF</string>
<string name="SearchImagesTitle">Buscar foto</string>
<string name="SearchGifsTitle">Buscar GIF</string>
<string name="CropImage">Recortar imagen</string>
<string name="EditImage">Editar imagen</string>
<string name="Enhance">Realzar</string>
@@ -172,13 +172,6 @@
<string name="AllVideo">Toutes les vidéos</string>
<string name="NoPhotos">Aucune photo pour le moment</string>
<string name="NoVideo">Aucune vidéo pour le moement</string>
<string name="NoRecentPhotos">Aucune photo récente</string>
<string name="NoRecentGIFs">Aucun GIF récent</string>
<string name="SearchImages">TROUVER LES IMAGES</string>
<string name="SearchImagesInfo">RECHERCHER SUR LE WEB</string>
<string name="SearchGifs">TROUVER DES GIFS</string>
<string name="SearchImagesTitle">Recherche sur le web</string>
<string name="SearchGifsTitle">Rechercher des GIF</string>
<string name="CropImage">Couper les images</string>
<string name="EditImage">Modifier les images</string>
<string name="Enhance">Améliorer</string>
@@ -174,13 +174,6 @@
<string name="AllVideo">Tutti i video</string>
<string name="NoPhotos">Ancora nessuna foto</string>
<string name="NoVideo">Ancora nessun video</string>
<string name="NoRecentPhotos">Nessuna foto recente</string>
<string name="NoRecentGIFs">Nessuna GIF recente</string>
<string name="SearchImages">CERCA IMMAGINI</string>
<string name="SearchImagesInfo">RICERCA WEB</string>
<string name="SearchGifs">CERCA GIF</string>
<string name="SearchImagesTitle">Cerca su web</string>
<string name="SearchGifsTitle">Cerca GIF</string>
<string name="CropImage">Ritaglia immagine</string>
<string name="EditImage">Modifica immagine</string>
<string name="Enhance">Migliora</string>
@@ -174,13 +174,6 @@
<string name="AllVideo">Alle video\'s</string>
<string name="NoPhotos">Nog geen foto\'s</string>
<string name="NoVideo">Nog geen video\'s</string>
<string name="NoRecentPhotos">Niets recents</string>
<string name="NoRecentGIFs">Niets recents</string>
<string name="SearchImages">ONLINE ZOEKEN</string>
<string name="SearchImagesInfo">ZOEK OP HET WEB</string>
<string name="SearchGifs">GIF\'S ZOEKEN </string>
<string name="SearchImagesTitle">Online zoeken</string>
<string name="SearchGifsTitle">GIF\'s zoeken</string>
<string name="CropImage">Foto bijsnijden</string>
<string name="EditImage">Foto bewerken</string>
<string name="Enhance">Verbeteren</string>
@@ -177,13 +177,6 @@
<string name="AllVideo">Wszystkie wideo</string>
<string name="NoPhotos">Nie ma zdjęć</string>
<string name="NoVideo">Nie ma jeszcze wideo</string>
<string name="NoRecentPhotos">Nie ma wcześniejszych zdjęć</string>
<string name="NoRecentGIFs">Nie ma wcześniejszych GIFów</string>
<string name="SearchImages">SZUKAJ OBRAZY</string>
<string name="SearchImagesInfo">W INTERNECIE</string>
<string name="SearchGifs">SZUKAJ GIFY</string>
<string name="SearchImagesTitle">Przeszukaj internet</string>
<string name="SearchGifsTitle">Szukaj GIFy</string>
<string name="CropImage">Przytnij zdjęcie</string>
<string name="EditImage">Edytuj zdjęcie</string>
<string name="Enhance">Ulepszenie</string>
@@ -173,13 +173,6 @@
<string name="AllVideo">Todos os Vídeos</string>
<string name="NoPhotos">Ainda não há fotos</string>
<string name="NoVideo">Nenhum vídeo ainda</string>
<string name="NoRecentPhotos">Nenhuma foto recente</string>
<string name="NoRecentGIFs">Nenhum GIF recente</string>
<string name="SearchImages">BUSCAR IMAGENS</string>
<string name="SearchImagesInfo">BUSCA GLOBAL</string>
<string name="SearchGifs">BUSCAR GIFS</string>
<string name="SearchImagesTitle">Procurar na web</string>
<string name="SearchGifsTitle">Procurar GIFs</string>
<string name="CropImage">Recortar imagem</string>
<string name="EditImage">Editar imagem</string>
<string name="Enhance">Realçar</string>
@@ -177,13 +177,6 @@
<string name="AllVideo">All Videos</string>
<string name="NoPhotos">No photos yet</string>
<string name="NoVideo">No videos yet</string>
<string name="NoRecentPhotos">No recent photos</string>
<string name="NoRecentGIFs">No recent GIFs</string>
<string name="SearchImages">FIND IMAGES</string>
<string name="SearchImagesInfo">WEB SEARCH</string>
<string name="SearchGifs">FIND GIFS</string>
<string name="SearchImagesTitle">Search web</string>
<string name="SearchGifsTitle">Search GIFs</string>
<string name="CropImage">Crop image</string>
<string name="EditImage">Edit image</string>
<string name="Enhance">Enhance</string>