Search in sources :

Example 36 with Callback

use of retrofit2.Callback in project MusicDNA by harjot-oberai.

the class HomeActivity method updateStreamingList.

private void updateStreamingList(String query) {
    if (!isLocalVisible) {
        mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if ((settings.isStreamOnlyOnWifiEnabled() && mWifi.isConnected()) || (!settings.isStreamOnlyOnWifiEnabled())) {
            new Thread(new CancelCall()).start();
            if (!query.equals("")) {
                streamRecyclerContainer.setVisibility(View.VISIBLE);
                startLoadingIndicator();
                Retrofit client = new Retrofit.Builder().baseUrl(Config.API_URL).addConverterFactory(GsonConverterFactory.create()).build();
                StreamService ss = client.create(StreamService.class);
                call = ss.getTracks(query, 75);
                call.enqueue(new Callback<List<Track>>() {

                    @Override
                    public void onResponse(Call<List<Track>> call, Response<List<Track>> response) {
                        if (response.isSuccessful()) {
                            streamingTrackList = response.body();
                            sAdapter = new StreamTracksHorizontalAdapter(streamingTrackList, ctx);
                            LinearLayoutManager mLayoutManager = new LinearLayoutManager(ctx, LinearLayoutManager.HORIZONTAL, false);
                            soundcloudRecyclerView.setLayoutManager(mLayoutManager);
                            soundcloudRecyclerView.setItemAnimator(new DefaultItemAnimator());
                            soundcloudRecyclerView.setAdapter(sAdapter);
                            if (streamingTrackList.size() == 0) {
                                streamRecyclerContainer.setVisibility(GONE);
                            } else {
                                streamRecyclerContainer.setVisibility(View.VISIBLE);
                            }
                            stopLoadingIndicator();
                            (soundcloudRecyclerView.getAdapter()).notifyDataSetChanged();
                            StreamMusicFragment sFrag = (StreamMusicFragment) fragMan.findFragmentByTag("stream");
                            if (sFrag != null) {
                                sFrag.dataChanged();
                            }
                        } else {
                            stopLoadingIndicator();
                        }
                        Log.d("RETRO", response.body() + "");
                    }

                    @Override
                    public void onFailure(Call<List<Track>> call, Throwable t) {
                        Log.d("RETRO1", t.getMessage());
                    }
                });
            } else {
                stopLoadingIndicator();
                streamRecyclerContainer.setVisibility(GONE);
            }
        } else {
            stopLoadingIndicator();
            streamRecyclerContainer.setVisibility(GONE);
        }
    }
}
Also used : StreamService(com.sdsmdg.harjot.MusicDNA.interfaces.StreamService) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) StreamTracksHorizontalAdapter(com.sdsmdg.harjot.MusicDNA.adapters.horizontalrecycleradapters.StreamTracksHorizontalAdapter) StreamMusicFragment(com.sdsmdg.harjot.MusicDNA.fragments.StreamFragment.StreamMusicFragment) Retrofit(retrofit2.Retrofit) ColorStateList(android.content.res.ColorStateList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 37 with Callback

use of retrofit2.Callback in project cw-omnibus by commonsguy.

the class QuestionsFragment method onViewCreated.

@Override
public void onViewCreated(final View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    OkHttpClient client = ((MainActivity) getActivity()).getOkHttpClient();
    Request request = new Request.Builder().url(SO_URL).build();
    client.newCall(request).enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
            Log.e(getClass().getSimpleName(), "Exception loading JSON", e);
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            if (response.isSuccessful()) {
                Reader in = response.body().charStream();
                BufferedReader reader = new BufferedReader(in);
                final SOQuestions questions = new Gson().fromJson(reader, SOQuestions.class);
                reader.close();
                view.post(new Runnable() {

                    @Override
                    public void run() {
                        setListAdapter(new ItemsAdapter(questions.items));
                    }
                });
            } else {
                Log.e(getClass().getSimpleName(), response.toString());
            }
        }
    });
}
Also used : Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) Gson(com.google.gson.Gson) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) BufferedReader(java.io.BufferedReader)

Example 38 with Callback

use of retrofit2.Callback in project plaid by nickbutcher.

the class DribbbleShot method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dribbble_shot);
    dribbblePrefs = DribbblePrefs.get(this);
    circleTransform = new CircleTransform(this);
    ButterKnife.bind(this);
    shotDescription = getLayoutInflater().inflate(R.layout.dribbble_shot_description, commentsList, false);
    shotSpacer = shotDescription.findViewById(R.id.shot_spacer);
    title = shotDescription.findViewById(R.id.shot_title);
    description = shotDescription.findViewById(R.id.shot_description);
    likeCount = (Button) shotDescription.findViewById(R.id.shot_like_count);
    viewCount = (Button) shotDescription.findViewById(R.id.shot_view_count);
    share = (Button) shotDescription.findViewById(R.id.shot_share_action);
    playerName = (TextView) shotDescription.findViewById(R.id.player_name);
    playerAvatar = (ImageView) shotDescription.findViewById(R.id.player_avatar);
    shotTimeAgo = (TextView) shotDescription.findViewById(R.id.shot_time_ago);
    setupCommenting();
    commentsList.addOnScrollListener(scrollListener);
    commentsList.setOnFlingListener(flingListener);
    back.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setResultAndFinish();
        }
    });
    fab.setOnClickListener(fabClick);
    chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(this) {

        @Override
        public void onDragDismissed() {
            setResultAndFinish();
        }
    };
    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_SHOT)) {
        shot = intent.getParcelableExtra(EXTRA_SHOT);
        bindShot(true);
    } else if (intent.getData() != null) {
        final HttpUrl url = HttpUrl.parse(intent.getDataString());
        if (url.pathSize() == 2 && url.pathSegments().get(0).equals("shots")) {
            try {
                final String shotPath = url.pathSegments().get(1);
                final long id = Long.parseLong(shotPath.substring(0, shotPath.indexOf("-")));
                final Call<Shot> shotCall = dribbblePrefs.getApi().getShot(id);
                shotCall.enqueue(new Callback<Shot>() {

                    @Override
                    public void onResponse(Call<Shot> call, Response<Shot> response) {
                        shot = response.body();
                        bindShot(false);
                    }

                    @Override
                    public void onFailure(Call<Shot> call, Throwable t) {
                        reportUrlError();
                    }
                });
            } catch (NumberFormatException | StringIndexOutOfBoundsException ex) {
                reportUrlError();
            }
        } else {
            reportUrlError();
        }
    }
}
Also used : Call(retrofit2.Call) CircleTransform(io.plaidapp.util.glide.CircleTransform) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) ForegroundImageView(io.plaidapp.ui.widget.ForegroundImageView) TextView(android.widget.TextView) FabOverlapTextView(io.plaidapp.ui.widget.FabOverlapTextView) ParallaxScrimageView(io.plaidapp.ui.widget.ParallaxScrimageView) RecyclerView(android.support.v7.widget.RecyclerView) HttpUrl(okhttp3.HttpUrl) Response(retrofit2.Response) ElasticDragDismissFrameLayout(io.plaidapp.ui.widget.ElasticDragDismissFrameLayout) Callback(retrofit2.Callback)

Example 39 with Callback

use of retrofit2.Callback in project Pokemap by omkarmoghe.

the class GoogleManager method authUser.

@Deprecated
@SuppressWarnings({ "deprecation", "unused" })
public void authUser(final LoginListener listener) {
    HttpUrl url = HttpUrl.parse(OAUTH_ENDPOINT).newBuilder().addQueryParameter("client_id", CLIENT_ID).addQueryParameter("scope", "openid email https://www.googleapis.com/auth/userinfo.email").addQueryParameter("response_type", "code").addQueryParameter("redirect_uri", "http://127.0.0.1:9004").build();
    Callback<GoogleService.AuthRequest> googleCallback = new Callback<GoogleService.AuthRequest>() {

        @Override
        public void onResponse(Call<GoogleService.AuthRequest> call, Response<GoogleService.AuthRequest> response) {
            GoogleService.AuthRequest body = response.body();
            if (body != null) {
                listener.authRequested(body);
            } else {
                Log.e(TAG, "Google login failed while authenticating. response.body() is null.");
                listener.authFailed("Google login failed while authenticating");
            }
        }

        @Override
        public void onFailure(Call<GoogleService.AuthRequest> call, Throwable t) {
            t.printStackTrace();
            Log.e(TAG, "Google authentication failed when calling  authUser(). googleCallback's onFailure() threw: " + t.getMessage());
            listener.authFailed("Failed on getting the information for the user auth");
        }
    };
    if (mGoogleService != null) {
        Call<GoogleService.AuthRequest> call = mGoogleService.requestAuth(url.toString());
        call.enqueue(googleCallback);
    }
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) Callback(retrofit2.Callback) HttpUrl(okhttp3.HttpUrl)

Example 40 with Callback

use of retrofit2.Callback in project Pokemap by omkarmoghe.

the class GoogleManager method requestToken.

public void requestToken(String deviceCode, final LoginListener listener) {
    HttpUrl url = HttpUrl.parse(OAUTH_TOKEN_ENDPOINT).newBuilder().build();
    RequestBody body = new FormBody.Builder().add("code", deviceCode).add("client_id", CLIENT_ID).add("client_secret", SECRET).add("redirect_uri", "http://127.0.0.1:8080").add("grant_type", "authorization_code").build();
    Callback<GoogleService.TokenResponse> googleCallback = new Callback<GoogleService.TokenResponse>() {

        @Override
        public void onResponse(Call<GoogleService.TokenResponse> call, Response<GoogleService.TokenResponse> response) {
            if (response.body() != null) {
                listener.authSuccessful(response.body().getIdToken(), response.body().getRefreshToken());
            } else {
                Log.e(TAG, "Google login failed while fetching token. response.body() is null.");
                listener.authFailed("Google login failed while authenticating. Token missing.");
            }
        }

        @Override
        public void onFailure(Call<GoogleService.TokenResponse> call, Throwable t) {
            t.printStackTrace();
            Log.e(TAG, "Google authentication failed while fetching request token using requestToken(). googleCallback's onFailure() threw: " + t.getMessage());
            listener.authFailed("Failed on requesting the id token");
        }
    };
    if (mGoogleService != null) {
        Call<GoogleService.TokenResponse> call = mGoogleService.requestToken(url.toString(), body);
        call.enqueue(googleCallback);
    }
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) Callback(retrofit2.Callback) HttpUrl(okhttp3.HttpUrl) RequestBody(okhttp3.RequestBody)

Aggregations

IOException (java.io.IOException)51 Response (okhttp3.Response)46 Call (okhttp3.Call)44 Callback (okhttp3.Callback)44 Request (okhttp3.Request)41 RequestBody (okhttp3.RequestBody)25 Call (retrofit2.Call)17 Callback (retrofit2.Callback)15 Test (org.junit.Test)14 Response (retrofit2.Response)14 CountDownLatch (java.util.concurrent.CountDownLatch)13 FormBody (okhttp3.FormBody)12 ToStringConverterFactory (retrofit2.helpers.ToStringConverterFactory)12 OkHttpClient (okhttp3.OkHttpClient)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 ResponseBody (okhttp3.ResponseBody)10 MockResponse (okhttp3.mockwebserver.MockResponse)10 Retrofit (retrofit2.Retrofit)9 TextView (android.widget.TextView)6 HttpUrl (okhttp3.HttpUrl)6