Search in sources :

Example 61 with Callback

use of zipkin2.Callback in project apollo-android by apollographql.

the class ApolloServerInterceptor method interceptAsync.

@Override
public void interceptAsync(@Nonnull final InterceptorRequest request, @Nonnull final ApolloInterceptorChain chain, @Nonnull Executor dispatcher, @Nonnull final CallBack callBack) {
    if (disposed)
        return;
    dispatcher.execute(new Runnable() {

        @Override
        public void run() {
            callBack.onFetch(FetchSourceType.NETWORK);
            try {
                httpCall = httpCall(request.operation);
            } catch (IOException e) {
                logger.e(e, "Failed to prepare http call for operation %s", request.operation.name().name());
                callBack.onFailure(new ApolloNetworkException("Failed to prepare http call", e));
                return;
            }
            httpCall.enqueue(new Callback() {

                @Override
                public void onFailure(@Nonnull Call call, @Nonnull IOException e) {
                    if (disposed)
                        return;
                    logger.e(e, "Failed to execute http call for operation %s", request.operation.name().name());
                    callBack.onFailure(new ApolloNetworkException("Failed to execute http call", e));
                }

                @Override
                public void onResponse(@Nonnull Call call, @Nonnull Response response) throws IOException {
                    if (disposed)
                        return;
                    callBack.onResponse(new ApolloInterceptor.InterceptorResponse(response));
                    callBack.onCompleted();
                }
            });
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Nonnull(javax.annotation.Nonnull) ApolloInterceptor(com.apollographql.apollo.interceptor.ApolloInterceptor) IOException(java.io.IOException) ApolloNetworkException(com.apollographql.apollo.exception.ApolloNetworkException)

Example 62 with Callback

use of zipkin2.Callback in project caronae-android by caronae.

the class RideOfferAct method configureActivityWithRide.

private void configureActivityWithRide(final RideForJson rideWithUsers, boolean isFull) {
    final boolean requested = getIntent().getBooleanExtra("requested", false);
    if (rideWithUsers == null) {
        Util.toast(getString(R.string.act_activeride_rideNUll));
        finish();
    }
    AllRidesFrag.setPageThatWas(rideWithUsers.isGoing());
    final User driver = rideWithUsers.getDriver();
    final boolean isDriver = driver.getDbId() == App.getUser().getDbId();
    int color = Util.getColorbyZone(rideWithUsers.getZone());
    join_bt.setBackgroundColor(color);
    location_dt.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.getApplicationContext()).load(R.drawable.user_pic).into(user_pic);
    } else {
        Picasso.with(this.getApplicationContext()).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(getApplicationContext(), ProfileAct.class);
                intent.putExtra("user", new Gson().toJson(driver));
                intent.putExtra("from", "rideoffer");
                startActivity(intent);
            }
        }
    });
    location_dt.setText(location);
    name_dt.setText(driver.getName());
    profile_dt.setText(driver.getProfile());
    if (rideWithUsers.getRoute().equals("")) {
        way_dt.setText("- - -");
    } else {
        way_dt.setText(rideWithUsers.getRoute());
    }
    if (rideWithUsers.getPlace().equals("")) {
        place_dt.setText("- - -");
    } else {
        place_dt.setText(rideWithUsers.getPlace());
    }
    course_dt.setText(driver.getCourse());
    if (rideWithUsers.isGoing())
        time_dt.setText(getString(R.string.arrivingAt, Util.formatTime(rideWithUsers.getTime())));
    else
        time_dt.setText(getString(R.string.leavingAt, Util.formatTime(rideWithUsers.getTime())));
    time_dt.setTextColor(color);
    date_dt.setText(Util.formatBadDateWithoutYear(rideWithUsers.getDate()));
    date_dt.setTextColor(color);
    if (rideWithUsers.getDescription().equals("")) {
        description_dt.setText("- - -");
    } else {
        description_dt.setText(rideWithUsers.getDescription());
    }
    if (isDriver) {
        join_bt.setVisibility(View.GONE);
    } else {
        if (requested) {
            join_bt.setVisibility(View.GONE);
            requested_dt.setVisibility(View.VISIBLE);
        } else {
            if (isFull) {
                join_bt.setText("CARONA CHEIA");
                join_bt.setClickable(false);
            } else {
                join_bt.setClickable(true);
                final Context context = this;
                join_bt.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        List<ActiveRide> list = ActiveRide.find(ActiveRide.class, "date = ? and going = ?", rideWithUsers.getDate(), rideWithUsers.isGoing() ? "1" : "0");
                        if (list != null && !list.isEmpty()) {
                            Util.toast(getString(R.string.act_rideOffer_rideConflict));
                            return;
                        }
                        com.rey.material.app.Dialog.Builder builder = new SimpleDialog.Builder(R.style.SlideInDialog) {

                            @Override
                            protected void onBuildDone(com.rey.material.app.Dialog dialog) {
                                dialog.layoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                                dialog.getWindow().getAttributes().windowAnimations = R.style.SlideInRightDialog;
                            }

                            @Override
                            public void onPositiveActionClicked(com.rey.material.app.DialogFragment fragment) {
                                final ProgressDialog pd = ProgressDialog.show(context, "", getString(R.string.wait), true, true);
                                CaronaeAPI.service(context).requestJoin(String.valueOf(rideWithUsers.getDbId())).enqueue(new Callback<ResponseBody>() {

                                    @Override
                                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                                        if (response.isSuccessful()) {
                                            RideRequestSent rideRequest = new RideRequestSent(rideWithUsers.getDbId(), rideWithUsers.isGoing(), rideWithUsers.getDate());
                                            rideRequest.save();
                                            createChatAssets(rideWithUsers);
                                            join_bt.startAnimation(getAnimationForSendButton());
                                            requested_dt.startAnimation(getAnimationForResquestedText());
                                            App.getBus().post(rideRequest);
                                            pd.dismiss();
                                            Util.snack(coordinatorLayout, getResources().getString(R.string.requestSent));
                                        } else {
                                            Util.treatResponseFromServer(response);
                                            pd.dismiss();
                                            Util.snack(coordinatorLayout, getResources().getString(R.string.errorRequestSent));
                                            Log.e("requestJoin", response.message());
                                        }
                                    }

                                    @Override
                                    public void onFailure(Call<ResponseBody> call, Throwable t) {
                                        pd.dismiss();
                                        Util.snack(coordinatorLayout, getResources().getString(R.string.requestSent));
                                        Log.e("requestJoin", t.getMessage());
                                    }
                                });
                                super.onPositiveActionClicked(fragment);
                            }

                            @Override
                            public void onNegativeActionClicked(com.rey.material.app.DialogFragment fragment) {
                                super.onNegativeActionClicked(fragment);
                            }
                        };
                        ((SimpleDialog.Builder) builder).message(getString(R.string.act_rideOffer_requestWarn)).title(getString(R.string.attention)).positiveAction(getString(R.string.ok)).negativeAction(getString(R.string.cancel));
                        com.rey.material.app.DialogFragment fragment = com.rey.material.app.DialogFragment.newInstance(builder);
                        fragment.show(getSupportFragmentManager(), "a");
                    }
                });
            }
        }
    }
    configureShareButton();
}
Also used : User(br.ufrj.caronae.models.User) Gson(com.google.gson.Gson) ProgressDialog(android.app.ProgressDialog) SimpleDialog(com.rey.material.app.SimpleDialog) List(java.util.List) ActiveRide(br.ufrj.caronae.models.ActiveRide) Context(android.content.Context) Call(retrofit2.Call) Intent(android.content.Intent) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) Response(retrofit2.Response) Callback(retrofit2.Callback) RideRequestSent(br.ufrj.caronae.models.RideRequestSent) RoundedTransformation(br.ufrj.caronae.RoundedTransformation)

Example 63 with Callback

use of zipkin2.Callback in project caronae-android by caronae.

the class MyProfileFrag method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_my_profile, container, false);
    ButterKnife.bind(this, view);
    callbackManager = ((MainAct) getActivity()).getFbCallbackManager();
    carOwner_sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            carOwnerSw();
        }
    });
    carPlate_et.setFilters(new InputFilter[] { new InputFilter.AllCaps() });
    loginButton.setReadPermissions("user_friends");
    loginButton.setFragment(this);
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {

        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.i("face", "onSuccess = " + loginResult.toString());
            Profile profile = Profile.getCurrentProfile();
            if (profile != null) {
                final String faceId = profile.getId();
                CaronaeAPI.service(getContext()).saveFaceId(new IdForJson(faceId)).enqueue(new Callback<ResponseBody>() {

                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        if (response.isSuccessful()) {
                            Log.i("saveFaceId", "face id saved");
                            User user = App.getUser();
                            user.setFaceId(faceId);
                            SharedPref.saveUser(user);
                        } else {
                            Util.treatResponseFromServer(response);
                            Util.toast(R.string.frag_myprofile_errorSaveFaceId);
                            Log.e("saveFaceId", response.message());
                        }
                    }

                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {
                        Util.toast(R.string.frag_myprofile_errorSaveFaceId);
                        Log.e("saveFaceId", t.getMessage());
                    }
                });
            }
        }

        @Override
        public void onCancel() {
            Log.i("face", "onCancel");
        }

        @Override
        public void onError(FacebookException exception) {
            Util.toast(R.string.frag_myprofile_errorFaceLogin);
            Log.e("face", "onError = " + exception.toString());
        }
    });
    setFieldValidatorsListeners();
    User user = App.getUser();
    if (user != null) {
        fillUserFields(user);
        CaronaeAPI.service(getContext()).getRidesHistoryCount(user.getDbId() + "").enqueue(new Callback<HistoryRideCountForJson>() {

            @Override
            public void onResponse(Call<HistoryRideCountForJson> call, Response<HistoryRideCountForJson> response) {
                if (response.isSuccessful()) {
                    HistoryRideCountForJson historyRideCountForJson = response.body();
                    ridesOffered_tv.setText(String.valueOf(historyRideCountForJson.getOfferedCount()));
                    ridesTaken_tv.setText(String.valueOf(historyRideCountForJson.getTakenCount()));
                } else {
                    Util.treatResponseFromServer(response);
                    Util.toast(R.string.act_profile_errorCountRidesHistory);
                    Log.e("getRidesHistoryCount", response.message());
                }
            }

            @Override
            public void onFailure(Call<HistoryRideCountForJson> call, Throwable t) {
                Util.toast(R.string.act_profile_errorCountRidesHistory);
                Log.e("getRidesHistoryCount", t.getMessage());
            }
        });
    }
    setETFormat();
    return view;
}
Also used : Call(retrofit2.Call) InputFilter(android.text.InputFilter) User(br.ufrj.caronae.models.User) LoginResult(com.facebook.login.LoginResult) CaretString(com.redmadrobot.inputmask.model.CaretString) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) Profile(com.facebook.Profile) Response(retrofit2.Response) FacebookCallback(com.facebook.FacebookCallback) Callback(retrofit2.Callback) FacebookException(com.facebook.FacebookException) IdForJson(br.ufrj.caronae.models.modelsforjson.IdForJson) HistoryRideCountForJson(br.ufrj.caronae.models.modelsforjson.HistoryRideCountForJson) CompoundButton(android.widget.CompoundButton)

Example 64 with Callback

use of zipkin2.Callback in project caronae-android by caronae.

the class MyRidesListFrag method getActiveRides.

private void getActiveRides() {
    getActivity().runOnUiThread(new Runnable() {

        @Override
        public void run() {
            CaronaeAPI.service(getContext()).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();
                        if (rideWithUsersList == null || rideWithUsersList.isEmpty()) {
                            MyRidesFrag.hideProgressBar();
                            myRidesList.setAdapter(new MyActiveRidesAdapter(new ArrayList<RideForJson>(), (MainAct) getActivity()));
                            myRidesList.setHasFixedSize(true);
                            myRidesList.setLayoutManager(new LinearLayoutManager(getActivity()));
                            new LoadRides().execute();
                            return;
                        }
                        ActiveRide.deleteAll(ActiveRide.class);
                        // subscribe to ride id topic
                        for (RideForJson rideWithUsers : rideWithUsersList) {
                            int rideId = rideWithUsers.getId().intValue();
                            rideWithUsers.setDbId(rideId);
                            FirebaseTopicsHandler.subscribeFirebaseTopic(rideId + "");
                            new ActiveRide(rideWithUsers.getDbId(), rideWithUsers.isGoing(), rideWithUsers.getDate()).save();
                        }
                        Collections.sort(rideWithUsersList, new RideOfferComparatorByDateAndTime());
                        addAllActiveRidesToList(rideWithUsersList);
                        MyRidesFrag.hideProgressBar();
                    } else {
                        Util.treatResponseFromServer(response);
                        MyRidesFrag.hideProgressBar();
                        norides_tv.setVisibility(View.VISIBLE);
                        Util.toast(R.string.frag_myactiverides_errorGetActiveRides);
                        Log.e("getMyActiveRides", response.message());
                    }
                    new LoadRides().execute();
                }

                @Override
                public void onFailure(Call<List<RideForJson>> call, Throwable t) {
                    MyRidesFrag.hideProgressBar();
                    norides_tv.setVisibility(View.VISIBLE);
                    Util.toast(R.string.frag_myactiverides_errorGetActiveRides);
                    new LoadRides().execute();
                    Log.e("getMyActiveRides", t.getMessage());
                }
            });
        }
    });
}
Also used : Call(retrofit2.Call) RideForJson(br.ufrj.caronae.models.modelsforjson.RideForJson) MyActiveRidesAdapter(br.ufrj.caronae.adapters.MyActiveRidesAdapter) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Response(retrofit2.Response) Callback(retrofit2.Callback) RideOfferComparatorByDateAndTime(br.ufrj.caronae.comparators.RideOfferComparatorByDateAndTime) MainAct(br.ufrj.caronae.acts.MainAct) ActiveRide(br.ufrj.caronae.models.ActiveRide)

Example 65 with Callback

use of zipkin2.Callback in project okhttp by square.

the class PrintEvents method run.

public void run() throws Exception {
    Request washingtonPostRequest = new Request.Builder().url("https://www.washingtonpost.com/").build();
    client.newCall(washingtonPostRequest).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            try (ResponseBody body = response.body()) {
                // Consume and discard the response body.
                body.source().readByteString();
            }
        }
    });
    Request newYorkTimesRequest = new Request.Builder().url("https://www.nytimes.com/").build();
    client.newCall(newYorkTimesRequest).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            try (ResponseBody body = response.body()) {
                // Consume and discard the response body.
                body.source().readByteString();
            }
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Request(okhttp3.Request) IOException(java.io.IOException) ResponseBody(okhttp3.ResponseBody)

Aggregations

Callback (okhttp3.Callback)173 IOException (java.io.IOException)137 Call (okhttp3.Call)132 Response (okhttp3.Response)132 Request (okhttp3.Request)110 Callback (retrofit2.Callback)42 Call (retrofit2.Call)41 Test (org.junit.Test)39 Response (retrofit2.Response)39 RequestBody (okhttp3.RequestBody)37 OkHttpClient (okhttp3.OkHttpClient)34 File (java.io.File)27 Context (android.content.Context)24 JSONObject (org.json.JSONObject)20 FormBody (okhttp3.FormBody)19 ArrayList (java.util.ArrayList)18 View (android.view.View)16 Intent (android.content.Intent)14 TextView (android.widget.TextView)14 GsonBuilder (com.google.gson.GsonBuilder)14