Форматирование ApiUtils
This commit is contained in:
parent
0b5f25a2dd
commit
f410b8ecfe
@ -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<ForumPost> getLastPosts() {
|
||||
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
||||
@ -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<ForumTopic> getTopics(int section) {
|
||||
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
||||
@ -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<ForumSection> 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<ForumSection> sections = new ArrayList<ForumSection>();
|
||||
sections.add(new ForumSection(ForumLoader.LAST_POSTS, context.getString(R.string.last_posts)));
|
||||
String jsonString = sb.toString();
|
||||
List<ForumSection> sections = new ArrayList<ForumSection>();
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user