Skip to content

Commit

Permalink
Merge branch 'master' into eventsPage
Browse files Browse the repository at this point in the history
  • Loading branch information
mwmlo committed Jun 15, 2023
2 parents f60a193 + 1a60ddc commit 71e66c1
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 7 deletions.
31 changes: 29 additions & 2 deletions app/src/main/java/com/example/drp25/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,35 @@ fun addMatchObserver(observer: Observer) {

fun addMatched(uniId: String, user1Id: String, user2Id: String) {
val usersRef = unisRef.child(uniId).child("users")
usersRef.child(user1Id).child("matched").push().setValue(user2Id)
usersRef.child(user2Id).child("matched").push().setValue(user1Id)
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) {
Expand Down
115 changes: 115 additions & 0 deletions 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 Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/example/drp25/matchers/MyMatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class MyMatcher : Matcher {
// Check not already matched
val user2Id = user2Snapshot.key
val matched1Ref = user1Snapshot.child("matched")
for (child in matched1Ref.children) {
if (child.value == user2Id) return false
for (match in matched1Ref.children) {
if (match.child("matchId").value == user2Id) return false
}

val interests1Ref = user1Snapshot.child("interests")
Expand Down
38 changes: 36 additions & 2 deletions app/src/main/res/layout/activity_interest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,55 @@
android:layout_height="match_parent"
tools:context=".InterestActivity">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/text_margin_32"
android:layout_marginHorizontal="56dp"
android:text="Select your interest!"
android:textColor="@color/stream_ui_accent_red"
android:textSize="20sp"
app:layout_constraintTop_toBottomOf="@id/back_button_interests"
app:layout_constraintBottom_toTopOf="@id/spinner"/>

<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="56dp"
android:entries="@array/interest_array"
android:hint="@string/interest_prompt"
android:maxWidth="360dp"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/back_button_interests" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/text_margin_32"
android:layout_marginHorizontal="56dp"
android:text="Filter by..."
android:textSize="20sp"
app:layout_constraintTop_toBottomOf="@id/spinner"
app:layout_constraintBottom_toTopOf="@id/filter_spinner"/>

<Spinner
android:id="@+id/filter_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="56dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="56dp"
android:entries="@array/category_array"
android:hint="Choose a category to filter by"
android:maxWidth="360dp"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinner" />

<com.google.android.material.chip.ChipGroup
android:id="@+id/interests_group"
Expand All @@ -45,7 +79,7 @@
android:text="@string/add_new_interest"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinner" />
app:layout_constraintTop_toBottomOf="@+id/filter_spinner" />

<Button
android:id="@+id/back_button_interests"
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<item>Musical Theatre</item>
<item>Netball</item>
<item>Orchestra</item>
<item>Photography</item>
<item>Ph otography</item>
<item>Poker</item>
<item>Pokemon</item>
<item>Radio</item>
Expand All @@ -149,6 +149,16 @@
<item>Tennis</item>
<item>Volleyball</item>
</string-array>
<string-array name="category_array">
<item>None</item>
<item>Academic related</item>
<item>Arts &amp; Entertainment</item>
<item>Charitable</item>
<item>Indoor</item>
<item>Outdoor</item>
<item>Social</item>
<item>Sports</item>
</string-array>
<string name="title_activity_club_interest">ClubInterestActivity</string>
<string name="large_text">
"Material is the metaphor.\n\n"
Expand Down

0 comments on commit 71e66c1

Please sign in to comment.