mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-23 16:37:30 +00:00
131 lines
4.1 KiB
Java
131 lines
4.1 KiB
Java
package org.thoughtcrime.securesms.components;
|
|
|
|
import android.content.Context;
|
|
|
|
import androidx.annotation.DrawableRes;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.appcompat.widget.AppCompatImageButton;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
|
|
import org.thoughtcrime.securesms.TransportOption;
|
|
import org.thoughtcrime.securesms.TransportOptions;
|
|
import org.thoughtcrime.securesms.TransportOptions.OnTransportChangedListener;
|
|
import org.thoughtcrime.securesms.TransportOptionsPopup;
|
|
import org.thoughtcrime.securesms.util.ThemeUtil;
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
|
|
|
import network.loki.messenger.R;
|
|
|
|
public class SendButton extends AppCompatImageButton
|
|
implements TransportOptions.OnTransportChangedListener,
|
|
TransportOptionsPopup.SelectedListener,
|
|
View.OnLongClickListener {
|
|
|
|
private final TransportOptions transportOptions;
|
|
|
|
private Optional<TransportOptionsPopup> transportOptionsPopup = Optional.absent();
|
|
|
|
@SuppressWarnings("unused")
|
|
public SendButton(Context context) {
|
|
super(context);
|
|
this.transportOptions = initializeTransportOptions(false);
|
|
ViewUtil.mirrorIfRtl(this, getContext());
|
|
}
|
|
|
|
@SuppressWarnings("unused")
|
|
public SendButton(Context context, AttributeSet attrs) {
|
|
super(context, attrs);
|
|
this.transportOptions = initializeTransportOptions(false);
|
|
ViewUtil.mirrorIfRtl(this, getContext());
|
|
}
|
|
|
|
@SuppressWarnings("unused")
|
|
public SendButton(Context context, AttributeSet attrs, int defStyle) {
|
|
super(context, attrs, defStyle);
|
|
this.transportOptions = initializeTransportOptions(false);
|
|
ViewUtil.mirrorIfRtl(this, getContext());
|
|
}
|
|
|
|
private TransportOptions initializeTransportOptions(boolean media) {
|
|
if (isInEditMode()) return null;
|
|
|
|
TransportOptions transportOptions = new TransportOptions(getContext(), media);
|
|
transportOptions.addOnTransportChangedListener(this);
|
|
|
|
setOnLongClickListener(this);
|
|
|
|
return transportOptions;
|
|
}
|
|
|
|
private TransportOptionsPopup getTransportOptionsPopup() {
|
|
if (!transportOptionsPopup.isPresent()) {
|
|
transportOptionsPopup = Optional.of(new TransportOptionsPopup(getContext(), this, this));
|
|
}
|
|
return transportOptionsPopup.get();
|
|
}
|
|
|
|
public boolean isManualSelection() {
|
|
return transportOptions.isManualSelection();
|
|
}
|
|
|
|
public void addOnTransportChangedListener(OnTransportChangedListener listener) {
|
|
transportOptions.addOnTransportChangedListener(listener);
|
|
}
|
|
|
|
public TransportOption getSelectedTransport() {
|
|
return transportOptions.getSelectedTransport();
|
|
}
|
|
|
|
public void resetAvailableTransports(boolean isMediaMessage) {
|
|
transportOptions.reset(isMediaMessage);
|
|
}
|
|
|
|
public void disableTransport(TransportOption.Type type) {
|
|
transportOptions.disableTransport(type);
|
|
}
|
|
|
|
public void setDefaultTransport(TransportOption.Type type) {
|
|
transportOptions.setDefaultTransport(type);
|
|
}
|
|
|
|
public void setTransport(@NonNull TransportOption option) {
|
|
transportOptions.setSelectedTransport(option);
|
|
}
|
|
|
|
public void setDefaultSubscriptionId(Optional<Integer> subscriptionId) {
|
|
transportOptions.setDefaultSubscriptionId(subscriptionId);
|
|
}
|
|
|
|
@Override
|
|
public void onSelected(TransportOption option) {
|
|
transportOptions.setSelectedTransport(option);
|
|
getTransportOptionsPopup().dismiss();
|
|
}
|
|
|
|
@Override
|
|
public void onChange(TransportOption newTransport, boolean isManualSelection) {
|
|
// Map send icon drawable resource from a transport type.
|
|
//TODO These values should come from XML layout as view's attributes and not be resolved in code like this.
|
|
@DrawableRes final int sendDrawable;
|
|
switch (newTransport.getType()) {
|
|
case SMS:
|
|
case TEXTSECURE:
|
|
default: {
|
|
sendDrawable = ThemeUtil.getThemedDrawableResId(
|
|
getContext(), R.attr.conversation_transport_sms_indicator);
|
|
}
|
|
}
|
|
|
|
setImageResource(sendDrawable);
|
|
setContentDescription(newTransport.getDescription());
|
|
}
|
|
|
|
@Override
|
|
public boolean onLongClick(View v) {
|
|
// Loki - Do nothing
|
|
return false;
|
|
}
|
|
}
|