friendAdapter : UserAdapter ?= null
private var friendList : ArrayList<UserModel> ?= null
private var friendRecyclerView : RecyclerView ?= null
private lateinit var dataRef : FirebaseDatabase
private lateinit var mAuth : FirebaseAuth
private lateinit var storageRef : FirebaseStorage
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mAuth = FirebaseAuth.getInstance()
storageRef = FirebaseStorage.getInstance()
dataRef = FirebaseDatabase.getInstance()
}
@SuppressLint("MissingInflatedId")
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val view = inflater.inflate(R.layout.fragment_profile, container, false)
val userID = FirebaseAuth.getInstance().currentUser!!.uid
dataRef.reference.child("Users").child(userID).addValueEventListener(object : ValueEventListener{
override fun onDataChange(dataSnapshot: DataSnapshot) {
if (dataSnapshot.exists()){
val user = dataSnapshot.getValue(UserModel :: class.java)
val cover_photo = view.findViewById<ImageView>(R.id.cover_photo)
val userName = view.findViewById<TextView>(R.id.userName)
val profession = view.findViewById<TextView>(R.id.profession)
val profile_image_profile = view?.findViewById<ImageView>(R.id.profile_image_profile)
userName.text = user!!.getName()
profession.text = user.getProfession()
Picasso.get().load(user.getCoverPhoto()).placeholder(R.drawable.child).into(cover_photo)
Picasso.get().load(user.getProfilePhoto()).placeholder(R.drawable.profile).into(profile_image_profile)
}
}
override fun onCancelled(error: DatabaseError) {
}
})
friendList = ArrayList()
friendAdapter = context?.let { UserAdapter(it, friendList as ArrayList<UserModel>) }
val linearLayoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
friendRecyclerView = view.findViewById(R.id.friend_RV)
friendRecyclerView!!.layoutManager = linearLayoutManager
friendRecyclerView!!.adapter = friendAdapter
dataRef.reference.child("Follow")
.child(mAuth.uid!!)
.child("Followers").addValueEventListener(object : ValueEventListener{
override fun onCancelled(error: DatabaseError) {}
@SuppressLint("SuspiciousIndentation")
override fun onDataChange(dataSnapshot: DataSnapshot) {
for (snapshot in dataSnapshot.children){
val user = snapshot.getValue(UserModel :: class.java)
if (user!= null)
user.setUserID(snapshot.key.toString())
user?.let { friendList!!.add(it) }
}
friendAdapter?.notifyDataSetChanged()
}
})
val changeCoverPhoto: ImageView = view.findViewById(R.id.change_cover_photo)
val verifyAccount : ImageView = view.findViewById(R.id.verifyAccaunt)
verifyAccount.setOnClickListener {
startActivityForResult( 22)
}
changeCoverPhoto.setOnClickListener {
startActivityForResult(11)
}
countFollowers()
countFollowings()
return view
}
private fun countFollowings() {
}
private fun countFollowers() {
}
@Deprecated("Deprecated in Java")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
val userID = FirebaseAuth.getInstance().currentUser!!.uid
Оберните код в теги: 3 символа ` до и после кода (в случае одиночной конструкции достаточно 1 ` с обеих сторон). Спасибо!
Обсуждают сегодня