Skip to content

Commit

Permalink
Adapted the test app to work with multi-device communication
Browse files Browse the repository at this point in the history
  • Loading branch information
bayosip committed Aug 5, 2021
1 parent 75b1726 commit 776d876
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,15 @@ private void bindBleService(){
}

public String getDeviceName() {
return deviceName;
StringBuilder names = new StringBuilder();
if (type.equalsIgnoreCase(Constants.BLE)){
for (Parcelable p: listDevice){
BluetoothDevice device = (BluetoothDevice)p;
names.append(device.getName());
names.append(", ");
}
}else return deviceName;
return names.toString();
}

public void unbindBleService(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public DevicesViewHolder(@NonNull View itemView, RefreshItem refreshItem) {

public void setItems(List<Devices> discoveredDevices){
this.devices = discoveredDevices;
deviceName.setText(discoveredDevices.get(getAdapterPosition()).getDeviceName());
deviceAddress.setText(discoveredDevices.get(getAdapterPosition()).getDeviceAddress());
deviceName.setText(discoveredDevices.get(getAbsoluteAdapterPosition()).getDeviceName());
deviceAddress.setText(discoveredDevices.get(getAbsoluteAdapterPosition()).getDeviceAddress());
}
public void setServiceItems(List<String> discoveredServices){
deviceName.setText(discoveredServices.get(getAdapterPosition()));
deviceName.setText(discoveredServices.get(getAbsoluteAdapterPosition()));
}

public void setDeviceListener(OnDiscoveredDevicesClickListener listener) {
Expand Down Expand Up @@ -89,10 +89,11 @@ public void onClick(View view) {
refresh.setSelectedPosition(getAbsoluteAdapterPosition());
listener1.selectAServiceWith(getAbsoluteAdapterPosition());
}else {
changeItemBackground(true);
if (getAbsoluteAdapterPosition() < devices.size())
listener.selectDevicesToConnectTo(devices.get(getAbsoluteAdapterPosition()));

GeneralUtil.getHandler().postDelayed(() -> deviceName.setTextColor(ContextCompat.getColor(context, R.color.title_color)), 200);
//GeneralUtil.getHandler().postDelayed(() -> deviceName.setTextColor(ContextCompat.getColor(context, R.color.title_color)), 200);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public DevicesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewT
public void onBindViewHolder(@NonNull DevicesViewHolder holder, int position) {
if(isListOfServices) {
holder.setServiceItems(discoveredServices);

Log.w(TAG, "onBindViewHolder: pos - " + position + " vs selectedPos - "+ selectedPos );
holder.changeItemBackground(position == selectedPos);
}else {
Expand Down

0 comments on commit 776d876

Please sign in to comment.