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-06-06 19:39:04 +02:00
|
|
|
import android.widget.ProgressBar;
|
2015-03-21 18:18:07 +01:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-08-21 08:41:57 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2015-03-21 18:18:07 +01:00
|
|
|
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-05-05 22:52:25 +02:00
|
|
|
TextView batteryStatusLabel = (TextView) view.findViewById(R.id.battery_status);
|
2015-03-31 23:34:19 +02:00
|
|
|
ImageView deviceImageView = (ImageView) view.findViewById(R.id.device_image);
|
2015-06-06 19:39:04 +02:00
|
|
|
ProgressBar busyIndicator = (ProgressBar) view.findViewById(R.id.device_busy_indicator);
|
2015-03-31 23:34:19 +02:00
|
|
|
|
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-06-06 19:39:04 +02:00
|
|
|
if (device.isBusy()) {
|
|
|
|
deviceStatusLabel.setText(device.getBusyTask());
|
|
|
|
busyIndicator.setVisibility(View.VISIBLE);
|
|
|
|
batteryStatusLabel.setVisibility(View.GONE);
|
|
|
|
deviceInfoLabel.setVisibility(View.GONE);
|
|
|
|
} else {
|
|
|
|
deviceStatusLabel.setText(device.getStateString());
|
|
|
|
busyIndicator.setVisibility(View.GONE);
|
|
|
|
batteryStatusLabel.setVisibility(View.VISIBLE);
|
|
|
|
deviceInfoLabel.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
2015-05-05 22:52:25 +02:00
|
|
|
short batteryLevel = device.getBatteryLevel();
|
2015-05-10 00:05:29 +02:00
|
|
|
if (batteryLevel != GBDevice.BATTERY_UNKNOWN) {
|
2015-05-05 22:52:25 +02:00
|
|
|
batteryStatusLabel.setText("BAT: " + device.getBatteryLevel() + "%");
|
2015-08-21 08:41:57 +02:00
|
|
|
GBDeviceEventBatteryInfo.BatteryState batteryState = device.getBatteryState();
|
|
|
|
if (GBDeviceEventBatteryInfo.BatteryState.BATTERY_CHARGING.equals(batteryState) ||
|
|
|
|
GBDeviceEventBatteryInfo.BatteryState.BATTERY_CHARGING_FULL.equals(batteryState)) {
|
|
|
|
batteryStatusLabel.append(" CHG");
|
|
|
|
}
|
2015-05-05 22:52:25 +02:00
|
|
|
} else {
|
|
|
|
batteryStatusLabel.setText("");
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|