Search in sources :

Example 41 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project Cangol-uiframe by Cangol.

the class RecyclerViewFragment method initViews.

@Override
protected void initViews(Bundle savedInstanceState) {
    this.setTitle(this.getClass().getSimpleName());
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
    mRecyclerView.setAdapter(mDataAdapter);
    mRecyclerView.setNestedScrollingEnabled(false);
    mDataAdapter.setOnItemClickListener(new DataAdapter.OnItemClickListener() {

        @Override
        public void onItemClicked(View view, int position) {
            String name = mDataAdapter.getItem(position);
            Bundle bundle = new Bundle();
            bundle.putString("flag", name);
            setContentFragment(ItemFragment.class, "ItemFragment_" + name, bundle);
        }
    });
}
Also used : Bundle(android.os.Bundle) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NestedScrollView(androidx.core.widget.NestedScrollView) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 42 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project BlurView by Dimezis.

the class ListFragment method init.

private void init() {
    RecyclerView recyclerView = getView().findViewById(R.id.recyclerView);
    recyclerView.setAdapter(new ExampleListAdapter(getContext()));
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 43 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project quickstart-android by firebase.

the class PostListFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    // Set up Layout Manager, reverse layout
    mManager = new LinearLayoutManager(getActivity());
    mManager.setReverseLayout(true);
    mManager.setStackFromEnd(true);
    mRecycler.setLayoutManager(mManager);
    // Set up FirebaseRecyclerAdapter with the Query
    Query postsQuery = getQuery(mDatabase);
    FirebaseRecyclerOptions options = new FirebaseRecyclerOptions.Builder<Post>().setQuery(postsQuery, Post.class).build();
    mAdapter = new FirebaseRecyclerAdapter<Post, PostViewHolder>(options) {

        @Override
        public PostViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
            LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
            return new PostViewHolder(inflater.inflate(R.layout.item_post, viewGroup, false));
        }

        @Override
        protected void onBindViewHolder(PostViewHolder viewHolder, int position, final Post model) {
            final DatabaseReference postRef = getRef(position);
            // Set click listener for the whole post view
            final String postKey = postRef.getKey();
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // Launch PostDetailFragment
                    NavController navController = Navigation.findNavController(requireActivity(), R.id.nav_host_fragment);
                    Bundle args = new Bundle();
                    args.putString(PostDetailFragment.EXTRA_POST_KEY, postKey);
                    navController.navigate(R.id.action_MainFragment_to_PostDetailFragment, args);
                }
            });
            // Determine if the current user has liked this post and set UI accordingly
            if (model.stars.containsKey(getUid())) {
                viewHolder.starView.setImageResource(R.drawable.ic_toggle_star_24);
            } else {
                viewHolder.starView.setImageResource(R.drawable.ic_toggle_star_outline_24);
            }
            // Bind Post to ViewHolder, setting OnClickListener for the star button
            viewHolder.bindToPost(model, new View.OnClickListener() {

                @Override
                public void onClick(View starView) {
                    // Need to write to both places the post is stored
                    DatabaseReference globalPostRef = mDatabase.child("posts").child(postRef.getKey());
                    DatabaseReference userPostRef = mDatabase.child("user-posts").child(model.uid).child(postRef.getKey());
                    // Run two transactions
                    onStarClicked(globalPostRef);
                    onStarClicked(userPostRef);
                }
            });
        }
    };
    mRecycler.setAdapter(mAdapter);
}
Also used : FirebaseRecyclerOptions(com.firebase.ui.database.FirebaseRecyclerOptions) PostViewHolder(com.google.firebase.quickstart.database.java.viewholder.PostViewHolder) Query(com.google.firebase.database.Query) DatabaseReference(com.google.firebase.database.DatabaseReference) Post(com.google.firebase.quickstart.database.java.models.Post) ViewGroup(android.view.ViewGroup) Bundle(android.os.Bundle) NavController(androidx.navigation.NavController) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) LayoutInflater(android.view.LayoutInflater)

Example 44 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project quickstart-android by firebase.

the class MainFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mBinding.filterBar.setOnClickListener(this);
    mBinding.buttonClearFilter.setOnClickListener(this);
    // View model
    mViewModel = new ViewModelProvider(this).get(MainActivityViewModel.class);
    // Enable Firestore logging
    FirebaseFirestore.setLoggingEnabled(true);
    // Firestore
    mFirestore = FirebaseFirestore.getInstance();
    // Get ${LIMIT} restaurants
    mQuery = mFirestore.collection("restaurants").orderBy("avgRating", Query.Direction.DESCENDING).limit(LIMIT);
    // RecyclerView
    mAdapter = new RestaurantAdapter(mQuery, this) {

        @Override
        protected void onDataChanged() {
            // Show/hide content if the query returns empty.
            if (getItemCount() == 0) {
                mBinding.recyclerRestaurants.setVisibility(View.GONE);
                mBinding.viewEmpty.setVisibility(View.VISIBLE);
            } else {
                mBinding.recyclerRestaurants.setVisibility(View.VISIBLE);
                mBinding.viewEmpty.setVisibility(View.GONE);
            }
        }

        @Override
        protected void onError(FirebaseFirestoreException e) {
            // Show a snackbar on errors
            Snackbar.make(mBinding.getRoot(), "Error: check logs for info.", Snackbar.LENGTH_LONG).show();
        }
    };
    mBinding.recyclerRestaurants.setLayoutManager(new LinearLayoutManager(requireContext()));
    mBinding.recyclerRestaurants.setAdapter(mAdapter);
    // Filter Dialog
    mFilterDialog = new FilterDialogFragment();
}
Also used : MainActivityViewModel(com.google.firebase.example.fireeats.java.viewmodel.MainActivityViewModel) FirebaseFirestoreException(com.google.firebase.firestore.FirebaseFirestoreException) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RestaurantAdapter(com.google.firebase.example.fireeats.java.adapter.RestaurantAdapter) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 45 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project quickstart-android by firebase.

the class RestaurantDetailFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mBinding.restaurantButtonBack.setOnClickListener(this);
    mBinding.fabShowRatingDialog.setOnClickListener(this);
    String restaurantId = RestaurantDetailFragmentArgs.fromBundle(getArguments()).getKeyRestaurantId();
    // Initialize Firestore
    mFirestore = FirebaseFirestore.getInstance();
    // Get reference to the restaurant
    mRestaurantRef = mFirestore.collection("restaurants").document(restaurantId);
    // Get ratings
    Query ratingsQuery = mRestaurantRef.collection("ratings").orderBy("timestamp", Query.Direction.DESCENDING).limit(50);
    // RecyclerView
    mRatingAdapter = new RatingAdapter(ratingsQuery) {

        @Override
        protected void onDataChanged() {
            if (getItemCount() == 0) {
                mBinding.recyclerRatings.setVisibility(View.GONE);
                mBinding.viewEmptyRatings.setVisibility(View.VISIBLE);
            } else {
                mBinding.recyclerRatings.setVisibility(View.VISIBLE);
                mBinding.viewEmptyRatings.setVisibility(View.GONE);
            }
        }
    };
    mBinding.recyclerRatings.setLayoutManager(new LinearLayoutManager(requireContext()));
    mBinding.recyclerRatings.setAdapter(mRatingAdapter);
    mRatingDialog = new RatingDialogFragment();
}
Also used : Query(com.google.firebase.firestore.Query) RatingAdapter(com.google.firebase.example.fireeats.java.adapter.RatingAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)470 RecyclerView (androidx.recyclerview.widget.RecyclerView)281 View (android.view.View)183 TextView (android.widget.TextView)65 ArrayList (java.util.ArrayList)37 Nullable (androidx.annotation.Nullable)33 Bundle (android.os.Bundle)32 Toolbar (androidx.appcompat.widget.Toolbar)32 Intent (android.content.Intent)30 ImageView (android.widget.ImageView)27 List (java.util.List)24 Test (org.junit.Test)24 Context (android.content.Context)23 NonNull (androidx.annotation.NonNull)23 ViewGroup (android.view.ViewGroup)22 AlertDialog (androidx.appcompat.app.AlertDialog)21 ContextualCard (com.android.settings.homepage.contextualcards.ContextualCard)20 LayoutInflater (android.view.LayoutInflater)18 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)16 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)16