Skip to content

Commit

Permalink
Manages broken remove-category action
Browse files Browse the repository at this point in the history
  • Loading branch information
federicoiosue committed May 29, 2014
1 parent 8cc8ac5 commit 94f4f7a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<item >Português (Portuguese Brazil)</item>
<item >Português (Portuguese Portugal)</item>
<item >Русский (Russian)</item>
<item >Slovenská (Slovak)</item>
<item >Slovenčina (Slovak)</item>
<item >Slovenščina (Slovenian)</item>
<item >Español (Spanish)</item>
<item >Kinesiska (Swedish)</item>
Expand Down
32 changes: 25 additions & 7 deletions src/it/feio/android/omninotes/ListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public class ListFragment extends Fragment implements UndoListener, OnNotesLoade
private boolean undoArchive = false;
private boolean undoCategorize = false;
private Category undoCategorizeCategory = null;
private Category removedCategory;
private SparseArray<Note> undoNotesList = new SparseArray<Note>();

// Search variables
Expand Down Expand Up @@ -1274,12 +1275,16 @@ private void categorizeSelectedNotes2(Category category) {
categorizeSelectedNotes3(note, category);
} else {
// Saves notes to be eventually restored at right position
removedCategory = note.getCategory();
undoNotesList.put(mAdapter.getPosition(note) + undoNotesList.size(), note);
}
// Update adapter content if actual navigation is the category
// associated with actually cycled note
if (Navigation.checkNavigation(Navigation.CATEGORY) && !Navigation.checkNavigationCategory(category)) {
mAdapter.remove(note);
} else {
note.setCategory(category);
mAdapter.replace(note, mAdapter.getPosition(note));
}
}

Expand Down Expand Up @@ -1441,19 +1446,32 @@ private void tagSelectedNotes2(List<String> tags, boolean[] selectedTags) {

@Override
public void onUndo(Parcelable token) {
undoTrash = false;
undoArchive = false;
undoCategorize = true;
undoCategorizeCategory = null;
Crouton.cancelAllCroutons();

// Cycles removed items to re-insert into adapter
for (Note note : selectedNotes) {
mAdapter.insert(note, undoNotesList.keyAt(undoNotesList.indexOfValue(note)));
}
// Manages trash/archive undo or notes removed from category navigated actually
if (!undoCategorize || Navigation.checkNavigationCategory(removedCategory)) {
mAdapter.insert(note,
undoNotesList.keyAt(undoNotesList.indexOfValue(note)));
// Replaces category colred strip
} else {
note.setCategory(removedCategory);
mAdapter.replace(note, mAdapter.getPosition(note));
}
}

listView.invalidateViews();

undoNotesList.clear();
selectedNotes.clear();

undoTrash = false;
undoArchive = false;
undoCategorize = false;
removedCategory = null;
undoCategorizeCategory = null;
Crouton.cancelAllCroutons();

if (mActionMode != null) {
mActionMode.finish();
}
Expand Down
10 changes: 10 additions & 0 deletions src/it/feio/android/omninotes/models/adapters/NoteAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,16 @@ public static boolean isNewWork(Uri uri, SquareImageView imageView) {
// cancelled
return true;
}


/**
* Replaces notes
* @param note
*/
public void replace(Note note, int index) {
notes.remove(index);
notes.add(index, note);
}
}


Expand Down

0 comments on commit 94f4f7a

Please sign in to comment.