Search in sources :

Example 1 with UserResponse

use of io.plaidapp.data.api.designernews.model.UserResponse 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);
        }
    });
}
Also used : User(io.plaidapp.data.api.designernews.model.User) CircleTransform(io.plaidapp.util.glide.CircleTransform) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) UserResponse(io.plaidapp.data.api.designernews.model.UserResponse) UserResponse(io.plaidapp.data.api.designernews.model.UserResponse) Response(retrofit.client.Response) Toast(android.widget.Toast) DesignerNewsService(io.plaidapp.data.api.designernews.DesignerNewsService) ClientAuthInterceptor(io.plaidapp.data.api.ClientAuthInterceptor) ImageView(android.widget.ImageView) RetrofitError(retrofit.RetrofitError)

Aggregations

View (android.view.View)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1 ClientAuthInterceptor (io.plaidapp.data.api.ClientAuthInterceptor)1 DesignerNewsService (io.plaidapp.data.api.designernews.DesignerNewsService)1 User (io.plaidapp.data.api.designernews.model.User)1 UserResponse (io.plaidapp.data.api.designernews.model.UserResponse)1 CircleTransform (io.plaidapp.util.glide.CircleTransform)1 RetrofitError (retrofit.RetrofitError)1 Response (retrofit.client.Response)1