package com.music.ting.utils;

import android.widget.Toast;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.music.ting.Ting;
import com.music.ting.data.GsonRequest;
import com.music.ting.model.Comments;
import com.music.ting.model.Songs;
import com.music.ting.model.UserInfo;

import java.util.List;

/**
 * Created by Jun on 2015/5/12.
 */
public class TingAPI {

    private final static String TingApi = "http://tinger.herokuapp.com/api";
    /**
     * 获取用户信息
     */
    private final static String TingUserApi = TingApi + "/users";

    private final static String TingUserName = TingUserApi + "?username=";

    private final static String TingUserId = TingUserApi + "?id=";
    /**
     * 获取歌曲信息
     */
    private final static String TingSongsApi = TingApi + "/songs";

    private final static String TingSongCount = TingSongsApi + "?songs_count=";
    /**
     * 根据歌曲Id获取评论
     */
    private final static String TingCommentApi = TingApi + "/comments?song_id=";
    /**
     * 根据歌曲s_id获取该歌曲的播放地址
     * 例：http://inmusic.sinaapp.com/xiami_api/ + s_id(歌曲虾米ID)
     */
    private final static String TingSongsAddressApi = " http://inmusic.sinaapp.com/xiami_api/";
    /**
     * 歌曲播放Id
     */
    private final static int sId = 0;


    /**
     * 根据用户名获取用户信息
     * @param userName 用户名
     * @return
     */
    public static GsonRequest<UserInfo> getUserInfoRequest(String userName){
        final String userUrl = TingUserName + userName;
        return new GsonRequest<UserInfo>(userUrl, UserInfo.class,
                null, buildDefaultErrorListener());
    }

    /**
     * 根据用户Id获取用户信息
     * @param userId 用户Id
     * @return
     */
    public static GsonRequest<UserInfo> getUserInfoRequestById(int userId){
        final String userUrl = TingUserId + userId;
        return new GsonRequest<UserInfo>(userUrl, UserInfo.class,
                null, buildDefaultErrorListener());
    }
     /**
     * 获取歌曲列表集合
     * @param songCount 集合长度
     * @return
     */
    public static GsonRequest<List<Songs>> getSongsRequest(int songCount){
        final String songsUrl;
        if(songCount == 0){//获取所有歌曲
            songsUrl = TingSongsApi;
        }else{
            songsUrl = TingSongCount + songCount;
        }
        return new GsonRequest<List<Songs>>(songsUrl, buildDefaultErrorListener());
    }

    /**
     * 获取歌曲被评论列表集合
     * @param songId
     * @return
     */
    public static GsonRequest<List<Comments>> getCommentsRequest(int songId){
        final String commentUrl = TingCommentApi + songId;
        return new GsonRequest<List<Comments>>(commentUrl,
                Comments.class,buildDefaultErrorListener());
    }

    /**
     * 响应失败
     * @return
     */
    private static Response.ErrorListener buildDefaultErrorListener() {
        return new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(Ting.getInstance(),"网络出现问题",Toast.LENGTH_LONG).show();
               // Log.e("Ting",error.getMessage());
            }
        };
    }
}

@@ -240,24 +240,66 @@
 .Comments;%0D%0A
+import com.music.ting.model.OnLineSongs;%0D%0A
 import com.m
@@ -1296,78 +1296,8 @@
 %22;%0D%0A
-    /**%0D%0A     * %E6%AD%8C%E6%9B%B2%E6%92%AD%E6%94%BEId%0D%0A     */%0D%0A    private final static int sId = 0;
 %0D%0A%0D%0A
@@ -2758,32 +2758,398 @@
 r());%0D%0A    %7D%0D%0A%0D%0A
+    /**%0D%0A     * %E6%A0%B9%E6%8D%AE%E6%AD%8C%E6%9B%B2%E6%92%AD%E6%94%BEId%E8%8E%B7%E5%8F%96%E6%AD%8C%E6%9B%B2%E4%BF%A1%E6%81%AF%0D%0A     * @param s_Id%0D%0A     * @return%0D%0A     */%0D%0A    public static GsonRequest%3COnLineSongs%3E getOnLineSongsRequest(long s_Id)%7B%0D%0A        final String onLineSongsUrl = TingSongsAddressApi + s_Id;%0D%0A        return new GsonRequest%3COnLineSongs%3E(onLineSongsUrl, OnLineSongs.class,%0D%0A                null, buildDefaultErrorListener());%0D%0A    %7D%0D%0A%0D%0A%0D%0A
     /**%0D%0A     * 

Update TingAPI util class