fix: chat attach menu
This commit is contained in:
parent
1b22f4636b
commit
421fe84e51
@ -1862,7 +1862,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
frameLayout.setClipChildren(false);
|
||||
textFieldContainer.addView(frameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM, 0, 0, 48, 0));
|
||||
|
||||
emojiButton = new ChatActivityEnterViewAnimatedIconView(context) {
|
||||
emojiButton = new ChatActivityEnterViewAnimatedIconView(context, this) {
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
@ -3166,7 +3166,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
if (recordCircle.isSendButtonVisible()) {
|
||||
if (!hasRecordVideo || calledRecordRunnable) {
|
||||
startedDraggingX = -1;
|
||||
if (hasRecordVideo && audioVideoButtonContainer.getTag() != null) {
|
||||
if (hasRecordVideo && isInVideoMode) {
|
||||
delegate.needStartRecordVideo(1, true, 0);
|
||||
} else {
|
||||
if (recordingAudioVideo && isInScheduleMode()) {
|
||||
@ -3177,7 +3177,6 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
}
|
||||
recordingAudioVideo = false;
|
||||
updateRecordInterface(RECORD_STATE_SENDING);
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -3351,7 +3350,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
});
|
||||
}
|
||||
|
||||
audioVideoSendButton = new ChatActivityEnterViewAnimatedIconView(context);
|
||||
audioVideoSendButton = new ChatActivityEnterViewAnimatedIconView(context, this);
|
||||
audioVideoSendButton.setContentDescription(LocaleController.getString("AccDescrVoiceMessage", R.string.AccDescrVoiceMessage));
|
||||
audioVideoSendButton.setFocusable(true);
|
||||
audioVideoSendButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
|
||||
@ -3856,10 +3855,10 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
}
|
||||
}
|
||||
|
||||
audioVideoSendButton.setTag(null);
|
||||
isInVideoMode = false;
|
||||
recordAudioVideoRunnable.run();
|
||||
delegate.onSwitchRecordMode(audioVideoSendButton.getTag() == null);
|
||||
setRecordVideoButtonVisible(audioVideoSendButton.getTag() == null, true);
|
||||
delegate.onSwitchRecordMode(isInVideoMode);
|
||||
setRecordVideoButtonVisible(isInVideoMode, true);
|
||||
if (!NekoConfig.disableVibration.Bool()) {
|
||||
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
||||
}
|
||||
@ -3888,10 +3887,10 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
}
|
||||
}
|
||||
|
||||
audioVideoSendButton.setTag(1);
|
||||
isInVideoMode = true;
|
||||
recordAudioVideoRunnable.run();
|
||||
delegate.onSwitchRecordMode(audioVideoSendButton.getTag() == null);
|
||||
setRecordVideoButtonVisible(audioVideoSendButton.getTag() == null, true);
|
||||
delegate.onSwitchRecordMode(isInVideoMode);
|
||||
setRecordVideoButtonVisible(isInVideoMode, true);
|
||||
if (!NekoConfig.disableVibration.Bool()) {
|
||||
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
||||
}
|
||||
@ -4405,8 +4404,6 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
if (audioVideoSendButton == null) {
|
||||
return;
|
||||
}
|
||||
// if (NekoConfig.useChatAttachMediaMenu.Bool()) visible = animated = false;
|
||||
audioVideoSendButton.setTag(visible ? 1 : null);
|
||||
|
||||
isInVideoMode = visible;
|
||||
|
||||
@ -4419,7 +4416,10 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
}
|
||||
preferences.edit().putBoolean(isChannel ? "currentModeVideoChannel" : "currentModeVideo", visible).apply();
|
||||
}
|
||||
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, animated);
|
||||
if (!NekoConfig.useChatAttachMediaMenu.Bool())
|
||||
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, animated);
|
||||
else
|
||||
audioVideoSendButton.setState(ChatActivityEnterViewAnimatedIconView.State.MENU, animated);
|
||||
audioVideoSendButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
|
||||
}
|
||||
|
||||
@ -6649,7 +6649,8 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
audioVideoSendButton.setScaleX(1f);
|
||||
audioVideoSendButton.setScaleY(1f);
|
||||
runningAnimationAudio.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.ALPHA, 1));
|
||||
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
|
||||
if (!NekoConfig.useChatAttachMediaMenu.Bool())
|
||||
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
|
||||
}
|
||||
if (scheduledButton != null) {
|
||||
runningAnimationAudio.playTogether(
|
||||
@ -6756,7 +6757,8 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_X, 1),
|
||||
ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_Y, 1)
|
||||
);
|
||||
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
|
||||
if (!NekoConfig.useChatAttachMediaMenu.Bool())
|
||||
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
|
||||
}
|
||||
|
||||
if (botCommandsMenuButton != null) {
|
||||
@ -6900,7 +6902,8 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.ALPHA, 1));
|
||||
iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_X, 1));
|
||||
iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_Y, 1));
|
||||
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
|
||||
if (!NekoConfig.useChatAttachMediaMenu.Bool())
|
||||
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
|
||||
}
|
||||
if (scheduledButton != null) {
|
||||
iconsAnimator.playTogether(
|
||||
@ -6998,7 +7001,8 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
audioVideoSendButton.setScaleX(1f);
|
||||
audioVideoSendButton.setScaleY(1f);
|
||||
iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.ALPHA, 1));
|
||||
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
|
||||
if (!NekoConfig.useChatAttachMediaMenu.Bool())
|
||||
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
|
||||
}
|
||||
if (attachLayout != null) {
|
||||
attachLayout.setTranslationX(0);
|
||||
@ -9160,7 +9164,8 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
}
|
||||
boolean audio = (Boolean) args[1];
|
||||
isInVideoMode = !audio;
|
||||
audioVideoSendButton.setState(audio ? ChatActivityEnterViewAnimatedIconView.State.VOICE : ChatActivityEnterViewAnimatedIconView.State.VIDEO, true);
|
||||
if (!NekoConfig.useChatAttachMediaMenu.Bool())
|
||||
audioVideoSendButton.setState(audio ? ChatActivityEnterViewAnimatedIconView.State.VOICE : ChatActivityEnterViewAnimatedIconView.State.VIDEO, true);
|
||||
if (!recordingAudioVideo) {
|
||||
recordingAudioVideo = true;
|
||||
updateRecordInterface(RECORD_STATE_ENTER);
|
||||
@ -10264,7 +10269,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
|
||||
}
|
||||
}
|
||||
|
||||
private int getThemedColor(String key) {
|
||||
int getThemedColor(String key) {
|
||||
Integer color = resourcesProvider != null ? resourcesProvider.getColor(key) : null;
|
||||
return color != null ? color : Theme.getColor(key);
|
||||
}
|
||||
|
@ -1,115 +1,122 @@
|
||||
package org.telegram.ui.Components;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.util.Property;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.telegram.messenger.AndroidUtilities;
|
||||
import org.telegram.messenger.R;
|
||||
import org.telegram.ui.ActionBar.Theme;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ChatActivityEnterViewAnimatedIconView extends RLottieImageView {
|
||||
public class ChatActivityEnterViewAnimatedIconView extends FrameLayout {
|
||||
private State currentState;
|
||||
private TransitState animatingState;
|
||||
|
||||
private Map<TransitState, RLottieDrawable> stateMap = new HashMap<TransitState, RLottieDrawable>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public RLottieDrawable get(@Nullable Object key) {
|
||||
RLottieDrawable obj = super.get(key);
|
||||
if (obj == null) {
|
||||
TransitState state = (TransitState) key;
|
||||
int res = state.resource;
|
||||
return new RLottieDrawable(res, String.valueOf(res), AndroidUtilities.dp(32), AndroidUtilities.dp(32));
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
};
|
||||
|
||||
public ChatActivityEnterViewAnimatedIconView(Context context) {
|
||||
private AnimatorSet buttonsAnimation;
|
||||
private final ImageView[] buttonViews = new ImageView[2];
|
||||
|
||||
public ChatActivityEnterViewAnimatedIconView(Context context, ChatActivityEnterView parentActivity) {
|
||||
super(context);
|
||||
for (int a = 0; a < 2; a++) {
|
||||
buttonViews[a] = new ImageView(context);
|
||||
buttonViews[a].setColorFilter(new PorterDuffColorFilter(parentActivity.getThemedColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
|
||||
buttonViews[a].setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
addView(buttonViews[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT,
|
||||
Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 0));
|
||||
}
|
||||
buttonViews[0].setVisibility(VISIBLE);
|
||||
buttonViews[1].setVisibility(GONE);
|
||||
}
|
||||
|
||||
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
buttonViews[0].setColorFilter(cf);
|
||||
buttonViews[1].setColorFilter(cf);
|
||||
}
|
||||
|
||||
private static class PropertyAlpha extends Property<LayerDrawable, Integer> {
|
||||
private final int index;
|
||||
|
||||
public PropertyAlpha(int index) {
|
||||
super(Integer.class, "alpha");
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(LayerDrawable object, Integer value) {
|
||||
object.getDrawable(index).setAlpha(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get(LayerDrawable object) {
|
||||
return object.getDrawable(index).getAlpha();
|
||||
}
|
||||
}
|
||||
|
||||
public void setState(State state, boolean animate) {
|
||||
if (animate && state == currentState) {
|
||||
return;
|
||||
}
|
||||
State fromState = currentState;
|
||||
currentState = state;
|
||||
if (!animate || fromState == null || getState(fromState, currentState) == null) {
|
||||
RLottieDrawable drawable = stateMap.get(getAnyState(currentState));
|
||||
drawable.stop();
|
||||
|
||||
drawable.setProgress(0, false);
|
||||
setAnimation(drawable);
|
||||
if (!animate || fromState == null) {
|
||||
buttonViews[0].setImageResource(currentState.resource);
|
||||
} else {
|
||||
TransitState transitState = getState(fromState, currentState);
|
||||
if (transitState == animatingState) {
|
||||
return;
|
||||
if (buttonsAnimation != null) {
|
||||
buttonsAnimation.cancel();
|
||||
}
|
||||
|
||||
animatingState = transitState;
|
||||
RLottieDrawable drawable = stateMap.get(transitState);
|
||||
drawable.stop();
|
||||
drawable.setProgress(0, false);
|
||||
drawable.setAutoRepeat(0);
|
||||
drawable.setOnAnimationEndListener(() -> animatingState = null);
|
||||
setAnimation(drawable);
|
||||
AndroidUtilities.runOnUIThread(drawable::start);
|
||||
buttonViews[1].setVisibility(VISIBLE);
|
||||
buttonViews[1].setImageResource(currentState.resource);
|
||||
buttonViews[0].setAlpha(1.0f);
|
||||
buttonViews[1].setAlpha(0.0f);
|
||||
buttonsAnimation = new AnimatorSet();
|
||||
buttonsAnimation.playTogether(
|
||||
ObjectAnimator.ofFloat(buttonViews[0], View.SCALE_X, 0.1f),
|
||||
ObjectAnimator.ofFloat(buttonViews[0], View.SCALE_Y, 0.1f),
|
||||
ObjectAnimator.ofFloat(buttonViews[0], View.ALPHA, 0.0f),
|
||||
ObjectAnimator.ofFloat(buttonViews[1], View.SCALE_X, 1.0f),
|
||||
ObjectAnimator.ofFloat(buttonViews[1], View.SCALE_Y, 1.0f),
|
||||
ObjectAnimator.ofFloat(buttonViews[1], View.ALPHA, 1.0f));
|
||||
buttonsAnimation.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (animation.equals(buttonsAnimation)) {
|
||||
buttonsAnimation = null;
|
||||
ImageView temp = buttonViews[1];
|
||||
buttonViews[1] = buttonViews[0];
|
||||
buttonViews[0] = temp;
|
||||
buttonViews[1].setVisibility(INVISIBLE);
|
||||
buttonViews[1].setAlpha(0.0f);
|
||||
buttonViews[1].setScaleX(0.1f);
|
||||
buttonViews[1].setScaleY(0.1f);
|
||||
}
|
||||
}
|
||||
});
|
||||
buttonsAnimation.setDuration(200);
|
||||
buttonsAnimation.start();
|
||||
}
|
||||
}
|
||||
|
||||
private TransitState getAnyState(State from) {
|
||||
for (TransitState transitState : TransitState.values()) {
|
||||
if (transitState.firstState == from) {
|
||||
return transitState;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private TransitState getState(State from, State to) {
|
||||
for (TransitState transitState : TransitState.values()) {
|
||||
if (transitState.firstState == from && transitState.secondState == to) {
|
||||
return transitState;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private enum TransitState {
|
||||
VOICE_TO_VIDEO(State.VOICE, State.VIDEO, R.raw.voice_to_video),
|
||||
STICKER_TO_KEYBOARD(State.STICKER, State.KEYBOARD, R.raw.sticker_to_keyboard),
|
||||
SMILE_TO_KEYBOARD(State.SMILE, State.KEYBOARD, R.raw.smile_to_keyboard),
|
||||
VIDEO_TO_VOICE(State.VIDEO, State.VOICE, R.raw.video_to_voice),
|
||||
KEYBOARD_TO_STICKER(State.KEYBOARD, State.STICKER, R.raw.keyboard_to_sticker),
|
||||
KEYBOARD_TO_GIF(State.KEYBOARD, State.GIF, R.raw.keyboard_to_gif),
|
||||
KEYBOARD_TO_SMILE(State.KEYBOARD, State.SMILE, R.raw.keyboard_to_smile),
|
||||
GIF_TO_KEYBOARD(State.GIF, State.KEYBOARD, R.raw.gif_to_keyboard),
|
||||
GIF_TO_SMILE(State.GIF, State.SMILE, R.raw.gif_to_smile),
|
||||
SMILE_TO_GIF(State.SMILE, State.GIF, R.raw.smile_to_gif),
|
||||
SMILE_TO_STICKER(State.SMILE, State.STICKER, R.raw.smile_to_sticker),
|
||||
STICKER_TO_SMILE(State.STICKER, State.SMILE, R.raw.sticker_to_smile);
|
||||
|
||||
final State firstState, secondState;
|
||||
|
||||
public enum State {
|
||||
VOICE(R.drawable.input_mic),
|
||||
VIDEO(R.drawable.input_video),
|
||||
STICKER(R.drawable.input_sticker),
|
||||
KEYBOARD(R.drawable.input_keyboard),
|
||||
SMILE(R.drawable.input_smile),
|
||||
GIF(R.drawable.input_gif),
|
||||
MENU(R.drawable.ic_ab_other);
|
||||
|
||||
final int resource;
|
||||
|
||||
TransitState(State firstState, State secondState, int resource) {
|
||||
this.firstState = firstState;
|
||||
this.secondState = secondState;
|
||||
|
||||
State(int resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
}
|
||||
|
||||
public enum State {
|
||||
VOICE,
|
||||
VIDEO,
|
||||
STICKER,
|
||||
KEYBOARD,
|
||||
SMILE,
|
||||
GIF
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user