package com.yuji.em.utility;
import java.net.ConnectException;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import com.yuji.em.R;
public class EvernoteUtil {
+ private static final int N = 50;
private String username;
private String password;
public enum Error {
return note;
}
- public NoteList getNoteList() {
- errorCode = Error.OTHER;
-
+ private NoteFilter getDefaultFilter(){
// \8c\9f\8dõ\8fð\8c\8f\82Æ\82µ\82Ä\81A\8c\9f\8dõ\8cê\82È\82µ\81A\8dX\90V\93ú\8f\87\83\\81[\83g\82ð\8ew\92è
NoteFilter filter = new NoteFilter();
filter.setOrder(NoteSortOrder.UPDATED.getValue());
- filter.setAscending(false);
+ filter.setAscending(false);
+
+ return filter;
+ }
+
+ public List<NoteList> getNoteList() {
+ NoteFilter filter = getDefaultFilter();
+ return getNoteList(filter);
+ }
- NoteList noteList = null;
+ public List<NoteList> getNoteListByNotebook(String notebookGuid) {
+ NoteFilter filter = getDefaultFilter();
+ filter.setNotebookGuid(notebookGuid);
+ return getNoteList(filter);
+ }
+
+ public List<NoteList> getNoteListByTag(String tagGuid) {
+ NoteFilter filter = getDefaultFilter();
+ List<String> tagGuids = new ArrayList<String>();
+ tagGuids.add(tagGuid);
+ filter.setTagGuids(tagGuids);
+ return getNoteList(filter);
+ }
+
+ public List<NoteList> getNoteList(NoteFilter filter) {
+ errorCode = Error.OTHER;
+
+ List<NoteList> list = new ArrayList<NoteList>();
try {
String token = getAuthenticationToken();
- if (token == null){
+ if (token == null) {
return null;
}
- noteList = noteStore.findNotes(token, filter, 0, 100);
+ 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;
+
+ if (e.getCause() instanceof ConnectException) {
+ errorCode = Error.CONNECT;
}
+ list = null;
}
- return noteList;
+ return list;
}
public Note updateNoteContext(String guid, String title, String text){