Skip to content

Commit

Permalink
Merge pull request #11 from gorkemgur/feature/user-profile
Browse files Browse the repository at this point in the history
Feature/user profile
  • Loading branch information
gorkemgur authored Jul 18, 2023
2 parents 2f06c63 + 56dc086 commit 5a14d19
Show file tree
Hide file tree
Showing 16 changed files with 569 additions and 24 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
implementation 'androidx.activity:activity-ktx:1.7.2'
implementation 'com.github.bumptech.glide:glide:4.15.1'
implementation("com.google.firebase:firebase-crashlytics-ktx")
implementation("com.google.firebase:firebase-analytics-ktx")
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand All @@ -58,4 +59,5 @@ dependencies {
implementation(platform("com.google.firebase:firebase-bom:32.1.1"))
implementation("com.google.firebase:firebase-analytics-ktx")
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.10"
implementation("com.google.firebase:firebase-storage-ktx")
}
44 changes: 37 additions & 7 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,38 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.CAMERA" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />

<uses-feature
android:name="android.hardware.camera"
android:required="false" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/ic_firebase"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="@drawable/ic_firebase"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<activity
android:name=".ui.common.profile.ProfileActivity"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden|screenSize"
android:exported="true">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".ui.SplashActivity"
android:exported="true">
Expand All @@ -20,16 +42,14 @@

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".chat.ui.GroupChatActivity"
android:exported="false"
android:label="@string/title_activity_group_chat"
android:theme="@style/Theme.MyApplication.NoActionBar">
android:label="@string/title_activity_group_chat">
<meta-data
android:name="android.app.lib_name"
android:value="" />
Expand All @@ -43,20 +63,30 @@
</activity>
<activity
android:name=".ui.login.LoginActivity"
android:exported="false"
android:noHistory="true">
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".ui.register.RegisterActivity"
android:exported="true"
android:noHistory="true">
android:exported="true">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>

</application>


</manifest>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sample.firebaseapp.chat.ui

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.View.OnLayoutChangeListener
import android.widget.Toast
Expand All @@ -15,6 +15,7 @@ import com.sample.firebaseapp.chat.adapter.MessageListener
import com.sample.firebaseapp.databinding.ActivityGroupChatBinding
import com.sample.firebaseapp.helpers.FirebaseHelper
import com.sample.firebaseapp.model.MessageModel
import com.sample.firebaseapp.ui.common.profile.ProfileActivity

class GroupChatActivity : AppCompatActivity() {

Expand Down Expand Up @@ -47,7 +48,9 @@ class GroupChatActivity : AppCompatActivity() {
override fun onFocusChange(v: View?, hasFocus: Boolean) {
if (hasFocus) {
binding.messageListRecyclerView.post {
binding.messageListRecyclerView.layoutManager?.scrollToPosition((viewModel.getMessageList()?.size ?: 0) - 1)
binding.messageListRecyclerView.layoutManager?.scrollToPosition(
(viewModel.getMessageList()?.size ?: 0) - 1
)
}
}
}
Expand Down Expand Up @@ -130,7 +133,10 @@ class GroupChatActivity : AppCompatActivity() {

override fun onUserNameClicked(userId: String?) {
FirebaseHelper.getUserModelWithUserId(userId) { userModel ->
Log.e("userModel", userModel.toString())
val intent = Intent(this@GroupChatActivity, ProfileActivity::class.java)
intent.putExtra("userId", userModel?.userId)
finish()
startActivity(intent)
}
}
}
Expand All @@ -142,7 +148,8 @@ class GroupChatActivity : AppCompatActivity() {
}

override fun onFailed(e: java.lang.Exception) {
Toast.makeText(this@GroupChatActivity, e.localizedMessage, Toast.LENGTH_SHORT).show()
Toast.makeText(this@GroupChatActivity, e.localizedMessage, Toast.LENGTH_SHORT)
.show()
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sample.firebaseapp.chat.ui

import android.app.Application
import android.graphics.Bitmap
import androidx.lifecycle.AndroidViewModel
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
Expand Down Expand Up @@ -112,4 +113,5 @@ class GroupChatViewModel(application: Application) : AndroidViewModel(applicatio
fun getUserId(): String? {
return userModel?.userId
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DashBoardActivity : AppCompatActivity() {
startActivity(Intent(this@DashBoardActivity, RegisterActivity::class.java))
}
binding.chatButton.setOnClickListener {
finish()
startActivity(Intent(this@DashBoardActivity, GroupChatActivity::class.java))
}
setLoggedInUI()
Expand Down
25 changes: 14 additions & 11 deletions app/src/main/java/com/sample/firebaseapp/helpers/FirebaseHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.ValueEventListener
import com.google.firebase.database.ktx.database
import com.google.firebase.database.ktx.getValue
import com.google.firebase.ktx.Firebase
import com.sample.firebaseapp.model.UserModel

Expand All @@ -16,7 +15,10 @@ object FirebaseHelper {
fun getCurrentUserModel(callback: (UserModel?) -> Unit) {
if (Firebase.auth.currentUser != null) {
reference.child("Users").child(Firebase.auth.currentUser?.uid ?: "")
.addValueEventListener(object : ValueEventListener {
//BURADA SINGLE EVENT KULLANMAMIZ GEREKIYOR YOKSA
//APP BOYUNCA KULLANICIDA YAPTIĞIMIZ TÜM DEĞİŞİKLİKLER BURAYI
//TETIKLIYOR VE BU FONKSIYONUN ILK KULLANILDIĞI YERİ AÇIYOR.
.addListenerForSingleValueEvent(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
callback(snapshot.getValue(UserModel::class.java))
}
Expand All @@ -32,14 +34,15 @@ object FirebaseHelper {


fun getUserModelWithUserId(userId: String?, callback: (UserModel?) -> Unit) {
reference.child("Users").child(userId ?: "").addListenerForSingleValueEvent(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
callback(snapshot.getValue(UserModel::class.java))
}

override fun onCancelled(error: DatabaseError) {
callback(null)
}
})
reference.child("Users").child(userId ?: "")
.addListenerForSingleValueEvent(object : ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
callback(snapshot.getValue(UserModel::class.java))
}

override fun onCancelled(error: DatabaseError) {
callback(null)
}
})
}
}
6 changes: 5 additions & 1 deletion app/src/main/java/com/sample/firebaseapp/model/UserModel.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.sample.firebaseapp.model

import android.os.Parcelable


data class UserModel(
var name: String?,
var surName: String?,
var userId: String?,
var email: String?,
var imageUrl: String?
) {
constructor() : this("", "", "","")
constructor() : this("", "", "", "", "")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.sample.firebaseapp.ui
import android.content.Intent
import android.os.Bundle
import com.google.firebase.auth.ktx.auth
import com.google.firebase.database.ktx.database
import com.google.firebase.ktx.Firebase
import com.sample.firebaseapp.dashboard.DashBoardActivity
import com.sample.firebaseapp.databinding.ActivitySplashBinding
Expand Down
Loading

0 comments on commit 5a14d19

Please sign in to comment.