2014-07-18 19:31:03 -07:00
|
|
|
package org.thoughtcrime.securesms.components;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.TransportOption;
|
|
|
|
import org.thoughtcrime.securesms.TransportOptions;
|
|
|
|
import org.thoughtcrime.securesms.TransportOptions.OnTransportChangedListener;
|
2015-03-11 14:23:45 -07:00
|
|
|
import org.thoughtcrime.securesms.TransportOptionsPopup;
|
2014-07-18 19:31:03 -07:00
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
public class SendButton extends ImageButton
|
|
|
|
implements TransportOptions.OnTransportChangedListener,
|
|
|
|
TransportOptionsPopup.SelectedListener,
|
|
|
|
View.OnLongClickListener
|
|
|
|
{
|
|
|
|
|
|
|
|
private final TransportOptions transportOptions;
|
|
|
|
private final TransportOptionsPopup transportOptionsPopup;
|
2014-07-18 19:31:03 -07:00
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public SendButton(Context context) {
|
|
|
|
super(context);
|
2015-03-11 14:23:45 -07:00
|
|
|
this.transportOptions = initializeTransportOptions(false);
|
|
|
|
this.transportOptionsPopup = initializeTransportOptionsPopup();
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public SendButton(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
2015-03-11 14:23:45 -07:00
|
|
|
this.transportOptions = initializeTransportOptions(false);
|
|
|
|
this.transportOptionsPopup = initializeTransportOptionsPopup();
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public SendButton(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
super(context, attrs, defStyle);
|
2015-03-11 14:23:45 -07:00
|
|
|
this.transportOptions = initializeTransportOptions(false);
|
|
|
|
this.transportOptionsPopup = initializeTransportOptionsPopup();
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
private TransportOptions initializeTransportOptions(boolean media) {
|
|
|
|
TransportOptions transportOptions = new TransportOptions(getContext(), media);
|
|
|
|
transportOptions.addOnTransportChangedListener(this);
|
|
|
|
|
|
|
|
setOnLongClickListener(this);
|
|
|
|
|
|
|
|
return transportOptions;
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
private TransportOptionsPopup initializeTransportOptionsPopup() {
|
2015-07-10 16:11:58 -07:00
|
|
|
return new TransportOptionsPopup(getContext(), this, this);
|
2015-03-11 14:23:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isManualSelection() {
|
|
|
|
return transportOptions.isManualSelection();
|
2015-02-16 02:38:09 -08:00
|
|
|
}
|
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
public void addOnTransportChangedListener(OnTransportChangedListener listener) {
|
|
|
|
transportOptions.addOnTransportChangedListener(listener);
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public TransportOption getSelectedTransport() {
|
|
|
|
return transportOptions.getSelectedTransport();
|
|
|
|
}
|
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
public void resetAvailableTransports(boolean isMediaMessage) {
|
|
|
|
transportOptions.reset(isMediaMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void disableTransport(TransportOption.Type type) {
|
|
|
|
transportOptions.disableTransport(type);
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
public void setDefaultTransport(TransportOption.Type type) {
|
|
|
|
transportOptions.setDefaultTransport(type);
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
@Override
|
|
|
|
public void onSelected(TransportOption option) {
|
|
|
|
transportOptions.setSelectedTransport(option.getType());
|
|
|
|
transportOptionsPopup.dismiss();
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
@Override
|
|
|
|
public void onChange(TransportOption newTransport) {
|
|
|
|
setImageResource(newTransport.getDrawable());
|
|
|
|
setContentDescription(newTransport.getDescription());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
if (transportOptions.getEnabledTransports().size() > 1) {
|
2015-07-10 16:11:58 -07:00
|
|
|
transportOptionsPopup.display(transportOptions.getEnabledTransports());
|
2015-03-11 14:23:45 -07:00
|
|
|
return true;
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
2015-03-11 14:23:45 -07:00
|
|
|
|
|
|
|
return false;
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
}
|