Skip to content

Commit

Permalink
Merge pull request #20 from ajayyy/master
Browse files Browse the repository at this point in the history
Improved UUID and end splitter code
  • Loading branch information
ajayyy authored Oct 30, 2018
2 parents a15f816 + dede199 commit 26332bd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,16 @@ public void run() {

}

public boolean stringListContains(ArrayList<String> list, String string) {
for (String listString : list) {
if (listString.equals(string)) {
return true;
}
}

return false;
}

public ArrayList<String> readData() throws IOException {

File sdCard = Environment.getExternalStorageDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class PullDataThread extends Thread{
int tries = 0;
int maxTries = 5;

final String endSplitter = "{e}";

public PullDataThread(MainActivity mainActivity, BluetoothDevice bluetoothDevice, View deviceMenu){
this.mainActivity = mainActivity;
this.device = bluetoothDevice;
Expand Down Expand Up @@ -77,7 +79,7 @@ public void run() {
}
});

out.write("REQUEST LABELSEND".getBytes(Charset.forName("UTF-8")));
out.write(("REQUEST LABELS" + endSplitter).getBytes(Charset.forName("UTF-8")));
String labels = waitForMessage();
labels = labels.substring(0, labels.length() - 3);

Expand Down Expand Up @@ -147,7 +149,7 @@ public void run() {
}

//this message has finished
scheduleMessage.append("END");
scheduleMessage.append(endSplitter);

out.write(scheduleMessage.toString().getBytes(Charset.forName("UTF-8")));
String receivedMessage = waitForMessage();
Expand All @@ -164,7 +166,7 @@ public void run() {
}
});

out.write("REQUEST DATAEND".getBytes(Charset.forName("UTF-8")));
out.write(("REQUEST DATA" + endSplitter).getBytes(Charset.forName("UTF-8")));
String message = waitForMessage();

message = message.substring(0, message.length() - 3);
Expand Down Expand Up @@ -196,13 +198,15 @@ public void run() {
});
}else{
for(int i = 0; i < data.length; i++){
if(mainActivity.uuids.contains(mainActivity.getUUIDFromData(data[i]))){
if(mainActivity.stringListContains(mainActivity.uuids, mainActivity.getUUIDFromData(data[i]))){
//send toast saying that the data already exists
mainActivity.runOnUiThread(new Thread(){
public void run(){
Toast.makeText(mainActivity, "Duplicate data detected and removed", Toast.LENGTH_LONG).show();
}
});

//don't save the data
continue;
}
mainActivity.save(data[i], mainActivity.labels);
Expand All @@ -212,7 +216,7 @@ public void run(){

}

out.write("RECEIVEDEND".getBytes(Charset.forName("UTF-8")));
out.write(("RECEIVED" + endSplitter).getBytes(Charset.forName("UTF-8")));

} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -282,7 +286,7 @@ public String waitForMessage(){
else continue;

String message = finalMessage + new String(bytes, Charset.forName("UTF-8"));
if(!message.endsWith("END")){
if(!message.endsWith("")){
finalMessage = message;
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pull All"
android:text="Sync All"
android:id="@+id/pullAll"/>

<Button
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/device_name.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
android:id="@+id/deviceName"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Device Name (Pulled X minutes ago)"
android:text="Device Name (Synced X minutes ago)"
android:layout_weight="1"
android:textSize="18sp" />

<Button
android:id="@+id/pull"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Pull" />
android:text="Sync" />

<Button
android:id="@+id/remove"
Expand Down

0 comments on commit 26332bd

Please sign in to comment.