import com.yuji.em.utility.BaseActivity;
public class NoteListActivity extends BaseActivity {
+ private static List<NoteListItem> noteList = null;
+
private ListView listView = null;
private Button closeButton = null;
private int index = -1;
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) {
// \83L\83\83\83\93\83Z\83\8b\83{\83^\83\93\89\9f\89º\8e\9e
closeButtonOnClick();
return;
}
+
+ List<NoteListItem> list = getNoteList(nList);
+ if (list == null) {
+ closeButtonOnClick();
+ return;
+ }
+ setNoteList(list);
+ noteList = list;
+ }
+
+ private void setNoteList(List<NoteListItem> list) {
+ NoteListViewArrayAdapter adapter = new NoteListViewArrayAdapter(this,
+ R.layout.simple_list_item_1, list);
+ listView.setAdapter(adapter);
+ }
+
+ private List<NoteListItem> getNoteList(NoteList nList) {
List<NoteListItem> list = new ArrayList<NoteListItem>();
// TODO
- List<com.evernote.edam.type.Note> notes = noteList.getNotes();
- if (notes == null){
- return;
+ List<com.evernote.edam.type.Note> 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 \83\\81[\83g\8f\87\82Í\81A\8dX\90V\93ú?
- String title = DateUtils
- .formatDateTime(this, l, DateUtils.FORMAT_SHOW_YEAR
- | DateUtils.FORMAT_SHOW_DATE);
+ // long l = note.getCreated(); // TODO \83\\81[\83g\8f\87\82Í\81A\8dX\90V\93ú?
+ 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);
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;
}
}