use of io.plaidapp.data.api.designernews.DesignerNewsService in project sbt-android by scala-android.
the class HomeActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
case RC_SEARCH:
// reset the search icon which we hid
View searchMenuView = toolbar.findViewById(R.id.menu_search);
if (searchMenuView != null) {
searchMenuView.setAlpha(1f);
}
if (resultCode == SearchActivity.RESULT_CODE_SAVE) {
String query = data.getStringExtra(SearchActivity.EXTRA_QUERY);
if (TextUtils.isEmpty(query))
return;
Source dribbbleSearch = null;
Source designerNewsSearch = null;
boolean newSource = false;
if (data.getBooleanExtra(SearchActivity.EXTRA_SAVE_DRIBBBLE, false)) {
dribbbleSearch = new Source.DribbbleSearchSource(query, true);
newSource |= filtersAdapter.addFilter(dribbbleSearch);
}
if (data.getBooleanExtra(SearchActivity.EXTRA_SAVE_DESIGNER_NEWS, false)) {
designerNewsSearch = new Source.DesignerNewsSearchSource(query, true);
newSource |= filtersAdapter.addFilter(designerNewsSearch);
}
if (newSource && (dribbbleSearch != null || designerNewsSearch != null)) {
highlightNewSources(dribbbleSearch, designerNewsSearch);
}
}
break;
case RC_NEW_DESIGNER_NEWS_STORY:
if (resultCode == PostNewDesignerNewsStory.RESULT_DRAG_DISMISSED) {
// need to reshow the FAB as there's no shared element transition
showFab();
} else if (resultCode == PostNewDesignerNewsStory.RESULT_POST) {
String title = data.getStringExtra(PostNewDesignerNewsStory.EXTRA_STORY_TITLE);
String url = data.getStringExtra(PostNewDesignerNewsStory.EXTRA_STORY_URL);
String comment = data.getStringExtra(PostNewDesignerNewsStory.EXTRA_STORY_COMMENT);
if (!TextUtils.isEmpty(title)) {
NewStoryRequest storyToPost = null;
if (!TextUtils.isEmpty(url)) {
storyToPost = NewStoryRequest.createWithUrl(title, url);
} else if (!TextUtils.isEmpty(comment)) {
storyToPost = NewStoryRequest.createWithComment(title, comment);
}
if (storyToPost != null) {
// TODO: move this to a service in follow up CL?
DesignerNewsService designerNewsApi = new RestAdapter.Builder().setEndpoint(DesignerNewsService.ENDPOINT).setRequestInterceptor(new ClientAuthInterceptor(designerNewsPrefs.getAccessToken(), BuildConfig.DESIGNER_NEWS_CLIENT_ID)).build().create(DesignerNewsService.class);
designerNewsApi.postStory(storyToPost, new Callback<StoriesResponse>() {
@Override
public void success(StoriesResponse story, Response response) {
if (story != null && story.stories != null && story.stories.size() > 0) {
long id = story.stories.get(0).id;
}
}
@Override
public void failure(RetrofitError error) {
Log.e("HomeActivity", "Failed posting story", error);
}
});
}
}
}
break;
case RC_NEW_DESIGNER_NEWS_LOGIN:
if (resultCode == RESULT_OK) {
showFab();
}
break;
case RC_AUTH_DRIBBBLE_FOLLOWING:
if (resultCode == RESULT_OK) {
filtersAdapter.enableFilterByKey(SourceManager.SOURCE_DRIBBBLE_FOLLOWING, this);
}
break;
case RC_AUTH_DRIBBBLE_USER_LIKES:
if (resultCode == RESULT_OK) {
filtersAdapter.enableFilterByKey(SourceManager.SOURCE_DRIBBBLE_USER_LIKES, this);
}
break;
case RC_AUTH_DRIBBBLE_USER_SHOTS:
if (resultCode == RESULT_OK) {
filtersAdapter.enableFilterByKey(SourceManager.SOURCE_DRIBBBLE_USER_SHOTS, this);
}
break;
}
}
use of io.plaidapp.data.api.designernews.DesignerNewsService in project sbt-android by scala-android.
the class DesignerNewsLogin method getAccessToken.
private void getAccessToken() {
DesignerNewsService designerNewsService = new RestAdapter.Builder().setEndpoint(DesignerNewsService.ENDPOINT).setRequestInterceptor(new ClientAuthInterceptor(designerNewsPrefs.getAccessToken(), BuildConfig.DESIGNER_NEWS_CLIENT_ID)).build().create(DesignerNewsService.class);
designerNewsService.login(buildLoginParams(username.getText().toString(), password.getText().toString()), new Callback<AccessToken>() {
@Override
public void success(AccessToken accessToken, Response response) {
designerNewsPrefs.setAccessToken(accessToken.access_token);
showLoggedInUser();
setResult(Activity.RESULT_OK);
finish();
}
@Override
public void failure(RetrofitError error) {
Log.e(getClass().getCanonicalName(), error.getMessage(), error);
// TODO snackbar?
Toast.makeText(getApplicationContext(), "Log in failed", Toast.LENGTH_LONG).show();
showLogin();
password.requestFocus();
}
});
}
use of io.plaidapp.data.api.designernews.DesignerNewsService in project sbt-android by scala-android.
the class DesignerNewsLogin method showLoggedInUser.
private void showLoggedInUser() {
DesignerNewsService designerNewsService = new RestAdapter.Builder().setEndpoint(DesignerNewsService.ENDPOINT).setRequestInterceptor(new ClientAuthInterceptor(designerNewsPrefs.getAccessToken(), BuildConfig.DESIGNER_NEWS_CLIENT_ID)).build().create(DesignerNewsService.class);
designerNewsService.getAuthedUser(new Callback<UserResponse>() {
@Override
public void success(UserResponse userResponse, Response response) {
final User user = userResponse.user;
designerNewsPrefs.setLoggedInUser(user);
Toast confirmLogin = new Toast(getApplicationContext());
View v = LayoutInflater.from(DesignerNewsLogin.this).inflate(R.layout.toast_logged_in_confirmation, null, false);
((TextView) v.findViewById(R.id.name)).setText(user.display_name);
// need to use app context here as the activity will be destroyed shortly
Glide.with(getApplicationContext()).load(user.portrait_url).placeholder(R.drawable.avatar_placeholder).transform(new CircleTransform(getApplicationContext())).into((ImageView) v.findViewById(R.id.avatar));
v.findViewById(R.id.scrim).setBackground(ScrimUtil.makeCubicGradientScrimDrawable(ContextCompat.getColor(DesignerNewsLogin.this, R.color.scrim), 5, Gravity.BOTTOM));
confirmLogin.setView(v);
confirmLogin.setGravity(Gravity.BOTTOM | Gravity.FILL_HORIZONTAL, 0, 0);
confirmLogin.setDuration(Toast.LENGTH_LONG);
confirmLogin.show();
}
@Override
public void failure(RetrofitError error) {
Log.e(getClass().getCanonicalName(), error.getMessage(), error);
}
});
}
Aggregations