OSDN Git Service

T28107
[everclip/source.git] / workspace / EverClip / src / com / yuji / ec / utility / EvernoteUtil.java
index 10ff414..b42cc48 100644 (file)
@@ -29,6 +29,7 @@ import com.yuji.ec.R;
 import com.yuji.ec.db.INoteItem;
 
 public class EvernoteUtil {
+       private static final int N = 50;
        private String username;
        private String password;
 
@@ -108,18 +109,18 @@ public class EvernoteUtil {
                return filter;
        }
        
-       public NoteList getNoteList() {
+       public List<NoteList> getNoteList() {
                NoteFilter filter = getDefaultFilter();
                return getNoteList(filter);
        }
 
-       public NoteList getNoteListByNotebook(String notebookGuid) {
+       public List<NoteList> getNoteListByNotebook(String notebookGuid) {
                NoteFilter filter = getDefaultFilter();
                filter.setNotebookGuid(notebookGuid);
                return getNoteList(filter);
        }
        
-       public NoteList getNoteListByTag(String tagGuid) {
+       public List<NoteList> getNoteListByTag(String tagGuid) {
                NoteFilter filter = getDefaultFilter();
                List<String> tagGuids = new ArrayList<String>();
                tagGuids.add(tagGuid);
@@ -127,33 +128,49 @@ public class EvernoteUtil {
                return getNoteList(filter);
        }
        
-       public NoteList getNoteList(NoteFilter filter) {
+       public List<NoteList> getNoteList(NoteFilter filter) {
                errorCode = Error.OTHER;
 
-               NoteList noteList = null;
+               List<NoteList> list = new ArrayList<NoteList>();
                try {
                        String token = getAuthenticationToken();
                        if (token == null) {
                                return null;
                        }
-                       // TODO #28107
-                       noteList = noteStore.findNotes(token, filter, 0, 1000);
+                       int index = 0;
+                       while (true){
+                               NoteList noteList = noteStore.findNotes(token, filter, index, N);
+                               int size = noteList.getNotesSize();
+                               
+                               if (size <= 0){
+                                       break;
+                               }
+                               list.add(noteList);
+                               if (size < N){
+                                       break;
+                               }
+                               index += size;
+                       }
                        
                        errorCode = Error.NONE;
                } catch (EDAMUserException e) {
                        Debug.d(this, null, e);
+                       list = null;
                } catch (EDAMSystemException e) {
                        Debug.d(this, null, e);
+                       list = null;
                } catch (EDAMNotFoundException e) {
                        Debug.d(this, null, e);
+                       list = null;
                } catch (TException e) {
                        Debug.d(this, null, e);
 
                        if (e.getCause() instanceof ConnectException) {
                                errorCode = Error.CONNECT;
                        }
+                       list = null;
                }
-               return noteList;
+               return list;
        }
 
        public List<Notebook> getNoteBookList() {
@@ -356,6 +373,18 @@ public class EvernoteUtil {
                return note;
        }
 
+       public List<com.yuji.ec.db.Note> getNoteContentList(List<NoteList> noteListList) {
+               List<com.yuji.ec.db.Note> list = new ArrayList<com.yuji.ec.db.Note>();
+               for (NoteList noteList : noteListList){
+                       List<com.yuji.ec.db.Note> l = getNoteContentList(noteList);
+                       if (l == null){
+                               return null;
+                       }
+                       list.addAll(l);
+               }
+               return list;
+       }
+       
        public List<com.yuji.ec.db.Note> getNoteContentList(NoteList noteList) {
                errorCode = Error.OTHER;
 
@@ -364,6 +393,8 @@ public class EvernoteUtil {
 
                try {
                        List<Note> notes = noteList.getNotes();
+                       int s = noteList.getNotesSize();
+                       System.out.println("" + s);
                        for (Note n : notes) {
                                String guid = n.getGuid();
                                Note nc = getNote(guid);
@@ -375,6 +406,8 @@ public class EvernoteUtil {
                                com.yuji.ec.db.Note note = toNote(nc, text);
                                list.add(note);
                        }
+                       notes = noteList.getNotes();
+                       s = noteList.getNotesSize();
                        errorCode = Error.NONE;
                } catch (EDAMNotFoundException e) {
                        errorCode = Error.NOT_FOUND;