diff --git a/app/src/main/java/com/example/citrusclient/views/MyBookshelfFragment.java b/app/src/main/java/com/example/citrusclient/views/MyBookshelfFragment.java index d216d81..5bbb9ca 100644 --- a/app/src/main/java/com/example/citrusclient/views/MyBookshelfFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/MyBookshelfFragment.java @@ -107,14 +107,14 @@ String accountId = citrus.getAccountId(); bookList = new ArrayList<>(); - bookList.add(new Book("a", 1, "a", true, "0")); + bookList.add(new Book("a", 1, "a", true, "#ff0000")); RecyclerView recyclerView = view.findViewById(R.id.my_books_list); recyclerView.setHasFixedSize(true); RecyclerView.LayoutManager layoutManager = new GridLayoutManager(view.getContext(), 2); //new LinearLayoutManager(view.getContext()); recyclerView.setLayoutManager(layoutManager); - RecyclerView.Adapter bookAdapter = new MyBookshelfAdapter(bookList); + MyBookshelfAdapter bookAdapter = new MyBookshelfAdapter(bookList); recyclerView.setAdapter(bookAdapter); FloatingActionButton addButton = view.findViewById(R.id.book_add_button); @@ -126,7 +126,7 @@ @Override public void onChanged(HashMap integerBookHashMap) { bookList = new ArrayList<>(integerBookHashMap.values()); - bookAdapter.notifyDataSetChanged(); + bookAdapter.setBooks(bookList); } }); @@ -145,6 +145,11 @@ this.bookList = book; } + public void setBooks(List books){ + bookList = books; + notifyDataSetChanged(); + } + @NonNull @Override public MyBookViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -156,7 +161,11 @@ public void onBindViewHolder(@NonNull MyBookViewHolder holder, int position) { Book bookData = this.bookList.get(position); holder.bookButton.setText(bookData.getTitle()); - holder.bookButton.setBackgroundColor(Color.RED); + int red = Integer.parseInt(bookData.getColor().substring(1, 3), 16); + int green = Integer.parseInt(bookData.getColor().substring(3, 5), 16); + int blue = Integer.parseInt(bookData.getColor().substring(5, 7), 16); + holder.bookButton.setBackgroundColor(Color.rgb(red, green, blue)); + holder.bookButton.setTextColor(Color.rgb(255 - red, 255 - green, 255 - blue)); } @Override