Skip to content

Instantly share code, notes, and snippets.

@senneco
Last active February 27, 2017 08:51
Show Gist options
  • Save senneco/4b7433dd90b8a2cb66d0a345713bb901 to your computer and use it in GitHub Desktop.
Save senneco/4b7433dd90b8a2cb66d0a345713bb901 to your computer and use it in GitHub Desktop.
public class ScanInteractor {
private final DevicesManager devicesManager;
public ScanInteractor() {
devicesManager = DevicesManager.getInstance();
}
public Observable<ScanResultData> getDevices() {
return devicesManager
.getDevices()
.map(ScanResultData::new);
}
public void stopScan() {
devicesManager.stopScan();
}
}
package com.arellomobile.bleworker.mvp.presentation.data;
import java.util.List;
import com.polidea.rxandroidble.RxBleDevice;
/**
* Date: 17.02.2017
* Time: 13:11
*
* @author Yuri Shmakov
*/
public class ScanResultData {
private List<RxBleDevice> bleDevices;
public ScanResultData(List<RxBleDevice> devices) {
this.bleDevices = devices;
}
public int size() {
return bleDevices.size();
}
public Device get(int position) {
return new Device(bleDevices.get(position));
}
public class Device {
private RxBleDevice device;
private Device(RxBleDevice device) {
this.device = device;
}
public String getMacAddress() {
return device.getMacAddress();
}
public String getName() {
return device.getName();
}
}
}
public class ScanResultsAdapter extends BaseAdapter {
private ScanResultData data;
public ScanResultsAdapter() {
this.data = new ScanResultData(Collections.emptyList());
}
public void setData(ScanResultData data) {
this.data = data;
notifyDataSetChanged();
}
@Override
public int getCount() {
return data.size();
}
@Override
public ScanResultData.Device getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// inflate view
return new View();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment