Search in sources :

Example 1 with DesignerNewsService

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;
    }
}
Also used : ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ActionMenuView(android.widget.ActionMenuView) Source(io.plaidapp.data.Source) StoriesResponse(io.plaidapp.data.api.designernews.model.StoriesResponse) StoriesResponse(io.plaidapp.data.api.designernews.model.StoriesResponse) Response(retrofit.client.Response) Callback(retrofit.Callback) FilterTouchHelperCallback(io.plaidapp.ui.recyclerview.FilterTouchHelperCallback) DesignerNewsService(io.plaidapp.data.api.designernews.DesignerNewsService) ClientAuthInterceptor(io.plaidapp.data.api.ClientAuthInterceptor) NewStoryRequest(io.plaidapp.data.api.designernews.model.NewStoryRequest) RestAdapter(retrofit.RestAdapter) RetrofitError(retrofit.RetrofitError)

Example 2 with DesignerNewsService

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();
        }
    });
}
Also used : UserResponse(io.plaidapp.data.api.designernews.model.UserResponse) Response(retrofit.client.Response) AccessToken(io.plaidapp.data.api.designernews.model.AccessToken) DesignerNewsService(io.plaidapp.data.api.designernews.DesignerNewsService) ClientAuthInterceptor(io.plaidapp.data.api.ClientAuthInterceptor) RetrofitError(retrofit.RetrofitError)

Example 3 with DesignerNewsService

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

ClientAuthInterceptor (io.plaidapp.data.api.ClientAuthInterceptor)3 DesignerNewsService (io.plaidapp.data.api.designernews.DesignerNewsService)3 RetrofitError (retrofit.RetrofitError)3 Response (retrofit.client.Response)3 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 UserResponse (io.plaidapp.data.api.designernews.model.UserResponse)2 RecyclerView (android.support.v7.widget.RecyclerView)1 ActionMenuView (android.widget.ActionMenuView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 Toast (android.widget.Toast)1 Source (io.plaidapp.data.Source)1 AccessToken (io.plaidapp.data.api.designernews.model.AccessToken)1 NewStoryRequest (io.plaidapp.data.api.designernews.model.NewStoryRequest)1 StoriesResponse (io.plaidapp.data.api.designernews.model.StoriesResponse)1 User (io.plaidapp.data.api.designernews.model.User)1 FilterTouchHelperCallback (io.plaidapp.ui.recyclerview.FilterTouchHelperCallback)1 CircleTransform (io.plaidapp.util.glide.CircleTransform)1 Callback (retrofit.Callback)1