Skip to content

Commit

Permalink
prevent multiple click when connecting (fixes #127) (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sriharsha-Singam authored and dogi committed Jan 10, 2019
1 parent c909d4c commit 87b888d
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.treehouses.remote.FragmentsOld.CustomHandler;
import io.treehouses.remote.InitialActivity;
import io.treehouses.remote.MiscOld.Constants;
Expand All @@ -36,7 +39,6 @@ public class RPIDialogFragment extends androidx.fragment.app.DialogFragment {

private static final String TAG = "RaspberryDialogFragment";
private static boolean isRead = false;

AlertDialog mDialog;
private ArrayAdapter<String> mConversationArrayAdapter;
ListView listView;
Expand Down Expand Up @@ -127,7 +129,7 @@ public void finish(int status, View mView){
mDialog.setTitle("BLUETOOTH IS NOT CONNECTED");
}
List<String> empty = new ArrayList<>();
listView.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, empty));
setAdapterNotNull(empty);
}

// private void connectDevice(Intent data) {
Expand Down Expand Up @@ -182,6 +184,14 @@ protected void bluetoothCheck() {
}
}

public void setAdapterNotNull(List<String> listVal){
if(getActivity() == null){
Log.e("RPI DIALOG ACTIVITY", "null");
}else{
listView.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, listVal));
}
}

// Create a BroadcastReceiver for ACTION_FOUND.
public final BroadcastReceiver mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
Expand All @@ -202,14 +212,10 @@ public void onReceive(Context context, Intent intent) {
if(!alreadyExist){
devices.add(device);
s.add(deviceName+ "\n" + deviceHardwareAddress);
listView.setAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, s));
setAdapterNotNull(s);
}
Log.e("Broadcast BT", device.getName() + "\n" + device.getAddress());
}
else if(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)){
dialog.dismiss();
mDialog.cancel();
}
}
};
private void setupBluetoothService() {
Expand Down

0 comments on commit 87b888d

Please sign in to comment.