OSDN Git Service

T28114
[everclip/source.git] / workspace / EverClip / src / com / yuji / ec / task / NoteTypeListTask.java
1 package com.yuji.ec.task;
2
3 import java.lang.ref.WeakReference;
4 import java.util.List;
5
6 import com.evernote.edam.type.Notebook;
7 import com.evernote.edam.type.Tag;
8 import com.yuji.ec.NoteTypeListActivity;
9 import com.yuji.ec.common.Constant;
10 import com.yuji.ec.db.INoteItem;
11 import com.yuji.ec.utility.AsyncTaskIF;
12 import com.yuji.ec.utility.EvernoteUtil;
13
14 public class NoteTypeListTask implements AsyncTaskIF {
15         private EvernoteUtil util = EvernoteUtil.getInstance();
16         //private NoteList noteList;
17         private WeakReference<NoteTypeListActivity> activityRef;
18         private EvernoteUtil.Error errorCode = null;
19
20         private List<INoteItem> list = null;
21         private int noteItemType;
22         
23         public NoteTypeListTask(NoteTypeListActivity activity, int noteItemType) {
24                 activityRef = new WeakReference<NoteTypeListActivity>(activity);
25                 this.noteItemType = noteItemType;
26         }
27
28         public void doExecute() {
29                 synchronized (util) {
30                         try {
31                                 EvernoteUtil util = EvernoteUtil.getInstance();
32                                 switch (noteItemType){
33                                 case Constant.NOTE_ITEM_TYPE_NOTE_BOOK:
34                                         List<Notebook> noteList = util.getNoteBookList();
35                                         list = util.toNoteItemFromNoteBook(noteList);
36                                         break;
37                                 case Constant.NOTE_ITEM_TYPE_TAG:
38                                         List<Tag> tagList = util.getTagList();
39                                         list = util.toNoteItemFromTag(tagList);
40                                         break;
41                                 default:
42                                         break;
43                                 }
44                         } finally {
45                                 errorCode = util.getErrorCode();
46                         }
47                 }
48         }
49
50         public void cancel() {
51
52         }
53
54         public void done(boolean isCancel) {
55                 NoteTypeListActivity activity = activityRef.get();
56                 if (activity != null) {
57                         activity.done(errorCode, list);
58                         activityRef = null;
59                 }
60         }
61
62         public int getStatus() {
63                 return 0;
64         }
65
66 //      public NoteList getNoteList() {
67 //              return noteList;
68 //      }
69
70         public EvernoteUtil.Error getErrorCode() {
71                 return errorCode;
72         }
73 }