Skip to content

Commit

Permalink
Added functionality for favorites (not yet connected to backend). Als…
Browse files Browse the repository at this point in the history
…o updated UI for the fitness room list items.
  • Loading branch information
meiron03 committed Sep 23, 2023
1 parent a137c5a commit d1df8f3
Show file tree
Hide file tree
Showing 17 changed files with 735 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.fragment.app.Fragment
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.pennapps.labs.pennmobile.adapters.FitnessPagerAdapter
Expand Down Expand Up @@ -50,7 +48,7 @@ class FitnessHolderFragment: Fragment() {
if (position == 0) {
tab.text = "Pottruck"
} else {
tab.text = "Other Facilities"
tab.text = "Favorites"
}
}.attach()
}
Expand All @@ -60,7 +58,7 @@ class FitnessHolderFragment: Fragment() {
* fills in the textViews for the title/date
*/
private fun initAppBar() {
val appBarLayout : AppBarLayout = mView.findViewById(R.id.appbar_home_holder);
val appBarLayout : AppBarLayout = mView.findViewById(R.id.appbar_home_holder)
val titleView : TextView = mView.findViewById(R.id.title_view)
val dateView : TextView = mView.findViewById(R.id.date_view)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.pennapps.labs.pennmobile

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.RecyclerView
import com.pennapps.labs.pennmobile.adapters.FitnessPreferenceAdapter
import com.pennapps.labs.pennmobile.classes.FitnessPreferenceViewModel

interface CloseListener {
fun updateAdapters()
}

class FitnessPreferencesFragment(private val dataModel: FitnessPreferenceViewModel,
private val listener: CloseListener) : DialogFragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_fitness_preferences, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val prefAdapter = FitnessPreferenceAdapter(dataModel)

val recyclerView: RecyclerView = view.findViewById(R.id.fitness_preference_recycler_view)
recyclerView.adapter = prefAdapter

val cancelText : TextView = view.findViewById(R.id.fitness_fragment_pref_cancel)
cancelText.setOnClickListener {
dataModel.restorePreferences()
dialog?.dismiss()
}

val saveText : TextView = view.findViewById(R.id.fitness_fragment_pref_save)
saveText.setOnClickListener {
dataModel.updatePositionMap()
dataModel.updateRemotePreferences()
listener.updateAdapters()

dialog?.dismiss()
}
}

override fun onStart() {
super.onStart()
val dialog = dialog

if (dialog != null) {
val width = ViewGroup.LayoutParams.MATCH_PARENT
val height = ViewGroup.LayoutParams.MATCH_PARENT
dialog.window!!.setLayout(width, height)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.appbar.AppBarLayout
import com.pennapps.labs.pennmobile.adapters.FitnessAdapter
import com.pennapps.labs.pennmobile.adapters.FitnessHeaderAdapter
import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.classes.FitnessPreferenceViewModel
import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior
import com.pennapps.labs.pennmobile.utils.Utils


class PottruckFragment : Fragment() {
private lateinit var mActivity : MainActivity
Expand All @@ -24,6 +33,12 @@ class PottruckFragment : Fragment() {
private lateinit var recyclerView : RecyclerView
private lateinit var loadingPanel : View

private lateinit var dataModel : FitnessPreferenceViewModel
private lateinit var favoritesAdapter : FitnessAdapter
private lateinit var otherAdapter : FitnessAdapter
private lateinit var favoriteHeaderAdapter : FitnessHeaderAdapter
private lateinit var otherHeaderAdapter : FitnessHeaderAdapter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mStudentLife = MainActivity.studentLifeInstance
Expand All @@ -48,12 +63,16 @@ class PottruckFragment : Fragment() {

swipeRefresh.setColorSchemeResources(R.color.color_accent, R.color.color_primary)
recyclerView.layoutManager = LinearLayoutManager(mActivity, LinearLayoutManager.VERTICAL, false)
swipeRefresh.setOnRefreshListener { getFitnessRooms() }
swipeRefresh.setOnRefreshListener { getFitnessRooms(view) }

getFitnessRooms()
// populate the title/date of the app bar
initAppBar()

// populate recyclerview
getFitnessRooms(view)
}

private fun getFitnessRooms() {
private fun getFitnessRooms(view: View) {
//displays banner if not connected
if (!getConnected()) return

Expand All @@ -63,11 +82,36 @@ class PottruckFragment : Fragment() {
Log.i("Fitness Room${room.roomId}", "${room.roomName}")
}
val sortedRooms = fitnessRooms.sortedBy {it.roomName}

dataModel = FitnessPreferenceViewModel(sortedRooms)

mActivity.runOnUiThread {
val adapter = FitnessAdapter(sortedRooms)
recyclerView.adapter = adapter

favoritesAdapter = FitnessAdapter(true, dataModel)
otherAdapter = FitnessAdapter(false, dataModel)

favoriteHeaderAdapter = FitnessHeaderAdapter("Favorites")
otherHeaderAdapter = FitnessHeaderAdapter("Other Facilities")

val concatenated = ConcatAdapter(favoriteHeaderAdapter, favoritesAdapter,
otherHeaderAdapter, otherAdapter)

recyclerView.adapter = concatenated
loadingPanel.visibility = View.GONE
swipeRefresh.isRefreshing = false

// set click listener for favorites button
val fitnessPref : ImageView = view.findViewById(R.id.fitness_preferences)
fitnessPref.setOnClickListener {
dataModel.savePreferences()
val prefDialog = FitnessPreferencesFragment(dataModel, object: CloseListener{
override fun updateAdapters() {
favoritesAdapter.notifyDataSetChanged()
otherAdapter.notifyDataSetChanged()
}
})
prefDialog.show(mActivity.supportFragmentManager, "Fitness Preferences Dialog")
}
}
}, {
Log.e("PottruckFragment", "Error getting fitness rooms", it)
Expand Down Expand Up @@ -98,4 +142,19 @@ class PottruckFragment : Fragment() {
connectionToolbar.visibility = View.GONE
return true
}

/**
* Initialize the app bar of the fragment and
* fills in the textViews for the title/date
*/
private fun initAppBar() {
val appBarLayout : AppBarLayout = mView.findViewById(R.id.appbar_home_holder)
val titleView : TextView = mView.findViewById(R.id.title_view)
val dateView : TextView = mView.findViewById(R.id.date_view)

(appBarLayout.layoutParams as CoordinatorLayout.LayoutParams).behavior = ToolbarBehavior()

titleView.text = getString(R.string.fitness)
dateView.text = Utils.getCurrentSystemTime()
}
}
Loading

0 comments on commit d1df8f3

Please sign in to comment.