From af327a5f2b9ce23813b355071c6fa676e3545be9 Mon Sep 17 00:00:00 2001 From: Yuji Konishi Date: Tue, 20 Mar 2012 15:57:29 +0900 Subject: [PATCH] T27595 --- .../EverMemo/src/com/yuji/em/NoteListActivity.java | 90 +++++++++++++--------- 1 file changed, 55 insertions(+), 35 deletions(-) diff --git a/workspace/EverMemo/src/com/yuji/em/NoteListActivity.java b/workspace/EverMemo/src/com/yuji/em/NoteListActivity.java index 9379ffa..dd94b0f 100644 --- a/workspace/EverMemo/src/com/yuji/em/NoteListActivity.java +++ b/workspace/EverMemo/src/com/yuji/em/NoteListActivity.java @@ -22,6 +22,8 @@ import com.yuji.em.utility.AsyncTaskCommand; import com.yuji.em.utility.BaseActivity; public class NoteListActivity extends BaseActivity { + private static List noteList = null; + private ListView listView = null; private Button closeButton = null; private int index = -1; @@ -37,82 +39,103 @@ public class NoteListActivity extends BaseActivity { listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View view, - int position, long id) { + int position, long id) { listViewOnItemClickListener(parent, view, position, id); } }); - closeButton.setOnClickListener(new OnClickListener(){ + closeButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { closeButtonOnClick(); - }}); + } + }); Bundle extras = getIntent().getExtras(); - index = extras.getInt(Constant.EXTRA_INDEX); - - NoteListTask task = new NoteListTask(this); - AsyncTaskCommand command = new AsyncTaskCommand(this, task); - command.execute(""); + index = extras.getInt(Constant.EXTRA_INDEX); + + if (noteList != null) { + setNoteList(noteList); + } else { + NoteListTask task = new NoteListTask(this); + AsyncTaskCommand command = new AsyncTaskCommand(this, task); + command.execute(""); + } } catch (Exception e) { // TODO e.printStackTrace(); } } - - private void closeButtonOnClick(){ + + private void closeButtonOnClick() { Intent intent = new Intent(); - setResult(RESULT_CANCELED, intent); - finish(); + setResult(RESULT_CANCELED, intent); + finish(); } private void listViewOnItemClickListener(AdapterView parent, View view, - int position, long id) { - ListView listView = (ListView) parent; - NoteListItem item = (NoteListItem) listView.getItemAtPosition(position); + int position, long id) { + ListView listView = (ListView) parent; + NoteListItem item = (NoteListItem) listView.getItemAtPosition(position); - Note note = item.getNote(); + Note note = item.getNote(); if (note == null) { return; } NoteDao dao = NoteDao.getInstance(); int n = dao.search(this, note); - if (n >= 0){ + if (n >= 0) { // #27613 Intent intent = new Intent(); - setResult(RESULT_CANCELED, intent); - finish(); + setResult(RESULT_CANCELED, intent); + finish(); return; } dao.update(this, note, index); - + Intent intent = new Intent(); - setResult(RESULT_OK, intent); + setResult(RESULT_OK, intent); finish(); } - public void done(NoteList noteList) { - if (noteList == null){ + public void done(NoteList nList) { + if (nList == null) { // ƒLƒƒƒ“ƒZƒ‹ƒ{ƒ^ƒ“‰Ÿ‰ºŽž closeButtonOnClick(); return; } + + List list = getNoteList(nList); + if (list == null) { + closeButtonOnClick(); + return; + } + setNoteList(list); + noteList = list; + } + + private void setNoteList(List list) { + NoteListViewArrayAdapter adapter = new NoteListViewArrayAdapter(this, + R.layout.simple_list_item_1, list); + listView.setAdapter(adapter); + } + + private List getNoteList(NoteList nList) { List list = new ArrayList(); // TODO - List notes = noteList.getNotes(); - if (notes == null){ - return; + List notes = nList.getNotes(); + if (notes == null) { + return null; } - + String oldTitle = ""; NoteListItem item; for (com.evernote.edam.type.Note note : notes) { long l = note.getUpdated(); - //long l = note.getCreated(); // TODO ƒ\[ƒg‡‚́AXV“ú? - String title = DateUtils - .formatDateTime(this, l, DateUtils.FORMAT_SHOW_YEAR - | DateUtils.FORMAT_SHOW_DATE); + // long l = note.getCreated(); // TODO ƒ\[ƒg‡‚́AXV“ú? + String title = DateUtils.formatDateTime(this, l, + DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE); if (!title.equals(oldTitle)) { item = new NoteListItem(title, null); list.add(item); @@ -123,9 +146,6 @@ public class NoteListActivity extends BaseActivity { item = new NoteListItem(null, n); list.add(item); } - - NoteListViewArrayAdapter adapter = new NoteListViewArrayAdapter(this, - R.layout.simple_list_item_1, list); - listView.setAdapter(adapter); + return list; } } -- 2.11.0