├── .gitignore ├── .idea ├── .gitignore ├── compiler.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml └── vcs.xml ├── app ├── .gitignore ├── build.gradle ├── google-services.json ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── firebaserecyclerviewkotlin │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── firebaserecyclerviewkotlin │ │ │ ├── MainActivity.kt │ │ │ ├── MyAdapter.kt │ │ │ ├── User.kt │ │ │ └── UserlistActivity.kt │ └── res │ │ ├── drawable-v24 │ │ ├── ic_launcher_foreground.xml │ │ └── shape.png │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_userlist.xml │ │ └── user_item.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── example │ └── firebaserecyclerviewkotlin │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | id 'com.google.gms.google-services' 5 | } 6 | 7 | android { 8 | compileSdkVersion 30 9 | buildToolsVersion "30.0.3" 10 | 11 | defaultConfig { 12 | applicationId "com.example.firebaserecyclerviewkotlin" 13 | minSdkVersion 23 14 | targetSdkVersion 30 15 | versionCode 1 16 | versionName "1.0" 17 | 18 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 19 | } 20 | 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | compileOptions { 28 | sourceCompatibility JavaVersion.VERSION_1_8 29 | targetCompatibility JavaVersion.VERSION_1_8 30 | } 31 | kotlinOptions { 32 | jvmTarget = '1.8' 33 | } 34 | } 35 | 36 | dependencies { 37 | 38 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 39 | implementation 'androidx.core:core-ktx:1.3.2' 40 | implementation 'androidx.appcompat:appcompat:1.2.0' 41 | implementation 'com.google.android.material:material:1.3.0' 42 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 43 | implementation 'com.google.firebase:firebase-database:19.7.0' 44 | testImplementation 'junit:junit:4.+' 45 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 46 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 47 | } -------------------------------------------------------------------------------- /app/google-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_info": { 3 | "project_number": "317372142110", 4 | "firebase_url": "https://relatimedatabase-eee95-default-rtdb.firebaseio.com", 5 | "project_id": "relatimedatabase-eee95", 6 | "storage_bucket": "relatimedatabase-eee95.appspot.com" 7 | }, 8 | "client": [ 9 | { 10 | "client_info": { 11 | "mobilesdk_app_id": "1:317372142110:android:38c52884d57c82804a540f", 12 | "android_client_info": { 13 | "package_name": "com.example.firebaserecyclerviewkotlin" 14 | } 15 | }, 16 | "oauth_client": [ 17 | { 18 | "client_id": "317372142110-kn7ao84mhf6glmdtdtdh2t2ubbgnndj1.apps.googleusercontent.com", 19 | "client_type": 3 20 | } 21 | ], 22 | "api_key": [ 23 | { 24 | "current_key": "AIzaSyDohCuro_SyBBSUBxKq-90i5jADH1N-D9U" 25 | } 26 | ], 27 | "services": { 28 | "appinvite_service": { 29 | "other_platform_oauth_client": [ 30 | { 31 | "client_id": "317372142110-kn7ao84mhf6glmdtdtdh2t2ubbgnndj1.apps.googleusercontent.com", 32 | "client_type": 3 33 | } 34 | ] 35 | } 36 | } 37 | } 38 | ], 39 | "configuration_version": "1" 40 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/firebaserecyclerviewkotlin/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.example.firebaserecyclerviewkotlin 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.example.firebaserecyclerviewkotlin", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/firebaserecyclerviewkotlin/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.firebaserecyclerviewkotlin 2 | 3 | import android.content.Intent 4 | import androidx.appcompat.app.AppCompatActivity 5 | import android.os.Bundle 6 | import android.widget.Button 7 | 8 | class MainActivity : AppCompatActivity() { 9 | 10 | lateinit var recyclerbtn : Button 11 | 12 | override fun onCreate(savedInstanceState: Bundle?) { 13 | super.onCreate(savedInstanceState) 14 | setContentView(R.layout.activity_main) 15 | 16 | recyclerbtn = findViewById(R.id.recyclerviewbtn) 17 | 18 | recyclerbtn.setOnClickListener { 19 | 20 | var i = Intent(this,UserlistActivity::class.java) 21 | startActivity(i) 22 | finish() 23 | 24 | 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/firebaserecyclerviewkotlin/MyAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.example.firebaserecyclerviewkotlin 2 | 3 | import android.view.LayoutInflater 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import android.widget.TextView 7 | import androidx.recyclerview.widget.RecyclerView 8 | 9 | class MyAdapter(private val userList : ArrayList) : RecyclerView.Adapter() { 10 | 11 | 12 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { 13 | 14 | val itemView = LayoutInflater.from(parent.context).inflate(R.layout.user_item, 15 | parent,false) 16 | return MyViewHolder(itemView) 17 | 18 | } 19 | 20 | override fun onBindViewHolder(holder: MyViewHolder, position: Int) { 21 | 22 | val currentitem = userList[position] 23 | 24 | holder.firstName.text = currentitem.firstName 25 | holder.lastName.text = currentitem.lastName 26 | holder.age.text = currentitem.age 27 | 28 | } 29 | 30 | override fun getItemCount(): Int { 31 | 32 | return userList.size 33 | } 34 | 35 | 36 | class MyViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView){ 37 | 38 | val firstName : TextView = itemView.findViewById(R.id.tvfirstName) 39 | val lastName : TextView = itemView.findViewById(R.id.tvlastName) 40 | val age : TextView = itemView.findViewById(R.id.tvage) 41 | 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/firebaserecyclerviewkotlin/User.kt: -------------------------------------------------------------------------------- 1 | package com.example.firebaserecyclerviewkotlin 2 | 3 | data class User(var firstName : String ?= null,var lastName : String ?= null,var age : String ?= null) 4 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/firebaserecyclerviewkotlin/UserlistActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.firebaserecyclerviewkotlin 2 | 3 | import androidx.appcompat.app.AppCompatActivity 4 | import android.os.Bundle 5 | import androidx.recyclerview.widget.LinearLayoutManager 6 | import androidx.recyclerview.widget.RecyclerView 7 | import com.google.firebase.database.* 8 | 9 | class UserlistActivity : AppCompatActivity() { 10 | 11 | private lateinit var dbref : DatabaseReference 12 | private lateinit var userRecyclerview : RecyclerView 13 | private lateinit var userArrayList : ArrayList 14 | 15 | 16 | override fun onCreate(savedInstanceState: Bundle?) { 17 | super.onCreate(savedInstanceState) 18 | setContentView(R.layout.activity_userlist) 19 | 20 | userRecyclerview = findViewById(R.id.userList) 21 | userRecyclerview.layoutManager = LinearLayoutManager(this) 22 | userRecyclerview.setHasFixedSize(true) 23 | 24 | userArrayList = arrayListOf() 25 | getUserData() 26 | 27 | } 28 | 29 | private fun getUserData() { 30 | 31 | dbref = FirebaseDatabase.getInstance().getReference("Users") 32 | 33 | dbref.addValueEventListener(object : ValueEventListener{ 34 | 35 | override fun onDataChange(snapshot: DataSnapshot) { 36 | 37 | if (snapshot.exists()){ 38 | 39 | for (userSnapshot in snapshot.children){ 40 | 41 | 42 | val user = userSnapshot.getValue(User::class.java) 43 | userArrayList.add(user!!) 44 | 45 | } 46 | 47 | userRecyclerview.adapter = MyAdapter(userArrayList) 48 | 49 | 50 | } 51 | 52 | } 53 | 54 | override fun onCancelled(error: DatabaseError) { 55 | TODO("Not yet implemented") 56 | } 57 | 58 | 59 | }) 60 | 61 | } 62 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/shape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foxandroid/FirebaseRecyclerViewKotlin/be9407ffa009904a28d4ee607198677767e2d51e/app/src/main/res/drawable-v24/shape.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 12 | 13 | 20 | 21 | 22 | 35 | 36 | 37 |