use of cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser in project androidApp by InspectorIncognito.
the class RankingRequest method processResult.
@NonNull
@Override
public Pair<ArrayList<TranSappUser>, ArrayList<TranSappUser>> processResult(@NonNull String result) {
ArrayList<TranSappUser> topRanking = new ArrayList<>();
ArrayList<TranSappUser> tranSappUserRanking = new ArrayList<>();
Pair<ArrayList<TranSappUser>, ArrayList<TranSappUser>> ranking = Pair.create(topRanking, tranSappUserRanking);
try {
JSONObject data = new JSONObject(result);
int status = data.getInt("status");
if (status != 200) {
return ranking;
}
JSONObject jRanking = data.getJSONObject("ranking");
JSONArray top = jRanking.getJSONArray("top");
for (int i = 0; i < top.length(); i++) {
JSONObject userData = top.getJSONObject(i);
TranSappUser tranSappUser = new TranSappUser(userData);
topRanking.add(tranSappUser);
}
JSONArray near = jRanking.getJSONArray("near");
for (int i = 0; i < near.length(); i++) {
JSONObject userData = near.getJSONObject(i);
TranSappUser tranSappUser = new TranSappUser(userData);
tranSappUserRanking.add(tranSappUser);
}
} catch (JSONException ignored) {
}
return ranking;
}
use of cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser in project androidApp by InspectorIncognito.
the class UserFragment method onStart.
@Override
public void onStart() {
super.onStart();
final TranSappAccount account = TranSappAccountManager.getCurrentAccount();
if (account == null) {
getActivity().finish();
return;
}
RankingRequest request = new RankingRequest(new Request.RequestListener<Pair<ArrayList<TranSappUser>, ArrayList<TranSappUser>>>() {
@Override
public void onRequestError() {
}
@Override
public void onRequestResult(@NonNull Pair<ArrayList<TranSappUser>, ArrayList<TranSappUser>> response) {
ArrayList<TranSappUser> ranking = response.second;
for (TranSappUser user : ranking) {
if (user.userId.equals(account.currentUser.userId) && !account.currentUser.userId.equals("")) {
if (account.currentUser.globalRankingPosition != user.globalRankingPosition) {
account.updateRankingData(user.globalRankingPosition);
if (UserFragment.this.getActivity() != null && !UserFragment.this.getActivity().isFinishing()) {
updateUI();
}
}
}
}
}
}, account);
ServerController.sendRequest(request, null);
}
use of cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser in project androidApp by InspectorIncognito.
the class RankingActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account_user_ranking);
ArrayList<TranSappUser> topRanking = this.getIntent().getExtras().getParcelableArrayList(TOP_RANKING_KEY);
ArrayList<TranSappUser> tranSappUserRanking = this.getIntent().getExtras().getParcelableArrayList(USER_RANKING_KEY);
rcyList = findViewById(R.id.rcyList);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
rcyList.setLayoutManager(layoutManager);
rcyList.addItemDecoration(new InsetDecoration(this));
adapter = new RankingTopUsersAdapter(this, topRanking);
rcyList.setAdapter(adapter);
if (!TranSappAccountManager.isLoggedIn()) {
finish();
return;
}
RankingAdapter rankingAdapter = new RankingAdapter(this, tranSappUserRanking, TranSappAccountManager.getCurrentAccount().currentUser);
listView = findViewById(R.id.list_view);
listView.setLayoutManager(new LinearLayoutManager(this));
listView.setAdapter(rankingAdapter);
listView.getLayoutManager().scrollToPosition(getFixedUserPosition(getCurrentUserPosition(tranSappUserRanking)));
setResult(RESULT_OK);
}
Aggregations