Search in sources :

Example 6 with TranSappUser

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;
}
Also used : JSONObject(org.json.JSONObject) TranSappUser(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) NonNull(android.support.annotation.NonNull)

Example 7 with TranSappUser

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);
}
Also used : TranSappAccount(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount) Request(cl.smartcities.isci.transportinspector.serverConnection.requests.Request) RankingRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.RankingRequest) TranSappUser(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser) ArrayList(java.util.ArrayList) RankingRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.RankingRequest) Pair(android.support.v4.util.Pair)

Example 8 with TranSappUser

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);
}
Also used : RankingTopUsersAdapter(cl.smartcities.isci.transportinspector.adapters.RankingTopUsersAdapter) TranSappUser(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser) RankingAdapter(cl.smartcities.isci.transportinspector.adapters.RankingAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

TranSappUser (cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser)8 TranSappAccount (cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount)3 ArrayList (java.util.ArrayList)3 NonNull (android.support.annotation.NonNull)2 Pair (android.support.v4.util.Pair)2 RankingRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.RankingRequest)2 JSONObject (org.json.JSONObject)2 Intent (android.content.Intent)1 UiThread (android.support.annotation.UiThread)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 RankingAdapter (cl.smartcities.isci.transportinspector.adapters.RankingAdapter)1 RankingTopUsersAdapter (cl.smartcities.isci.transportinspector.adapters.RankingTopUsersAdapter)1 BusAvatar (cl.smartcities.isci.transportinspector.backend.BusAvatar)1 ActiveBusView (cl.smartcities.isci.transportinspector.drawables.ActiveBusView)1 Request (cl.smartcities.isci.transportinspector.serverConnection.requests.Request)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1