OSDN Git Service

create jsonParse()
authorYuta Kawabe <yuyu3165@gmail>
Fri, 27 Jul 2012 02:38:30 +0000 (11:38 +0900)
committerYuta Kawabe <yuyu3165@gmail>
Fri, 27 Jul 2012 02:38:30 +0000 (11:38 +0900)
CUTEn/src/jp/ac/titech/sharp4k/cuten/DownloadActivity.java
CUTEn/src/jp/ac/titech/sharp4k/cuten/LectureFolderActivity.java

index 805222f..891773f 100644 (file)
@@ -2,7 +2,6 @@ package jp.ac.titech.sharp4k.cuten;
 
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.ArrayList;
 import java.util.List;
 import org.json.JSONArray;
 import org.json.JSONException;
@@ -22,7 +21,7 @@ import android.widget.TextView;
 
 public class DownloadActivity extends Activity {
        DownloadTask task;
-       List<Lecture> lectures, haveLecture, newLecture;
+       List<Lecture> haveLecture, newLecture;
        TextView tv;
        ListView lectureList;
        ArrayAdapter<String> haveAdapter, newAdapter;
@@ -112,7 +111,6 @@ public class DownloadActivity extends Activity {
        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");
index 9db10bf..e326622 100644 (file)
@@ -7,6 +7,10 @@ import java.util.Collection;
 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;
@@ -670,23 +674,49 @@ public class LectureFolderActivity extends BaseMenuActivity {
                        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();
                }
+       }
 }