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 f3511a1..3ebfb26 100644 --- a/app/src/main/java/com/example/citrusclient/views/MyBookshelfFragment.java +++ b/app/src/main/java/com/example/citrusclient/views/MyBookshelfFragment.java @@ -1,5 +1,7 @@ package com.example.citrusclient.views; +import android.app.Activity; +import android.content.Context; import android.graphics.Color; import android.media.Image; import android.os.Bundle; @@ -115,7 +117,7 @@ RecyclerView.LayoutManager layoutManager = new GridLayoutManager(view.getContext(), 2); //new LinearLayoutManager(view.getContext()); recyclerView.setLayoutManager(layoutManager); - MyBookshelfAdapter bookAdapter = new MyBookshelfAdapter(bookList, citrus); + MyBookshelfAdapter bookAdapter = new MyBookshelfAdapter(bookList, getActivity()); recyclerView.setAdapter(bookAdapter); FloatingActionButton addButton = view.findViewById(R.id.book_add_button); @@ -141,11 +143,11 @@ class MyBookshelfAdapter extends RecyclerView.Adapter{ private List bookList; - private Citrus citrus; + private Context context; - MyBookshelfAdapter(List book, Citrus citrus){ + MyBookshelfAdapter(List book, Context context){ this.bookList = book; - this.citrus = citrus; + this.context = context; } public void setBooks(List books){ @@ -171,9 +173,13 @@ holder.bookButton.setTextColor(Color.rgb(255 - red, 255 - green, 255 - blue)); holder.bookButton.setOnClickListener(v -> { Calendar c = Calendar.getInstance(); + Activity activity = (Activity) context; + Citrus citrus = (Citrus) activity.getApplication(); citrus.setCurYear(c.get(Calendar.YEAR)); citrus.setCurMonth(c.get(Calendar.MONTH) + 1); citrus.setCurDay(c.get(Calendar.DATE)); + ((MainActivity) activity).showFragment(new HomeFragment()); + }); }