Skip to content

Commit

Permalink
Helper class refactored
Browse files Browse the repository at this point in the history
Remove repeated code
  • Loading branch information
Alexandre Reis committed Oct 1, 2019
1 parent 2a1fa54 commit 08aa33b
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ protected void validateFirstMessage(JSONObject data, final String[]... serverInf
} else {

if (data.getString("door_command").equals("open")) {
Dremote_main._tvState.setText("Opened");
Toast.makeText(Dremote_main._context, "Correct Message.", Toast.LENGTH_LONG).show();

Dremote_main._formLayout.setVisibility(View.VISIBLE);
Dremote_main._serverFieldsLayout.setVisibility(View.INVISIBLE);
Dremote_main._buttonOpenLayout.setVisibility(View.INVISIBLE);
setStatusText("Opened", "Correct Message.");
setUIVisibility();

new Timer().schedule(new TimerTask() {
@Override
Expand All @@ -33,16 +29,12 @@ public void run() {
}, 4000);

} else {
Dremote_main._tvState.setText("Closed");
Toast.makeText(Dremote_main._context, "Command not found", Toast.LENGTH_LONG).show();

setStatusText("Closed", "Command not found");
}
}

} catch (JSONException e) {
Log.e("Validation Message 1:", "Error:", e);
}

}

protected void validateSecondMessage(JSONObject data) {
Expand Down Expand Up @@ -70,4 +62,14 @@ private void restoreUI(){
Dremote_main._buttonOpenLayout.setVisibility(View.VISIBLE);
}

private void setStatusText(String dremoteMessage, String toastMessage){
Dremote_main._tvState.setText(dremoteMessage);
Toast.makeText(Dremote_main._context, toastMessage, Toast.LENGTH_LONG).show();
}

private void setUIVisibility(){
Dremote_main._formLayout.setVisibility(View.VISIBLE);
Dremote_main._serverFieldsLayout.setVisibility(View.INVISIBLE);
Dremote_main._buttonOpenLayout.setVisibility(View.INVISIBLE);
}
}

0 comments on commit 08aa33b

Please sign in to comment.