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