forked from Ijaiswalshivam/Talk-In
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got an issue at line 17 of MainActivity while working on Ijaiswalshiv…
- Loading branch information
1 parent
ed7f6e3
commit 0f68745
Showing
6 changed files
with
115 additions
and
64 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
50 changes: 50 additions & 0 deletions
50
TalkIn/app/src/main/java/com/example/talk_in/MainViewModel.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.example.talk_in | ||
|
||
import android.widget.Toast | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import com.example.talk_in.databinding.ActivityMainBinding | ||
import com.google.firebase.auth.FirebaseAuth | ||
import com.google.firebase.database.DataSnapshot | ||
import com.google.firebase.database.DatabaseError | ||
import com.google.firebase.database.DatabaseReference | ||
import com.google.firebase.database.FirebaseDatabase | ||
import com.google.firebase.database.ValueEventListener | ||
|
||
class MainViewModel { | ||
private val _userList = MutableLiveData<List<User>>() | ||
val userList: LiveData<List<User>> get()=_userList | ||
|
||
private val mAuth: FirebaseAuth=FirebaseAuth.getInstance() | ||
private val mDbRef: DatabaseReference=FirebaseDatabase.getInstance().reference | ||
|
||
init { | ||
fetchUsers() | ||
} | ||
|
||
// Firebase Fetch | ||
|
||
private fun fetchUsers(){ | ||
mDbRef.child("user").addValueEventListener(object :ValueEventListener{ | ||
override fun onDataChange(snapshot: DataSnapshot) { | ||
val tempList = mutableListOf<User>() | ||
for (postSnapshot in snapshot.children){ | ||
val currentUser =postSnapshot.getValue(User::class.java) | ||
if (currentUser != null && mAuth.currentUser?.uid !=currentUser.uid&¤tUser.verified==true){ | ||
tempList.add(currentUser) | ||
} | ||
} | ||
_userList.value=tempList | ||
} | ||
|
||
override fun onCancelled(error: DatabaseError) { | ||
|
||
} | ||
}) | ||
|
||
} | ||
fun filterList(query: String):List<User>{ | ||
return _userList.value?.filter { it.name?.startsWith(query,ignoreCase = true)==true }?: emptyList() | ||
} | ||
|
||
} |
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