sync original

This commit is contained in:
wrwrabbit 2021-11-12 00:12:47 +03:00
commit 115dc20754
141 changed files with 11747 additions and 5544 deletions

View file

@ -66,6 +66,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScrollerEnd;
import androidx.recyclerview.widget.RecyclerView;
import android.text.Editable;
import android.text.Layout;
import android.text.Selection;
import android.text.Spannable;
@ -125,6 +126,7 @@ import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.analytics.AnalyticsListener;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.util.Log;
import com.google.android.gms.vision.Frame;
import com.google.android.gms.vision.face.Face;
import com.google.android.gms.vision.face.FaceDetector;
@ -201,6 +203,7 @@ import org.telegram.ui.Components.GestureDetector2;
import org.telegram.ui.Components.GroupedPhotosListView;
import org.telegram.ui.Components.HideViewAfterAnimation;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.Components.MediaActivity;
import org.telegram.ui.Components.NumberPicker;
import org.telegram.ui.Components.OtherDocumentPlaceholderDrawable;
import org.telegram.ui.Components.PaintingOverlay;
@ -560,6 +563,11 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
return classGuid;
}
public void setCaption(CharSequence caption) {
hasCaptionForAllMedia = !TextUtils.isEmpty(caption);
captionForAllMedia = caption;
}
private static class SavedVideoPosition {
public final float position;
@ -1086,11 +1094,13 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private long currentDialogId;
private long mergeDialogId;
private int totalImagesCount;
private int startOffset;
private int totalImagesCountMerge;
private boolean isFirstLoading;
private boolean needSearchImageInArr;
private boolean loadingMoreImages;
private boolean[] endReached = new boolean[]{false, true};
private boolean startReached = false;
private boolean opennedFromMedia;
private boolean attachedToWindow;
@ -1710,6 +1720,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
public ImageReceiver imageReceiver;
public int viewX;
public int viewY;
public int viewY2;
public View parentView;
public ImageReceiver.BitmapHolder thumb;
public long dialogId;
@ -1724,6 +1735,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
public int animatingImageViewYOffset;
public boolean allowTakeAnimation = true;
public boolean canEdit;
public int starOffset;
}
public static class EmptyPhotoViewerProvider implements PhotoViewerProvider {
@ -3186,10 +3198,10 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (needSearchImageInArr && isFirstLoading) {
isFirstLoading = false;
loadingMoreImages = true;
MediaDataController.getInstance(currentAccount).loadMedia(currentDialogId, 20, 0, sharedMediaType, 1, classGuid);
MediaDataController.getInstance(currentAccount).loadMedia(currentDialogId, 20, 0, 0, sharedMediaType, 1, classGuid, 0);
} else if (!imagesArr.isEmpty()) {
if (opennedFromMedia) {
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, currentIndex + 1, totalImagesCount + totalImagesCountMerge));
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, startOffset + currentIndex + 1, totalImagesCount + totalImagesCountMerge));
} else {
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, (totalImagesCount + totalImagesCountMerge - imagesArr.size()) + currentIndex + 1, totalImagesCount + totalImagesCountMerge));
}
@ -3204,6 +3216,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
int loadIndex = uid == currentDialogId ? 0 : 1;
ArrayList<MessageObject> arr = (ArrayList<MessageObject>) args[2];
endReached[loadIndex] = (Boolean) args[5];
boolean fromStart = (boolean) args[6];
if (needSearchImageInArr) {
if (arr.isEmpty() && (loadIndex != 0 || mergeDialogId == 0) || currentIndex < 0 || currentIndex >= imagesArr.size()) {
needSearchImageInArr = false;
@ -3274,16 +3287,26 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (!endReached[loadIndex]) {
loadingMoreImages = true;
MediaDataController.getInstance(currentAccount).loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 40, loadFromMaxId, sharedMediaType, 1, classGuid);
MediaDataController.getInstance(currentAccount).loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 40, loadFromMaxId, 0, sharedMediaType, 1, classGuid, 0);
}
}
} else {
int added = 0;
for (MessageObject message : arr) {
for (int i = 0; i < arr.size(); i++) {
MessageObject message = arr.get(fromStart ? arr.size() - 1 - i : i);
if (imagesByIds[loadIndex].indexOfKey(message.getId()) < 0) {
added++;
if (opennedFromMedia) {
imagesArr.add(message);
if (fromStart) {
imagesArr.add(0, message);
startOffset--;
currentIndex++;
if (startOffset < 0) {
startOffset = 0;
}
} else {
imagesArr.add(message);
}
} else {
imagesArr.add(0, message);
}
@ -3291,8 +3314,8 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
if (opennedFromMedia) {
if (added == 0) {
totalImagesCount = imagesArr.size();
if (added == 0 && !fromStart) {
totalImagesCount = startOffset + imagesArr.size();
totalImagesCountMerge = 0;
}
} else {
@ -3836,7 +3859,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
disableShowCheck = true;
Bundle args2 = new Bundle();
args2.putLong("dialog_id", currentDialogId);
MediaActivity mediaActivity = new MediaActivity(args2, new int[]{-1, -1, -1, -1, -1, -1}, null, sharedMediaType);
MediaActivity mediaActivity = new MediaActivity(args2, null);
if (parentChatActivity != null) {
mediaActivity.setChatInfo(parentChatActivity.getCurrentChatInfo());
}
@ -6728,6 +6751,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
return parentChatActivity != null && (parentChatActivity.currentEncryptedChat == null || AndroidUtilities.getPeerLayerVersion(parentChatActivity.currentEncryptedChat.layer) >= 101);
}
public boolean hasCaptionForAllMedia;
public CharSequence captionForAllMedia;
private void closeCaptionEnter(boolean apply) {
if (currentIndex < 0 || currentIndex >= imagesArrLocals.size() || captionEditText.getTag() == null) {
return;
@ -6738,7 +6764,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
CharSequence[] result = new CharSequence[] {caption};
ArrayList<TLRPC.MessageEntity> entities = MediaDataController.getInstance(currentAccount).getEntities(result, supportsSendingNewEntities());
if (object instanceof MediaController.PhotoEntry) {
if (hasCaptionForAllMedia) {
captionForAllMedia = caption;
} else if (object instanceof MediaController.PhotoEntry) {
MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) object;
photoEntry.caption = result[0];
photoEntry.entities = entities;
@ -7077,7 +7105,6 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (orientationEventListener == null || aspectRatioFrameLayout == null || aspectRatioFrameLayout.getVisibility() != View.VISIBLE) {
return;
}
FileLog.d("orientation = " + orientation);
if (parentActivity != null && fullscreenedByButton != 0) {
if (fullscreenedByButton == 1) {
if (orientation >= 270 - 30 && orientation <= 270 + 30) {
@ -7623,7 +7650,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private void updateCaptionTextForCurrentPhoto(Object object) {
CharSequence caption = null;
if (object instanceof MediaController.PhotoEntry) {
if (hasCaptionForAllMedia) {
caption = captionForAllMedia;
} else if (object instanceof MediaController.PhotoEntry) {
caption = ((MediaController.PhotoEntry) object).caption;
} else if (object instanceof TLRPC.BotInlineResult) {
//caption = ((TLRPC.BotInlineResult) object).send_message.caption;
@ -7759,7 +7788,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
private Bitmap createCroppedBitmap(Bitmap bitmap, MediaController.CropState cropState, int[] extraTransform, boolean mirror) {
try {
int tr = cropState.transformRotation + (extraTransform != null ? extraTransform[0] : 0);
int tr = (cropState.transformRotation + (extraTransform != null ? extraTransform[0] : 0)) % 360;
int w = bitmap.getWidth();
int h = bitmap.getHeight();
int fw = w, rotatedW = w;
@ -9861,6 +9890,9 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
MessageObject openingObject = imagesArr.get(index);
if (!openingObject.scheduled && (parentChatActivity == null || !parentChatActivity.isThreadChat())) {
opennedFromMedia = true;
if (object != null) {
startOffset = object.starOffset;
}
menuItem.showSubItem(gallery_menu_showinchat);
if (openingObject.canForwardMessage()) {
setItemVisible(sendItem, true, false);
@ -10159,7 +10191,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
} else {
if (totalImagesCount + totalImagesCountMerge != 0 && !needSearchImageInArr) {
if (opennedFromMedia) {
if (imagesArr.size() < totalImagesCount + totalImagesCountMerge && !loadingMoreImages && switchingToIndex > imagesArr.size() - 5) {
if (startOffset + imagesArr.size() < totalImagesCount + totalImagesCountMerge && !loadingMoreImages && switchingToIndex > imagesArr.size() - 5) {
int loadFromMaxId = imagesArr.isEmpty() ? 0 : imagesArr.get(imagesArr.size() - 1).getId();
int loadIndex = 0;
if (endReached[loadIndex] && mergeDialogId != 0) {
@ -10168,8 +10200,18 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
loadFromMaxId = 0;
}
}
if (!placeProvider.loadMore()) {
MediaDataController.getInstance(currentAccount).loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 40, loadFromMaxId, sharedMediaType, 1, classGuid);
MediaDataController.getInstance(currentAccount).loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 40, loadFromMaxId, 0, sharedMediaType, 1, classGuid, 0);
loadingMoreImages = true;
}
}
if (startOffset > 0 && switchingToIndex < 5 && !imagesArr.isEmpty()) {
int loadFromMinId = imagesArr.get(0).getId();
int loadIndex = 0;
if (!placeProvider.loadMore()) {
MediaDataController.getInstance(currentAccount).loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 40, 0, loadFromMinId, sharedMediaType, 1, classGuid, 0);
loadingMoreImages = true;
}
}
@ -10180,7 +10222,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
actionBar.setSubtitle(subtitle);
actionBar.setTitleScrollNonFitText(true);
} else {
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, switchingToIndex + 1, totalImagesCount + totalImagesCountMerge));
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, startOffset + switchingToIndex + 1, totalImagesCount + totalImagesCountMerge));
}
} else {
if (imagesArr.size() < totalImagesCount + totalImagesCountMerge && !loadingMoreImages && switchingToIndex < 5) {
@ -10193,7 +10235,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
}
}
MediaDataController.getInstance(currentAccount).loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 80, loadFromMaxId, sharedMediaType, 1, classGuid);
MediaDataController.getInstance(currentAccount).loadMedia(loadIndex == 0 ? currentDialogId : mergeDialogId, 80, loadFromMaxId, 0, sharedMediaType, 1, classGuid, 0);
loadingMoreImages = true;
}
actionBar.setTitle(LocaleController.formatString("Of", R.string.Of, (totalImagesCount + totalImagesCountMerge - imagesArr.size()) + switchingToIndex + 1, totalImagesCount + totalImagesCountMerge));
@ -10422,7 +10464,11 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
if (object instanceof MediaController.PhotoEntry) {
MediaController.PhotoEntry photoEntry = ((MediaController.PhotoEntry) object);
fromCamera = photoEntry.bucketId == 0 && photoEntry.dateTaken == 0 && imagesArrLocals.size() == 1;
caption = photoEntry.caption;
if (hasCaptionForAllMedia) {
caption = captionForAllMedia;
} else {
caption = photoEntry.caption;
}
ttl = photoEntry.ttl;
isFiltered = photoEntry.isFiltered;
isPainted = photoEntry.isPainted;
@ -11995,6 +12041,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat
return false;
}
hasCaptionForAllMedia = false;
doneButtonPressed = false;
allowShowFullscreenButton = true;
parentChatActivity = chatActivity;