Search in sources :

Example 1 with TranSappAccount

use of cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount 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);
        }
    });
}
Also used : TranSappAccount(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount) ArrayList(java.util.ArrayList) TranSappUser(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser) Intent(android.content.Intent) BusAvatar(cl.smartcities.isci.transportinspector.backend.BusAvatar) ImageView(android.widget.ImageView) View(android.view.View) ActiveBusView(cl.smartcities.isci.transportinspector.drawables.ActiveBusView) TextView(android.widget.TextView) NonNull(android.support.annotation.NonNull) RankingRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.RankingRequest) Pair(android.support.v4.util.Pair) UiThread(android.support.annotation.UiThread)

Example 2 with TranSappAccount

use of cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount 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);
}
Also used : TranSappAccount(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount) JSONObject(org.json.JSONObject) TranSappUser(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser)

Example 3 with TranSappAccount

use of cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount in project androidApp by InspectorIncognito.

the class NicknameFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_account_nickname_fragment, container, false);
    AvatarView userPicture = view.findViewById(R.id.user_image);
    final SocialMediaAccount account = SocialMediaAccount.getCurrentAccount();
    if (account == null) {
        getActivity().finish();
        return view;
    }
    account.loadImage(userPicture);
    View submitButton = view.findViewById(R.id.submit_button);
    final EditText nicknameEditText = view.findViewById(R.id.nickname_edit_text);
    submitButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final String nickname = nicknameEditText.getText().toString();
            if (nickname.length() == 0) {
                Toast.makeText(getContext(), "Debes ingresar un nickname", Toast.LENGTH_SHORT).show();
            } else if (nickname.length() > 30) {
                Toast.makeText(getContext(), "Ingresa un nick con menos de 30 caracteres", Toast.LENGTH_SHORT).show();
            } else {
                final ProgressDialog dialog = new ProgressDialog(getActivity());
                dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                dialog.setMessage("Iniciando Sesión");
                dialog.setCanceledOnTouchOutside(false);
                dialog.show();
                TranSappAccountManager.loginWithTransapp(new AccountLogInListener() {

                    @Override
                    public void onAccountReady(TranSappAccount account) {
                        loginCallback.onTranSappLogin();
                        dialog.dismiss();
                    }

                    @Override
                    public void onError(ServerStatusCode error) {
                        dialog.dismiss();
                        if (error.getErrorCode() == ServerStatusCode.SERVER_ERROR || error.getErrorCode() == ServerStatusCode.INTERNAL_SERVER_ERROR || error.getErrorCode() == ServerStatusCode.PARSE_ERROR || error.getErrorCode() == ServerStatusCode.INVALID_SESSION_TOKEN) {
                            Toast.makeText(TranSappApplication.getAppContext(), "No se pudo iniciar sesión con TranSapp", Toast.LENGTH_SHORT).show();
                        }
                    }
                }, nickname, account);
            }
        }
    });
    return view;
}
Also used : EditText(android.widget.EditText) SocialMediaAccount(cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount) TranSappAccount(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount) AvatarView(agency.tango.android.avatarview.views.AvatarView) ServerStatusCode(cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode) ProgressDialog(android.app.ProgressDialog) AvatarView(agency.tango.android.avatarview.views.AvatarView) View(android.view.View) AccountLogInListener(cl.smartcities.isci.transportinspector.gamification.ui.listener.AccountLogInListener)

Example 4 with TranSappAccount

use of cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount 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)

Aggregations

TranSappAccount (cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount)4 TranSappUser (cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser)3 Pair (android.support.v4.util.Pair)2 View (android.view.View)2 RankingRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.RankingRequest)2 ArrayList (java.util.ArrayList)2 AvatarView (agency.tango.android.avatarview.views.AvatarView)1 ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1 UiThread (android.support.annotation.UiThread)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BusAvatar (cl.smartcities.isci.transportinspector.backend.BusAvatar)1 ActiveBusView (cl.smartcities.isci.transportinspector.drawables.ActiveBusView)1 SocialMediaAccount (cl.smartcities.isci.transportinspector.gamification.socialAccount.SocialMediaAccount)1 AccountLogInListener (cl.smartcities.isci.transportinspector.gamification.ui.listener.AccountLogInListener)1 ServerStatusCode (cl.smartcities.isci.transportinspector.serverConnection.ServerStatusCode)1 Request (cl.smartcities.isci.transportinspector.serverConnection.requests.Request)1