From 3f6dc59fc2ba56668ec1c14448e6da972617823a Mon Sep 17 00:00:00 2001 From: hettysymes Date: Thu, 15 Jun 2023 13:07:41 +0100 Subject: [PATCH 1/6] filtering by none ans sport works --- .../com/example/drp25/InterestActivity.kt | 108 ++++++++++++++++++ app/src/main/res/layout/activity_interest.xml | 17 ++- app/src/main/res/values/strings.xml | 6 +- 3 files changed, 128 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/drp25/InterestActivity.kt b/app/src/main/java/com/example/drp25/InterestActivity.kt index 44d1b45..94c4800 100644 --- a/app/src/main/java/com/example/drp25/InterestActivity.kt +++ b/app/src/main/java/com/example/drp25/InterestActivity.kt @@ -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 @@ -13,14 +14,97 @@ 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() { + val allInterests = arrayOf( + "Anime", + "Archery", + "Art", + "Astronomy", + "Badminton", + "Baking", + "Baseball and Softball", + "Basketball", + "Bridge", + "Caving", + "Charity and Volunteering", + "Choir and Chamber Music", + "Chess", + "Cycling", + "Dance", + "Dogs", + "Drama", + "Environmental", + "Football", + "Fencing", + "Films and Movies", + "Gaming and E-sports", + "Golf", + "Hip Hop", + "History", + "Hockey", + "Jazz, Soul and Funk", + "K-pop", + "Knitting", + "Lacrosse", + "Martial Arts", + "Model United Nations", + "Mountaineering", + "Musical Theatre", + "Netball", + "Orchestra", + "Photography", + "Poker", + "Pokemon", + "Radio", + "Rail and Transport", + "Robotics", + "Rugby", + "Science Fiction and Fantasy", + "Skating", + "Snooker and Pool", + "Squash", + "Tabletop Gaming", + "Tennis", + "Volleyball" + ) + + val sportInterests = arrayOf( + "Archery", + "Badminton", + "Baseball and Softball", + "Basketball", + "Caving", + "Chess", + "Cycling", + "Dance", + "Football", + "Fencing", + "Gaming and E-sports", + "Golf", + "Hockey", + "Lacrosse", + "Martial Arts", + "Mountaineering", + "Netball", + "Rugby", + "Skating", + "Snooker and Pool", + "Squash", + "Tennis", + "Volleyball" + ) + + val displayedEntries = ArrayList() + @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) @@ -30,8 +114,14 @@ class InterestActivity : AppCompatActivity() { displayExistingInterests(interestsChipGroup) // Select interest from drop down list + allInterests.forEach { displayedEntries.add(it) } + val spinner: Spinner = findViewById(R.id.spinner) var selectedInterest = "" + val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, displayedEntries) + 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 @@ -42,6 +132,24 @@ 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 + displayedEntries.clear() + if (category == "None") { + allInterests.forEach { displayedEntries.add(it) } + } else if (category == "Sport") { + sportInterests.forEach { displayedEntries.add(it) } + } + adapter.notifyDataSetChanged() + } + + override fun onNothingSelected(parent: AdapterView<*>?) { + // Handle no selection + } + } + // Add new interest to list of selected interests val addInterestButton = findViewById