package com.qvdev.apps.readerkid;


import android.view.View;
import android.widget.ImageButton;

import com.qvdev.apps.readerkid.utils.ItemWrapper;
import com.sdk.blendle.models.generated.pinned.Pinned;
import com.sdk.response.EmptyResponse;

import retrofit.Callback;
import retrofit.Response;
import retrofit.Retrofit;


public class PinnedArticlesFragment extends BaseArticlesFragment implements View.OnClickListener {

    public static PinnedArticlesFragment newInstance() {
        PinnedArticlesFragment fragment = new PinnedArticlesFragment();
        return fragment;
    }

    public PinnedArticlesFragment() {
        // Required empty public constructor
    }

    @Override
    protected void loadArticles() {
        mBlendleApi.getPinned(this, mBlendleApi.getUserId());
    }

    @Override
    protected void processResponse(Response<?> response) {
        Pinned pinnedResponse = (Pinned) response.body();
        mNextItems = null;
        transformToItemWrapper(pinnedResponse);
    }

    @Override
    protected void loadMoreArticles() {
        if (mNextItems != null) {
            mBlendleApi.loadNextArticles(this, mNextItems);
        }
    }

    @Override
    public void onClick(View view) {
        ItemWrapper item = getItemWrapper(view.getRootView().findViewById(R.id.card_view));
        mBlendleApi.pinItem(mEmptyResponseCallback, mBlendleApi.getUserId(), item.getId(), false);
        ImageButton pinButton = (ImageButton) view;
        pinButton.setImageResource(R.drawable.ic_bookmark_border_black_24dp);
        int removalIndex = mArticles.indexOf(item);
        mArticles.remove(removalIndex);
        mAdapter.notifyItemRemoved(removalIndex);
    }

    private Callback<EmptyResponse> mEmptyResponseCallback = new Callback<EmptyResponse>() {
        @Override
        public void onResponse(Response<EmptyResponse> response, Retrofit retrofit) {
        }

        @Override
        public void onFailure(Throwable t) {

        }
    };
}

@@ -1212,24 +1212,104 @@
 iew view) %7B%0A
+        switch (view.getId()) %7B%0A            case R.id.pinArticleButton:%0A        
         Item
@@ -1388,32 +1388,40 @@
 view));%0A        
+   
+     
 mBlendleApi.pinI
@@ -1491,24 +1491,32 @@
 (), false);%0A
+        
         Imag
@@ -1563,16 +1563,24 @@
         
+ 
+       
 pinButto
@@ -1649,16 +1649,24 @@
         
+      
+  
 int remo
@@ -1701,16 +1701,24 @@
 (item);%0A
+        
         
@@ -1757,16 +1757,24 @@
         
+    
+    
 mAdapter
@@ -1803,24 +1803,115 @@
 ovalIndex);%0A
+                break;%0A            default:%0A                super.onClick(view);%0A        %7D%0A
     %7D%0A%0A    p

Fix pinned articles detail crash