This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mDatabase = FirebaseDatabase.getInstance() | |
mPersonTable = mDatabase.getReference("Person") | |
btn_subscribe.setOnClickListener { | |
progressBarStyle.visibility = ProgressBar.VISIBLE | |
val valueEventListener = object : ValueEventListener { | |
override fun onCancelled(databaseError: DatabaseError) {} | |
override fun onDataChange(dataSnapshot: DataSnapshot) { | |
progressBarStyle.visibility = ProgressBar.INVISIBLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implementation 'com.google.firebase:firebase-firestore:17.1.5' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PersonFirestoredapter(private val context: Context, | |
private val people: List<Person>) : | |
RecyclerView.Adapter<PersonFirestoredapter.Holder>() { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder { | |
val layoutInflater = LayoutInflater.from(context) | |
val view = layoutInflater.inflate(R.layout.layout_list_subscribers, | |
parent, false) | |
return Holder(view, people, context) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mPeople: ArrayList<Person> = ArrayList() | |
var mAdapter: PersonFirestoredapter = PersonFirestoredapter(this, mPeople) | |
var mRecyclerView: RecyclerView = findViewById(R.id.rv) | |
mRecyclerView.setHasFixedSize(true) | |
mRecyclerView.layoutManager = LinearLayoutManager(this) | |
var db: FirebaseFirestore = FirebaseFirestore.getInstance() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.collection("Person").get().addOnSuccessListener { query -> | |
if (!query.isEmpty) { | |
val list = query.documents | |
for (d in list) { | |
val person: Person? = d.toObject(Person::class.java) | |
if (person != null) { | |
person.id = d.id | |
mPeople.add(person) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Holder( | |
itemView: View, | |
val people: List<Person>, | |
val context: Context) : RecyclerView.ViewHolder(itemView), | |
View.OnClickListener { | |
val name: TextView = itemView.findViewById(R.id.list_name) | |
val email: TextView = itemView.findViewById(R.id.list_email) | |
val phone: TextView = itemView.findViewById(R.id.list_phone) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.collection("Person").document(personExtra.id!!).delete().addOnSuccessListener { | |
"Person was deleted.".toast(this@UpdateFirestoreActivity) | |
finish() | |
}.addOnFailureListener { exception -> | |
"Error: ${exception.message}".toast(this@UpdateFirestoreActivity) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var db: FirebaseFirestore = FirebaseFirestore.getInstance() | |
var personExtra = intent.getSerializableExtra("Person") as Person | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
etName_firestore_update.text.append(personExtra.name) | |
etEmail_firestore_update.text.append(personExtra.email) | |
etPhone_firestore_update.text.append(personExtra.phone) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.collection("Person").document(personExtra.id!!) | |
.update("name",etName_firestore_update.text) | |
.addOnSuccessListener { | |
"Updated Successful.".toast(this@UpdateFirestoreActivity) | |
finish() | |
startActivity(Intent(this, FirestoreListActivity::class.java)) | |
progressBarStyle.visibility = ProgressBar.INVISIBLE | |
}.addOnFailureListener { exception -> |
OlderNewer