| |
---|
| | String token = citrus.getToken(); |
---|
| | 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); |
---|
| | addButton.setOnClickListener(v -> { |
---|
| |
---|
| | booksViewModel.getBookLiveData().observe(getViewLifecycleOwner(), new Observer<HashMap<Integer, Book>>() { |
---|
| | @Override |
---|
| | public void onChanged(HashMap<Integer, Book> integerBookHashMap) { |
---|
| | bookList = new ArrayList<>(integerBookHashMap.values()); |
---|
| | bookAdapter.notifyDataSetChanged(); |
---|
| | bookAdapter.setBooks(bookList); |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | booksViewModel.loadBooks("bird", "xyz"); |
---|
| |
---|
| | MyBookshelfAdapter(List<Book> book){ |
---|
| | this.bookList = book; |
---|
| | } |
---|
| | |
---|
| | public void setBooks(List<Book> books){ |
---|
| | bookList = books; |
---|
| | notifyDataSetChanged(); |
---|
| | } |
---|
| | |
---|
| | @NonNull |
---|
| | @Override |
---|
| | public MyBookViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { |
---|
| | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.a_book, parent, false); |
---|
| |
---|
| | @Override |
---|
| | 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 |
---|
| | public int getItemCount() { |
---|
| |
---|
| | |