Skip to content

Commit

Permalink
AddGroupsWithNotification
Browse files Browse the repository at this point in the history
Added new features and unfortunately, more bugs.
  • Loading branch information
DaChelimo committed Aug 20, 2020
1 parent c1d48bb commit 30cd55b
Show file tree
Hide file tree
Showing 46 changed files with 2,134 additions and 185 deletions.
2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ android {
}
}

//allprojects {
// repositories {
// flatDir {
// dirs '/libs'
// }
// }
//}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
Expand All @@ -40,10 +48,19 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.google.firebase:firebase-messaging:20.2.4'
implementation 'com.google.android.material:material:1.2.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation(name:'sinch-android-rtc-3.17.4', ext:'aar')

implementation 'androidx.lifecycle:lifecycle-runtime:2.2.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
kapt 'androidx.lifecycle:lifecycle-compiler:2.2.0'

implementation 'net.danlew:android.joda:2.10.6.1'

implementation 'com.google.firebase:firebase-analytics-ktx:17.5.0'
implementation 'com.google.firebase:firebase-auth-ktx:19.3.2'
implementation 'com.google.firebase:firebase-database-ktx:19.3.1'
Expand All @@ -64,7 +81,7 @@ dependencies {
implementation "com.squareup.moshi:moshi-kotlin:$version_moshi"

// Retrofit
implementation "com.squareup.retrofit2:retrofit:2.4.0"
implementation "com.squareup.retrofit2:retrofit:2.6.2"
implementation "com.squareup.retrofit2:converter-moshi:$version_retrofit"
implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"

Expand Down
Binary file added app/libs/sinch-android-rtc-3.17.4.aar
Binary file not shown.
28 changes: 22 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.messenger">

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature
android:name="android.hardware.microphone"
android:required="false"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<application
android:name=".MainApplication"
android:allowBackup="true"
Expand All @@ -10,21 +20,27 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".GroupProfileActivity"></activity>
<activity
android:name=".EachGroupChatActivity"
android:theme="@style/NoActionBar" />
<activity
android:name=".CreateGroupDetailsActivity"
android:parentActivityName=".CreateGroupActivity" />
<activity
android:name=".CreateGroupActivity"
android:parentActivityName=".LatestMessagesActivity" />
<activity
android:name=".OthersProfileActivity"
android:theme="@style/NoActionBar"/>

android:theme="@style/NoActionBar" />
<activity
android:name=".UserProfileActivity"
android:parentActivityName=".LatestMessagesActivity"
android:theme="@style/NoActionBar" />

<activity
android:name=".EachChatActivity"
android:name=".EachPersonalChatActivity"
android:parentActivityName=".LatestMessagesActivity"
android:theme="@style/NoActionBar" />

<activity
android:name=".NewUsersActivity"
android:parentActivityName=".LatestMessagesActivity">
Expand Down
131 changes: 131 additions & 0 deletions app/src/main/java/com/example/messenger/CreateGroupActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.example.messenger

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.LinearLayoutManager
import com.bumptech.glide.Glide
import com.example.messenger.databinding.ActivityCreateGroupBinding
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.ValueEventListener
import com.xwray.groupie.GroupAdapter
import com.xwray.groupie.GroupieViewHolder
import com.xwray.groupie.Item
import kotlinx.android.synthetic.main.create_group_chosen_member.view.*
import kotlinx.android.synthetic.main.each_user_layout.view.*
import timber.log.Timber

class CreateGroupActivity : AppCompatActivity() {

lateinit var binding: ActivityCreateGroupBinding
lateinit var userListAdapter: GroupAdapter<GroupieViewHolder>
lateinit var chosenMembersAdapter: GroupAdapter<GroupieViewHolder>
var chosenMembersList = HashMap<String, ChosenMemberItem>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

supportActionBar?.title = "New Group"
supportActionBar?.subtitle = "Add participants"

binding = DataBindingUtil.setContentView(this, R.layout.activity_create_group)
val userListRecyclerView = binding.createGroupRecyclerview
val chosenMembersRecyclerView = binding.chosenMembersRecyclerview
chosenMembersRecyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)

userListAdapter = GroupAdapter()
chosenMembersAdapter = GroupAdapter()

userListRecyclerView.adapter = userListAdapter
chosenMembersRecyclerView.adapter = chosenMembersAdapter

Timber.i("Init: Size of adapter is ${userListAdapter.groupCount}")

fetchUsers()

userListAdapter.setOnItemClickListener { item, _ ->
val userListItem = item as UserListItem
val chosenMember = userListItem.user
if (chosenMembersList.containsKey(chosenMember.uid.toString())) {
Toast.makeText(this, "User already added to group.", Toast.LENGTH_SHORT).show()
}
chosenMembersList[chosenMember.uid] = ChosenMemberItem(chosenMember)
Timber.d("values are ${chosenMembersList.values}")
chosenMembersAdapter.update(chosenMembersList.values)
supportActionBar?.subtitle = "${chosenMembersList.values.size} selected"
}

binding.proceedBtn.setOnClickListener {
Timber.d("itemCount is ${chosenMembersAdapter.itemCount}")
if (chosenMembersAdapter.itemCount == 0){
Toast.makeText(this, "At least one contact must be selected", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}

val intent = Intent(this, CreateGroupDetailsActivity::class.java)
val chosenMembersIntentExtra = ArrayList<User>()
chosenMembersList.values.forEach {
chosenMembersIntentExtra.add(it.user)
}
intent.putExtra(PARTICIPANTS_DATA, chosenMembersIntentExtra)
startActivity(intent)
}
}

private fun fetchUsers(){
val allUsers = firebaseDatabase.getReference("/users")
allUsers.addListenerForSingleValueEvent(object : ValueEventListener {
override fun onCancelled(error: DatabaseError) {
Timber.i("error: ${error.details}")
}

override fun onDataChange(snapshot: DataSnapshot) {
snapshot.children.forEach {
val firebaseUser = it.getValue(User::class.java)
Timber.i("firebaseUser is $firebaseUser")
Timber.d("firebaseUser.uid is ${firebaseUser?.uid} and firebaseAuth.uid is ${firebaseAuth.uid}")
if (firebaseUser != null && firebaseUser.uid != firebaseAuth.uid ){
userListAdapter.add(UserListItem(firebaseUser))
Timber.i("Item added in list.")
}
}
Timber.i("End: Size of adapter is ${userListAdapter.groupCount}")
}
})
}

class UserListItem(val user: User): Item<GroupieViewHolder>() {
override fun getLayout(): Int = R.layout.each_user_layout

override fun bind(viewHolder: GroupieViewHolder, position: Int) {
val image = viewHolder.itemView.each_user_image
val userName = viewHolder.itemView.each_user_name

val view = viewHolder.itemView
Glide.with(view)
.load(user.profilePictureUrl)
.into(image)
userName.text = user.userName
Timber.i("each uid: ${user.uid}")

}
}

class ChosenMemberItem(val user: User): Item<GroupieViewHolder>() {
override fun getLayout(): Int = R.layout.create_group_chosen_member

override fun bind(viewHolder: GroupieViewHolder, position: Int) {
val layout = viewHolder.itemView
val image = layout.chosen_member_image
val name = layout.chosen_member_name

name.text = user.userName
Glide.with(layout)
.load(user.profilePictureUrl)
.into(image)
}
}
}
Loading

0 comments on commit 30cd55b

Please sign in to comment.