use of cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser in project androidApp by InspectorIncognito.
the class UserFragment method updateUI.
@UiThread
private void updateUI() {
final TranSappAccount account = TranSappAccountManager.getCurrentAccount();
if (!TranSappAccountManager.isLoggedIn()) {
getActivity().finish();
return;
}
progressImage.setProgressValues(account.getScore(), account.getLevelMinScore(), account.getLevelMaxScore());
progressImage.loadImage(account);
userName.setText(account.getName());
level.setText(String.format(Locale.getDefault(), "NIVEL %d", account.getLevelPosition()));
score.setText(String.format(Locale.getDefault(), "%s de %s ptos", account.getFormattedScore(), account.getFormattedLevelMaxScore()));
levelName.setText(account.getLevelName());
levelBackground.setImageResource(account.getLevelBackgroundImage());
rankingPosition.setText(String.format(Locale.getDefault(), "%d", account.currentUser.globalRankingPosition));
rankingFrame.setImageResource(account.getLevelSimpleFrame());
int id = account.getBusAvatarId();
userBusAvatarView.setAvatarId(id);
BusAvatar avatar = Avatar.getBusAvatarById(id);
userBusAvatarTitle.setText(getString(avatar.titleId));
rankingButton.setClickable(true);
rankingPosition.setVisibility(View.VISIBLE);
rankingProgressBar.setVisibility(View.GONE);
rankingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
rankingButton.setClickable(false);
rankingPosition.setVisibility(View.GONE);
rankingProgressBar.setVisibility(View.VISIBLE);
RankingRequest request = new RankingRequest(new Request.RequestListener<Pair<ArrayList<TranSappUser>, ArrayList<TranSappUser>>>() {
@Override
public void onRequestError() {
if (getActivity() == null || getContext() == null) {
return;
}
Toast.makeText(getActivity(), "Ranking no disponible", Toast.LENGTH_SHORT).show();
rankingButton.setClickable(true);
rankingPosition.setVisibility(View.VISIBLE);
rankingProgressBar.setVisibility(View.GONE);
}
@Override
public void onRequestResult(@NonNull Pair<ArrayList<TranSappUser>, ArrayList<TranSappUser>> response) {
if (getActivity() == null || getContext() == null) {
return;
}
Intent intent = new Intent(getActivity(), RankingActivity.class);
intent.putParcelableArrayListExtra(RankingActivity.TOP_RANKING_KEY, response.first);
intent.putParcelableArrayListExtra(RankingActivity.USER_RANKING_KEY, response.second);
startActivityForResult(intent, RANKING_ACTIVITY_CODE);
}
}, account);
ServerController.sendRequest(request, null);
}
});
}
use of cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser in project androidApp by InspectorIncognito.
the class RankingActivity method getCurrentUserPosition.
private int getCurrentUserPosition(ArrayList<TranSappUser> tranSappUserRanking) {
TranSappUser currentUser = TranSappAccountManager.getCurrentAccount().currentUser;
int position = 0;
for (TranSappUser user : tranSappUserRanking) {
if (user.userId.equals(currentUser.userId)) {
return position;
}
position++;
}
return 0;
}
use of cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser in project androidApp by InspectorIncognito.
the class TranSappAccountManager method createAccountFromLoginResult.
private static TranSappAccount createAccountFromLoginResult(String result, String nickname, SocialMediaAccount socialMediaAccount) throws JSONException {
TranSappUser tranSappUser = new TranSappUser();
tranSappUser.nickname = nickname;
JSONObject data = new JSONObject(result);
String sessionToken = data.getString(LoginRequest.SESSION_TOKEN_KEY);
JSONObject userSettings = data.getJSONObject("userSettings");
int busAvatarId = userSettings.getInt(LoginRequest.BUS_AVATAR_ID_KEY);
updateUserSettings(tranSappUser, userSettings);
updateGamificationData(tranSappUser, data);
SocialAccountLoaderManager manager = new SocialAccountLoaderManager();
manager.saveAccount(socialMediaAccount, nickname);
return new TranSappAccount(socialMediaAccount, tranSappUser, sessionToken, busAvatarId);
}
use of cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser in project androidApp by InspectorIncognito.
the class RankingAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
TranSappUser tranSappUser = items.get(position);
holder.setUserData(tranSappUser, currentTranSappUser);
}
use of cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser in project androidApp by InspectorIncognito.
the class RankingTopUsersAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
TranSappUser tranSappUser = items.get(position);
holder.setUserData(tranSappUser);
}
Aggregations