Добавлен метод получения списка тем

This commit is contained in:
Victor 2014-01-10 16:56:39 +02:00
parent 9e7bb86239
commit 8c18983280
2 changed files with 41 additions and 1 deletions

View File

@ -18,7 +18,7 @@ public class ForumLoader<T> extends AsyncTask<Integer, Void, List<T>> {
public static final int LAST_POSTS = -110;
public static final int MODE_TOPICS = -120;
public static final int MODE_POSTS = -120;
public static final int MODE_POSTS = -121;
private final Context mContext;
private final FinishLoadingListener<T> mListener;
@ -41,6 +41,11 @@ public class ForumLoader<T> extends AsyncTask<Integer, Void, List<T>> {
return (List<T>) ApiUtils.getLastPosts();
}
if (params[0] == MODE_TOPICS) {
int section = params[1];
return (List<T>) ApiUtils.getTopics(section);
}
if (params[0] == MODE_POSTS) {
int topicId = params[1];
}

View File

@ -22,6 +22,7 @@ import org.json.JSONObject;
import com.annimon.client.R;
import com.annimon.client.entities.ForumPost;
import com.annimon.client.entities.ForumSection;
import com.annimon.client.entities.ForumTopic;
import com.annimon.client.tasks.ForumLoader;
import android.content.Context;
@ -71,6 +72,40 @@ public class ApiUtils {
return posts;
}
/**
* Get topics of selection section.
* @param section ðàçäåë ôîðóìà
* @return arraylist of forum topic data
*/
public static List<ForumTopic> getTopics(int section) {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("key", getKey(ApiForum.CLASS)));
nameValuePairs.add(new BasicNameValuePair("act", ApiForum.ACT_GET_TOPICS));
nameValuePairs.add(new BasicNameValuePair("section", String.valueOf(section)));
List<ForumTopic> topics = new ArrayList<ForumTopic>();
try {
HttpResponse response = sendPost(ApiForum.PATH, nameValuePairs);
String text = EntityUtils.toString(response.getEntity());
if (TextUtils.isEmpty(text)) return topics;
JSONArray jsonArray = new JSONArray(text);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
ForumTopic post = new ForumTopic();
post.setId(jsonObject.getInt("topic_id"));
post.setTitle(jsonObject.getString("title"));
post.setCreationDate(jsonObject.getInt("time"));
topics.add(post);
}
} catch (IOException ex) {
ExceptionHandler.log("getLastPosts", ex);
} catch (JSONException ex) {
ExceptionHandler.log("getLastPosts", ex);
}
return topics;
}
/**
* Get forum sections.
* @return arraylist of forum sections from raw resource