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 3019a14..5bbb9ca 100644 --- a/app/src/main/java/com/example/citrusclient/views/MyBookshelfFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/MyBookshelfFragment.java @@ -90,9 +90,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View rootView = inflater.inflate(R.layout.fragment_my_bookshelf_fragment, container, false); - return rootView; + return inflater.inflate(R.layout.fragment_my_bookshelf_fragment, container, false); } @@ -108,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); @@ -127,7 +126,7 @@ @Override public void onChanged(HashMap integerBookHashMap) { bookList = new ArrayList<>(integerBookHashMap.values()); - bookAdapter.notifyDataSetChanged(); + bookAdapter.setBooks(bookList); } }); @@ -146,6 +145,11 @@ this.bookList = book; } + public void setBooks(List books){ + bookList = books; + notifyDataSetChanged(); + } + @NonNull @Override public MyBookViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -157,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