2014-06-12 01:13:15 +00:00
|
|
|
/*
|
2015-10-29 17:10:07 +00:00
|
|
|
* This is the source code of Telegram for Android v. 3.x.x.
|
2014-06-12 01:13:15 +00:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2016-01-11 17:19:48 +00:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2016.
|
2014-06-12 01:13:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2015-03-26 17:34:47 +00:00
|
|
|
import android.app.AlertDialog;
|
2014-06-12 01:13:15 +00:00
|
|
|
import android.content.Context;
|
2015-03-26 17:34:47 +00:00
|
|
|
import android.content.DialogInterface;
|
2015-01-02 22:15:07 +00:00
|
|
|
import android.graphics.Bitmap;
|
2014-06-12 01:13:15 +00:00
|
|
|
import android.os.Build;
|
2015-01-02 22:15:07 +00:00
|
|
|
import android.util.Base64;
|
|
|
|
import android.view.Gravity;
|
2014-06-12 01:13:15 +00:00
|
|
|
import android.view.LayoutInflater;
|
2014-10-07 20:14:27 +00:00
|
|
|
import android.view.MotionEvent;
|
2014-06-12 01:13:15 +00:00
|
|
|
import android.view.Surface;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
import android.view.WindowManager;
|
2015-01-02 22:15:07 +00:00
|
|
|
import android.widget.AbsListView;
|
2014-06-12 01:13:15 +00:00
|
|
|
import android.widget.AdapterView;
|
2015-01-02 22:15:07 +00:00
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.FrameLayout;
|
2014-06-12 01:13:15 +00:00
|
|
|
import android.widget.GridView;
|
2015-01-02 22:15:07 +00:00
|
|
|
import android.widget.ProgressBar;
|
2014-06-12 01:13:15 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONObject;
|
2015-09-24 20:52:02 +00:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2015-10-29 17:10:07 +00:00
|
|
|
import org.telegram.messenger.AnimationCompat.ViewProxy;
|
2016-01-11 17:19:48 +00:00
|
|
|
import org.telegram.messenger.FileLoader;
|
2015-09-24 20:52:02 +00:00
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MediaController;
|
|
|
|
import org.telegram.messenger.MessagesStorage;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
|
|
|
import org.telegram.messenger.volley.AuthFailureError;
|
|
|
|
import org.telegram.messenger.volley.Request;
|
|
|
|
import org.telegram.messenger.volley.RequestQueue;
|
|
|
|
import org.telegram.messenger.volley.Response;
|
|
|
|
import org.telegram.messenger.volley.VolleyError;
|
|
|
|
import org.telegram.messenger.volley.toolbox.JsonObjectRequest;
|
|
|
|
import org.telegram.messenger.volley.toolbox.Volley;
|
2014-12-01 17:56:31 +00:00
|
|
|
import org.telegram.messenger.ApplicationLoader;
|
2015-01-02 22:15:07 +00:00
|
|
|
import org.telegram.messenger.BuildVars;
|
|
|
|
import org.telegram.messenger.FileLog;
|
2014-06-12 01:13:15 +00:00
|
|
|
import org.telegram.messenger.R;
|
2016-01-11 17:19:48 +00:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
|
|
|
import org.telegram.tgnet.RequestDelegate;
|
|
|
|
import org.telegram.tgnet.TLObject;
|
2015-09-24 20:52:02 +00:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
|
|
|
import org.telegram.messenger.MessageObject;
|
2015-05-03 11:48:36 +00:00
|
|
|
import org.telegram.messenger.UserConfig;
|
2015-01-02 22:15:07 +00:00
|
|
|
import org.telegram.messenger.Utilities;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenuItem;
|
2014-06-20 00:18:13 +00:00
|
|
|
import org.telegram.ui.Adapters.BaseFragmentAdapter;
|
2014-11-13 20:10:14 +00:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2015-01-02 22:15:07 +00:00
|
|
|
import org.telegram.ui.Cells.PhotoPickerPhotoCell;
|
2014-12-01 17:56:31 +00:00
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
2015-05-03 11:48:36 +00:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2015-07-22 18:56:37 +00:00
|
|
|
import org.telegram.ui.Components.PickerBottomLayout;
|
2014-06-12 01:13:15 +00:00
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
import java.net.URLEncoder;
|
2014-06-12 01:13:15 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
2015-01-02 22:15:07 +00:00
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Map;
|
2014-06-12 01:13:15 +00:00
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
public class PhotoPickerActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, PhotoViewer.PhotoViewerProvider {
|
2014-06-12 01:13:15 +00:00
|
|
|
|
2015-03-18 23:09:45 +00:00
|
|
|
public interface PhotoPickerActivityDelegate {
|
|
|
|
void selectedPhotosChanged();
|
2016-01-11 17:19:48 +00:00
|
|
|
|
2015-03-18 23:09:45 +00:00
|
|
|
void actionButtonPressed(boolean canceled);
|
2016-01-11 17:19:48 +00:00
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
boolean didSelectVideo(String path);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
private RequestQueue requestQueue;
|
|
|
|
|
|
|
|
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;
|
2015-02-01 18:51:02 +00:00
|
|
|
private boolean giphySearchEndReached = true;
|
2015-01-02 22:15:07 +00:00
|
|
|
private String lastSearchString;
|
|
|
|
private boolean loadingRecent;
|
2016-01-11 17:19:48 +00:00
|
|
|
private int nextGiphySearchOffset;
|
|
|
|
private int giphyReqId;
|
|
|
|
private int lastSearchToken;
|
2015-01-02 22:15:07 +00:00
|
|
|
|
|
|
|
private MediaController.AlbumEntry selectedAlbum;
|
2014-06-12 01:13:15 +00:00
|
|
|
|
|
|
|
private GridView listView;
|
|
|
|
private ListAdapter listAdapter;
|
2015-07-22 18:56:37 +00:00
|
|
|
private PickerBottomLayout pickerBottomLayout;
|
2015-01-02 22:15:07 +00:00
|
|
|
private FrameLayout progressView;
|
2014-06-12 01:13:15 +00:00
|
|
|
private TextView emptyView;
|
2015-01-02 22:15:07 +00:00
|
|
|
private ActionBarMenuItem searchItem;
|
2014-06-12 01:13:15 +00:00
|
|
|
private int itemWidth = 100;
|
2015-01-02 22:15:07 +00:00
|
|
|
private boolean sendPressed;
|
2015-02-26 01:32:51 +00:00
|
|
|
private boolean singlePhoto;
|
2015-05-03 11:48:36 +00:00
|
|
|
private ChatActivity chatActivity;
|
2014-06-12 01:13:15 +00:00
|
|
|
|
|
|
|
private PhotoPickerActivityDelegate delegate;
|
|
|
|
|
2015-05-03 11:48:36 +00:00
|
|
|
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) {
|
2015-01-02 22:15:07 +00:00
|
|
|
super();
|
|
|
|
this.selectedAlbum = selectedAlbum;
|
|
|
|
this.selectedPhotos = selectedPhotos;
|
|
|
|
this.selectedWebPhotos = selectedWebPhotos;
|
|
|
|
this.type = type;
|
|
|
|
this.recentImages = recentImages;
|
2015-02-26 01:32:51 +00:00
|
|
|
this.singlePhoto = onlyOnePhoto;
|
2015-05-03 11:48:36 +00:00
|
|
|
this.chatActivity = chatActivity;
|
|
|
|
if (selectedAlbum != null && selectedAlbum.isVideo) {
|
|
|
|
singlePhoto = true;
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.closeChats);
|
2015-01-02 22:15:07 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.recentImagesDidLoaded);
|
|
|
|
if (selectedAlbum == null) {
|
|
|
|
requestQueue = Volley.newRequestQueue(ApplicationLoader.applicationContext);
|
|
|
|
if (recentImages.isEmpty()) {
|
|
|
|
MessagesStorage.getInstance().loadWebRecent(type);
|
|
|
|
loadingRecent = true;
|
|
|
|
}
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
return super.onFragmentCreate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.closeChats);
|
2015-01-02 22:15:07 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.recentImagesDidLoaded);
|
|
|
|
if (requestQueue != null) {
|
|
|
|
requestQueue.cancelAll("search");
|
|
|
|
requestQueue.stop();
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
super.onFragmentDestroy();
|
|
|
|
}
|
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2014-06-12 01:13:15 +00:00
|
|
|
@Override
|
2015-07-22 18:56:37 +00:00
|
|
|
public View createView(Context context) {
|
2015-04-09 18:00:14 +00:00
|
|
|
actionBar.setBackgroundColor(0xff333333);
|
|
|
|
actionBar.setItemsBackground(R.drawable.bar_selector_picker);
|
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
actionBar.setTitle(selectedAlbum.bucketName);
|
|
|
|
} else if (type == 0) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
|
|
|
|
} else if (type == 1) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
|
|
|
|
}
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
if (Build.VERSION.SDK_INT < 11) {
|
|
|
|
listView.setAdapter(null);
|
|
|
|
listView = null;
|
|
|
|
listAdapter = null;
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
finishFragment();
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
}
|
|
|
|
});
|
2015-01-02 22:15:07 +00:00
|
|
|
|
2015-04-09 18:00:14 +00:00
|
|
|
if (selectedAlbum == null) {
|
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
|
|
|
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
|
|
|
|
@Override
|
|
|
|
public void onSearchExpand() {
|
2015-01-02 22:15:07 +00:00
|
|
|
|
2015-04-09 18:00:14 +00:00
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
|
2015-04-09 18:00:14 +00:00
|
|
|
@Override
|
2015-06-29 17:12:11 +00:00
|
|
|
public boolean canCollapseSearch() {
|
2015-04-09 18:00:14 +00:00
|
|
|
finishFragment();
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
|
2015-04-09 18:00:14 +00:00
|
|
|
@Override
|
|
|
|
public void onTextChanged(EditText editText) {
|
|
|
|
if (editText.getText().length() == 0) {
|
2015-01-02 22:15:07 +00:00
|
|
|
searchResult.clear();
|
|
|
|
searchResultKeys.clear();
|
2015-04-09 18:00:14 +00:00
|
|
|
lastSearchString = null;
|
2015-01-02 22:15:07 +00:00
|
|
|
nextSearchBingString = null;
|
2015-02-01 18:51:02 +00:00
|
|
|
giphySearchEndReached = true;
|
2015-04-09 18:00:14 +00:00
|
|
|
searching = false;
|
|
|
|
requestQueue.cancelAll("search");
|
2015-01-02 22:15:07 +00:00
|
|
|
if (type == 0) {
|
2015-04-09 18:00:14 +00:00
|
|
|
emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
|
2015-01-02 22:15:07 +00:00
|
|
|
} else if (type == 1) {
|
2015-04-09 18:00:14 +00:00
|
|
|
emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
|
|
|
updateSearchInterface();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-09 18:00:14 +00:00
|
|
|
public void onSearchPressed(EditText editText) {
|
|
|
|
if (editText.getText().toString().length() == 0) {
|
2015-01-02 22:15:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
searchResult.clear();
|
|
|
|
searchResultKeys.clear();
|
|
|
|
nextSearchBingString = null;
|
|
|
|
giphySearchEndReached = true;
|
|
|
|
if (type == 0) {
|
|
|
|
searchBingImages(editText.getText().toString(), 0, 53);
|
|
|
|
} else if (type == 1) {
|
2016-01-11 17:19:48 +00:00
|
|
|
nextGiphySearchOffset = 0;
|
|
|
|
searchGiphyImages(editText.getText().toString(), 0);
|
2015-04-09 18:00:14 +00:00
|
|
|
}
|
|
|
|
lastSearchString = editText.getText().toString();
|
|
|
|
if (lastSearchString.length() == 0) {
|
|
|
|
lastSearchString = null;
|
|
|
|
if (type == 0) {
|
|
|
|
emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
|
|
|
|
} else if (type == 1) {
|
|
|
|
emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
|
|
|
|
}
|
|
|
|
updateSearchInterface();
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
|
|
|
});
|
2015-04-09 18:00:14 +00:00
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
|
2015-04-09 18:00:14 +00:00
|
|
|
if (selectedAlbum == null) {
|
|
|
|
if (type == 0) {
|
|
|
|
searchItem.getSearchField().setHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
|
|
|
|
} else if (type == 1) {
|
|
|
|
searchItem.getSearchField().setHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
|
2015-03-26 17:34:47 +00:00
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
}
|
2015-03-26 17:34:47 +00:00
|
|
|
|
2015-04-09 18:00:14 +00:00
|
|
|
fragmentView = new FrameLayout(context);
|
|
|
|
|
|
|
|
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
|
|
|
frameLayout.setBackgroundColor(0xff000000);
|
|
|
|
|
|
|
|
listView = new GridView(context);
|
|
|
|
listView.setPadding(AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4), AndroidUtilities.dp(4));
|
|
|
|
listView.setClipToPadding(false);
|
|
|
|
listView.setDrawSelectorOnTop(true);
|
|
|
|
listView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
|
|
|
|
listView.setHorizontalScrollBarEnabled(false);
|
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
|
|
|
listView.setNumColumns(GridView.AUTO_FIT);
|
|
|
|
listView.setVerticalSpacing(AndroidUtilities.dp(4));
|
|
|
|
listView.setHorizontalSpacing(AndroidUtilities.dp(4));
|
|
|
|
listView.setSelector(R.drawable.list_selector);
|
|
|
|
frameLayout.addView(listView);
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
|
2015-05-03 11:48:36 +00:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
2015-04-09 18:00:14 +00:00
|
|
|
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
|
|
|
|
listView.setLayoutParams(layoutParams);
|
|
|
|
listView.setAdapter(listAdapter = new ListAdapter(context));
|
|
|
|
AndroidUtilities.setListViewEdgeEffectColor(listView, 0xff333333);
|
|
|
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
2015-05-03 11:48:36 +00:00
|
|
|
if (selectedAlbum != null && selectedAlbum.isVideo) {
|
|
|
|
if (i < 0 || i >= selectedAlbum.photos.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (delegate.didSelectVideo(selectedAlbum.photos.get(i).path)) {
|
|
|
|
finishFragment();
|
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
} else {
|
2015-05-21 21:27:27 +00:00
|
|
|
ArrayList<Object> arrayList;
|
2015-05-03 11:48:36 +00:00
|
|
|
if (selectedAlbum != null) {
|
|
|
|
arrayList = (ArrayList) selectedAlbum.photos;
|
2015-04-09 18:00:14 +00:00
|
|
|
} else {
|
2015-05-03 11:48:36 +00:00
|
|
|
if (searchResult.isEmpty() && lastSearchString == null) {
|
|
|
|
arrayList = (ArrayList) recentImages;
|
|
|
|
} else {
|
|
|
|
arrayList = (ArrayList) searchResult;
|
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
if (i < 0 || i >= arrayList.size()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-29 17:10:07 +00:00
|
|
|
if (searchItem != null) {
|
|
|
|
AndroidUtilities.hideKeyboard(searchItem.getSearchField());
|
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
PhotoViewer.getInstance().setParentActivity(getParentActivity());
|
|
|
|
PhotoViewer.getInstance().openPhotoForSelect(arrayList, i, singlePhoto ? 1 : 0, PhotoPickerActivity.this, chatActivity);
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
}
|
|
|
|
});
|
2015-01-02 22:15:07 +00:00
|
|
|
|
2015-04-09 18:00:14 +00:00
|
|
|
if (selectedAlbum == null) {
|
|
|
|
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
if (searchResult.isEmpty() && lastSearchString == null) {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
|
|
|
|
builder.setMessage(LocaleController.getString("ClearSearch", R.string.ClearSearch));
|
|
|
|
builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
recentImages.clear();
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
MessagesStorage.getInstance().clearWebRecent(type);
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
});
|
|
|
|
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
2015-05-21 21:27:27 +00:00
|
|
|
showDialog(builder.create());
|
2015-04-09 18:00:14 +00:00
|
|
|
return true;
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
|
2015-04-09 18:00:14 +00:00
|
|
|
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 == 0) {
|
|
|
|
emptyView.setText(LocaleController.getString("NoRecentPhotos", R.string.NoRecentPhotos));
|
|
|
|
} else if (type == 1) {
|
|
|
|
emptyView.setText(LocaleController.getString("NoRecentGIFs", R.string.NoRecentGIFs));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
frameLayout.addView(emptyView);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) emptyView.getLayoutParams();
|
2015-05-03 11:48:36 +00:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
2015-04-09 18:00:14 +00:00
|
|
|
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
|
|
|
|
emptyView.setLayoutParams(layoutParams);
|
|
|
|
emptyView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
});
|
2015-01-02 22:15:07 +00:00
|
|
|
|
2015-04-09 18:00:14 +00:00
|
|
|
if (selectedAlbum == null) {
|
|
|
|
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
2014-06-12 01:13:15 +00:00
|
|
|
@Override
|
2015-04-09 18:00:14 +00:00
|
|
|
public void onScrollStateChanged(AbsListView absListView, int i) {
|
|
|
|
if (i == SCROLL_STATE_TOUCH_SCROLL) {
|
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
@Override
|
2015-04-09 18:00:14 +00:00
|
|
|
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
|
|
|
if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2 && !searching) {
|
|
|
|
if (type == 0 && nextSearchBingString != null) {
|
|
|
|
searchBingImages(lastSearchString, searchResult.size(), 54);
|
|
|
|
} else if (type == 1 && !giphySearchEndReached) {
|
2016-01-11 17:19:48 +00:00
|
|
|
searchGiphyImages(searchItem.getSearchField().getText().toString(), nextGiphySearchOffset);
|
2015-04-09 18:00:14 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-04-09 18:00:14 +00:00
|
|
|
progressView = new FrameLayout(context);
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
frameLayout.addView(progressView);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
|
2015-05-03 11:48:36 +00:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
|
|
|
layoutParams.height = LayoutHelper.MATCH_PARENT;
|
2015-04-09 18:00:14 +00:00
|
|
|
layoutParams.bottomMargin = singlePhoto ? 0 : AndroidUtilities.dp(48);
|
|
|
|
progressView.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
ProgressBar progressBar = new ProgressBar(context);
|
|
|
|
progressView.addView(progressBar);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) progressBar.getLayoutParams();
|
2015-05-03 11:48:36 +00:00
|
|
|
layoutParams.width = LayoutHelper.WRAP_CONTENT;
|
|
|
|
layoutParams.height = LayoutHelper.WRAP_CONTENT;
|
2015-04-09 18:00:14 +00:00
|
|
|
layoutParams.gravity = Gravity.CENTER;
|
|
|
|
progressBar.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
updateSearchInterface();
|
|
|
|
}
|
|
|
|
|
2015-07-22 18:56:37 +00:00
|
|
|
pickerBottomLayout = new PickerBottomLayout(context);
|
|
|
|
frameLayout.addView(pickerBottomLayout);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) pickerBottomLayout.getLayoutParams();
|
2015-05-03 11:48:36 +00:00
|
|
|
layoutParams.width = LayoutHelper.MATCH_PARENT;
|
2015-04-09 18:00:14 +00:00
|
|
|
layoutParams.height = AndroidUtilities.dp(48);
|
|
|
|
layoutParams.gravity = Gravity.BOTTOM;
|
2015-07-22 18:56:37 +00:00
|
|
|
pickerBottomLayout.setLayoutParams(layoutParams);
|
|
|
|
pickerBottomLayout.cancelButton.setOnClickListener(new View.OnClickListener() {
|
2015-04-09 18:00:14 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
delegate.actionButtonPressed(true);
|
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
});
|
2015-07-22 18:56:37 +00:00
|
|
|
pickerBottomLayout.doneButton.setOnClickListener(new View.OnClickListener() {
|
2015-04-09 18:00:14 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
sendSelectedPhotos();
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
});
|
|
|
|
if (singlePhoto) {
|
2015-07-22 18:56:37 +00:00
|
|
|
pickerBottomLayout.setVisibility(View.GONE);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
2015-04-09 18:00:14 +00:00
|
|
|
|
|
|
|
listView.setEmptyView(emptyView);
|
2015-07-22 18:56:37 +00:00
|
|
|
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
|
2015-04-09 18:00:14 +00:00
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
if (searchItem != null) {
|
2015-09-24 20:52:02 +00:00
|
|
|
searchItem.openSearch(true);
|
2015-01-02 22:15:07 +00:00
|
|
|
getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
fixLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
fixLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2015-01-02 22:15:07 +00:00
|
|
|
if (id == NotificationCenter.closeChats) {
|
2014-06-12 01:13:15 +00:00
|
|
|
removeSelfFromStack();
|
2015-01-02 22:15:07 +00:00
|
|
|
} else if (id == NotificationCenter.recentImagesDidLoaded) {
|
|
|
|
if (selectedAlbum == null && type == (Integer) args[0]) {
|
|
|
|
recentImages = (ArrayList<MediaController.SearchImage>) args[1];
|
|
|
|
loadingRecent = false;
|
|
|
|
updateSearchInterface();
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
private PhotoPickerPhotoCell getCellForIndex(int index) {
|
2014-06-12 01:13:15 +00:00
|
|
|
int count = listView.getChildCount();
|
|
|
|
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = listView.getChildAt(a);
|
2015-01-02 22:15:07 +00:00
|
|
|
if (view instanceof PhotoPickerPhotoCell) {
|
|
|
|
PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
|
2016-01-11 17:19:48 +00:00
|
|
|
int num = (Integer) cell.photoImage.getTag();
|
2015-01-02 22:15:07 +00:00
|
|
|
if (selectedAlbum != null) {
|
|
|
|
if (num < 0 || num >= selectedAlbum.photos.size()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2015-05-21 21:27:27 +00:00
|
|
|
ArrayList<MediaController.SearchImage> array;
|
2015-01-02 22:15:07 +00:00
|
|
|
if (searchResult.isEmpty() && lastSearchString == null) {
|
|
|
|
array = recentImages;
|
|
|
|
} else {
|
|
|
|
array = searchResult;
|
|
|
|
}
|
|
|
|
if (num < 0 || num >= array.size()) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
if (num == index) {
|
2015-01-02 22:15:07 +00:00
|
|
|
return cell;
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
@Override
|
|
|
|
public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
PhotoPickerPhotoCell cell = getCellForIndex(index);
|
|
|
|
if (cell != null) {
|
|
|
|
int coords[] = new int[2];
|
|
|
|
cell.photoImage.getLocationInWindow(coords);
|
|
|
|
PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
|
|
|
|
object.viewX = coords[0];
|
|
|
|
object.viewY = coords[1] - AndroidUtilities.statusBarHeight;
|
2015-10-29 17:10:07 +00:00
|
|
|
if (Build.VERSION.SDK_INT < 11) {
|
|
|
|
float scale = ViewProxy.getScaleX(cell.photoImage);
|
|
|
|
if (scale != 1) {
|
|
|
|
int width = cell.photoImage.getMeasuredWidth();
|
|
|
|
object.viewX += (width - width * scale) / 2;
|
|
|
|
object.viewY += (width - width * scale) / 2;
|
|
|
|
}
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
object.parentView = listView;
|
2015-04-09 18:00:14 +00:00
|
|
|
object.imageReceiver = cell.photoImage.getImageReceiver();
|
2015-01-02 22:15:07 +00:00
|
|
|
object.thumb = object.imageReceiver.getBitmap();
|
2015-10-29 17:10:07 +00:00
|
|
|
object.scale = ViewProxy.getScaleX(cell.photoImage);
|
2015-01-02 22:15:07 +00:00
|
|
|
cell.checkBox.setVisibility(View.GONE);
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-02-26 01:32:51 +00:00
|
|
|
@Override
|
|
|
|
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) {
|
|
|
|
cell.photoImage.setImage(photoEntry.thumbPath, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
} else if (photoEntry.path != null) {
|
|
|
|
cell.photoImage.setOrientation(photoEntry.orientation, true);
|
2015-05-03 11:48:36 +00:00
|
|
|
if (photoEntry.isVideo) {
|
|
|
|
cell.photoImage.setImage("vthumb://" + photoEntry.imageId + ":" + photoEntry.path, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
} else {
|
|
|
|
cell.photoImage.setImage("thumb://" + photoEntry.imageId + ":" + photoEntry.path, null, cell.getContext().getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
} else {
|
|
|
|
cell.photoImage.setImageResource(R.drawable.nophotos);
|
|
|
|
}
|
|
|
|
} else {
|
2015-05-21 21:27:27 +00:00
|
|
|
ArrayList<MediaController.SearchImage> array;
|
2015-02-26 01:32:51 +00:00
|
|
|
if (searchResult.isEmpty() && lastSearchString == null) {
|
|
|
|
array = recentImages;
|
|
|
|
} else {
|
|
|
|
array = searchResult;
|
|
|
|
}
|
|
|
|
MediaController.SearchImage photoEntry = array.get(index);
|
2016-01-11 17:19:48 +00:00
|
|
|
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) {
|
2015-02-26 01:32:51 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
@Override
|
|
|
|
public Bitmap getThumbForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
PhotoPickerPhotoCell cell = getCellForIndex(index);
|
|
|
|
if (cell != null) {
|
2015-04-09 18:00:14 +00:00
|
|
|
return cell.photoImage.getImageReceiver().getBitmap();
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-06-12 01:13:15 +00:00
|
|
|
@Override
|
|
|
|
public void willSwitchFromPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index) {
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = listView.getChildAt(a);
|
2014-10-23 07:55:32 +00:00
|
|
|
if (view.getTag() == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
|
2016-01-11 17:19:48 +00:00
|
|
|
int num = (Integer) view.getTag();
|
2015-01-02 22:15:07 +00:00
|
|
|
if (selectedAlbum != null) {
|
|
|
|
if (num < 0 || num >= selectedAlbum.photos.size()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
2015-05-21 21:27:27 +00:00
|
|
|
ArrayList<MediaController.SearchImage> array;
|
2015-01-02 22:15:07 +00:00
|
|
|
if (searchResult.isEmpty() && lastSearchString == null) {
|
|
|
|
array = recentImages;
|
|
|
|
} else {
|
|
|
|
array = searchResult;
|
|
|
|
}
|
|
|
|
if (num < 0 || num >= array.size()) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
if (num == index) {
|
2015-01-02 22:15:07 +00:00
|
|
|
cell.checkBox.setVisibility(View.VISIBLE);
|
2014-06-12 01:13:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void willHidePhotoViewer() {
|
|
|
|
if (listAdapter != null) {
|
|
|
|
listAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPhotoChecked(int index) {
|
2015-01-02 22:15:07 +00:00
|
|
|
if (selectedAlbum != null) {
|
|
|
|
return !(index < 0 || index >= selectedAlbum.photos.size()) && selectedPhotos.containsKey(selectedAlbum.photos.get(index).imageId);
|
|
|
|
} else {
|
2015-05-21 21:27:27 +00:00
|
|
|
ArrayList<MediaController.SearchImage> array;
|
2015-01-02 22:15:07 +00:00
|
|
|
if (searchResult.isEmpty() && lastSearchString == null) {
|
|
|
|
array = recentImages;
|
|
|
|
} else {
|
|
|
|
array = searchResult;
|
|
|
|
}
|
|
|
|
return !(index < 0 || index >= array.size()) && selectedWebPhotos.containsKey(array.get(index).id);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPhotoChecked(int index) {
|
2015-01-02 22:15:07 +00:00
|
|
|
boolean add = true;
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
if (index < 0 || index >= selectedAlbum.photos.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
|
|
|
|
if (selectedPhotos.containsKey(photoEntry.imageId)) {
|
|
|
|
selectedPhotos.remove(photoEntry.imageId);
|
|
|
|
add = false;
|
|
|
|
} else {
|
|
|
|
selectedPhotos.put(photoEntry.imageId, photoEntry);
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
} else {
|
2015-05-21 21:27:27 +00:00
|
|
|
MediaController.SearchImage photoEntry;
|
|
|
|
ArrayList<MediaController.SearchImage> array;
|
2015-01-02 22:15:07 +00:00
|
|
|
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);
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View view = listView.getChildAt(a);
|
2015-01-02 22:15:07 +00:00
|
|
|
int num = (Integer) view.getTag();
|
2014-06-12 01:13:15 +00:00
|
|
|
if (num == index) {
|
2015-10-29 17:10:07 +00:00
|
|
|
((PhotoPickerPhotoCell) view).setChecked(add, false);
|
2014-06-12 01:13:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-07-22 18:56:37 +00:00
|
|
|
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
|
2015-01-02 22:15:07 +00:00
|
|
|
delegate.selectedPhotosChanged();
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-29 17:10:07 +00:00
|
|
|
public boolean cancelButtonPressed() {
|
2015-01-02 22:15:07 +00:00
|
|
|
delegate.actionButtonPressed(true);
|
2014-06-12 01:13:15 +00:00
|
|
|
finishFragment();
|
2015-10-29 17:10:07 +00:00
|
|
|
return true;
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendButtonPressed(int index) {
|
2015-01-02 22:15:07 +00:00
|
|
|
if (selectedAlbum != null) {
|
|
|
|
if (selectedPhotos.isEmpty()) {
|
|
|
|
if (index < 0 || index >= selectedAlbum.photos.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
|
|
|
|
selectedPhotos.put(photoEntry.imageId, photoEntry);
|
|
|
|
}
|
|
|
|
} else if (selectedPhotos.isEmpty()) {
|
2015-05-21 21:27:27 +00:00
|
|
|
ArrayList<MediaController.SearchImage> array;
|
2015-01-02 22:15:07 +00:00
|
|
|
if (searchResult.isEmpty() && lastSearchString == null) {
|
|
|
|
array = recentImages;
|
|
|
|
} else {
|
|
|
|
array = searchResult;
|
|
|
|
}
|
|
|
|
if (index < 0 || index >= array.size()) {
|
2014-06-12 01:13:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
MediaController.SearchImage photoEntry = array.get(index);
|
|
|
|
selectedWebPhotos.put(photoEntry.id, photoEntry);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
sendSelectedPhotos();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSelectedCount() {
|
2015-01-02 22:15:07 +00:00
|
|
|
return selectedPhotos.size() + selectedWebPhotos.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-29 17:10:07 +00:00
|
|
|
public void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
|
|
|
|
if (isOpen && searchItem != null) {
|
2015-01-02 22:15:07 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-11 17:19:48 +00:00
|
|
|
private void searchGiphyImages(final String query, int offset) {
|
2015-01-02 22:15:07 +00:00
|
|
|
if (searching) {
|
|
|
|
searching = false;
|
2016-01-11 17:19:48 +00:00
|
|
|
if (giphyReqId != 0) {
|
|
|
|
ConnectionsManager.getInstance().cancelRequest(giphyReqId, true);
|
|
|
|
giphyReqId = 0;
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
requestQueue.cancelAll("search");
|
|
|
|
}
|
2016-01-11 17:19:48 +00:00
|
|
|
searching = true;
|
|
|
|
TLRPC.TL_messages_searchGifs req = new TLRPC.TL_messages_searchGifs();
|
|
|
|
req.q = query;
|
|
|
|
req.offset = offset;
|
|
|
|
final int token = ++lastSearchToken;
|
|
|
|
giphyReqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
|
|
|
|
@Override
|
|
|
|
public void run(final TLObject response, TLRPC.TL_error error) {
|
|
|
|
AndroidUtilities.runOnUIThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (token != lastSearchToken) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (response != null) {
|
|
|
|
boolean added = false;
|
|
|
|
TLRPC.TL_messages_foundGifs res = (TLRPC.TL_messages_foundGifs) response;
|
|
|
|
nextGiphySearchOffset = res.next_offset;
|
|
|
|
for (int a = 0; a < res.results.size(); a++) {
|
|
|
|
TLRPC.FoundGif gif = res.results.get(a);
|
|
|
|
if (searchResultKeys.containsKey(gif.url)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
added = true;
|
|
|
|
MediaController.SearchImage bingImage = new MediaController.SearchImage();
|
|
|
|
bingImage.id = gif.url;
|
|
|
|
if (gif.document != null) {
|
|
|
|
for (int b = 0; b < gif.document.attributes.size(); b++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = gif.document.attributes.get(b);
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) {
|
|
|
|
bingImage.width = attribute.w;
|
|
|
|
bingImage.height = attribute.h;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bingImage.width = gif.w;
|
|
|
|
bingImage.height = gif.h;
|
|
|
|
}
|
|
|
|
bingImage.size = 0;
|
|
|
|
bingImage.imageUrl = gif.content_url;
|
|
|
|
bingImage.thumbUrl = gif.thumb_url;
|
|
|
|
bingImage.localUrl = gif.url + "|" + query;
|
|
|
|
bingImage.document = gif.document;
|
|
|
|
if (gif.photo != null && gif.document != null) {
|
|
|
|
TLRPC.PhotoSize size = FileLoader.getClosestPhotoSizeWithSize(gif.photo.sizes, itemWidth, true);
|
|
|
|
if (size != null) {
|
|
|
|
gif.document.thumb = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bingImage.type = 1;
|
|
|
|
searchResult.add(bingImage);
|
|
|
|
searchResultKeys.put(bingImage.id, bingImage);
|
|
|
|
}
|
|
|
|
giphySearchEndReached = !added;
|
|
|
|
}
|
|
|
|
searching = false;
|
|
|
|
updateSearchInterface();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ConnectionsManager.getInstance().bindRequestToGuid(giphyReqId, classGuid);
|
|
|
|
/*try {
|
2015-02-26 01:32:51 +00:00
|
|
|
String url = String.format(Locale.US, "https://api.giphy.com/v1/gifs/search?q=%s&offset=%d&limit=%d&api_key=141Wa2KDAfNfxu", URLEncoder.encode(query, "UTF-8"), offset, count);
|
2015-01-02 22:15:07 +00:00
|
|
|
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, url, null,
|
|
|
|
new Response.Listener<JSONObject>() {
|
|
|
|
@Override
|
|
|
|
public void onResponse(JSONObject response) {
|
|
|
|
try {
|
|
|
|
JSONArray result = response.getJSONArray("data");
|
|
|
|
try {
|
|
|
|
JSONObject pagination = response.getJSONObject("pagination");
|
|
|
|
int total_count = pagination.getInt("total_count");
|
2015-02-01 18:51:02 +00:00
|
|
|
giphySearchEndReached = searchResult.size() + result.length() >= total_count;
|
2015-01-02 22:15:07 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
boolean added = false;
|
|
|
|
for (int a = 0; a < result.length(); a++) {
|
|
|
|
try {
|
|
|
|
JSONObject object = result.getJSONObject(a);
|
|
|
|
String id = object.getString("id");
|
|
|
|
if (searchResultKeys.containsKey(id)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
added = true;
|
|
|
|
JSONObject images = object.getJSONObject("images");
|
|
|
|
JSONObject thumb = images.getJSONObject("downsized_still");
|
|
|
|
JSONObject original = images.getJSONObject("original");
|
|
|
|
MediaController.SearchImage bingImage = new MediaController.SearchImage();
|
|
|
|
bingImage.id = id;
|
|
|
|
bingImage.width = original.getInt("width");
|
|
|
|
bingImage.height = original.getInt("height");
|
|
|
|
bingImage.size = original.getInt("size");
|
|
|
|
bingImage.imageUrl = original.getString("url");
|
|
|
|
bingImage.thumbUrl = thumb.getString("url");
|
|
|
|
bingImage.type = 1;
|
|
|
|
searchResult.add(bingImage);
|
|
|
|
searchResultKeys.put(id, bingImage);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
2016-01-11 17:19:48 +00:00
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
searching = false;
|
|
|
|
updateSearchInterface();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new Response.ErrorListener() {
|
|
|
|
@Override
|
|
|
|
public void onErrorResponse(VolleyError error) {
|
|
|
|
FileLog.e("tmessages", "Error: " + error.getMessage());
|
2015-02-01 18:51:02 +00:00
|
|
|
giphySearchEndReached = true;
|
2015-01-02 22:15:07 +00:00
|
|
|
searching = false;
|
|
|
|
updateSearchInterface();
|
|
|
|
}
|
|
|
|
});
|
2015-08-13 09:23:31 +00:00
|
|
|
jsonObjReq.setShouldCache(false);
|
2015-01-02 22:15:07 +00:00
|
|
|
jsonObjReq.setTag("search");
|
|
|
|
requestQueue.add(jsonObjReq);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
2016-01-11 17:19:48 +00:00
|
|
|
}*/
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void searchBingImages(String query, int offset, int count) {
|
|
|
|
if (searching) {
|
|
|
|
searching = false;
|
2016-01-11 17:19:48 +00:00
|
|
|
if (giphyReqId != 0) {
|
|
|
|
ConnectionsManager.getInstance().cancelRequest(giphyReqId, true);
|
|
|
|
giphyReqId = 0;
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
requestQueue.cancelAll("search");
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
searching = true;
|
|
|
|
String url;
|
|
|
|
if (nextSearchBingString != null) {
|
|
|
|
url = nextSearchBingString;
|
|
|
|
} else {
|
2015-05-21 21:27:27 +00:00
|
|
|
boolean adult;
|
2015-05-03 11:48:36 +00:00
|
|
|
String phone = UserConfig.getCurrentUser().phone;
|
|
|
|
adult = phone.startsWith("44") || phone.startsWith("49") || phone.startsWith("43") || phone.startsWith("31") || phone.startsWith("1");
|
|
|
|
url = String.format(Locale.US, "https://api.datamarket.azure.com/Bing/Search/v1/Image?Query='%s'&$skip=%d&$top=%d&$format=json%s", URLEncoder.encode(query, "UTF-8"), offset, count, adult ? "" : "&Adult='Off'");
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
|
|
|
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, url, null,
|
|
|
|
new Response.Listener<JSONObject>() {
|
|
|
|
@Override
|
|
|
|
public void onResponse(JSONObject response) {
|
|
|
|
nextSearchBingString = null;
|
|
|
|
try {
|
|
|
|
JSONObject d = response.getJSONObject("d");
|
|
|
|
JSONArray result = d.getJSONArray("results");
|
|
|
|
try {
|
|
|
|
nextSearchBingString = d.getString("__next");
|
|
|
|
} catch (Exception e) {
|
|
|
|
nextSearchBingString = null;
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
for (int a = 0; a < result.length(); a++) {
|
|
|
|
try {
|
|
|
|
JSONObject object = result.getJSONObject(a);
|
|
|
|
String id = Utilities.MD5(object.getString("MediaUrl"));
|
|
|
|
if (searchResultKeys.containsKey(id)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MediaController.SearchImage bingImage = new MediaController.SearchImage();
|
|
|
|
bingImage.id = id;
|
|
|
|
bingImage.width = object.getInt("Width");
|
|
|
|
bingImage.height = object.getInt("Height");
|
|
|
|
bingImage.size = object.getInt("FileSize");
|
|
|
|
bingImage.imageUrl = object.getString("MediaUrl");
|
|
|
|
JSONObject thumbnail = object.getJSONObject("Thumbnail");
|
|
|
|
bingImage.thumbUrl = thumbnail.getString("MediaUrl");
|
|
|
|
searchResult.add(bingImage);
|
|
|
|
searchResultKeys.put(id, bingImage);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
searching = false;
|
|
|
|
if (nextSearchBingString != null && !nextSearchBingString.contains("json")) {
|
|
|
|
nextSearchBingString += "&$format=json";
|
|
|
|
}
|
|
|
|
updateSearchInterface();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
new Response.ErrorListener() {
|
|
|
|
@Override
|
|
|
|
public void onErrorResponse(VolleyError error) {
|
|
|
|
FileLog.e("tmessages", "Error: " + error.getMessage());
|
|
|
|
nextSearchBingString = null;
|
|
|
|
searching = false;
|
|
|
|
updateSearchInterface();
|
|
|
|
}
|
|
|
|
}) {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, String> getHeaders() throws AuthFailureError {
|
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
|
String auth = "Basic " + Base64.encodeToString((BuildVars.BING_SEARCH_KEY + ":" + BuildVars.BING_SEARCH_KEY).getBytes(), Base64.NO_WRAP);
|
|
|
|
headers.put("Authorization", auth);
|
|
|
|
return headers;
|
|
|
|
}
|
|
|
|
};
|
2015-08-13 09:23:31 +00:00
|
|
|
jsonObjReq.setShouldCache(false);
|
2015-01-02 22:15:07 +00:00
|
|
|
jsonObjReq.setTag("search");
|
|
|
|
requestQueue.add(jsonObjReq);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
nextSearchBingString = null;
|
|
|
|
searching = false;
|
|
|
|
updateSearchInterface();
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setDelegate(PhotoPickerActivityDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendSelectedPhotos() {
|
2015-01-02 22:15:07 +00:00
|
|
|
if (selectedPhotos.isEmpty() && selectedWebPhotos.isEmpty() || delegate == null || sendPressed) {
|
2014-06-12 01:13:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-06-12 19:55:13 +00:00
|
|
|
sendPressed = true;
|
2015-01-02 22:15:07 +00:00
|
|
|
delegate.actionButtonPressed(false);
|
2014-06-12 01:13:15 +00:00
|
|
|
finishFragment();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 17:12:11 +00:00
|
|
|
return true;
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fixLayoutInternal() {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-06-12 19:55:13 +00:00
|
|
|
int position = listView.getFirstVisiblePosition();
|
2014-12-01 17:56:31 +00:00
|
|
|
WindowManager manager = (WindowManager) ApplicationLoader.applicationContext.getSystemService(Activity.WINDOW_SERVICE);
|
2014-06-12 01:13:15 +00:00
|
|
|
int rotation = manager.getDefaultDisplay().getRotation();
|
|
|
|
|
2015-05-21 21:27:27 +00:00
|
|
|
int columnsCount;
|
2015-01-02 22:15:07 +00:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
columnsCount = 3;
|
2014-06-12 01:13:15 +00:00
|
|
|
} else {
|
|
|
|
if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
|
2015-01-02 22:15:07 +00:00
|
|
|
columnsCount = 5;
|
|
|
|
} else {
|
|
|
|
columnsCount = 3;
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
listView.setNumColumns(columnsCount);
|
2014-09-24 02:17:27 +00:00
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
itemWidth = (AndroidUtilities.dp(490) - ((columnsCount + 1) * AndroidUtilities.dp(4))) / columnsCount;
|
|
|
|
} else {
|
|
|
|
itemWidth = (AndroidUtilities.displaySize.x - ((columnsCount + 1) * AndroidUtilities.dp(4))) / columnsCount;
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
listView.setColumnWidth(itemWidth);
|
|
|
|
|
|
|
|
listAdapter.notifyDataSetChanged();
|
2014-06-12 19:55:13 +00:00
|
|
|
listView.setSelection(position);
|
2014-06-12 01:13:15 +00:00
|
|
|
|
2015-01-02 22:15:07 +00:00
|
|
|
if (selectedAlbum == null) {
|
2016-01-11 17:19:48 +00:00
|
|
|
emptyView.setPadding(0, 0, 0, (int) ((AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight()) * 0.4f));
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 00:18:13 +00:00
|
|
|
private class ListAdapter extends BaseFragmentAdapter {
|
2014-06-12 01:13:15 +00:00
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areAllItemsEnabled() {
|
2015-01-02 22:15:07 +00:00
|
|
|
return selectedAlbum != null;
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled(int i) {
|
2015-01-02 22:15:07 +00:00
|
|
|
if (selectedAlbum == null) {
|
|
|
|
if (searchResult.isEmpty() && lastSearchString == null) {
|
|
|
|
return i < recentImages.size();
|
|
|
|
} else {
|
|
|
|
return i < searchResult.size();
|
|
|
|
}
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
2015-01-02 22:15:07 +00:00
|
|
|
if (selectedAlbum == null) {
|
|
|
|
if (searchResult.isEmpty() && lastSearchString == null) {
|
|
|
|
return recentImages.size();
|
|
|
|
} else if (type == 0) {
|
|
|
|
return searchResult.size() + (nextSearchBingString == null ? 0 : 1);
|
|
|
|
} else if (type == 1) {
|
2015-02-01 18:51:02 +00:00
|
|
|
return searchResult.size() + (giphySearchEndReached ? 0 : 1);
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
return selectedAlbum.photos.size();
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int i) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasStableIds() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
2015-01-02 22:15:07 +00:00
|
|
|
int viewType = getItemViewType(i);
|
|
|
|
if (viewType == 0) {
|
|
|
|
PhotoPickerPhotoCell cell = (PhotoPickerPhotoCell) view;
|
2014-06-12 01:13:15 +00:00
|
|
|
if (view == null) {
|
2015-01-02 22:15:07 +00:00
|
|
|
view = new PhotoPickerPhotoCell(mContext);
|
|
|
|
cell = (PhotoPickerPhotoCell) view;
|
|
|
|
cell.checkFrame.setOnClickListener(new View.OnClickListener() {
|
2014-06-12 01:13:15 +00:00
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
2015-02-26 01:32:51 +00:00
|
|
|
int index = (Integer) ((View) v.getParent()).getTag();
|
2015-01-02 22:15:07 +00:00
|
|
|
if (selectedAlbum != null) {
|
2015-02-26 01:32:51 +00:00
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
|
2015-01-02 22:15:07 +00:00
|
|
|
if (selectedPhotos.containsKey(photoEntry.imageId)) {
|
|
|
|
selectedPhotos.remove(photoEntry.imageId);
|
2015-02-01 18:51:02 +00:00
|
|
|
photoEntry.imagePath = null;
|
2015-02-26 01:32:51 +00:00
|
|
|
photoEntry.thumbPath = null;
|
|
|
|
updatePhotoAtIndex(index);
|
2015-01-02 22:15:07 +00:00
|
|
|
} else {
|
|
|
|
selectedPhotos.put(photoEntry.imageId, photoEntry);
|
|
|
|
}
|
2015-10-29 17:10:07 +00:00
|
|
|
((PhotoPickerPhotoCell) v.getParent()).setChecked(selectedPhotos.containsKey(photoEntry.imageId), true);
|
2014-06-12 01:13:15 +00:00
|
|
|
} else {
|
2015-01-02 22:15:07 +00:00
|
|
|
AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
|
2015-05-21 21:27:27 +00:00
|
|
|
MediaController.SearchImage photoEntry;
|
2015-01-02 22:15:07 +00:00
|
|
|
if (searchResult.isEmpty() && lastSearchString == null) {
|
2016-01-11 17:19:48 +00:00
|
|
|
photoEntry = recentImages.get((Integer) ((View) v.getParent()).getTag());
|
2015-01-02 22:15:07 +00:00
|
|
|
} else {
|
2016-01-11 17:19:48 +00:00
|
|
|
photoEntry = searchResult.get((Integer) ((View) v.getParent()).getTag());
|
2015-01-02 22:15:07 +00:00
|
|
|
}
|
|
|
|
if (selectedWebPhotos.containsKey(photoEntry.id)) {
|
|
|
|
selectedWebPhotos.remove(photoEntry.id);
|
2015-02-26 01:32:51 +00:00
|
|
|
photoEntry.imagePath = null;
|
|
|
|
photoEntry.thumbPath = null;
|
|
|
|
updatePhotoAtIndex(index);
|
2015-01-02 22:15:07 +00:00
|
|
|
} else {
|
|
|
|
selectedWebPhotos.put(photoEntry.id, photoEntry);
|
|
|
|
}
|
2015-10-29 17:10:07 +00:00
|
|
|
((PhotoPickerPhotoCell) v.getParent()).setChecked(selectedWebPhotos.containsKey(photoEntry.id), true);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
2015-07-22 18:56:37 +00:00
|
|
|
pickerBottomLayout.updateSelectedCount(selectedPhotos.size() + selectedWebPhotos.size(), true);
|
2015-01-02 22:15:07 +00:00
|
|
|
delegate.selectedPhotosChanged();
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
});
|
2015-02-26 01:32:51 +00:00
|
|
|
cell.checkFrame.setVisibility(singlePhoto ? View.GONE : View.VISIBLE);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
cell.itemWidth = itemWidth;
|
|
|
|
BackupImageView imageView = ((PhotoPickerPhotoCell) view).photoImage;
|
2014-06-12 01:13:15 +00:00
|
|
|
imageView.setTag(i);
|
|
|
|
view.setTag(i);
|
2015-05-21 21:27:27 +00:00
|
|
|
boolean showing;
|
2015-02-26 01:32:51 +00:00
|
|
|
imageView.setOrientation(0, true);
|
2015-01-02 22:15:07 +00:00
|
|
|
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(i);
|
2015-02-26 01:32:51 +00:00
|
|
|
if (photoEntry.thumbPath != null) {
|
|
|
|
imageView.setImage(photoEntry.thumbPath, null, mContext.getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
} else if (photoEntry.path != null) {
|
|
|
|
imageView.setOrientation(photoEntry.orientation, true);
|
2015-05-03 11:48:36 +00:00
|
|
|
if (photoEntry.isVideo) {
|
|
|
|
imageView.setImage("vthumb://" + photoEntry.imageId + ":" + photoEntry.path, null, mContext.getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
} else {
|
|
|
|
imageView.setImage("thumb://" + photoEntry.imageId + ":" + photoEntry.path, null, mContext.getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
} else {
|
|
|
|
imageView.setImageResource(R.drawable.nophotos);
|
|
|
|
}
|
2015-10-29 17:10:07 +00:00
|
|
|
cell.setChecked(selectedPhotos.containsKey(photoEntry.imageId), false);
|
2015-01-02 22:15:07 +00:00
|
|
|
showing = PhotoViewer.getInstance().isShowingImage(photoEntry.path);
|
2014-06-12 01:13:15 +00:00
|
|
|
} else {
|
2015-05-21 21:27:27 +00:00
|
|
|
MediaController.SearchImage photoEntry;
|
2015-01-02 22:15:07 +00:00
|
|
|
if (searchResult.isEmpty() && lastSearchString == null) {
|
|
|
|
photoEntry = recentImages.get(i);
|
|
|
|
} else {
|
|
|
|
photoEntry = searchResult.get(i);
|
|
|
|
}
|
2015-02-26 01:32:51 +00:00
|
|
|
if (photoEntry.thumbPath != null) {
|
|
|
|
imageView.setImage(photoEntry.thumbPath, null, mContext.getResources().getDrawable(R.drawable.nophotos));
|
|
|
|
} else if (photoEntry.thumbUrl != null && photoEntry.thumbUrl.length() > 0) {
|
2015-01-02 22:15:07 +00:00
|
|
|
imageView.setImage(photoEntry.thumbUrl, null, mContext.getResources().getDrawable(R.drawable.nophotos));
|
2016-01-11 17:19:48 +00:00
|
|
|
} else if (photoEntry.document != null && photoEntry.document.thumb != null) {
|
|
|
|
imageView.setImage(photoEntry.document.thumb.location, null, mContext.getResources().getDrawable(R.drawable.nophotos));
|
2015-01-02 22:15:07 +00:00
|
|
|
} else {
|
|
|
|
imageView.setImageResource(R.drawable.nophotos);
|
|
|
|
}
|
2015-10-29 17:10:07 +00:00
|
|
|
cell.setChecked(selectedWebPhotos.containsKey(photoEntry.id), false);
|
2016-01-11 17:19:48 +00:00
|
|
|
if (photoEntry.document != null) {
|
|
|
|
showing = PhotoViewer.getInstance().isShowingImage(FileLoader.getPathToAttach(photoEntry.document, true).getAbsolutePath());
|
|
|
|
} else {
|
|
|
|
showing = PhotoViewer.getInstance().isShowingImage(photoEntry.imageUrl);
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
2015-05-03 11:48:36 +00:00
|
|
|
imageView.getImageReceiver().setVisible(!showing, true);
|
2015-02-26 01:32:51 +00:00
|
|
|
cell.checkBox.setVisibility(singlePhoto || showing ? View.GONE : View.VISIBLE);
|
2015-01-02 22:15:07 +00:00
|
|
|
} else if (viewType == 1) {
|
|
|
|
if (view == null) {
|
2016-01-11 17:19:48 +00:00
|
|
|
LayoutInflater li = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
2015-01-02 22:15:07 +00:00
|
|
|
view = li.inflate(R.layout.media_loading_layout, viewGroup, false);
|
|
|
|
}
|
|
|
|
ViewGroup.LayoutParams params = view.getLayoutParams();
|
|
|
|
params.width = itemWidth;
|
|
|
|
params.height = itemWidth;
|
|
|
|
view.setLayoutParams(params);
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
2015-01-02 22:15:07 +00:00
|
|
|
if (selectedAlbum != null || searchResult.isEmpty() && lastSearchString == null && i < recentImages.size() || i < searchResult.size()) {
|
|
|
|
return 0;
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
2015-01-02 22:15:07 +00:00
|
|
|
return 1;
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEmpty() {
|
|
|
|
if (selectedAlbum != null) {
|
|
|
|
return selectedAlbum.photos.isEmpty();
|
2015-01-02 22:15:07 +00:00
|
|
|
} else {
|
|
|
|
if (searchResult.isEmpty() && lastSearchString == null) {
|
|
|
|
return recentImages.isEmpty();
|
|
|
|
} else {
|
|
|
|
return searchResult.isEmpty();
|
|
|
|
}
|
2014-06-12 01:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|