package net.somethingdreadful.MAL.tasks;

import android.app.Activity;
import android.os.AsyncTask;

import net.somethingdreadful.MAL.ContentManager;
import net.somethingdreadful.MAL.Theme;
import net.somethingdreadful.MAL.account.AccountService;
import net.somethingdreadful.MAL.api.APIHelper;
import net.somethingdreadful.MAL.api.BaseModels.Forum;

import java.util.ArrayList;

public class ForumNetworkTask extends AsyncTask<String, Void, ArrayList<Forum>> {
    private final ForumNetworkTaskListener callback;
    private final ForumJob type;
    private final int id;
    private final Activity activity;

    public ForumNetworkTask(ForumNetworkTaskListener callback, Activity activity, ForumJob type, int id) {
        this.callback = callback;
        this.type = type;
        this.id = id;
        this.activity = activity;
    }

    @Override
    protected ArrayList<Forum> doInBackground(String... params) {
        ArrayList<Forum> result = new ArrayList<>();
        ContentManager cManager = new ContentManager(activity);
        if (!AccountService.isMAL() && APIHelper.isNetworkAvailable(activity))
            cManager.verifyAuthentication();

        try {
            switch (type) {
                case MENU: // list with all categories
                    result = cManager.getForumCategories();
                    break;
                case CATEGORY: // list with all topics of a certain category
                    result = cManager.getCategoryTopics(id, Integer.parseInt(params[0]));
                    break;
                case SUBCATEGORY:
                    result = cManager.getSubCategory(id, Integer.parseInt(params[0]));
                    break;
                case TOPIC: // list with all comments of users
                    result = cManager.getTopic(id, Integer.parseInt(params[0]));
                    break;
                case SEARCH:
                    result = cManager.search(params[0]);
                    break;
                case ADDCOMMENT:
                    result = cManager.addComment(id, params[0]) ? new ArrayList<Forum>() : null;
                    if (result != null)
                        result = cManager.getTopic(id, Integer.parseInt(params[1]));
                    break;
                case UPDATECOMMENT:
                    result = cManager.updateComment(id, params[0]) ? new ArrayList<Forum>() : null;
                    break;
                /*
                case DISCUSSION:
                    if (params[1].equals(MALApi.ListType.ANIME.toString()))
                        result = cManager.getDiscussion(id, Integer.parseInt(params[0]), MALApi.ListType.ANIME);
                    else
                        result = cManager.getDiscussion(id, Integer.parseInt(params[0]), MALApi.ListType.MANGA);
                    break;
                case TOPICS:
                    result = cManager.getTopics(id, Integer.parseInt(params[0]));
                    break;
                case POSTS:
                    result = cManager.getPosts(id, Integer.parseInt(params[0]));
                    break;
                case ADDTOPIC:
                    result.setList(cManager.addTopic(id, params[0], params[1]) ? new ArrayList<Forum>() : null);
                    break;
                case ADDCOMMENT:
                    result.setList(cManager.addComment(id, params[0]) ? new ArrayList<Forum>() : null);
                    break;
                case UPDATECOMMENT:
                    result.setList(cManager.updateComment(id, params[0]) ? new ArrayList<Forum>() : null);
                    break;*/
            }
        } catch (Exception e) {
            Theme.logTaskCrash(this.getClass().getSimpleName(), "doInBackground(6): " + String.format("%s-task unknown API error on id %s", type.toString(), id), e);
        }
        return result;
    }

    @Override
    protected void onPostExecute(ArrayList<Forum> result) {
        if (callback != null)
            callback.onForumNetworkTaskFinished(result, type);
    }

    public interface ForumNetworkTaskListener {
        void onForumNetworkTaskFinished(ArrayList<Forum> result, ForumJob task);
    }
}

@@ -2416,1195 +2416,8 @@
 ak;%0A
-                /*%0A                case DISCUSSION:%0A                    if (params%5B1%5D.equals(MALApi.ListType.ANIME.toString()))%0A                        result = cManager.getDiscussion(id, Integer.parseInt(params%5B0%5D), MALApi.ListType.ANIME);%0A                    else%0A                        result = cManager.getDiscussion(id, Integer.parseInt(params%5B0%5D), MALApi.ListType.MANGA);%0A                    break;%0A                case TOPICS:%0A                    result = cManager.getTopics(id, Integer.parseInt(params%5B0%5D));%0A                    break;%0A                case POSTS:%0A                    result = cManager.getPosts(id, Integer.parseInt(params%5B0%5D));%0A                    break;%0A                case ADDTOPIC:%0A                    result.setList(cManager.addTopic(id, params%5B0%5D, params%5B1%5D) ? new ArrayList%3CForum%3E() : null);%0A                    break;%0A                case ADDCOMMENT:%0A                    result.setList(cManager.addComment(id, params%5B0%5D) ? new ArrayList%3CForum%3E() : null);%0A                    break;%0A                case UPDATECOMMENT:%0A                    result.setList(cManager.updateComment(id, params%5B0%5D) ? new ArrayList%3CForum%3E() : null);%0A                    break;*/%0A
     

Remove old forumTask code which was disabled