Search in sources :

Example 6 with Query

use of retrofit2.http.Query 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 7 with Query

use of retrofit2.http.Query in project retrofit by square.

the class RequestBuilderTest method getWithPathAndQueryAmpersandParam.

@Test
public void getWithPathAndQueryAmpersandParam() {
    class Example {

        //
        @GET("/foo/bar/{ping}/")
        Call<ResponseBody> method(@Path("ping") String ping, @Query("kit") String kit) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "pong&", "kat&");
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/pong&/?kit=kat%26");
    assertThat(request.body()).isNull();
}
Also used : Path(retrofit2.http.Path) Query(retrofit2.http.Query) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 8 with Query

use of retrofit2.http.Query in project retrofit by square.

the class RequestBuilderTest method getWithQueryParamMap.

@Test
public void getWithQueryParamMap() {
    class Example {

        //
        @GET("/foo/bar/")
        Call<ResponseBody> method(@QueryMap Map<String, Object> query) {
            return null;
        }
    }
    Map<String, Object> params = new LinkedHashMap<>();
    params.put("kit", "kat");
    params.put("ping", "pong");
    Request request = buildRequest(Example.class, params);
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?kit=kat&ping=pong");
    assertThat(request.body()).isNull();
}
Also used : QueryMap(retrofit2.http.QueryMap) Request(okhttp3.Request) PartMap(retrofit2.http.PartMap) HashMap(java.util.HashMap) HeaderMap(retrofit2.http.HeaderMap) FieldMap(retrofit2.http.FieldMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) QueryMap(retrofit2.http.QueryMap) ResponseBody(okhttp3.ResponseBody) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 9 with Query

use of retrofit2.http.Query in project retrofit by square.

the class RequestBuilderTest method multipleParameterAnnotationsOnlyOneRetrofitAllowed.

@Test
public void multipleParameterAnnotationsOnlyOneRetrofitAllowed() throws Exception {
    class Example {

        //
        @GET("/")
        Call<ResponseBody> method(@Query("maybe") @NonNull Object o) {
            return null;
        }
    }
    Request request = buildRequest(Example.class, "yep");
    assertThat(request.url().toString()).isEqualTo("http://example.com/?maybe=yep");
}
Also used : Query(retrofit2.http.Query) Request(okhttp3.Request) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Example 10 with Query

use of retrofit2.http.Query in project retrofit by square.

the class RequestBuilderTest method getWithQueryParamList.

@Test
public void getWithQueryParamList() {
    class Example {

        //
        @GET("/foo/bar/")
        Call<ResponseBody> method(@Query("key") List<Object> keys) {
            return null;
        }
    }
    List<Object> values = Arrays.<Object>asList(1, 2, null, "three", "1");
    Request request = buildRequest(Example.class, values);
    assertThat(request.method()).isEqualTo("GET");
    assertThat(request.headers().size()).isZero();
    assertThat(request.url().toString()).isEqualTo("http://example.com/foo/bar/?key=1&key=2&key=three&key=1");
    assertThat(request.body()).isNull();
}
Also used : Query(retrofit2.http.Query) Request(okhttp3.Request) List(java.util.List) ResponseBody(okhttp3.ResponseBody) Test(org.junit.Test)

Aggregations

ResponseBody (okhttp3.ResponseBody)18 Request (okhttp3.Request)16 Test (org.junit.Test)16 Query (retrofit2.http.Query)14 Path (retrofit2.http.Path)4 List (java.util.List)3 Retrofit (retrofit2.Retrofit)3 QueryTroubleshootingParameters (com.microsoft.azure.management.network.QueryTroubleshootingParameters)2 ServiceResponse (com.microsoft.rest.ServiceResponse)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Response (retrofit2.Response)2 FieldMap (retrofit2.http.FieldMap)2 HeaderMap (retrofit2.http.HeaderMap)2 PartMap (retrofit2.http.PartMap)2 QueryMap (retrofit2.http.QueryMap)2 ContentUris (android.content.ContentUris)1 Context (android.content.Context)1 Intent (android.content.Intent)1