Skip to content

Commit

Permalink
Merge pull request #109 from proninyaroslav/master
Browse files Browse the repository at this point in the history
Option to undo the removal of tags/notes
  • Loading branch information
konradrenner committed Feb 12, 2016
2 parents 5c9957f + 3aa3c8a commit 0b327d6
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions .idea/scopes/scope_settings.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support.test/runner/0.4.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/cardview-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.mikepenz/iconics/1.2.0/jars" />
Expand All @@ -84,7 +85,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/release" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
Expand All @@ -100,13 +100,14 @@
<orderEntry type="library" exported="" scope="TEST" name="runner-0.4.1" level="project" />
<orderEntry type="library" exported="" name="iconics-1.2.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-library-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="javax.annotation-api-1.2" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-library-1.3" level="project" />
<orderEntry type="library" exported="" name="kolabnotes-java-2.2.1" level="project" />
<orderEntry type="library" exported="" name="richeditor-android-1.0.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="javax.inject-1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-integration-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="rules-0.4.1" level="project" />
<orderEntry type="library" exported="" name="design-23.1.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="javawriter-2.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
Expand Down
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'jp.wasabeef:richeditor-android:1.0.0'
compile 'com.android.support:design:23.1.1'

// Add dependency for UI test
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public void clearNotes() {
}
}

public void deleteNotes(List<Note> notes) {
this.notes.removeAll(notes);
this.notifyDataSetChanged();
}

public void addNotes(List<Note> notes) {
this.notes.addAll(notes);
Collections.sort(this.notes, new NoteSortingComparator(Utils.getNoteSorting(context)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public void clearTags() {
}
}

public void deleteTags(List<Tag> tags) {
this.tags.removeAll(tags);
this.notifyDataSetChanged();
}

public void addTags(List<Tag> tags) {
this.tags.addAll(tags);
Collections.sort(this.tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.SwipeRefreshLayout;
Expand Down Expand Up @@ -68,6 +70,7 @@
import org.kore.kolabnotes.android.content.ActiveAccount;
import org.kore.kolabnotes.android.content.ActiveAccountRepository;
import org.kore.kolabnotes.android.content.NoteRepository;
import org.kore.kolabnotes.android.content.NoteSorting;
import org.kore.kolabnotes.android.content.NoteTagRepository;
import org.kore.kolabnotes.android.content.NotebookRepository;
import org.kore.kolabnotes.android.content.TagRepository;
Expand Down Expand Up @@ -104,12 +107,13 @@ public class OverviewFragment extends Fragment implements /*NoteAdapter.NoteSele


private NoteAdapter mAdapter;
private ImageButton mFabButton;
private FloatingActionButton mFabButton;
private RecyclerView mRecyclerView;
private TextView mEmptyView;
private SwipeRefreshLayout mSwipeRefreshLayout;
private SearchView mSearchView;
private String mSearchKeyWord;
private Snackbar mSnackbarDelete;

private ActionMode mActionMode;
private ActionModeCallback mActionModeCallback = new ActionModeCallback();
Expand Down Expand Up @@ -232,7 +236,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
mAccountManager = AccountManager.get(activity);

// Fab Button
mFabButton = (ImageButton) getActivity().findViewById(R.id.fab_button);
mFabButton = (FloatingActionButton) getActivity().findViewById(R.id.fab_button);
//mFabButton.setImageDrawable(new IconicsDrawable(this, FontAwesome.Icon.faw_upload).color(Color.WHITE).actionBarSize());
Utils.configureFab(mFabButton);
mFabButton.setOnClickListener(new CreateButtonListener());
Expand Down Expand Up @@ -306,6 +310,15 @@ public void run() {
setListState();
}

@Override
public void onPause() {
super.onPause();

if (mSnackbarDelete != null) {
mSnackbarDelete.dismiss();
}
}

@Override
public void onSaveInstanceState(Bundle outState) {
outState.putIntegerArrayList(TAG_SELECTABLE_ADAPTER, mAdapter.getSelectedItems());
Expand Down Expand Up @@ -463,40 +476,57 @@ void deleteNotes(final List<Integer> items) {
final String account = activeAccountRepository.getActiveAccount().getAccount();
final String rootFolder = activeAccountRepository.getActiveAccount().getRootFolder();

AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final ArrayList<Note> notes = new ArrayList<Note>();
for (int position : items) {
final String uid = mSelectedNotes.get(position);
final Note note = notesRepository.getByUID(account, rootFolder, uid);
notes.add(note);
}
mAdapter.deleteNotes(notes);
setListState();
mSelectedNotes.clear();

builder.setTitle(R.string.dialog_delete_notes);
builder.setMessage(R.string.dialog_question_delete_notes);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for (int position : items) {
final String uid = mSelectedNotes.get(position);
final Note note = notesRepository.getByUID(account, rootFolder, uid);

if (note != null) {
Notebook book = checkModificationPermissionInCurrentBook(account, rootFolder, uid);
if (book == null) continue;
notesRepository.delete(account, rootFolder, note);
if (mSnackbarDelete != null) {
mSnackbarDelete.dismiss();
}

mSnackbarDelete = Snackbar.make(activity.findViewById(R.id.coordinator_overview), R.string.snackbar_delete_message, Snackbar.LENGTH_LONG)
.setCallback(new Snackbar.Callback() {
@Override
public void onDismissed(Snackbar snackbar, int event) {
switch(event) {
/* If undo button pressed */
case Snackbar.Callback.DISMISS_EVENT_ACTION:
mAdapter.clearNotes();
mAdapter.addNotes(notesRepository.getAll(account, rootFolder, Utils.getNoteSorting(getActivity())));
setListState();
break;
default:
for (Note note : notes) {
if (note != null) {
Notebook book = checkModificationPermissionInCurrentBook(account, rootFolder,
note.getIdentification().getUid());
if (book == null) continue;
notesRepository.delete(account, rootFolder, note);
}
}
reloadData();
Utils.setSelectedTagName(activity,null);
Utils.setSelectedNotebookName(activity, null);
if (tabletMode) {
displayBlankFragment();
}
break;
}
}
}
mSelectedNotes.clear();
Utils.setSelectedTagName(activity,null);
Utils.setSelectedNotebookName(activity, null);
reloadData();
if (tabletMode) {
displayBlankFragment();
}
}
});
}).setAction(R.string.snackbar_undo_delete, new View.OnClickListener() {
@Override
public void onClick(View v) {
/* Nothing */
}
});

builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//nothing
}
});
builder.show();
mSnackbarDelete.show();
}
}

Expand Down
Loading

0 comments on commit 0b327d6

Please sign in to comment.