Search in sources :

Example 1 with StoriesResponse

use of io.plaidapp.data.api.designernews.model.StoriesResponse 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)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 ActionMenuView (android.widget.ActionMenuView)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 Source (io.plaidapp.data.Source)1 ClientAuthInterceptor (io.plaidapp.data.api.ClientAuthInterceptor)1 DesignerNewsService (io.plaidapp.data.api.designernews.DesignerNewsService)1 NewStoryRequest (io.plaidapp.data.api.designernews.model.NewStoryRequest)1 StoriesResponse (io.plaidapp.data.api.designernews.model.StoriesResponse)1 FilterTouchHelperCallback (io.plaidapp.ui.recyclerview.FilterTouchHelperCallback)1 Callback (retrofit.Callback)1 RestAdapter (retrofit.RestAdapter)1 RetrofitError (retrofit.RetrofitError)1 Response (retrofit.client.Response)1