Search in sources :

Example 1 with ChatAssets

use of br.ufrj.caronae.models.ChatAssets in project caronae-android by caronae.

the class Util method createChatAssets.

public static void createChatAssets(Ride ride, Context context) {
    Ride rideWithUsers = ride;
    int color = 0, bgRes = 0;
    if (rideWithUsers.getZone().equals("Centro")) {
        color = ContextCompat.getColor(context, R.color.zone_centro);
        bgRes = R.drawable.bg_bt_raise_zone_centro;
    }
    if (rideWithUsers.getZone().equals("Zona Sul")) {
        color = ContextCompat.getColor(context, R.color.zone_sul);
        bgRes = R.drawable.bg_bt_raise_zone_sul;
    }
    if (rideWithUsers.getZone().equals("Zona Oeste")) {
        color = ContextCompat.getColor(context, R.color.zone_oeste);
        bgRes = R.drawable.bg_bt_raise_zone_oeste;
    }
    if (rideWithUsers.getZone().equals("Zona Norte")) {
        color = ContextCompat.getColor(context, R.color.zone_norte);
        bgRes = R.drawable.bg_bt_raise_zone_norte;
    }
    if (rideWithUsers.getZone().equals("Baixada")) {
        color = ContextCompat.getColor(context, R.color.zone_baixada);
        bgRes = R.drawable.bg_bt_raise_zone_baixada;
    }
    if (rideWithUsers.getZone().equals("Grande Niterói")) {
        color = ContextCompat.getColor(context, R.color.zone_niteroi);
        bgRes = R.drawable.bg_bt_raise_zone_niteroi;
    }
    if (rideWithUsers.getZone().equals("Outros")) {
        color = ContextCompat.getColor(context, R.color.zone_outros);
        bgRes = R.drawable.bg_bt_raise_zone_outros;
    }
    final String location;
    if (rideWithUsers.isGoing())
        location = rideWithUsers.getNeighborhood() + " ➜ " + rideWithUsers.getHub();
    else
        location = rideWithUsers.getHub() + " ➜ " + rideWithUsers.getNeighborhood();
    final int finalColor = color, finalBgRes = bgRes;
    List<ChatAssets> l = ChatAssets.find(ChatAssets.class, "ride_id = ?", rideWithUsers.getDbId() + "");
    if (l == null || l.isEmpty())
        new ChatAssets(rideWithUsers.getDbId() + "", location, finalColor, finalBgRes, Util.formatBadDateWithoutYear(rideWithUsers.getDate()), Util.formatTime(rideWithUsers.getTime())).save();
}
Also used : ChatAssets(br.ufrj.caronae.models.ChatAssets) Ride(br.ufrj.caronae.models.Ride) Paint(android.graphics.Paint)

Example 2 with ChatAssets

use of br.ufrj.caronae.models.ChatAssets in project caronae-android by caronae.

the class RideOfferAct method createChatAssets.

private void createChatAssets(RideForJson rideWithUsers) {
    Context context = this.getApplicationContext();
    int color = 0, bgRes = 0;
    if (rideWithUsers.getZone().equals("Centro")) {
        color = ContextCompat.getColor(context, R.color.zone_centro);
        bgRes = R.drawable.bg_bt_raise_zone_centro;
    }
    if (rideWithUsers.getZone().equals("Zona Sul")) {
        color = ContextCompat.getColor(context, R.color.zone_sul);
        bgRes = R.drawable.bg_bt_raise_zone_sul;
    }
    if (rideWithUsers.getZone().equals("Zona Oeste")) {
        color = ContextCompat.getColor(context, R.color.zone_oeste);
        bgRes = R.drawable.bg_bt_raise_zone_oeste;
    }
    if (rideWithUsers.getZone().equals("Zona Norte")) {
        color = ContextCompat.getColor(context, R.color.zone_norte);
        bgRes = R.drawable.bg_bt_raise_zone_norte;
    }
    if (rideWithUsers.getZone().equals("Baixada")) {
        color = ContextCompat.getColor(context, R.color.zone_baixada);
        bgRes = R.drawable.bg_bt_raise_zone_baixada;
    }
    if (rideWithUsers.getZone().equals("Grande Niterói")) {
        color = ContextCompat.getColor(context, R.color.zone_niteroi);
        bgRes = R.drawable.bg_bt_raise_zone_niteroi;
    }
    if (rideWithUsers.getZone().equals("Outros")) {
        color = ContextCompat.getColor(context, R.color.zone_outros);
        bgRes = R.drawable.bg_bt_raise_zone_outros;
    }
    final String location;
    if (rideWithUsers.isGoing())
        location = rideWithUsers.getNeighborhood() + " ➜ " + rideWithUsers.getHub();
    else
        location = rideWithUsers.getHub() + " ➜ " + rideWithUsers.getNeighborhood();
    final int finalColor = color, finalBgRes = bgRes;
    List<ChatAssets> l = ChatAssets.find(ChatAssets.class, "ride_id = ?", rideWithUsers.getDbId() + "");
    if (l == null || l.isEmpty())
        new ChatAssets(rideWithUsers.getDbId() + "", location, finalColor, finalBgRes, Util.formatBadDateWithoutYear(rideWithUsers.getDate()), Util.formatTime(rideWithUsers.getTime())).save();
}
Also used : Context(android.content.Context) ChatAssets(br.ufrj.caronae.models.ChatAssets)

Example 3 with ChatAssets

use of br.ufrj.caronae.models.ChatAssets in project caronae-android by caronae.

the class MyActiveRidesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder viewHolder, final int position) {
    final RideForJson rideOffer = ridesList.get(position);
    int color = ContextCompat.getColor(activity, R.color.zone_outros);
    int bgRes = R.drawable.bg_bt_raise_zone_outros;
    if (rideOffer.getZone().equals("Centro")) {
        color = ContextCompat.getColor(activity, R.color.zone_centro);
        bgRes = R.drawable.bg_bt_raise_zone_centro;
    }
    if (rideOffer.getZone().equals("Zona Sul")) {
        color = ContextCompat.getColor(activity, R.color.zone_sul);
        bgRes = R.drawable.bg_bt_raise_zone_sul;
    }
    if (rideOffer.getZone().equals("Zona Oeste")) {
        color = ContextCompat.getColor(activity, R.color.zone_oeste);
        bgRes = R.drawable.bg_bt_raise_zone_oeste;
    }
    if (rideOffer.getZone().equals("Zona Norte")) {
        color = ContextCompat.getColor(activity, R.color.zone_norte);
        bgRes = R.drawable.bg_bt_raise_zone_norte;
    }
    if (rideOffer.getZone().equals("Baixada")) {
        color = ContextCompat.getColor(activity, R.color.zone_baixada);
        bgRes = R.drawable.bg_bt_raise_zone_baixada;
    }
    if (rideOffer.getZone().equals("Grande Niterói")) {
        color = ContextCompat.getColor(activity, R.color.zone_niteroi);
        bgRes = R.drawable.bg_bt_raise_zone_niteroi;
    }
    viewHolder.location_tv.setTextColor(color);
    String profilePicUrl = rideOffer.getDriver().getProfilePicUrl();
    if (profilePicUrl != null && !profilePicUrl.isEmpty()) {
        Picasso.with(activity).load(profilePicUrl).placeholder(R.drawable.user_pic).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(viewHolder.photo_iv);
    }
    if (App.getUser().getDbId() != rideOffer.getDriver().getDbId())
        viewHolder.photo_iv.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(activity, ProfileAct.class);
                intent.putExtra("user", new Gson().toJson(rideOffer.getDriver()));
                intent.putExtra("from", "myactiveridesadapter");
                activity.startActivity(intent);
            }
        });
    String timeText;
    if (rideOffer.isGoing())
        timeText = activity.getResources().getString(R.string.arrivingAt, Util.formatTime(rideOffer.getTime()));
    else
        timeText = activity.getResources().getString(R.string.leavingAt, Util.formatTime(rideOffer.getTime()));
    viewHolder.time_tv.setText(timeText);
    viewHolder.date_tv.setText(Util.formatBadDateWithoutYear(rideOffer.getDate()));
    viewHolder.name_tv.setText(rideOffer.getDriver().getName());
    String location;
    if (rideOffer.isGoing())
        location = rideOffer.getNeighborhood() + " ➜ " + rideOffer.getHub();
    else
        location = rideOffer.getHub() + " ➜ " + rideOffer.getNeighborhood();
    viewHolder.location_tv.setText(location);
    viewHolder.cardView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            NewChatMsgIndicator.deleteAll(NewChatMsgIndicator.class, "db_id = ?", rideOffer.getDbId() + "");
            viewHolder.newMsgIndicator_iv.setVisibility(View.INVISIBLE);
            int colorChat = ContextCompat.getColor(activity, R.color.gray);
            viewHolder.newMsgIndicator_iv.setColorFilter(colorChat);
            Intent intent = new Intent(activity, ActiveRideAct.class);
            intent.putExtra("ride", rideOffer);
            activity.startActivity(intent);
        }
    });
    final int finalColor = color;
    final int finalBgRes = bgRes;
    final String finallocation = location;
    viewHolder.newMsgIndicator_iv.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            List<ChatAssets> l = ChatAssets.find(ChatAssets.class, "ride_id = ?", rideOffer.getDbId() + "");
            if (l == null || l.isEmpty())
                new ChatAssets(rideOffer.getDbId() + "", finallocation, finalColor, finalBgRes, Util.formatBadDateWithoutYear(rideOffer.getDate()), Util.formatTime(rideOffer.getTime())).save();
            Intent intent = new Intent(activity, ChatAct.class);
            intent.putExtra("rideId", rideOffer.getDbId() + "");
            activity.startActivity(intent);
        }
    });
    boolean found = false;
    for (NewChatMsgIndicator newChatMsgIndicator : newChatMsgIndicatorList) {
        if (newChatMsgIndicator.getDbId() == rideOffer.getDbId()) {
            viewHolder.newMsgIndicator_iv.setVisibility(View.VISIBLE);
            found = true;
            break;
        }
    }
    if (!found) {
        int colorChat = ContextCompat.getColor(activity, R.color.gray);
        viewHolder.newMsgIndicator_iv.setColorFilter(colorChat);
        viewHolder.newMsgIndicator_iv.setVisibility(View.INVISIBLE);
    }
}
Also used : ActiveRideAct(br.ufrj.caronae.acts.ActiveRideAct) RideForJson(br.ufrj.caronae.models.modelsforjson.RideForJson) ChatAssets(br.ufrj.caronae.models.ChatAssets) NewChatMsgIndicator(br.ufrj.caronae.models.NewChatMsgIndicator) Gson(com.google.gson.Gson) Intent(android.content.Intent) ImageView(android.widget.ImageView) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) CardView(android.support.v7.widget.CardView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) RoundedTransformation(br.ufrj.caronae.RoundedTransformation) List(java.util.List) ChatAct(br.ufrj.caronae.acts.ChatAct)

Example 4 with ChatAssets

use of br.ufrj.caronae.models.ChatAssets in project caronae-android by caronae.

the class ActiveRideAct method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_active_ride);
    ButterKnife.bind(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setDisplayHomeAsUpEnabled(true);
    }
    rideWithUsers = getIntent().getExtras().getParcelable("ride");
    if (rideWithUsers == null) {
        Util.toast(getString(R.string.act_activeride_rideNUll));
        finish();
        return;
    }
    final User driver = rideWithUsers.getDriver();
    final boolean isDriver = driver.getDbId() == App.getUser().getDbId();
    int color = 0, colorPressed = 0, bgRes = 0;
    if (rideWithUsers.getZone().equals("Centro")) {
        color = ContextCompat.getColor(this, R.color.zone_centro);
        colorPressed = ContextCompat.getColor(this, R.color.light_zone_centro_transparency);
        bgRes = R.drawable.bg_bt_raise_zone_centro;
    }
    if (rideWithUsers.getZone().equals("Zona Sul")) {
        color = ContextCompat.getColor(this, R.color.zone_sul);
        colorPressed = ContextCompat.getColor(this, R.color.light_zone_sul_transparency);
        bgRes = R.drawable.bg_bt_raise_zone_sul;
    }
    if (rideWithUsers.getZone().equals("Zona Oeste")) {
        color = ContextCompat.getColor(this, R.color.zone_oeste);
        colorPressed = ContextCompat.getColor(this, R.color.light_zone_oeste_transparency);
        bgRes = R.drawable.bg_bt_raise_zone_oeste;
    }
    if (rideWithUsers.getZone().equals("Zona Norte")) {
        color = ContextCompat.getColor(this, R.color.zone_norte);
        colorPressed = ContextCompat.getColor(this, R.color.light_zone_norte_transparency);
        bgRes = R.drawable.bg_bt_raise_zone_norte;
    }
    if (rideWithUsers.getZone().equals("Baixada")) {
        color = ContextCompat.getColor(this, R.color.zone_baixada);
        colorPressed = ContextCompat.getColor(this, R.color.light_zone_baixada_transparency);
        bgRes = R.drawable.bg_bt_raise_zone_baixada;
    }
    if (rideWithUsers.getZone().equals("Grande Niterói")) {
        color = ContextCompat.getColor(this, R.color.zone_niteroi);
        colorPressed = ContextCompat.getColor(this, R.color.light_zone_niteroi_transparency);
        bgRes = R.drawable.bg_bt_raise_zone_niteroi;
    }
    if (rideWithUsers.getZone().equals("Outros")) {
        color = ContextCompat.getColor(this, R.color.zone_outros);
        colorPressed = ContextCompat.getColor(this, R.color.light_gray);
        bgRes = R.drawable.bg_bt_raise_zone_outros;
    }
    lay1.setBackgroundColor(color);
    toolbar.setBackgroundColor(color);
    chat_bt.setColorNormal(color);
    chat_bt.setColorPressed(colorPressed);
    finish_bt.setTextColor(color);
    final String location;
    if (rideWithUsers.isGoing())
        location = rideWithUsers.getNeighborhood() + " ➜ " + rideWithUsers.getHub();
    else
        location = rideWithUsers.getHub() + " ➜ " + rideWithUsers.getNeighborhood();
    String profilePicUrl = driver.getProfilePicUrl();
    if (profilePicUrl == null || profilePicUrl.isEmpty()) {
        Picasso.with(this).load(R.drawable.user_pic).into(user_pic);
    } else {
        Picasso.with(this).load(profilePicUrl).placeholder(R.drawable.user_pic).error(R.drawable.user_pic).transform(new RoundedTransformation()).into(user_pic);
    }
    user_pic.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!isDriver) {
                // dont allow user to open own profile
                Intent intent = new Intent(ActiveRideAct.this, ProfileAct.class);
                intent.putExtra("user", new Gson().toJson(driver));
                intent.putExtra("from", "activeRides");
                startActivity(intent);
            }
        }
    });
    location_tv.setText(location);
    name_tv.setText(driver.getName());
    profile_tv.setText(driver.getProfile());
    if (rideWithUsers.getRoute().equals("")) {
        way_tv.setVisibility(View.GONE);
        way_text_tv.setVisibility(View.GONE);
    } else {
        way_tv.setText(rideWithUsers.getRoute());
    }
    if (rideWithUsers.getPlace().equals("")) {
        place_text_tv.setVisibility(View.GONE);
        place_tv.setVisibility(View.GONE);
    } else {
        place_tv.setText(rideWithUsers.getPlace());
    }
    phoneNumber_tv.setText(driver.getPhoneNumber());
    course_tv.setText(driver.getCourse());
    if (rideWithUsers.isGoing())
        time_tv.setText(getString(R.string.arrivingAt, Util.formatTime(rideWithUsers.getTime())));
    else
        time_tv.setText(getString(R.string.leavingAt, Util.formatTime(rideWithUsers.getTime())));
    time_tv.setTextColor(color);
    date_tv.setText(Util.formatBadDateWithoutYear(rideWithUsers.getDate()));
    date_tv.setTextColor(color);
    carModel_tv.setText(driver.getCarModel());
    carColor_tv.setText(driver.getCarColor());
    carPlate_tv.setText(driver.getCarPlate());
    if (rideWithUsers.getDescription().equals("")) {
        description_text_tv.setVisibility(View.GONE);
        description_tv.setVisibility(View.GONE);
    } else {
        description_tv.setText(rideWithUsers.getDescription());
    }
    ridersList.setAdapter(new RidersAdapter(rideWithUsers.getRiders(), this));
    ridersList.setHasFixedSize(true);
    ridersList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    final int finalColor = color, finalBgRes = bgRes;
    chat_bt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            List<ChatAssets> l = ChatAssets.find(ChatAssets.class, "ride_id = ?", rideWithUsers.getDbId() + "");
            if (l == null || l.isEmpty())
                new ChatAssets(rideWithUsers.getDbId() + "", location, finalColor, finalBgRes, Util.formatBadDateWithoutYear(rideWithUsers.getDate()), Util.formatTime(rideWithUsers.getTime())).save();
            Intent intent = new Intent(ActiveRideAct.this, ChatAct.class);
            intent.putExtra("rideId", rideWithUsers.getDbId() + "");
            startActivity(intent);
        }
    });
    rideId2 = rideWithUsers.getDbId() + "";
    final String rideId = rideId2;
    if (isDriver) {
        leave_bt.setText(R.string.act_activeride_quitBtn);
        seeProfile_iv.setVisibility(View.GONE);
    }
    leave_bt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {

                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    final ProgressDialog pd = ProgressDialog.show(ActiveRideAct.this, "", getString(R.string.wait), true, true);
                    CaronaeAPI.service(getApplicationContext()).leaveRide(rideId).enqueue(new Callback<ResponseBody>() {

                        @Override
                        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                            if (response.isSuccessful()) {
                                pd.dismiss();
                                if (isDriver)
                                    Util.toast(getString(R.string.act_activeride_cancelledRide));
                                else
                                    Util.toast(getString(R.string.act_activeride_quitRide));
                                FirebaseTopicsHandler.unsubscribeFirebaseTopic(rideId + "");
                                List<Ride> rides = Ride.find(Ride.class, "db_id = ?", rideId);
                                if (rides != null && !rides.isEmpty())
                                    rides.get(0).delete();
                                ActiveRide.deleteAll(ActiveRide.class, "db_id = ?", rideId);
                                SharedPref.saveRemoveRideFromList(rideId);
                                finish();
                            } else {
                                Util.treatResponseFromServer(response);
                                pd.dismiss();
                                Util.toast(R.string.errorRideDeleted);
                                Log.e("leaveRide", response.message());
                            }
                        }

                        @Override
                        public void onFailure(Call<ResponseBody> call, Throwable t) {
                            pd.dismiss();
                            Util.toast(R.string.errorRideDeleted);
                            Log.e("leaveRide", t.getMessage());
                        }
                    });
                    super.onPositiveActionClicked(fragment);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    super.onNegativeActionClicked(fragment);
                }
            };
            String title;
            if (isDriver) {
                title = getString(R.string.act_activeRide_sureWantToCancel);
                ((SimpleDialog.Builder) builder).message(getString(R.string.act_activeRide_cancelRideMsg)).title(title).positiveAction(getString(R.string.ok)).negativeAction(getString(R.string.cancel));
            } else {
                title = getString(R.string.act_activeRide_sureWantToQuit);
                builder.title(title).positiveAction(getString(R.string.ok)).negativeAction(getString(R.string.cancel));
            }
            DialogFragment fragment = DialogFragment.newInstance(builder);
            fragment.show(getSupportFragmentManager(), null);
        }
    });
    if (!isDriver) {
        finish_bt.setVisibility(View.GONE);
    }
    finish_bt.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Dialog.Builder builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {

                @Override
                public void onPositiveActionClicked(DialogFragment fragment) {
                    final ProgressDialog pd = ProgressDialog.show(ActiveRideAct.this, "", getString(R.string.wait), true, true);
                    CaronaeAPI.service(getApplicationContext()).finishRide(rideId).enqueue(new Callback<ResponseBody>() {

                        @Override
                        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                            if (response.isSuccessful()) {
                                pd.dismiss();
                                Util.toast(R.string.rideFinished);
                                FirebaseTopicsHandler.unsubscribeFirebaseTopic(rideId + "");
                                List<Ride> rides = Ride.find(Ride.class, "db_id = ?", rideId);
                                if (rides != null && !rides.isEmpty())
                                    rides.get(0).delete();
                                ActiveRide.deleteAll(ActiveRide.class, "db_id = ?", rideId);
                                SharedPref.saveRemoveRideFromList(rideId);
                                finish();
                            } else {
                                Util.treatResponseFromServer(response);
                                pd.dismiss();
                                if (response.code() == 403) {
                                    Util.toast(R.string.finishFutureRide);
                                } else {
                                    Util.toast(R.string.errorFinishRide);
                                    Log.e("finish_bt", response.message());
                                }
                            }
                        }

                        @Override
                        public void onFailure(Call<ResponseBody> call, Throwable t) {
                            pd.dismiss();
                            Util.toast(R.string.errorFinishRide);
                            Log.e("finish_bt", t.getMessage());
                        }
                    });
                    super.onPositiveActionClicked(fragment);
                }

                @Override
                public void onNegativeActionClicked(DialogFragment fragment) {
                    super.onNegativeActionClicked(fragment);
                }
            };
            builder.title(getString(R.string.act_activeride_sureWantToFinish)).positiveAction(getString(R.string.ok)).negativeAction(getString(R.string.cancel));
            DialogFragment fragment = DialogFragment.newInstance(builder);
            fragment.show(getSupportFragmentManager(), null);
        }
    });
    phoneNumber_tv.setOnClickListener((View v) -> {
        actionNumberTouch(0, driver);
    });
    phoneNumber_tv.setOnLongClickListener((View v) -> {
        actionNumberTouch(1, driver);
        return true;
    });
    App.getBus().register(this);
    notVisible = false;
    scheduledToClose = false;
    configureShareBt();
}
Also used : User(br.ufrj.caronae.models.User) ChatAssets(br.ufrj.caronae.models.ChatAssets) DialogFragment(com.rey.material.app.DialogFragment) Gson(com.google.gson.Gson) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ProgressDialog(android.app.ProgressDialog) SimpleDialog(com.rey.material.app.SimpleDialog) List(java.util.List) RidersAdapter(br.ufrj.caronae.adapters.RidersAdapter) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) Call(retrofit2.Call) Intent(android.content.Intent) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) Response(retrofit2.Response) Callback(retrofit2.Callback) RoundedTransformation(br.ufrj.caronae.RoundedTransformation) ActiveRide(br.ufrj.caronae.models.ActiveRide) Ride(br.ufrj.caronae.models.Ride)

Example 5 with ChatAssets

use of br.ufrj.caronae.models.ChatAssets in project caronae-android by caronae.

the class ChatAct method getRideFromServer.

private Ride getRideFromServer(final Activity activity) {
    final RideForJson[] ride = { null };
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            final ProgressDialog pd = ProgressDialog.show(activity, "", activity.getString(R.string.wait), true, true);
            CaronaeAPI.service(activity).getMyActiveRides().enqueue(new Callback<List<RideForJson>>() {

                @Override
                public void onResponse(Call<List<RideForJson>> call, Response<List<RideForJson>> response) {
                    if (response.isSuccessful()) {
                        List<RideForJson> rideWithUsersList = response.body();
                        Log.e("RIDE", "rides encontradas: " + rideWithUsersList.size());
                        if (rideWithUsersList == null || rideWithUsersList.isEmpty()) {
                            pd.dismiss();
                            return;
                        }
                        for (int rideIndex = 0; rideIndex < rideWithUsersList.size(); rideIndex++) {
                            if ((rideWithUsersList.get(rideIndex).getId() + "").equals(rideId)) {
                                ride[0] = rideWithUsersList.get(rideIndex);
                            }
                        }
                        if (ride[0] != null) {
                            String location;
                            if (ride[0].isGoing())
                                location = ride[0].getNeighborhood() + " -> " + ride[0].getHub();
                            else
                                location = ride[0].getHub() + " -> " + ride[0].getNeighborhood();
                            ChatAssets chatAssets = new ChatAssets(rideId, location, Util.getColorbyZone(ride[0].getZone()), Util.getBgResByZone(ride[0].getZone()), Util.formatBadDateWithoutYear(ride[0].getDate()), Util.formatTime(ride[0].getTime()));
                            chatAssets.save();
                            configureActivityWithChatAssets(chatAssets);
                        } else {
                            Intent intent = new Intent(getApplicationContext(), MainAct.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            finish();
                        }
                        pd.dismiss();
                    } else {
                        Util.treatResponseFromServer(response);
                        pd.dismiss();
                        Log.e("getMyActiveRides", response.message());
                    }
                }

                @Override
                public void onFailure(Call<List<RideForJson>> call, Throwable t) {
                    pd.dismiss();
                    Log.e("getMyActiveRides", t.getMessage());
                }
            });
        }
    });
    return ride[0];
}
Also used : Call(retrofit2.Call) RideForJson(br.ufrj.caronae.models.modelsforjson.RideForJson) ChatAssets(br.ufrj.caronae.models.ChatAssets) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) ChatMessageSendResponse(br.ufrj.caronae.models.ChatMessageSendResponse) Response(retrofit2.Response) Callback(retrofit2.Callback)

Aggregations

ChatAssets (br.ufrj.caronae.models.ChatAssets)7 Intent (android.content.Intent)4 Ride (br.ufrj.caronae.models.Ride)3 ProgressDialog (android.app.ProgressDialog)2 Context (android.content.Context)2 ActionBar (android.support.v7.app.ActionBar)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 RoundedTransformation (br.ufrj.caronae.RoundedTransformation)2 ChatAct (br.ufrj.caronae.acts.ChatAct)2 RideForJson (br.ufrj.caronae.models.modelsforjson.RideForJson)2 Gson (com.google.gson.Gson)2 List (java.util.List)2 Call (retrofit2.Call)2 Callback (retrofit2.Callback)2 Response (retrofit2.Response)2 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1