2015-03-21 18:18:07 +01:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.adapter;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ArrayAdapter;
|
2015-03-31 23:34:19 +02:00
|
|
|
import android.widget.ImageView;
|
2015-03-21 18:18:07 +01:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
|
|
|
|
public class GBDeviceAdapter extends ArrayAdapter<GBDevice> {
|
|
|
|
|
|
|
|
private final Context context;
|
|
|
|
|
|
|
|
public GBDeviceAdapter(Context context, List<GBDevice> deviceList) {
|
|
|
|
super(context, 0, deviceList);
|
|
|
|
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int position, View view, ViewGroup parent) {
|
|
|
|
GBDevice device = getItem(position);
|
|
|
|
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater inflater = (LayoutInflater) context
|
|
|
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
|
|
|
|
view = inflater.inflate(R.layout.device_item, parent, false);
|
|
|
|
}
|
|
|
|
TextView deviceStatusLabel = (TextView) view.findViewById(R.id.device_status);
|
|
|
|
TextView deviceNameLabel = (TextView) view.findViewById(R.id.device_name);
|
2015-05-05 11:16:57 +02:00
|
|
|
TextView deviceInfoLabel = (TextView) view.findViewById(R.id.device_info);
|
2015-03-31 23:34:19 +02:00
|
|
|
ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image);
|
|
|
|
|
2015-05-05 11:16:57 +02:00
|
|
|
deviceStatusLabel.setText(device.getStateString());
|
2015-03-21 18:18:07 +01:00
|
|
|
deviceNameLabel.setText(device.getName());
|
2015-05-05 11:16:57 +02:00
|
|
|
deviceInfoLabel.setText(device.getInfoString());
|
2015-03-21 18:18:07 +01:00
|
|
|
|
2015-03-31 23:34:19 +02:00
|
|
|
switch (device.getType()) {
|
|
|
|
case PEBBLE:
|
|
|
|
deviceImageView.setImageResource(R.drawable.ic_device_pebble);
|
|
|
|
break;
|
|
|
|
case MIBAND:
|
2015-04-01 22:12:49 +02:00
|
|
|
deviceImageView.setImageResource(R.drawable.ic_device_miband);
|
2015-03-31 23:34:19 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
deviceImageView.setImageResource(R.drawable.ic_launcher);
|
|
|
|
}
|
|
|
|
|
2015-03-21 18:18:07 +01:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|