Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/res/values/strings.xml
  • Loading branch information
Hazel Wright committed Jun 15, 2023
2 parents dec449a + 2909935 commit 94dc297
Show file tree
Hide file tree
Showing 21 changed files with 861 additions and 55 deletions.
14 changes: 12 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.drp25">
<uses-permission android:name="android.permission.INTERNET"/>

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

<application
android:allowBackup="true"
Expand All @@ -13,6 +14,15 @@
android:supportsRtl="true"
android:theme="@style/Theme.DRP25"
tools:targetApi="31">
<activity
android:name=".NewEventActivity"
android:exported="false" />
<activity
android:name=".CommitteeEventsActivity"
android:exported="false" />
<activity
android:name=".CommitteeProfileActivity"
android:exported="false" />
<activity
android:name=".SplashScreenActivity"
android:exported="false">
Expand All @@ -36,7 +46,7 @@
android:name=".InterestActivity"
android:exported="false" />
<activity
android:name=".ProfileActivity"
android:name=".UserProfileActivity"
android:exported="false" />
<activity
android:name=".MatchActivity"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/example/drp25/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,14 @@ class ChatActivity : AppCompatActivity() {
}

binding.channelListHeaderView.setOnUserAvatarClickListener{
val intent = Intent(this, ProfileActivity::class.java)
val intent = Intent(this, UserProfileActivity::class.java)
startActivity(intent)
}

binding.channelListHeaderView.setOnTitleLongClickListener {
// Broadcast to all channels.
//val intent = Intent(this, )
}
setContentView(binding.root)

binding.channelListHeaderView.setOnlineTitle("Globe Chatter")
Expand Down
69 changes: 69 additions & 0 deletions app/src/main/java/com/example/drp25/CommitteeEventsActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.example.drp25

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
import com.google.firebase.database.ValueEventListener

class CommitteeEventsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_committee_events)

/* Functionality to reach profile page from events (home) page. */
val toProfile = findViewById<Button>(R.id.to_profile_button)
toProfile.setOnClickListener {
val intent = Intent(this, CommitteeProfileActivity::class.java)
startActivity(intent)
}

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

/* Display events from database */
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 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.committee_event_view, eventsList, false
) as CardView
eventCard.findViewById<TextView>(R.id.new_event_title).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)
}
}

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

/* Functionality for the New Event button. */
val newEvent = findViewById<Button>(R.id.new_event_button)
newEvent.setOnClickListener {
val intent = Intent(this, NewEventActivity::class.java)
startActivity(intent)
}
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/com/example/drp25/CommitteeProfileActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.drp25

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button

class CommitteeProfileActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_committee_profile)

val backButton = findViewById<Button>(R.id.committee_profile_back_button)
backButton.setOnClickListener {
val intent = Intent(this, CommitteeEventsActivity::class.java)
startActivity(intent)
}
}
}
57 changes: 49 additions & 8 deletions app/src/main/java/com/example/drp25/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.drp25

import android.widget.LinearLayout
import android.widget.RatingBar
import com.example.drp25.matchers.MyMatcher
import com.example.drp25.matchers.RatingMatcherWithNationality
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
Expand All @@ -10,13 +11,13 @@ import com.google.firebase.database.ValueEventListener
import com.google.gson.Gson

private val unisRef = FirebaseDatabase.getInstance().reference.child("universities")
private val matcher: Matcher = RatingMatcherWithNationality()
private val matcher: Matcher = MyMatcher()
val matches = mutableSetOf<String>()
val matchObservers = mutableListOf<Observer>()

fun sendStamp(uniId: String, userId: String, imageId: Int) {
fun sendStamp(uniId: String, userId: String, stampName: String) {
val stampsRef = unisRef.child(uniId).child("users").child(userId).child("stamps")
stampsRef.push().setValue(imageId)
stampsRef.push().setValue(stampName)
}

fun updatePfp(uniId: String, userId: String, filepath: String) {
Expand All @@ -28,6 +29,39 @@ fun addMatchObserver(observer: Observer) {
observer.notify(matches)
}

fun addMatched(uniId: String, user1Id: String, user2Id: String) {
val usersRef = unisRef.child(uniId).child("users")
val key1 = usersRef.child(user1Id).child("matched").push()
val key2 = usersRef.child(user2Id).child("matched").push()
key1.child("matchId").setValue(user2Id)
key2.child("matchId").setValue(user1Id)

usersRef.child(user1Id).child("interests").addListenerForSingleValueEvent(object: ValueEventListener {
override fun onDataChange(snapshot1: DataSnapshot) {
usersRef.child(user2Id).child("interests").addListenerForSingleValueEvent(object: ValueEventListener {
override fun onDataChange(snapshot2: DataSnapshot) {
for (child in snapshot1.children) {
if (child.key?.let { snapshot2.hasChild(it) } == true) {
key1.child("sharedInterests").push().setValue(child.key)
key2.child("sharedInterests").push().setValue(child.key)
}
}
}

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

})
}

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

})
}

fun listenToUser(uniId: String, userId: String) {
val userRef = unisRef.child(uniId).child("users").child(userId)
userRef.addValueEventListener(object: ValueEventListener {
Expand Down Expand Up @@ -99,11 +133,6 @@ fun addUser(uniId: String, name: String, nationality: String, year: String, cour
return userId
}

//fun putInterestRating(uniId: String, userId: String, interest: String) {
// val interestsRef = unisRef.child(uniId).child("users").child(userId).child("interests")
// interestsRef.child(interest).setValue(null)
//}

fun addInterest(uniId: String, userId: String, interest: String) {
val interestsRef = unisRef.child(uniId).child("users").child(userId).child("interests")
interestsRef.child(interest).setValue(5)
Expand All @@ -112,4 +141,16 @@ fun addInterest(uniId: String, userId: String, interest: String) {
fun removeInterest(uniId: String, userId: String, interest: String) {
val interestsRef = unisRef.child(uniId).child("users").child(userId).child("interests")
interestsRef.child(interest).removeValue()
}

fun addEvent(uniId: String, eventName: String, eventDate: String, eventDesc: String) {
val eventsRef = unisRef.child(uniId).child("events")
val eventId = eventsRef.push().key
if (eventId != null) {
val eventRef = eventsRef.child(eventId)
eventRef.child("eventName").setValue(eventName)
eventRef.child("eventDate").setValue(eventDate)
eventRef.child("eventDesc").setValue(eventDesc)
eventRef.child("society").setValue("ballet")
}
}
117 changes: 116 additions & 1 deletion app/src/main/java/com/example/drp25/InterestActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.drp25

import android.annotation.SuppressLint
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
Expand All @@ -13,14 +14,79 @@ 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 okhttp3.internal.notify

class InterestActivity : AppCompatActivity() {

enum class HobbyCategory {
ACADEMIC_RELATED,
ARTS_ENTERTAINMENT,
CHARITABLE,
INDOOR,
OUTDOOR,
SOCIAL,
SPORTS
}

val hobbiesCategoriesMap = mapOf(
"Anime" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Archery" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR),
"Art" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Astronomy" to listOf(HobbyCategory.ACADEMIC_RELATED),
"Badminton" to listOf(HobbyCategory.SPORTS, HobbyCategory.INDOOR),
"Baking" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Baseball and Softball" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR),
"Basketball" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR),
"Bridge" to listOf(HobbyCategory.SOCIAL),
"Caving" to listOf(HobbyCategory.OUTDOOR),
"Charity and Volunteering" to listOf(HobbyCategory.CHARITABLE, HobbyCategory.SOCIAL),
"Choir and Chamber Music" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Chess" to listOf(HobbyCategory.SOCIAL),
"Cycling" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR),
"Dance" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Dogs" to listOf(HobbyCategory.SOCIAL),
"Drama" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Environmental" to listOf(HobbyCategory.CHARITABLE),
"Football" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR),
"Fencing" to listOf(HobbyCategory.SPORTS),
"Films and Movies" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Gaming and E-sports" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Golf" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR),
"Hip Hop" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"History" to listOf(HobbyCategory.ACADEMIC_RELATED),
"Hockey" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR),
"Jazz, Soul and Funk" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"K-pop" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Knitting" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Lacrosse" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR),
"Martial Arts" to listOf(HobbyCategory.SPORTS),
"Model United Nations" to listOf(HobbyCategory.ACADEMIC_RELATED),
"Mountaineering" to listOf(HobbyCategory.OUTDOOR),
"Musical Theatre" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Netball" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR),
"Orchestra" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Photography" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Poker" to listOf(HobbyCategory.SOCIAL),
"Pokemon" to listOf(HobbyCategory.SOCIAL),
"Radio" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Rail and Transport" to listOf(HobbyCategory.SOCIAL),
"Robotics" to listOf(HobbyCategory.ACADEMIC_RELATED),
"Rugby" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR),
"Science Fiction and Fantasy" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Skating" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR),
"Snooker and Pool" to listOf(HobbyCategory.SPORTS),
"Squash" to listOf(HobbyCategory.SPORTS),
"Tabletop Gaming" to listOf(HobbyCategory.ARTS_ENTERTAINMENT),
"Tennis" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR),
"Volleyball" to listOf(HobbyCategory.SPORTS, HobbyCategory.OUTDOOR)
)

@Deprecated("Deprecated in Java")
override fun onBackPressed() {
// Remove back press option, to prevent double updates to database
}

@SuppressLint("MissingInflatedId")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_interest)
Expand All @@ -32,6 +98,10 @@ class InterestActivity : AppCompatActivity() {
// Select interest from drop down list
val spinner: Spinner = findViewById(R.id.spinner)
var selectedInterest = ""
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, hobbiesCategoriesMap.keys.toList())
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = adapter

spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
selectedInterest = spinner.selectedItem as String
Expand All @@ -42,6 +112,51 @@ class InterestActivity : AppCompatActivity() {
}
}

val filterSpinner: Spinner = findViewById(R.id.filter_spinner)
filterSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
val category = filterSpinner.selectedItem as String
if (category == "None") {
val adapter = ArrayAdapter(this@InterestActivity, android.R.layout.simple_spinner_item, hobbiesCategoriesMap.keys.toList())
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = adapter
} else {
var categoryToFilter: HobbyCategory? = null
when (category) {
"Academic related" -> {
categoryToFilter = HobbyCategory.ACADEMIC_RELATED
}
"Arts & Entertainment" -> {
categoryToFilter = HobbyCategory.ARTS_ENTERTAINMENT
}
"Charitable" -> {
categoryToFilter = HobbyCategory.CHARITABLE
}
"Indoor" -> {
categoryToFilter = HobbyCategory.INDOOR
}
"Outdoor" -> {
categoryToFilter = HobbyCategory.OUTDOOR
}
"Social" -> {
categoryToFilter = HobbyCategory.SOCIAL
}
"Sports" -> {
categoryToFilter = HobbyCategory.SPORTS
}
}
val adapter = ArrayAdapter(this@InterestActivity, android.R.layout.simple_spinner_item, hobbiesCategoriesMap.filter { it.value.contains(categoryToFilter) }.keys.toList())
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = adapter
}
adapter.notifyDataSetChanged()
}

override fun onNothingSelected(parent: AdapterView<*>?) {
// Handle no selection
}
}

// Add new interest to list of selected interests
val addInterestButton = findViewById<Button>(R.id.add_new_interest_button)
addInterestButton.setOnClickListener {
Expand All @@ -55,7 +170,7 @@ class InterestActivity : AppCompatActivity() {
// Back button returns to profile
val backButton = findViewById<Button>(R.id.back_button_interests)
backButton.setOnClickListener {
val intent = Intent(this, ProfileActivity::class.java)
val intent = Intent(this, UserProfileActivity::class.java)
startActivity(intent)
}
}
Expand Down
Loading

0 comments on commit 94dc297

Please sign in to comment.