2014-07-18 19:31:03 -07:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.BaseAdapter;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2020-08-20 20:36:56 +10:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
2016-02-05 16:10:33 -08:00
|
|
|
import org.thoughtcrime.securesms.util.ViewUtil;
|
|
|
|
|
2014-07-18 19:31:03 -07:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2014-07-18 19:31:03 -07:00
|
|
|
public class TransportOptionsAdapter extends BaseAdapter {
|
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
private final LayoutInflater inflater;
|
|
|
|
|
|
|
|
private List<TransportOption> enabledTransports;
|
|
|
|
|
|
|
|
public TransportOptionsAdapter(@NonNull Context context,
|
|
|
|
@NonNull List<TransportOption> enabledTransports)
|
|
|
|
{
|
2014-07-18 19:31:03 -07:00
|
|
|
super();
|
|
|
|
this.inflater = LayoutInflater.from(context);
|
|
|
|
this.enabledTransports = enabledTransports;
|
|
|
|
}
|
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
public void setEnabledTransports(List<TransportOption> enabledTransports) {
|
2014-07-18 19:31:03 -07:00
|
|
|
this.enabledTransports = enabledTransports;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
2015-03-11 14:23:45 -07:00
|
|
|
return enabledTransports.size();
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int position) {
|
2015-03-11 14:23:45 -07:00
|
|
|
return enabledTransports.get(position);
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
|
|
if (convertView == null) {
|
2015-03-11 14:23:45 -07:00
|
|
|
convertView = inflater.inflate(R.layout.transport_selection_list_item, parent, false);
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
2016-02-05 16:10:33 -08:00
|
|
|
TransportOption transport = (TransportOption) getItem(position);
|
|
|
|
ImageView imageView = ViewUtil.findById(convertView, R.id.icon);
|
|
|
|
TextView textView = ViewUtil.findById(convertView, R.id.text);
|
|
|
|
TextView subtextView = ViewUtil.findById(convertView, R.id.subtext);
|
2015-03-11 14:23:45 -07:00
|
|
|
|
2020-08-20 20:36:56 +10:00
|
|
|
imageView.setImageResource(R.drawable.ic_arrow_up_circle_24);
|
2015-03-11 14:23:45 -07:00
|
|
|
textView.setText(transport.getDescription());
|
2014-07-18 19:31:03 -07:00
|
|
|
|
2016-02-05 16:10:33 -08:00
|
|
|
if (transport.getSimName().isPresent()) {
|
|
|
|
subtextView.setText(transport.getSimName().get());
|
|
|
|
subtextView.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
subtextView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
2015-03-11 14:23:45 -07:00
|
|
|
return convertView;
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
}
|