Search in sources :

Example 1 with BusAvatar

use of cl.smartcities.isci.transportinspector.backend.BusAvatar 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 BusAvatar

use of cl.smartcities.isci.transportinspector.backend.BusAvatar in project androidApp by InspectorIncognito.

the class BusAvatarRowAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    final BusAvatar avatar = items.get(position);
    holder.position = holder.getAdapterPosition();
    holder.busView.setAvatarId(avatar.getServerId());
    holder.level.setText(String.format(Locale.getDefault(), "Nv.%d", avatar.getMinLevelRequired()));
    holder.title.setText(holder.itemView.getContext().getString(avatar.titleId));
    holder.description.setText(holder.itemView.getContext().getString(avatar.descriptionId));
    holder.row.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (selectedHolder == holder) {
                return;
            }
            if (currentLevel < avatar.getMinLevelRequired()) {
                Toast.makeText(holder.row.getContext(), String.format(Locale.getDefault(), "Debes tener al menos nivel %d", avatar.getMinLevelRequired()), Toast.LENGTH_SHORT).show();
                return;
            }
            unSelectHolder(selectedHolder);
            selectedHolder = holder;
            selectHolder(selectedHolder);
            listener.onNewAvatarSelected(avatar.getServerId());
        }
    });
    if (selectedHolder != null && holder.equals(selectedHolder) && avatar.getServerId() != selectedAvatarId) {
        selectedHolder = null;
    }
    if (avatar.getServerId() == selectedAvatarId) {
        selectedHolder = holder;
        selectHolder(holder);
    } else if (currentLevel < avatar.getMinLevelRequired()) {
        lockHolder(holder);
    } else {
        unSelectHolder(holder);
    }
}
Also used : BusAvatar(cl.smartcities.isci.transportinspector.backend.BusAvatar) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) ActiveBusView(cl.smartcities.isci.transportinspector.drawables.ActiveBusView) TextView(android.widget.TextView) View(android.view.View)

Example 3 with BusAvatar

use of cl.smartcities.isci.transportinspector.backend.BusAvatar in project androidApp by InspectorIncognito.

the class ActiveBusView method setLayout.

private void setLayout() {
    BusAvatar avatar = Avatar.getBusAvatarById(avatarId);
    colorImage.setImageResource(avatar.getColor());
    bodyImage.setImageResource(avatar.getBase());
    colorImage.setColorFilter(color);
    if (service == null || service.length() == 0) {
        text.setVisibility(GONE);
    } else {
        text.setVisibility(VISIBLE);
        text.setText(service);
    }
    fixedDefaultFrogBus(colorImage, bodyImage);
    if (flipped) {
        colorImage.setScaleX(-1);
        bodyImage.setScaleX(-1);
    }
    setTextMargins();
}
Also used : BusAvatar(cl.smartcities.isci.transportinspector.backend.BusAvatar)

Aggregations

BusAvatar (cl.smartcities.isci.transportinspector.backend.BusAvatar)3 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 ActiveBusView (cl.smartcities.isci.transportinspector.drawables.ActiveBusView)2 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1 UiThread (android.support.annotation.UiThread)1 Pair (android.support.v4.util.Pair)1 RecyclerView (android.support.v7.widget.RecyclerView)1 TranSappAccount (cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount)1 TranSappUser (cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser)1 RankingRequest (cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.RankingRequest)1 ArrayList (java.util.ArrayList)1