2015-03-11 14:23:45 -07:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.widget.ListPopupWindow;
|
2015-03-11 14:23:45 -07:00
|
|
|
import android.view.View;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.ListView;
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2015-07-10 16:11:58 -07:00
|
|
|
public class TransportOptionsPopup extends ListPopupWindow implements ListView.OnItemClickListener {
|
2015-03-11 14:23:45 -07:00
|
|
|
|
|
|
|
private final TransportOptionsAdapter adapter;
|
|
|
|
private final SelectedListener listener;
|
|
|
|
|
2015-07-10 16:11:58 -07:00
|
|
|
public TransportOptionsPopup(@NonNull Context context, @NonNull View anchor, @NonNull SelectedListener listener) {
|
|
|
|
super(context);
|
2015-03-11 14:23:45 -07:00
|
|
|
this.listener = listener;
|
|
|
|
this.adapter = new TransportOptionsAdapter(context, new LinkedList<TransportOption>());
|
|
|
|
|
2015-07-10 16:11:58 -07:00
|
|
|
setVerticalOffset(context.getResources().getDimensionPixelOffset(R.dimen.transport_selection_popup_yoff));
|
|
|
|
setHorizontalOffset(context.getResources().getDimensionPixelOffset(R.dimen.transport_selection_popup_xoff));
|
|
|
|
setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
|
|
|
|
setModal(true);
|
|
|
|
setAnchorView(anchor);
|
|
|
|
setAdapter(adapter);
|
|
|
|
setContentWidth(context.getResources().getDimensionPixelSize(R.dimen.transport_selection_popup_width));
|
2015-06-30 17:45:39 -07:00
|
|
|
|
2015-07-10 16:11:58 -07:00
|
|
|
setOnItemClickListener(this);
|
2015-03-11 14:23:45 -07:00
|
|
|
}
|
|
|
|
|
2015-07-10 16:11:58 -07:00
|
|
|
public void display(List<TransportOption> enabledTransports) {
|
|
|
|
adapter.setEnabledTransports(enabledTransports);
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
show();
|
2015-03-11 14:23:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
listener.onSelected((TransportOption)adapter.getItem(position));
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface SelectedListener {
|
2015-06-30 17:45:39 -07:00
|
|
|
void onSelected(TransportOption option);
|
2015-03-11 14:23:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|