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);
}
});
}
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()));
}
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);
}
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();
}
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();
}
Aggregations