Skip to content

Commit

Permalink
Changed from list to HashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
tcrosado committed May 19, 2017
1 parent 73fdc7b commit 611fa49
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public void onReceive(Context context, Intent intent) {

if (action.equals(BluetoothDevice.ACTION_FOUND)){
BluetoothDevice device = intent.getParcelableExtra (BluetoothDevice.EXTRA_DEVICE);
List<BluetoothDevice> list = dataHolder.getBleContent();
list.add(device);
dataHolder.setBleContent(list);
dataHolder.addBleContent(device);
names = dataHolder.getBleNames();
mDeviceListAdapter.notifyDataSetChanged();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package pt.ulisboa.tecnico.cmu.tg14.locmessclient.DataObjects;

import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
Expand All @@ -15,7 +18,7 @@

public class ServicesDataHolder {

private List<BluetoothDevice> bleContent;
private AbstractMap<String,BluetoothDevice> bleContent;
private AbstractMap<String,String> ssidContent;
private Float longitude;
private Float latitude;
Expand All @@ -40,7 +43,7 @@ public static ServicesDataHolder getInstance() {

private ServicesDataHolder() {

bleContent = new ArrayList<>();
bleContent = new HashMap<>();
ssidContent = new HashMap<>();
latitude = new Float(0);
longitude = new Float(0);
Expand Down Expand Up @@ -112,13 +115,17 @@ public void setUsername(String username) {
public void setPassword(String password) {
this.password = password;
}
public List<BluetoothDevice> getBleContent() {
public AbstractMap<String, BluetoothDevice> getBleContent() {
return bleContent;
}

public void setBleContent(List<BluetoothDevice> bleContent) {
public void setBleContent(AbstractMap<String,BluetoothDevice> bleContent) {
this.bleContent = bleContent;
}
public void addBleContent(BluetoothDevice device){
String name = (device.getName() == null) ? device.getAddress() : device.getName();
this.bleContent.put(name,device);
}

public AbstractMap<String, String> getSsidContent() {
return ssidContent;
Expand All @@ -145,12 +152,7 @@ public void setLatitude(Float latitude) {
}

public List<String> getBleNames(){
List<String> bleNames = new ArrayList<>();
for(BluetoothDevice device : bleContent){
String name = (device.getName() == null) ? device.getAddress() : device.getName();
bleNames.add(name);
}
return bleNames;
return new ArrayList<>(bleContent.keySet());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ public void onWifiReceived(String name, String ssid) {

@Override
public void onBleReceived(BluetoothDevice device) {
List<BluetoothDevice> devices = dataHolder.getBleContent();
devices.add(device);
dataHolder.setBleContent(devices);
dataHolder.addBleContent(device);

}

@Override
Expand All @@ -81,7 +80,7 @@ public void clearWifiList() {

@Override
public void clearBluetoothList() {
dataHolder.setBleContent(new ArrayList<BluetoothDevice>());
dataHolder.setBleContent(new HashMap<String,BluetoothDevice>());
}

@Override
Expand Down

0 comments on commit 611fa49

Please sign in to comment.