Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void afterTextChanged(Editable s) {
});

final MaterialAlertDialogBuilder alertDialogBuilder = new MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.change_category_title)
.setTitle(R.string.action_edit_category)
.setView(dialogView)
.setCancelable(true)
.setPositiveButton(R.string.action_edit_save, (dialog, which) -> listener.onCategoryChosen(editCategory.getText().toString()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ class ItemActionBottomSheet(
setTitle()
addActions(
listOf(
if (note.favorite) NoteAction.UNFAVORITE else NoteAction.FAVORITE,
NoteAction.EDIT_CATEGORY,
NoteAction.SEE_DETAILS,
NoteAction.SEND_SHARE
NoteAction.SEND_SHARE,
NoteAction.DELETE
)
)

Expand Down Expand Up @@ -73,6 +76,7 @@ class ItemActionBottomSheet(
when (action) {
NoteAction.SEE_DETAILS -> openInfo(ItemDetailsActivity.PAGE.ACTIVITIES)
NoteAction.SEND_SHARE -> openInfo(ItemDetailsActivity.PAGE.SHARE)
else -> (activity as? Listener)?.onNoteActionSelected(note, action)
}
dismiss()
}
Expand Down Expand Up @@ -101,6 +105,10 @@ class ItemActionBottomSheet(
}


interface Listener {
fun onNoteActionSelected(note: Note, action: NoteAction)
}

companion object {
@JvmField
val TAG: String = ItemActionBottomSheet::class.simpleName ?: "ItemActionBottomSheet"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ enum class NoteAction(
@param:StringRes val title: Int,
@param:DrawableRes val icon: Int
) {
FAVORITE(R.id.action_favorite, R.string.action_favorite, R.drawable.ic_star_border_white_24dp),
UNFAVORITE(R.id.action_unfavorite, R.string.action_unfavorite, R.drawable.ic_star_white_24dp),
EDIT_CATEGORY(R.id.action_edit_category, R.string.action_edit_category, R.drawable.ic_folder_grey600_24dp),
SEE_DETAILS(R.id.action_see_details, R.string.action_see_details, R.drawable.ic_info_outline_grey600_24dp),
SEND_SHARE(R.id.action_send_share, R.string.action_send_share, R.drawable.ic_share_white_24dp),
DELETE(R.id.action_delete, R.string.action_delete_note, R.drawable.ic_delete_grey600_24dp),
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@

import java.net.HttpURLConnection;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All @@ -104,6 +105,7 @@
import it.niedermann.owncloud.notes.exception.IntendedOfflineException;
import it.niedermann.owncloud.notes.importaccount.ImportAccountActivity;
import it.niedermann.owncloud.notes.itemactions.ItemActionBottomSheet;
import it.niedermann.owncloud.notes.itemactions.NoteAction;
import it.niedermann.owncloud.notes.main.items.ItemAdapter;
import it.niedermann.owncloud.notes.main.items.grid.GridItemDecoration;
import it.niedermann.owncloud.notes.main.items.list.NotesListViewItemTouchHelper;
Expand All @@ -127,7 +129,7 @@
import it.niedermann.owncloud.notes.shared.util.NoteUtil;
import it.niedermann.owncloud.notes.shared.util.ShareUtil;

public class MainActivity extends LockedActivity implements NoteClickListener, AccountPickerListener, AccountSwitcherListener, CategoryDialogFragment.CategoryDialogListener {
public class MainActivity extends LockedActivity implements NoteClickListener, AccountPickerListener, AccountSwitcherListener, CategoryDialogFragment.CategoryDialogListener, ItemActionBottomSheet.Listener {

private static final String TAG = MainActivity.class.getSimpleName();

Expand All @@ -145,6 +147,7 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A

private static final int REQUEST_CODE_CREATE_NOTE = 0;
private static final int REQUEST_CODE_SERVER_SETTINGS = 1;
private static final String STATE_CATEGORY_NOTE_ID = "categoryNoteId";

protected ItemAdapter adapter;
private NavigationAdapter adapterCategories;
Expand All @@ -161,6 +164,8 @@ public class MainActivity extends LockedActivity implements NoteClickListener, A
private SwipeRefreshLayout swipeRefreshLayout;
private RecyclerView listView;
private ActionMode mActionMode;
@Nullable
private Long categoryNoteId;

boolean canMoveNoteToAnotherAccounts = false;

Expand Down Expand Up @@ -494,6 +499,17 @@ public void onError(@NonNull Throwable t) {
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mainViewModel.restoreInstanceState();
if (savedInstanceState.containsKey(STATE_CATEGORY_NOTE_ID)) {
categoryNoteId = savedInstanceState.getLong(STATE_CATEGORY_NOTE_ID);
}
}

@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
if (categoryNoteId != null) {
outState.putLong(STATE_CATEGORY_NOTE_ID, categoryNoteId);
}
}

private void handleEcosystemIntent(Intent intent) {
Expand Down Expand Up @@ -926,6 +942,22 @@ public void openInfoBottomSheet(int position) {
}
}

@Override
public void onNoteActionSelected(@NonNull Note note, @NonNull NoteAction action) {
switch (action) {
case FAVORITE, UNFAVORITE -> mainViewModel.toggleFavoriteAndSync(note);
case EDIT_CATEGORY -> {
categoryNoteId = note.getId();
CategoryDialogFragment
.newInstance(note.getAccountId(), note.getCategory())
.show(getSupportFragmentManager(), CategoryDialogFragment.class.getSimpleName());
}
case DELETE -> NotesListViewItemTouchHelper.deleteNoteWithUndo(this, mainViewModel, this, coordinatorLayout, fabCreate, note.getId());
default -> {
}
}
}

private void updateToolbars(boolean enableSearch) {
activityBinding.searchBar.searchBarWrapper.setVisibility(enableSearch ? GONE : VISIBLE);
activityBinding.searchToolbar.setVisibility(enableSearch ? VISIBLE : GONE);
Expand Down Expand Up @@ -964,7 +996,14 @@ public void onAccountPicked(@NonNull Account account) {

@Override
public void onCategoryChosen(String category) {
final var categoryLiveData = mainViewModel.setCategory(tracker.getSelection(), category);
final Iterable<Long> noteIds;
if (tracker.hasSelection() || categoryNoteId == null) {
noteIds = tracker.getSelection();
} else {
noteIds = List.of(categoryNoteId);
}
categoryNoteId = null;
final var categoryLiveData = mainViewModel.setCategory(noteIds, category);
categoryLiveData.observe(this, (next) -> categoryLiveData.removeObservers(this));
tracker.clearSelection();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,10 @@ public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction)
switch (direction) {
case ItemTouchHelper.LEFT -> {
viewHolder.setIsRecyclable(false);
final var dbNoteWithoutContent = (Note) adapter.getItem(viewHolder.getLayoutPosition());
final var dbNoteLiveData = mainViewModel.getFullNote$(dbNoteWithoutContent.getId());
dbNoteLiveData.observe(lifecycleOwner, (dbNote) -> {
dbNoteLiveData.removeObservers(lifecycleOwner);
tracker.deselect(dbNote.getId());
final var deleteLiveData = mainViewModel.deleteNoteAndSync(dbNote.getId());
deleteLiveData.observe(lifecycleOwner, (next) -> deleteLiveData.removeObservers(lifecycleOwner));
Log.v(TAG, "Item deleted through swipe ----------------------------------------------");
BrandedSnackbar.make(view, context.getString(R.string.action_note_deleted, dbNote.getTitle()), UNDO_DURATION)
.setAnchorView(anchorView)
.setAction(R.string.action_undo, (View v) -> {
final var undoLiveData = mainViewModel.addNoteAndSync(dbNote);
undoLiveData.observe(lifecycleOwner, (o) -> undoLiveData.removeObservers(lifecycleOwner));
BrandedSnackbar.make(view, context.getString(R.string.action_note_restored, dbNote.getTitle()), Snackbar.LENGTH_SHORT)
.setAnchorView(anchorView)
.show();
})
.show();
});
final var note = (Note) adapter.getItem(viewHolder.getLayoutPosition());
tracker.deselect(note.getId());
Log.v(TAG, "Item deleted through swipe ----------------------------------------------");
deleteNoteWithUndo(context, mainViewModel, lifecycleOwner, view, anchorView, note.getId());
}
case ItemTouchHelper.RIGHT -> {
viewHolder.setIsRecyclable(false);
Expand Down Expand Up @@ -148,4 +133,28 @@ public float getSwipeEscapeVelocity(float defaultValue) {
}
});
}

public static void deleteNoteWithUndo(@NonNull Context context,
@NonNull MainViewModel mainViewModel,
@NonNull LifecycleOwner lifecycleOwner,
@NonNull View view,
@NonNull View anchorView,
long noteId) {
final var dbNoteLiveData = mainViewModel.getFullNote$(noteId);
dbNoteLiveData.observe(lifecycleOwner, (dbNote) -> {
dbNoteLiveData.removeObservers(lifecycleOwner);
final var deleteLiveData = mainViewModel.deleteNoteAndSync(dbNote.getId());
deleteLiveData.observe(lifecycleOwner, (next) -> deleteLiveData.removeObservers(lifecycleOwner));
BrandedSnackbar.make(view, context.getString(R.string.action_note_deleted, dbNote.getTitle()), UNDO_DURATION)
.setAnchorView(anchorView)
.setAction(R.string.action_undo, (View v) -> {
final var undoLiveData = mainViewModel.addNoteAndSync(dbNote);
undoLiveData.observe(lifecycleOwner, (o) -> undoLiveData.removeObservers(lifecycleOwner));
BrandedSnackbar.make(view, context.getString(R.string.action_note_restored, dbNote.getTitle()), Snackbar.LENGTH_SHORT)
.setAnchorView(anchorView)
.show();
})
.show();
});
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/dialog_change_category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacer_1x"
android:hint="@string/change_category_title"
android:hint="@string/category_name"
android:labelFor="@id/search">

<com.google.android.material.textfield.TextInputEditText
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
~ SPDX-License-Identifier: GPL-3.0-or-later
-->
<resources>
<item name="action_favorite" type="id"/>
<item name="action_unfavorite" type="id"/>
<item name="action_edit_category" type="id"/>
<item name="action_see_details" type="id"/>
<item name="action_send_share" type="id"/>
<item name="action_delete" type="id"/>
</resources>
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<string name="search_in_category">Search in %1$s</string>
<string name="search_in_all">Search all notes</string>

<string name="change_category_title">Choose a category</string>
<string name="category_name">Category name</string>

<!-- UsersAndGroupsSearchProvider -->
<string name="users_and_groups_search_provider_authority">com.nextcloud.android.providers.UsersAndGroupsSearchProvider</string>
Expand Down Expand Up @@ -567,5 +567,9 @@

<string name="action_see_details">Details</string>
<string name="action_send_share">Send/share</string>
<string name="action_favorite">Add to favorites</string>
<string name="action_unfavorite">Remove from favorites</string>
<string name="action_edit_category">Edit category</string>
<string name="action_delete_note">Delete note</string>

</resources>
Loading