public void add(View view) {
if (!text.getText().toString().equals("")) {
model.add(text.getText().toString());
recycler.smoothScrollToPosition(model.list.getValue().size());
text.setText("");
}
}
public void add(final String bib) {
service.submit(new Runnable() {
@Override
public void run() {
String time = df.format(Calendar.getInstance().getTime());
String point = sPref.getString("POINT", "");
long id = dataBase.BoxModel().addBox(new Box(bib, time, 0, point));
Log.d("SIZE ADD: ", ""+list.getValue().size());
try {
Response<Result> response = App.getApi().send(sPref.getString("URL", ""), bib, time, point, 1).execute();
if (response.code() == 200) {
Log.d("ID IN: ", id+" "+bib+" "+time);
dataBase.BoxModel().updateItemStatus(id, 1);
}
else {
dataBase.BoxModel().updateItemStatus(id, -1);
}
}
catch (Exception e) {
dataBase.BoxModel().updateItemStatus(id, -1);
}
}
}
);
}
// Listener
public interface OnDataChangedListener {
public void onSuccess();
}
// onClick
public void add(View view) {
if (!text.getText().toString().equals("")) {
model.add(text.getText().toString(), new OnDataChangedListener() {
public void onSuccess() {
recycler.smoothScrollToPosition(model.list.getValue().size());
}
});
text.setText("");
}
}
// model.add
public void add(final String bib, OnDataChangedListener listener) {
service.submit(new Runnable() {
@Override
public void run() {
String time = df.format(Calendar.getInstance().getTime());
String point = sPref.getString("POINT", "");
long id = dataBase.BoxModel().addBox(new Box(bib, time, 0, point));
Log.d("SIZE ADD: ", ""+list.getValue().size());
try {
Response<Result> response = App.getApi().send(sPref.getString("URL", ""), bib, time, point, 1).execute();
if (response.code() == 200) {
Log.d("ID IN: ", id+" "+bib+" "+time);
dataBase.BoxModel().updateItemStatus(id, 1);
listener.onSuccess();
}
else {
dataBase.BoxModel().updateItemStatus(id, -1);
}
}
catch (Exception e) {
dataBase.BoxModel().updateItemStatus(id, -1);
}
}
}
);
}