From f410b8ecfeeb9fd6c214f7e67d88d6063c2a25e7 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 10 Jan 2014 17:28:35 +0200 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20ApiUtils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/annimon/client/utils/ApiUtils.java | 65 ++++++++++------------ 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/src/com/annimon/client/utils/ApiUtils.java b/src/com/annimon/client/utils/ApiUtils.java index 694d318..4c8a207 100644 --- a/src/com/annimon/client/utils/ApiUtils.java +++ b/src/com/annimon/client/utils/ApiUtils.java @@ -19,7 +19,6 @@ import org.json.JSONException; import org.json.JSONObject; import android.content.Context; import android.text.TextUtils; -import android.util.Base64; import com.annimon.client.R; import com.annimon.client.entities.ForumPost; import com.annimon.client.entities.ForumSection; @@ -36,8 +35,8 @@ public class ApiUtils { private static final String PHP = ".php"; /** - * Get last posts. - * @return arraylist of forum post data + * Получение списка последних сообщений. + * @return arraylist */ public static List getLastPosts() { List nameValuePairs = new ArrayList(); @@ -70,9 +69,9 @@ public class ApiUtils { } /** - * Get topics of selection section. + * Получение списка тем заданного раздела. * @param section раздел форума - * @return arraylist of forum topic data + * @return arraylist */ public static List getTopics(int section) { List nameValuePairs = new ArrayList(); @@ -89,11 +88,11 @@ public class ApiUtils { 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")); - post.setTitle(jsonObject.getString("title")); - post.setCreationDate(jsonObject.getInt("time")); - topics.add(post); + ForumTopic topic = new ForumTopic(); + topic.setId(jsonObject.getInt("topic")); + topic.setTitle(jsonObject.getString("title")); + topic.setCreationDate(jsonObject.getInt("time")); + topics.add(topic); } } catch (IOException ex) { ExceptionHandler.log("getTopics", ex); @@ -140,27 +139,27 @@ public class ApiUtils { } /** - * Get forum sections. - * @return arraylist of forum sections from raw resource + * Получение списка разделов форума. + * @return arraylist списка разделов из raw ресурса */ public static List getForumSections(Context context) { - InputStream is = context.getResources().openRawResource(R.raw.forum); - StringBuilder sb = new StringBuilder(); - try { - BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); - int length; - char[] buffer = new char[1024]; - while ((length = reader.read(buffer)) != -1) { - sb.append(buffer, 0, length); - } - reader.close(); - } catch (IOException ex) { - ExceptionHandler.log("getForumSections RAW", ex); - } + InputStream is = context.getResources().openRawResource(R.raw.forum); + StringBuilder sb = new StringBuilder(); + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); + int length; + char[] buffer = new char[1024]; + while ((length = reader.read(buffer)) != -1) { + sb.append(buffer, 0, length); + } + reader.close(); + } catch (IOException ex) { + ExceptionHandler.log("getForumSections RAW", ex); + } - String jsonString = sb.toString(); - List sections = new ArrayList(); - sections.add(new ForumSection(ForumLoader.LAST_POSTS, context.getString(R.string.last_posts))); + String jsonString = sb.toString(); + List sections = new ArrayList(); + sections.add(new ForumSection(ForumLoader.LAST_POSTS, context.getString(R.string.last_posts))); try { if (TextUtils.isEmpty(jsonString)) return sections; @@ -170,9 +169,9 @@ public class ApiUtils { sections.add(new ForumSection(jsonObject.getString("name"))); JSONArray subsections = jsonObject.getJSONArray("topics"); for (int j = 0; j < subsections.length(); j++) { - int id = subsections.getJSONObject(j).getInt("id"); - String name = subsections.getJSONObject(j).getString("name"); - sections.add(new ForumSection(id, name)); + int id = subsections.getJSONObject(j).getInt("id"); + String name = subsections.getJSONObject(j).getString("name"); + sections.add(new ForumSection(id, name)); } } } catch (JSONException ex) { @@ -188,10 +187,6 @@ public class ApiUtils { return httpclient.execute(httppost); } - private static String encode(String string) { - return Base64.encodeToString(string.getBytes(), Base64.DEFAULT); - } - private static String getKey(String apiclass) { StringBuilder key = new StringBuilder(); key.append(7);