fix: chat attach menu

This commit is contained in:
Next Alone 2022-09-04 02:27:11 +08:00
parent 1b22f4636b
commit 421fe84e51
No known key found for this signature in database
GPG Key ID: DBA7B0AEF8C1CD2C
2 changed files with 122 additions and 110 deletions

View File

@ -1862,7 +1862,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
frameLayout.setClipChildren(false); frameLayout.setClipChildren(false);
textFieldContainer.addView(frameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM, 0, 0, 48, 0)); 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 @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
super.onDraw(canvas); super.onDraw(canvas);
@ -3166,7 +3166,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
if (recordCircle.isSendButtonVisible()) { if (recordCircle.isSendButtonVisible()) {
if (!hasRecordVideo || calledRecordRunnable) { if (!hasRecordVideo || calledRecordRunnable) {
startedDraggingX = -1; startedDraggingX = -1;
if (hasRecordVideo && audioVideoButtonContainer.getTag() != null) { if (hasRecordVideo && isInVideoMode) {
delegate.needStartRecordVideo(1, true, 0); delegate.needStartRecordVideo(1, true, 0);
} else { } else {
if (recordingAudioVideo && isInScheduleMode()) { if (recordingAudioVideo && isInScheduleMode()) {
@ -3177,7 +3177,6 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
} }
recordingAudioVideo = false; recordingAudioVideo = false;
updateRecordInterface(RECORD_STATE_SENDING); updateRecordInterface(RECORD_STATE_SENDING);
} }
return; 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.setContentDescription(LocaleController.getString("AccDescrVoiceMessage", R.string.AccDescrVoiceMessage));
audioVideoSendButton.setFocusable(true); audioVideoSendButton.setFocusable(true);
audioVideoSendButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES); 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(); recordAudioVideoRunnable.run();
delegate.onSwitchRecordMode(audioVideoSendButton.getTag() == null); delegate.onSwitchRecordMode(isInVideoMode);
setRecordVideoButtonVisible(audioVideoSendButton.getTag() == null, true); setRecordVideoButtonVisible(isInVideoMode, true);
if (!NekoConfig.disableVibration.Bool()) { if (!NekoConfig.disableVibration.Bool()) {
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
} }
@ -3888,10 +3887,10 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
} }
} }
audioVideoSendButton.setTag(1); isInVideoMode = true;
recordAudioVideoRunnable.run(); recordAudioVideoRunnable.run();
delegate.onSwitchRecordMode(audioVideoSendButton.getTag() == null); delegate.onSwitchRecordMode(isInVideoMode);
setRecordVideoButtonVisible(audioVideoSendButton.getTag() == null, true); setRecordVideoButtonVisible(isInVideoMode, true);
if (!NekoConfig.disableVibration.Bool()) { if (!NekoConfig.disableVibration.Bool()) {
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP); performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
} }
@ -4405,8 +4404,6 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
if (audioVideoSendButton == null) { if (audioVideoSendButton == null) {
return; return;
} }
// if (NekoConfig.useChatAttachMediaMenu.Bool()) visible = animated = false;
audioVideoSendButton.setTag(visible ? 1 : null);
isInVideoMode = visible; isInVideoMode = visible;
@ -4419,7 +4416,10 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
} }
preferences.edit().putBoolean(isChannel ? "currentModeVideoChannel" : "currentModeVideo", visible).apply(); preferences.edit().putBoolean(isChannel ? "currentModeVideoChannel" : "currentModeVideo", visible).apply();
} }
if (!NekoConfig.useChatAttachMediaMenu.Bool())
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, animated); audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, animated);
else
audioVideoSendButton.setState(ChatActivityEnterViewAnimatedIconView.State.MENU, animated);
audioVideoSendButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); audioVideoSendButton.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
} }
@ -6649,6 +6649,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
audioVideoSendButton.setScaleX(1f); audioVideoSendButton.setScaleX(1f);
audioVideoSendButton.setScaleY(1f); audioVideoSendButton.setScaleY(1f);
runningAnimationAudio.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.ALPHA, 1)); runningAnimationAudio.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.ALPHA, 1));
if (!NekoConfig.useChatAttachMediaMenu.Bool())
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true); audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
} }
if (scheduledButton != null) { if (scheduledButton != null) {
@ -6756,6 +6757,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_X, 1), ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_X, 1),
ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_Y, 1) ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_Y, 1)
); );
if (!NekoConfig.useChatAttachMediaMenu.Bool())
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true); audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
} }
@ -6900,6 +6902,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.ALPHA, 1)); iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.ALPHA, 1));
iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_X, 1)); iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_X, 1));
iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_Y, 1)); iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.SCALE_Y, 1));
if (!NekoConfig.useChatAttachMediaMenu.Bool())
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true); audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
} }
if (scheduledButton != null) { if (scheduledButton != null) {
@ -6998,6 +7001,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
audioVideoSendButton.setScaleX(1f); audioVideoSendButton.setScaleX(1f);
audioVideoSendButton.setScaleY(1f); audioVideoSendButton.setScaleY(1f);
iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.ALPHA, 1)); iconsAnimator.playTogether(ObjectAnimator.ofFloat(audioVideoSendButton, View.ALPHA, 1));
if (!NekoConfig.useChatAttachMediaMenu.Bool())
audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true); audioVideoSendButton.setState(isInVideoMode() ? ChatActivityEnterViewAnimatedIconView.State.VIDEO : ChatActivityEnterViewAnimatedIconView.State.VOICE, true);
} }
if (attachLayout != null) { if (attachLayout != null) {
@ -9160,6 +9164,7 @@ public class ChatActivityEnterView extends BlurredFrameLayout implements Notific
} }
boolean audio = (Boolean) args[1]; boolean audio = (Boolean) args[1];
isInVideoMode = !audio; isInVideoMode = !audio;
if (!NekoConfig.useChatAttachMediaMenu.Bool())
audioVideoSendButton.setState(audio ? ChatActivityEnterViewAnimatedIconView.State.VOICE : ChatActivityEnterViewAnimatedIconView.State.VIDEO, true); audioVideoSendButton.setState(audio ? ChatActivityEnterViewAnimatedIconView.State.VOICE : ChatActivityEnterViewAnimatedIconView.State.VIDEO, true);
if (!recordingAudioVideo) { if (!recordingAudioVideo) {
recordingAudioVideo = true; recordingAudioVideo = true;
@ -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; Integer color = resourcesProvider != null ? resourcesProvider.getColor(key) : null;
return color != null ? color : Theme.getColor(key); return color != null ? color : Theme.getColor(key);
} }

View File

@ -1,36 +1,63 @@
package org.telegram.ui.Components; 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.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.messenger.R;
import org.telegram.ui.ActionBar.Theme;
import java.util.HashMap; public class ChatActivityEnterViewAnimatedIconView extends FrameLayout {
import java.util.Map;
import java.util.Objects;
public class ChatActivityEnterViewAnimatedIconView extends RLottieImageView {
private State currentState; private State currentState;
private TransitState animatingState; private AnimatorSet buttonsAnimation;
private final ImageView[] buttonViews = new ImageView[2];
private Map<TransitState, RLottieDrawable> stateMap = new HashMap<TransitState, RLottieDrawable>() { public ChatActivityEnterViewAnimatedIconView(Context context, ChatActivityEnterView parentActivity) {
@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) {
super(context); 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) { public void setState(State state, boolean animate) {
@ -39,77 +66,57 @@ public class ChatActivityEnterViewAnimatedIconView extends RLottieImageView {
} }
State fromState = currentState; State fromState = currentState;
currentState = state; currentState = state;
if (!animate || fromState == null || getState(fromState, currentState) == null) { if (!animate || fromState == null) {
RLottieDrawable drawable = stateMap.get(getAnyState(currentState)); buttonViews[0].setImageResource(currentState.resource);
drawable.stop();
drawable.setProgress(0, false);
setAnimation(drawable);
} else { } else {
TransitState transitState = getState(fromState, currentState); if (buttonsAnimation != null) {
if (transitState == animatingState) { buttonsAnimation.cancel();
return;
} }
buttonViews[1].setVisibility(VISIBLE);
animatingState = transitState; buttonViews[1].setImageResource(currentState.resource);
RLottieDrawable drawable = stateMap.get(transitState); buttonViews[0].setAlpha(1.0f);
drawable.stop(); buttonViews[1].setAlpha(0.0f);
drawable.setProgress(0, false); buttonsAnimation = new AnimatorSet();
drawable.setAutoRepeat(0); buttonsAnimation.playTogether(
drawable.setOnAnimationEndListener(() -> animatingState = null); ObjectAnimator.ofFloat(buttonViews[0], View.SCALE_X, 0.1f),
setAnimation(drawable); ObjectAnimator.ofFloat(buttonViews[0], View.SCALE_Y, 0.1f),
AndroidUtilities.runOnUIThread(drawable::start); 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);
} }
} }
});
private TransitState getAnyState(State from) { buttonsAnimation.setDuration(200);
for (TransitState transitState : TransitState.values()) { buttonsAnimation.start();
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;
final int resource;
TransitState(State firstState, State secondState, int resource) {
this.firstState = firstState;
this.secondState = secondState;
this.resource = resource;
} }
} }
public enum State { public enum State {
VOICE, VOICE(R.drawable.input_mic),
VIDEO, VIDEO(R.drawable.input_video),
STICKER, STICKER(R.drawable.input_sticker),
KEYBOARD, KEYBOARD(R.drawable.input_keyboard),
SMILE, SMILE(R.drawable.input_smile),
GIF GIF(R.drawable.input_gif),
MENU(R.drawable.ic_ab_other);
final int resource;
State(int resource) {
this.resource = resource;
}
} }
} }