import java.net.URI;
import java.net.URISyntaxException;
-import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
public class DownloadActivity extends Activity {
DownloadTask task;
- List<Lecture> lectures, haveLecture, newLecture;
+ List<Lecture> haveLecture, newLecture;
TextView tv;
ListView lectureList;
ArrayAdapter<String> haveAdapter, newAdapter;
void jsonParse(String data) {
try {
JSONArray root = new JSONArray(data);
- lectures = new ArrayList<Lecture>();
for (int i = 0; i < root.length(); i++) {
JSONObject lecture = root.getJSONObject(i);
JSONObject teacher = lecture.getJSONObject("teacher");
import java.util.List;
import java.util.Map;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import jp.ac.titech.sharp4k.cuten.util.XmlUtility;
import jp.ac.titech.sharp4k.cuten.R;
e.printStackTrace();
}
}
-
+
// 通信スレッド終了後に呼ばれるメソッド
public void postExecute(String result) {
if (result != null) {
-
+ jsonParse(result);
} else {
showAlertDialog("サーバからデータを取得できませんでした");
}
}
-
+
// 警告ダイアログ(ネットワークエラー時に表示)
- public void showAlertDialog(String message) {
- new AlertDialog.Builder(this).setTitle("警告").setMessage(message)
- .setPositiveButton("OK", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- }
- }).setCancelable(false).show();
+ public void showAlertDialog(String message) {
+ new AlertDialog.Builder(this).setTitle("警告").setMessage(message)
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ }
+ }).setCancelable(false).show();
+ }
+
+ // 課題情報付き講義リストから、課題情報を取り出してデータベースに格納する
+ private void jsonParse(String data) {
+ try {
+ JSONArray root = new JSONArray(data);
+ for (int i = 0; i < root.length(); i++) {
+ JSONObject lecture = root.getJSONObject(i);
+ JSONObject teacher = lecture.getJSONObject("teacher");
+ Teacher t1 = new Teacher(teacher.getInt("id"),
+ teacher.getString("name"));
+ Lecture l = new Lecture(lecture.getInt("id"),
+ lecture.getString("name"), t1);
+ JSONArray taskList = lecture.getJSONArray("tasks");
+ for (int j = 0; i < root.length(); i++) {
+ JSONObject task = taskList.getJSONObject(j);
+ Task t2 = new Task(task.getInt("id"), task.getString("name"), l);
+ t2.save(database);
+ JSONObject apk = task.getJSONObject("apk");
+ Apk a = new Apk(apk.getInt("id"), apk.getInt("revision"), apk.getString("name"), t2);
+ a.save(database);
+ }
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
}
+ }
}