Am nevoie să actualizez mai multe TextViews cu date primite de la Backendless și aș dori să știu ce părere aveți despre următoarea abordare:
Cod: Selectaţi tot
Bundle bundle = getIntent().getExtras();
if (bundle != null && bundle.getString("user_name") != "") {
ArrayList<BackendlessUser> users = Session.get().getSearchUsers();
Iterator<BackendlessUser> iterator = users.iterator();
while (iterator.hasNext()) {
final BackendlessUser user = iterator.next();
if (user.getProperty("name").toString().equals(bundle.getString("user_name"))) {
Runnable loadAvatar = new Runnable() {
public void run() {
UserProfileActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
userName.setText(user.getProperty("name").toString());
if (!user.getProperty("avatarURL").toString().equals("")) {
Picasso.with(UserProfileActivity.this).load(user.getProperty("avatarURL").toString()).into(avatar);
} else {
Picasso.with(UserProfileActivity.this).load(R.drawable.avatar).into(avatar);
}
Log.v(Constants.TAG, "1");
}
});
}
};
Runnable loadNumberOfSelfies = new Runnable() {
@Override
public void run() {
try {
Services.getNumberOfSelfies(context, user);
} catch (InterruptedException e) {
e.printStackTrace();
}
UserProfileActivity.this.runOnUiThread((new Runnable() {
@Override
public void run() {
numberOfSeflies.setText(Session.get().getTempData("nrOfSelfies"));
Log.v(Constants.TAG, "2");
}
}));
}
};
Runnable loadNumberOfFollowers = new Runnable() {
public void run() {
try {
Services.getNumberOfFollowers(context, user);
} catch (InterruptedException e) {
e.printStackTrace();
}
UserProfileActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
numberOfFollowers.setText(Session.get().getTempData("nrOfFollowers"));
Log.v(Constants.TAG, "3");
}
});
}
};
Runnable loadNumberOfFollowing = new Runnable() {
public void run() {
try {
Services.getNumberOfFollowing(context, user);
} catch (InterruptedException e) {
e.printStackTrace();
}
UserProfileActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
numberOfFollowing.setText(Session.get().getTempData("nrOfFollowing"));
Log.v(Constants.TAG, "4");
}
});
}
};
worker.schedule(loadAvatar, 1, TimeUnit.MILLISECONDS);
worker.schedule(loadNumberOfSelfies, 1, TimeUnit.MILLISECONDS);
worker.schedule(loadNumberOfFollowers, 1, TimeUnit.MILLISECONDS);
worker.schedule(loadNumberOfFollowing, 1, TimeUnit.MILLISECONDS);
}
}
}
Mulțumesc