// Path: app/src/main/java/com/music/ting/data/GsonRequest.java
// public class  GsonRequest<T> extends Request<T> {
//     private static final String TAG = "Ting";
// 
//     private Gson GSON = new Gson();
// 
//     private final Class<T> mClazz;
//     private Type type ;
// 
//     private Listener mListener;
//     private Map<String, String> mHeader;
// 
//     public GsonRequest(int method, String url, Class<T> clazz, Map<String, String> header,
//                        Listener<T> listener, ErrorListener errorListener) {
//         super(method, url, errorListener);
//         mClazz = clazz;
//         mListener = listener;
//         mHeader = header;
//     }
// 
//     public GsonRequest(String url, ErrorListener errorListener){
//         this(Method.GET, url, null, null, errorListener);
//         type = new TypeToken<List<Songs>>(){
//         }.getType();
//     }
//     public GsonRequest(String url,Class clazz, ErrorListener errorListener){
//         this(Method.GET, url,clazz, null, null, errorListener);
//         type = new TypeToken<List<Comments>>(){
//         }.getType();
//     }
// 
// 
//    public GsonRequest(int method, String url, Class<T> clazz, Map<String, String> header,
//                        ErrorListener errorListener) {
//         this(method, url, clazz, header, null, errorListener);
//     }
// 
//     public GsonRequest(String url, Class clazz, Listener<T> listener, ErrorListener errorListener) {
//         this(Method.GET, url, clazz, null, listener, errorListener);
//     }
// 
//     @Override
//     protected Response parseNetworkResponse(NetworkResponse response) {
//         try {
//             String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
//             if (type != null) {
//                 return Response.success(GSON.fromJson(json, type),
//                         HttpHeaderParser.parseCacheHeaders(response));
//             } else {
//                 return Response.success(GSON.fromJson(json, mClazz),
//                         HttpHeaderParser.parseCacheHeaders(response));
//             }
//         } catch (UnsupportedEncodingException e) {
//             Log.e(TAG, e.getMessage(), e);
//             return Response.error(new ParseError(e));
//         } catch (JsonSyntaxException e) {
//             Log.e(TAG, e.getMessage(), e);
//             return Response.error(new ParseError(e));
//         }
//     }
// 
//     @Override
//     protected void deliverResponse(T response) {
//         if (mListener != null) {
//             mListener.onResponse(response);
//         }
//     }
// 
//     public void setSuccessListener(Listener listener) {
//         mListener = listener;
//     }
// 
// }
// 
// Path: app/src/main/java/com/music/ting/data/RequestManager.java
// public final class RequestManager {
// 
//     private static final RequestQueue mRequestQueue = Volley.newRequestQueue(Ting.getInstance());
// 
//     private RequestManager(){
// 
//     }
// 
//     public static void addRequest(Request<?> request, Object tag){
//         if(tag != null) {
//             request.setTag(tag);
//         }
//         mRequestQueue.add(request);
//     }
// 
//     public static void cancelAll(Object tag ){
//         mRequestQueue.cancelAll(tag);
//     }
// 
//     public static RequestQueue getRequestQueue(){
//         return mRequestQueue;
//     }
// }


import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.android.volley.Response;
import com.music.ting.R;
import com.music.ting.adapter.LikeSongsAdapter;
import com.music.ting.data.GsonRequest;
import com.music.ting.data.RequestManager;
import com.music.ting.model.user.UserLikeSongs;
import com.music.ting.utils.TingAPI;
import butterknife.ButterKnife;
import butterknife.InjectView;

            @Override
            public void run() {
                songsSwipe.setRefreshing(true);
            }
        });
        initData();
        songsSwipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                initData();
            }
        });

        return view;
    }


    public void initData(){

        final GsonRequest<UserLikeSongs> request = TingAPI.getUserLikeSongs(userId);

        final Response.Listener<UserLikeSongs> response = new Response.Listener<UserLikeSongs>() {
            @Override
            public void onResponse(UserLikeSongs songs) {
                Log.i("UserSongs",songs.toString()+",UserId:"+userId);
                recyclerView.setAdapter(new LikeSongsAdapter(view.getContext(), songs));
                songsSwipe.setRefreshing(false);
            }
        };
        request.setSuccessListener(response);

// Path: app/src/main/java/com/music/ting/data/GsonRequest.java
// public class  GsonRequest<T> extends Request<T> {
//     private static final String TAG = "Ting";
// 
//     private Gson GSON = new Gson();
// 
//     private final Class<T> mClazz;
//     private Type type ;
// 
//     private Listener mListener;
//     private Map<String, String> mHeader;
// 
//     public GsonRequest(int method, String url, Class<T> clazz, Map<String, String> header,
//                        Listener<T> listener, ErrorListener errorListener) {
//         super(method, url, errorListener);
//         mClazz = clazz;
//         mListener = listener;
//         mHeader = header;
//     }
// 
//     public GsonRequest(String url, ErrorListener errorListener){
//         this(Method.GET, url, null, null, errorListener);
//         type = new TypeToken<List<Songs>>(){
//         }.getType();
//     }
//     public GsonRequest(String url,Class clazz, ErrorListener errorListener){
//         this(Method.GET, url,clazz, null, null, errorListener);
//         type = new TypeToken<List<Comments>>(){
//         }.getType();
//     }
// 
// 
//    public GsonRequest(int method, String url, Class<T> clazz, Map<String, String> header,
//                        ErrorListener errorListener) {
//         this(method, url, clazz, header, null, errorListener);
//     }
// 
//     public GsonRequest(String url, Class clazz, Listener<T> listener, ErrorListener errorListener) {
//         this(Method.GET, url, clazz, null, listener, errorListener);
//     }
// 
//     @Override
//     protected Response parseNetworkResponse(NetworkResponse response) {
//         try {
//             String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
//             if (type != null) {
//                 return Response.success(GSON.fromJson(json, type),
//                         HttpHeaderParser.parseCacheHeaders(response));
//             } else {
//                 return Response.success(GSON.fromJson(json, mClazz),
//                         HttpHeaderParser.parseCacheHeaders(response));
//             }
//         } catch (UnsupportedEncodingException e) {
//             Log.e(TAG, e.getMessage(), e);
//             return Response.error(new ParseError(e));
//         } catch (JsonSyntaxException e) {
//             Log.e(TAG, e.getMessage(), e);
//             return Response.error(new ParseError(e));
//         }
//     }
// 
//     @Override
//     protected void deliverResponse(T response) {
//         if (mListener != null) {
//             mListener.onResponse(response);
//         }
//     }
// 
//     public void setSuccessListener(Listener listener) {
//         mListener = listener;
//     }
// 
// }
// 
// Path: app/src/main/java/com/music/ting/data/RequestManager.java
// public final class RequestManager {
// 
//     private static final RequestQueue mRequestQueue = Volley.newRequestQueue(Ting.getInstance());
// 
//     private RequestManager(){
// 
//     }
// 
//     public static void addRequest(Request<?> request, Object tag){
//         if(tag != null) {
//             request.setTag(tag);
//         }
//         mRequestQueue.add(request);
//     }
// 
//     public static void cancelAll(Object tag ){
//         mRequestQueue.cancelAll(tag);
//     }
// 
//     public static RequestQueue getRequestQueue(){
//         return mRequestQueue;
//     }
// }


// Path: app/src/main/java/com/music/ting/ui/fragment/LikeSongsListFragment.java
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.android.volley.Response;
import com.music.ting.R;
import com.music.ting.adapter.LikeSongsAdapter;
import com.music.ting.data.GsonRequest;
import com.music.ting.data.RequestManager;
import com.music.ting.model.user.UserLikeSongs;
import com.music.ting.utils.TingAPI;
import butterknife.ButterKnife;
import butterknife.InjectView;

            @Override
            public void run() {
                songsSwipe.setRefreshing(true);
            }
        });
        initData();
        songsSwipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                initData();
            }
        });

        return view;
    }


    public void initData(){

        final GsonRequest<UserLikeSongs> request = TingAPI.getUserLikeSongs(userId);

        final Response.Listener<UserLikeSongs> response = new Response.Listener<UserLikeSongs>() {
            @Override
            public void onResponse(UserLikeSongs songs) {
                Log.i("UserSongs",songs.toString()+",UserId:"+userId);
                recyclerView.setAdapter(new LikeSongsAdapter(view.getContext(), songs));
                songsSwipe.setRefreshing(false);
            }
        };
        request.setSuccessListener(response);

        RequestManager.addRequest(request, userId);
