项目作者: Commit451

项目描述 :
RecyclerView Adapter for Firebase Firestore
高级语言: Kotlin
项目地址: git://github.com/Commit451/FirestoreAdapter.git
创建时间: 2018-01-02T23:15:31Z
项目社区:https://github.com/Commit451/FirestoreAdapter

开源协议:Apache License 2.0

下载


FirestoreAdapter

Build Status

RecyclerView Adapter for Firebase Firestore

Usage

Start by subclassing FirestoreAdapter:

  1. class ItemAdapter(creator: QueryCreator) : FirestoreAdapter<State, ItemViewHolder>(State::class.java, creator) {
  2. override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
  3. return ItemViewHolder.inflate(parent)
  4. }
  5. override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
  6. holder.bind(get(position))
  7. }
  8. }

Usage will look like so:

  1. val firestore = FirebaseFirestore.getInstance()
  2. val ref = firestore.collection("states")
  3. adapter = ItemAdapter({
  4. ref.limit(10)
  5. .orderBy("name")
  6. })
  7. val list = findViewById<RecyclerView>(R.id.list)
  8. val layoutManager = LinearLayoutManager(this)
  9. list.adapter = adapter
  10. list.layoutManager = layoutManager
  11. //this allows for endless scrolling
  12. adapter.setupOnScrollListener(list, layoutManager)

Limitations

  • Items added to a collection after queries have been started will always be added to the bottom of the list. This is due to the fact that we cannot know which query the document change originates from.
  • If an items position changes in the list, it will not update, only the data will. We cannot associate the changed item with the right spot in the list since it differs from the spot in the query

License

  1. Copyright 2018 Commit 451
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.