Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
hettysymes committed Jun 15, 2023
2 parents 5c21d38 + 0cc8500 commit ca25fdd
Show file tree
Hide file tree
Showing 10 changed files with 346 additions and 23 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.DRP25"
tools:targetApi="31">
<activity
android:name=".UserEventsActivity"
android:exported="false" />
<activity
android:name=".NewEventActivity"
android:exported="false" />
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/example/drp25/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ class ChatActivity : AppCompatActivity() {
startActivity(intent)
}

binding.homeEventsButton.setOnClickListener {
val intent = Intent(this, UserEventsActivity::class.java)
startActivity(intent)
}

binding.channelListHeaderView.setOnUserAvatarClickListener{
val intent = Intent(this, UserProfileActivity::class.java)
startActivity(intent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.widget.*
import androidx.cardview.widget.CardView
import androidx.core.view.allViews
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.FirebaseDatabase
Expand Down Expand Up @@ -43,13 +41,9 @@ class CommitteeEventsActivity : AppCompatActivity() {
val eventCard = inflater.inflate(
R.layout.committee_event_view, eventsList, false
) as CardView
eventCard.findViewById<TextView>(R.id.new_event_title).text = name
eventCard.findViewById<TextView>(R.id.share_prompt).text = name
eventCard.findViewById<TextView>(R.id.new_event_descr).text = desc
eventCard.findViewById<TextView>(R.id.new_event_date).text = date
val broadcastBtn = eventCard.findViewById<Button>(R.id.broadcast_button)
broadcastBtn.setOnClickListener {
// TODO: broadcast message
}
eventsList.addView(eventCard)
}
}
Expand Down
163 changes: 163 additions & 0 deletions app/src/main/java/com/example/drp25/UserEventsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package com.example.drp25

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.PopupWindow
import android.widget.TextView
import androidx.cardview.widget.CardView
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.database.ValueEventListener
import org.w3c.dom.Text

class UserEventsActivity : AppCompatActivity() {

private val interests: MutableList<String> = ArrayList()

private fun getInterestedFriends(society: String, view: View) {

}

private fun createEventCard(event: DataSnapshot, inflater: LayoutInflater, eventsList: LinearLayout, society: String) {
val name: String = event.child("eventName").value as String
val date = event.child("eventDate").value as String
val desc = event.child("eventDesc").value as String

val eventCard = inflater.inflate(
R.layout.user_event_view, eventsList, false
) as CardView
eventCard.findViewById<TextView>(R.id.share_prompt).text = name
eventCard.findViewById<TextView>(R.id.new_event_descr).text = desc
eventCard.findViewById<TextView>(R.id.new_event_date).text = date

val shareBtn = eventCard.findViewById<Button>(R.id.share_button)
shareBtn.setOnClickListener {
// Inflate the pop-up overlay layout
val view = inflater.inflate(R.layout.popup_share, null)

// Fill in share prompt and friend details
val invite = "Invite your friends to come along to $name!"
view.findViewById< TextView>(R.id.share_prompt).text = invite

val friends: MutableList<String> = ArrayList()
// Get list of matched friends with the same interest
val userRef = FirebaseDatabase.getInstance().reference.child("universities")
.child(UNI_ID).child("users").child(USER_ID)
userRef.addListenerForSingleValueEvent(object: ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
for (match in snapshot.child("matched").children) {
val sharedInterests = match.child("sharedInterests").children
for (interest in sharedInterests) {
if (society == interest.value.toString()) {
friends.add(match.child("matchId").value.toString())
}
}

}
}
override fun onCancelled(error: DatabaseError) {
TODO("Not yet implemented")
}
})
// Find name of friends
val usersRef = FirebaseDatabase.getInstance().reference.child("universities")
.child(UNI_ID).child("users")
val names: MutableList<String> = ArrayList()
usersRef.addListenerForSingleValueEvent(object: ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
for (user in snapshot.children) {
if (friends.contains(user.key)) {
names.add(user.child("name").value.toString())
val namesString = names.toString()
.replace(",", ", ")
.replace("[", "")
.replace("]", "")
.trim()
val friendPrompt = "$namesString might be interested."
view.findViewById<TextView>(R.id.friends_list).text = friendPrompt
}

}
}
override fun onCancelled(error: DatabaseError) {
TODO("Not yet implemented")
}
})

// Create the pop-up window
val popupWindow = PopupWindow(view,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT,
true)

// Set up dismiss listener to close the pop-up window when clicked outside
popupWindow.isOutsideTouchable = true
popupWindow.isFocusable = true

// Show the pop-up window
popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0)
}
eventsList.addView(eventCard)
}

private fun getInterests() {
val userRef = FirebaseDatabase.getInstance().reference.child("universities")
.child(UNI_ID).child("users").child(USER_ID)
userRef.addListenerForSingleValueEvent(object: ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
for (interest in snapshot.child("interests").children) {
val interestName = interest.key.toString()
interests.add(interestName)
}
}
override fun onCancelled(error: DatabaseError) {
TODO("Not yet implemented")
}
})
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_user_events)

/* LinearLayout containing the content. */
val eventsList = findViewById<LinearLayout>(R.id.committee_events)

/* Display events from database */
getInterests()
val eventsRef = FirebaseDatabase.getInstance().reference.child("universities")
.child(UNI_ID).child("events")

val inflater = LayoutInflater.from(this)
eventsRef.addValueEventListener(object: ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
for (event in snapshot.children) {
val society = event.child("society").value as String
if (interests.contains(society)) {
createEventCard(event, inflater, eventsList, society)
}
}
}

override fun onCancelled(error: DatabaseError) {
TODO("Not yet implemented")
}
})

/* Return to home page */
val backButton = findViewById<Button>(R.id.profile_back_button)
backButton.setOnClickListener {
val intent = Intent(this, ChatActivity::class.java)
startActivity(intent)
}
}
}
15 changes: 15 additions & 0 deletions app/src/main/res/layout/activity_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/stream_ui_accent_blue"
app:layout_constraintBottom_toTopOf="@+id/home_events_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/home_events_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/text_margin_32"
android:backgroundTint="@color/stream_ui_blue_alice"
android:text="@string/recommended_events"
android:textSize="18sp"
android:textStyle="bold"
android:textColor="@color/stream_ui_accent_blue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand Down
57 changes: 57 additions & 0 deletions app/src/main/res/layout/activity_user_events.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".UserEventsActivity">

<Button
android:id="@+id/profile_back_button"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="@dimen/margin_16"
android:background="@drawable/arrow_back"
android:contentDescription="@string/back_to_chats"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/events_list_prompt"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_margin="@dimen/margin_16"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:gravity="center_vertical"
android:minWidth="300dp"
android:text="@string/upcoming_events_related_to_your_interests"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="24dp"
android:contentDescription="@string/list_of_events"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/events_list_prompt">

<LinearLayout
android:id="@+id/committee_events"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">

</LinearLayout>

</ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
21 changes: 5 additions & 16 deletions app/src/main/res/layout/committee_event_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,16 @@
android:id="@+id/new_event_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/text_margin_32"
android:layout_marginTop="0dp"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_toStartOf="@id/broadcast_button"
android:textSize="20sp"/>

<Button
android:id="@+id/broadcast_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:backgroundTint="@color/stream_ui_blue_alice"
android:text="@string/broadcast_event"
android:textColor="@color/stream_ui_accent_blue"
android:textSize="16sp"/>
android:layout_centerVertical="true"
android:layout_marginTop="0dp"
android:layout_marginEnd="@dimen/text_margin_32"
android:textSize="20sp" />

</RelativeLayout>

<TextView
android:id="@+id/new_event_title"
android:id="@+id/share_prompt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/text_margin_32"
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/res/layout/popup_share.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/stream_ui_blue_alice"
android:layout_marginHorizontal="@dimen/margin_16"
android:layout_marginVertical="@dimen/margin_8">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/text_margin_32"
android:orientation="vertical" >

<TextView
android:id="@+id/share_prompt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/text_margin_32"
android:layout_marginTop="@dimen/text_margin_16"
android:textColor="@color/black"
android:textSize="24sp"/>

<TextView
android:id="@+id/friends_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/text_margin_32"
android:layout_marginTop="@dimen/text_margin_16"
android:textColor="@color/black"
android:textSize="24sp"/>

</LinearLayout>

</androidx.cardview.widget.CardView>
Loading

0 comments on commit ca25fdd

Please sign in to comment.