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);
}
}
}
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();
}
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();
}
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");
}
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();
}
Aggregations