package code.abdulrahman.bookStore;

import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public class BookTitleAndDescriptionlFragment extends Fragment {
    int position = 0;
    TextView booktitle;
    TextView bookDetails;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (savedInstanceState == null) {
            // Get back arguments
            if (getArguments() != null) {
                position = getArguments().getInt("position", 0);
            }
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater,
                             @Nullable ViewGroup parent, @Nullable Bundle savedInstanceState) {
        // Inflate the xml file for the fragment
        return inflater.inflate(R.layout.fragment_book_title_and_descriptionl, parent, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        // Set values for view here
        booktitle = view.findViewById(R.id.bookTitle);
        bookDetails = view.findViewById(R.id.bookDetails);
        bookDetails.setMovementMethod(new ScrollingMovementMethod());
        // update view
        booktitle.setText(Book.bookList[position]);
        bookDetails.setText(Book.BookDescription[position]);
    }
    // Activity is calling this to update view on Fragment
    public void updateView(int position) {
        booktitle.setText(Book.bookList[position]);
        bookDetails.setText(Book.BookDescription[position]);
    }
}
