diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-05-09 12:32:18 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-05-09 12:32:18 +0300 |
commit | 06404d6e81a2dd1daded266784729a87a947aad0 (patch) | |
tree | dd3966882d448c6166f5f70f91618f747b520e9d /app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards | |
parent | 3f857534e6e65eaab778ff81723a2b79bb0d112a (diff) |
Actions for archived boards
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards')
3 files changed, 94 insertions, 6 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardViewHolder.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardViewHolder.java index de82d2707..03d125f6b 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardViewHolder.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardViewHolder.java @@ -1,10 +1,21 @@ package it.niedermann.nextcloud.deck.ui.archivedboards; +import android.content.Context; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; + +import androidx.appcompat.widget.PopupMenu; +import androidx.core.util.Consumer; +import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.RecyclerView; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.ItemArchivedBoardBinding; import it.niedermann.nextcloud.deck.model.Board; +import it.niedermann.nextcloud.deck.ui.board.DeleteBoardDialogFragment; +import it.niedermann.nextcloud.deck.ui.board.EditBoardDialogFragment; +import it.niedermann.nextcloud.deck.ui.board.accesscontrol.AccessControlDialogFragment; import it.niedermann.nextcloud.deck.util.ViewUtil; @SuppressWarnings("WeakerAccess") @@ -17,8 +28,47 @@ public class ArchivedBoardViewHolder extends RecyclerView.ViewHolder { this.binding = binding; } - void bind(Board board) { + void bind(Board board, FragmentManager fragmentManager, Consumer<Board> dearchiveBoardListener) { + final Context context = itemView.getContext(); binding.boardIcon.setImageDrawable(ViewUtil.getTintedImageView(binding.boardIcon.getContext(), R.drawable.circle_grey600_36dp, "#" + board.getColor())); + binding.boardMenu.setVisibility(View.GONE); binding.boardTitle.setText(board.getTitle()); + if (board.isPermissionManage()) { + binding.boardMenu.setVisibility(View.VISIBLE); + binding.boardMenu.setImageDrawable(ViewUtil.getTintedImageView(context, R.drawable.ic_menu, R.color.grey600)); + + binding.boardMenu.setOnClickListener((v) -> { + PopupMenu popup = new PopupMenu(context, binding.boardMenu); + popup.getMenuInflater().inflate(R.menu.archived_board_menu, popup.getMenu()); + final int SHARE_BOARD_ID = -1; + if (board.isPermissionShare()) { + popup.getMenu().add(Menu.NONE, SHARE_BOARD_ID, 5, R.string.share_board); + } + popup.setOnMenuItemClickListener((MenuItem item) -> { + final String editBoard = context.getString(R.string.edit_board); + switch (item.getItemId()) { + case SHARE_BOARD_ID: + AccessControlDialogFragment.newInstance(board.getLocalId()).show(fragmentManager, AccessControlDialogFragment.class.getSimpleName()); + return true; + case R.id.edit_board: + EditBoardDialogFragment.newInstance(board.getLocalId()).show(fragmentManager, editBoard); + return true; + case R.id.dearchive_board: + dearchiveBoardListener.accept(board); + return true; + case R.id.delete_board: + DeleteBoardDialogFragment.newInstance(board).show(fragmentManager, DeleteBoardDialogFragment.class.getSimpleName()); + return true; + default: + return false; + } + }); + popup.show(); + }); + } else if (board.isPermissionShare()) { + binding.boardMenu.setVisibility(View.VISIBLE); + binding.boardMenu.setImageDrawable(ViewUtil.getTintedImageView(context, R.drawable.ic_share_grey600_18dp, R.color.grey600)); + binding.boardMenu.setOnClickListener((v) -> AccessControlDialogFragment.newInstance(board.getLocalId()).show(fragmentManager, AccessControlDialogFragment.class.getSimpleName())); + } } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsActvitiy.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsActvitiy.java index 263e4ac85..98789157d 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsActvitiy.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsActvitiy.java @@ -6,17 +6,27 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.lifecycle.ViewModelProvider; + +import java.util.Collections; import it.niedermann.nextcloud.deck.databinding.ActivityArchivedBinding; import it.niedermann.nextcloud.deck.model.Account; +import it.niedermann.nextcloud.deck.model.Board; +import it.niedermann.nextcloud.deck.model.full.FullBoard; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; +import it.niedermann.nextcloud.deck.ui.MainViewModel; +import it.niedermann.nextcloud.deck.ui.board.ArchiveBoardListener; +import it.niedermann.nextcloud.deck.ui.board.DeleteBoardListener; +import it.niedermann.nextcloud.deck.ui.board.EditBoardListener; import it.niedermann.nextcloud.deck.ui.branding.BrandedActivity; import it.niedermann.nextcloud.deck.ui.exception.ExceptionHandler; -public class ArchivedBoardsActvitiy extends BrandedActivity { +public class ArchivedBoardsActvitiy extends BrandedActivity implements DeleteBoardListener, EditBoardListener, ArchiveBoardListener { private static final String BUNDLE_KEY_ACCOUNT = "accountId"; + private MainViewModel viewModel; private ActivityArchivedBinding binding; private ArchivedBoardsAdapter adapter; private SyncManager syncManager; @@ -44,12 +54,17 @@ public class ArchivedBoardsActvitiy extends BrandedActivity { setContentView(binding.getRoot()); setSupportActionBar(binding.toolbar); + viewModel = new ViewModelProvider(this).get(MainViewModel.class); + viewModel.setCurrentAccount(account); syncManager = new SyncManager(this); - adapter = new ArchivedBoardsAdapter(); + adapter = new ArchivedBoardsAdapter(getSupportFragmentManager(), (board) -> syncManager.dearchiveBoard(board)); binding.recyclerView.setAdapter(adapter); - syncManager.getBoards(account.getId(), true).observe(this, (boards) -> adapter.setBoards(boards)); + syncManager.getBoards(account.getId(), true).observe(this, (boards) -> { + viewModel.setCurrentAccountHasArchivedBoards(boards != null && boards.size() > 0); + adapter.setBoards(boards == null ? Collections.emptyList() : boards); + }); } @@ -64,4 +79,19 @@ public class ArchivedBoardsActvitiy extends BrandedActivity { .putExtra(BUNDLE_KEY_ACCOUNT, account) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } + + @Override + public void onBoardDeleted(Board board) { + syncManager.deleteBoard(board); + } + + @Override + public void onUpdateBoard(FullBoard fullBoard) { + syncManager.updateBoard(fullBoard); + } + + @Override + public void onArchive(Board board) { + syncManager.dearchiveBoard(board); + } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsAdapter.java index 4df0c1cab..86a194319 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsAdapter.java @@ -4,6 +4,8 @@ import android.view.LayoutInflater; import android.view.ViewGroup; import androidx.annotation.NonNull; +import androidx.core.util.Consumer; +import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; @@ -15,10 +17,16 @@ import it.niedermann.nextcloud.deck.model.Board; public class ArchivedBoardsAdapter extends RecyclerView.Adapter<ArchivedBoardViewHolder> { @NonNull + private final Consumer<Board> onDearchiveListener; + @NonNull + private final FragmentManager fragmentManager; + @NonNull private List<Board> boards = new ArrayList<>(); @SuppressWarnings("WeakerAccess") - public ArchivedBoardsAdapter() { + public ArchivedBoardsAdapter(@NonNull FragmentManager fragmentManager, @NonNull Consumer<Board> onDearchiveListener) { + this.fragmentManager = fragmentManager; + this.onDearchiveListener = onDearchiveListener; setHasStableIds(true); } @@ -35,7 +43,7 @@ public class ArchivedBoardsAdapter extends RecyclerView.Adapter<ArchivedBoardVie @Override public void onBindViewHolder(@NonNull ArchivedBoardViewHolder holder, int position) { - holder.bind(boards.get(position)); + holder.bind(boards.get(position), fragmentManager, onDearchiveListener); } @Override |