Support
Quality
Security
License
Reuse
kandi has reviewed GravitySnapHelper and discovered the below as its top functions. This is intended to give you an instant insight into GravitySnapHelper implemented functionality, and help decide if they suit your requirements.
setMaxFlingDistance or setMaxFlingSizeFraction - changes the max fling distance allowed.
setScrollMsPerInch - changes the scroll speed.
setGravity - changes the gravity of the SnapHelper.
setSnapToPadding - enables snapping to padding (default is false)
smoothScrollToPosition and scrollToPosition
RTL support out of the box
Setup
implementation 'com.github.rubensousa:gravitysnaphelper:2.2.1'
How to use
val snapHelper = GravitySnapHelper(Gravity.START)
snapHelper.attachToRecyclerView(recyclerView)
Start snapping
val snapHelper = GravitySnapHelper(Gravity.START)
snapHelper.attachToRecyclerView(recyclerView)
Center snapping
val snapHelper = GravitySnapHelper(Gravity.CENTER)
snapHelper.attachToRecyclerView(recyclerView)
License
Copyright 2018 The Android Open Source Project
Copyright 2019 Rúben Sousa
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
How to show a subСollection when navigating to a specific document in Firestore
private final FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
private final CollectionReference collectionReference = firebaseFirestore
.collection("Items")
.document("TurnKeyFactory")
.collection("TheKeyOpens");
private final CollectionReference collectionReference = firebaseFirestore
.collection("Items")
.document("Factory exit key(Factory)")
.collection("TheKeyOpens");
-----------------------
private final FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
private final CollectionReference collectionReference = firebaseFirestore
.collection("Items")
.document("TurnKeyFactory")
.collection("TheKeyOpens");
private final CollectionReference collectionReference = firebaseFirestore
.collection("Items")
.document("Factory exit key(Factory)")
.collection("TheKeyOpens");
RecyclerView PagerSnapHelper Snap on Start/Top instead of center Android
// remember to initialize snaphelper
snapHelper = object : GravitySnapHelper(Gravity.TOP){
override fun findTargetSnapPosition(
layoutManager: RecyclerView.LayoutManager,
velocityX: Int,
velocityY: Int
): Int {
val centerView = findSnapView(layoutManager) ?: return RecyclerView.NO_POSITION
val position = layoutManager.getPosition(centerView)
var targetPosition = -1
if (layoutManager.canScrollHorizontally()) {
targetPosition = if (velocityX < 0) {
position - 1
} else {
position + 1
}
}
if (layoutManager.canScrollVertically()) {
// Log.d("debug", "velocityY $velocityY")
targetPosition = if (velocityY < 0) {
position - 1
} else {
position + 1
}
}
val firstItem = 0
val lastItem = layoutManager.itemCount - 1
targetPosition = Math.min(lastItem, Math.max(targetPosition, firstItem))
return targetPosition
}
}
// lower the value higher the speed of scroll
// default is 100f
snapHelper.scrollMsPerInch = 40f
snapHelper.attachToRecyclerView(binding?.yourRecyclerView)
QUESTION
How to show a subСollection when navigating to a specific document in Firestore
Asked 2021-Apr-20 at 05:54I have a collection on Firestore inside it there are documents, they are displayed in the RecyclerView
in my application, how can I make it so that when this document is clicked, its subcollection opens?
When you click on a document, the following happens:
private FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
private final CollectionReference collectionReference = firebaseFirestore.collection("Items");
AdapterFactoryKeysSnap adapterFactoryKeysSnap;
RecyclerView rv_keys_factory;
RecyclerView.LayoutManager RLM_keys_factory;
ProgressBar pb_keys_factory;
private void RecyclerViewFactory() {
Query query = collectionReference.orderBy("TurnKeyFactory", Query.Direction.DESCENDING);
FirestoreRecyclerOptions<ItemKeys> firestoreRecyclerOptions = new FirestoreRecyclerOptions.Builder<ItemKeys>()
.setQuery(query, ItemKeys.class).build();
adapterFactoryKeysSnap = new AdapterFactoryKeysSnap((ClickKeysBlanc) getContext(), getContext(), firestoreRecyclerOptions);
rv_keys_factory = requireView().findViewById(R.id.rv_keys_factory);
RLM_keys_factory = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
SnapHelper snapHelper = new GravitySnapHelper(Gravity.START);
snapHelper.attachToRecyclerView(rv_keys_factory);
rv_keys_factory.setHasFixedSize(false);
rv_keys_factory.setLayoutManager(RLM_keys_factory);
rv_keys_factory.setNestedScrollingEnabled(true);
rv_keys_factory.setAdapter(adapterFactoryKeysSnap);
adapterFactoryKeysSnap.startListening();
pb_keys_factory = requireView().findViewById(R.id.pb_keys_factory);
Objects.requireNonNull(rv_keys_factory.getAdapter()).setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY);
pb_keys_factory.setVisibility(View.GONE);
}
The application understands which document was clicked due to "TurnKeyFactory". Inside this document is a subСollection called "TheKeyOpens".
I found a way to implement what was conceived inside this document, I write the following
"Factory exit key(Factory)"- name document
private final FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
private final CollectionReference collectionReference = firebaseFirestore.collection("Items").document("Factory exit key(Factory)").collection("TheKeyOpens");
The whole problem is that after I write this, it appears in all documents of the main collection, not in the specific selected.
I thought that if my application opens the selected document by "TurnKeyFactory" it will work if I write like this:
private final FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
private final CollectionReference collectionReference = firebaseFirestore.collection("Items").document("TurnKeyFactory").collection("TheKeyOpens");
But it didn't work.Help solve the problem.
Need to
Items->
- Factory exit key(Factory)->
- TheKeyOpens->
-TheKeyOpens 1
-TheKeyOpens 2
-TheKeyOpens 3
- TurnKeyFactory: “1”
- Factory exit key(Customs)->
- TheKeyOpens->
-TheKeyOpens 1
-TheKeyOpens 2
-TheKeyOpens 3
- TurnKeyFactory: “2”
ANSWER
Answered 2021-Apr-20 at 05:54I thought that if my application opens the selected document by "TurnKeyFactory" it will work if I write like this:
private final FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
private final CollectionReference collectionReference = firebaseFirestore
.collection("Items")
.document("TurnKeyFactory")
.collection("TheKeyOpens");
This reference doesn't work because you are passing an incorrect ID to the document() method. The ID of the document should be "Factory exit key(Factory)" as seen in the screenshot and not "TurnKeyFactory" as you actually added. In order to make it work, please use the following reference:
private final CollectionReference collectionReference = firebaseFirestore
.collection("Items")
.document("Factory exit key(Factory)")
.collection("TheKeyOpens");
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
No vulnerabilities reported
Save this library and start creating your kit
Explore Related Topics
Save this library and start creating your kit