diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-05-08 15:49:47 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-05-08 15:49:47 +0300 |
commit | 8dac2606c421fe9060f3155e594da3d82ade3fb5 (patch) | |
tree | ad9fab793d8be72386e94d302147b5957d1ba429 /app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards | |
parent | 5fc9af847128af63d82912a2ef983d8e4df9f23e (diff) |
Archived boards
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards')
3 files changed, 137 insertions, 0 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 new file mode 100644 index 000000000..1ccd4679d --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardViewHolder.java @@ -0,0 +1,19 @@ +package it.niedermann.nextcloud.deck.ui.archivedboards; + +import androidx.recyclerview.widget.RecyclerView; + +import it.niedermann.nextcloud.deck.databinding.ItemArchivedBoardBinding; +import it.niedermann.nextcloud.deck.model.Board; + +public class ArchivedBoardViewHolder extends RecyclerView.ViewHolder { + + ItemArchivedBoardBinding binding; + + public ArchivedBoardViewHolder(ItemArchivedBoardBinding binding) { + super(binding.getRoot()); + } + + void bind(Board board) { + binding.boardTitle.setText(board.getTitle()); + } +} 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 new file mode 100644 index 000000000..fec1f7ec4 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsActvitiy.java @@ -0,0 +1,67 @@ +package it.niedermann.nextcloud.deck.ui.archivedboards; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import it.niedermann.nextcloud.deck.databinding.ActivityArchivedCardsBinding; +import it.niedermann.nextcloud.deck.model.Account; +import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; +import it.niedermann.nextcloud.deck.ui.branding.BrandedActivity; +import it.niedermann.nextcloud.deck.ui.exception.ExceptionHandler; + +public class ArchivedBoardsActvitiy extends BrandedActivity { + + private static final String BUNDLE_KEY_ACCOUNT = "accountId"; + + private ActivityArchivedCardsBinding binding; + private ArchivedBoardsAdapter adapter; + private SyncManager syncManager; + + private Account account; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); + + final Bundle args = getIntent().getExtras(); + if (args == null || !args.containsKey(BUNDLE_KEY_ACCOUNT)) { + throw new IllegalArgumentException("Please provide at least " + BUNDLE_KEY_ACCOUNT); + } + + this.account = (Account) args.getSerializable(BUNDLE_KEY_ACCOUNT); + + if (this.account == null) { + throw new IllegalArgumentException(BUNDLE_KEY_ACCOUNT + " must not be null."); + } + + binding = ActivityArchivedCardsBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + setSupportActionBar(binding.toolbar); + + syncManager = new SyncManager(this); + + adapter = new ArchivedBoardsAdapter(); + binding.recyclerView.setAdapter(adapter); + + syncManager.getBoards(account.getId(), true).observe(this, (boards) -> adapter.setBoards(boards)); + + } + + @Override + public void applyBrand(int mainColor, int textColor) { + applyBrandToPrimaryToolbar(mainColor, textColor, binding.toolbar); + } + + @NonNull + public static Intent createIntent(@NonNull Context context, @NonNull Account account) { + return new Intent(context, ArchivedBoardsActvitiy.class) + .putExtra(BUNDLE_KEY_ACCOUNT, account) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + } +} 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 new file mode 100644 index 000000000..4df0c1cab --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/archivedboards/ArchivedBoardsAdapter.java @@ -0,0 +1,51 @@ +package it.niedermann.nextcloud.deck.ui.archivedboards; + +import android.view.LayoutInflater; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.ArrayList; +import java.util.List; + +import it.niedermann.nextcloud.deck.databinding.ItemArchivedBoardBinding; +import it.niedermann.nextcloud.deck.model.Board; + +public class ArchivedBoardsAdapter extends RecyclerView.Adapter<ArchivedBoardViewHolder> { + + @NonNull + private List<Board> boards = new ArrayList<>(); + + @SuppressWarnings("WeakerAccess") + public ArchivedBoardsAdapter() { + setHasStableIds(true); + } + + @NonNull + @Override + public ArchivedBoardViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new ArchivedBoardViewHolder(ItemArchivedBoardBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false)); + } + + @Override + public long getItemId(int position) { + return boards.get(position).getLocalId(); + } + + @Override + public void onBindViewHolder(@NonNull ArchivedBoardViewHolder holder, int position) { + holder.bind(boards.get(position)); + } + + @Override + public int getItemCount() { + return boards.size(); + } + + public void setBoards(@NonNull List<Board> boards) { + this.boards.clear(); + this.boards.addAll(boards); + notifyDataSetChanged(); + } +} |