/*
 * Copyright 2013 Uwe Trottmann
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package com.battlelancer.seriesguide.loaders;

import android.content.Context;
import android.os.Bundle;

import com.battlelancer.seriesguide.util.ServiceUtils;
import com.battlelancer.seriesguide.util.ShareUtils.ShareItems;
import com.battlelancer.seriesguide.util.Utils;
import com.jakewharton.apibuilder.ApiException;
import com.jakewharton.trakt.ServiceManager;
import com.jakewharton.trakt.TraktException;
import com.jakewharton.trakt.entities.Comment;
import com.uwetrottmann.androidutils.GenericSimpleLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * Loads up comments from trakt for a movie (tvdbId arg is 0), show (episode arg
 * is 0) or episode.
 */
public class TraktCommentsLoader extends GenericSimpleLoader<List<Comment>> {

    private static final String TAG = "TraktCommentsLoader";

    private Bundle mArgs;

    public TraktCommentsLoader(Context context, Bundle args) {
        super(context);
        mArgs = args;
    }

    @Override
    public List<Comment> loadInBackground() {
        int tvdbId = mArgs.getInt(ShareItems.TVDBID);
        int episode = mArgs.getInt(ShareItems.EPISODE);

        ServiceManager manager = ServiceUtils.getTraktServiceManager(getContext());
        List<Comment> comments = new ArrayList<Comment>();
        try {
            if (tvdbId == 0) {
                // movie comments
                int tmdbId = mArgs.getInt(ShareItems.TMDBID);
                comments = manager.movieService().comments(tmdbId).fire();
            } else if (episode == 0) {
                // show comments
                comments = manager.showService().comments(tvdbId).fire();
            } else {
                // episode comments
                int season = mArgs.getInt(ShareItems.SEASON);
                comments = manager.showService().episodeComments(tvdbId, season, episode)
                        .fire();
            }

        } catch (TraktException e) {
            Utils.trackExceptionAndLog(TAG, e);
            return null;
        } catch (ApiException e) {
            Utils.trackExceptionAndLog(TAG, e);
            return null;
        }

        return comments;
    }
}

@@ -647,67 +647,8 @@
 s;%0A%0A
-import android.content.Context;%0Aimport android.os.Bundle;%0A%0A
 impo
@@ -814,101 +814,8 @@
 ls;%0A
-import com.jakewharton.apibuilder.ApiException;%0Aimport com.jakewharton.trakt.ServiceManager;%0A
 impo
@@ -844,25 +844,16 @@
 kt.Trakt
-Exception
 ;%0Aimport
@@ -952,16 +952,75 @@
 oader;%0A%0A
+import android.content.Context;%0Aimport android.os.Bundle;%0A%0A
 import j
@@ -1063,16 +1063,48 @@
 .List;%0A%0A
+import retrofit.RetrofitError;%0A%0A
 /**%0A * L
@@ -1668,30 +1668,21 @@
         
-ServiceManager
+Trakt
  manager
@@ -1997,31 +1997,24 @@
 ents(tmdbId)
-.fire()
 ;%0A          
@@ -2140,23 +2140,16 @@
 (tvdbId)
-.fire()
 ;%0A      
@@ -2354,40 +2354,8 @@
 ode)
-%0A                        .fire()
 ;%0A  
@@ -2388,130 +2388,21 @@
 ch (
-TraktException e) %7B%0A            Utils.trackExceptionAndLog(TAG, e);%0A            return null;%0A        %7D catch (ApiException
+RetrofitError
  e) 

Update TraktCommentsLoader.