From 8423916b2ed671f1e0053c93daaf929a17da62bc Mon Sep 17 00:00:00 2001 From: meiron03 Date: Thu, 13 Apr 2023 12:33:42 -0400 Subject: [PATCH 01/36] Add fitness (currently replaces PCA) with bar chart for room usage. --- PennMobile/build.gradle | 3 +- .../labs/pennmobile/DiningHolderFragment.kt | 1 - .../labs/pennmobile/FitnessFragment.kt | 24 -- .../labs/pennmobile/FitnessHolderFragment.kt | 71 ++++ .../pennapps/labs/pennmobile/MainActivity.kt | 2 +- .../PennCourseAlertCreateAlertFragment.kt | 6 +- .../labs/pennmobile/PottruckFragment.kt | 100 ++++++ .../pennmobile/adapters/FitnessAdapter.kt | 318 +++++++++++++----- .../adapters/FitnessPagerAdapter.kt | 16 + .../labs/pennmobile/api/StudentLife.java | 8 +- .../labs/pennmobile/classes/FitnessRoom.kt | 36 ++ .../pennmobile/classes/FitnessRoomUsage.kt | 22 ++ .../classes/RoundedBarChartRenderer.kt | 146 ++++++++ .../src/main/res/layout/fitness_list_item.xml | 219 +++++++++--- .../src/main/res/layout/fragment_dining.xml | 2 - .../res/layout/fragment_dining_holder.xml | 3 +- .../res/layout/fragment_fitness_holder.xml | 150 +++++++++ .../src/main/res/layout/fragment_pottruck.xml | 69 ++++ PennMobile/src/main/res/values/strings.xml | 5 + PennMobile/src/main/res/values/styles.xml | 11 + 20 files changed, 1049 insertions(+), 163 deletions(-) create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessHolderFragment.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/PottruckFragment.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/FitnessPagerAdapter.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/FitnessRoom.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/FitnessRoomUsage.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/RoundedBarChartRenderer.kt create mode 100644 PennMobile/src/main/res/layout/fragment_fitness_holder.xml create mode 100644 PennMobile/src/main/res/layout/fragment_pottruck.xml diff --git a/PennMobile/build.gradle b/PennMobile/build.gradle index 4140cb0c0..e1a0df414 100644 --- a/PennMobile/build.gradle +++ b/PennMobile/build.gradle @@ -65,7 +65,6 @@ dependencies { implementation 'androidx.multidex:multidex:2.0.1' implementation 'com.google.maps:google-maps-services:0.13.0' implementation 'org.jsoup:jsoup:1.13.1' - implementation 'com.google.android.material:material:1.1.0' implementation 'androidx.percentlayout:percentlayout:1.0.0' implementation 'androidx.exifinterface:exifinterface:1.2.0' implementation 'androidx.preference:preference-ktx:1.1.1' @@ -73,7 +72,7 @@ dependencies { implementation 'com.google.android.gms:play-services-location:17.0.0' implementation 'joda-time:joda-time:2.10.6' implementation 'org.apache.commons:commons-lang3:3.10' - implementation 'com.google.android.material:material:1.1.0' + implementation 'com.google.android.material:material:1.2.0' implementation 'com.jakewharton:butterknife:10.2.1' implementation 'androidx.annotation:annotation:1.1.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt index aa8decd26..59699baf0 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt @@ -26,7 +26,6 @@ class DiningHolderFragment : Fragment() { super.onCreate(savedInstanceState) mActivity = activity as MainActivity mActivity.closeKeyboard() - } @RequiresApi(Build.VERSION_CODES.M) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessFragment.kt index dbae8c0cb..82ef219dd 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessFragment.kt @@ -68,30 +68,6 @@ class FitnessFragment : Fragment() { internetConnectionFitness?.visibility = View.GONE } - // get API data - val labs = MainActivity.studentLifeInstance - labs.gymData.subscribe({ gyms -> - mActivity.runOnUiThread { - gym_list?.adapter = FitnessAdapter(gyms) - // get rid of loading screen - loadingPanel?.visibility = View.GONE - if (gyms.size > 0) { - no_results?.visibility = View.GONE - } else { - no_results?.visibility = View.VISIBLE - } - // stop refreshing - gym_refresh_layout?.isRefreshing = false - } - }, { throwable -> - mActivity.runOnUiThread { - throwable.printStackTrace() - Toast.makeText(activity, "Could not load gym information", Toast.LENGTH_LONG).show() - loadingPanel?.visibility = View.GONE - no_results?.visibility = View.VISIBLE - gym_refresh_layout?.isRefreshing = false - } - }) } override fun onResume() { diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessHolderFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessHolderFragment.kt new file mode 100644 index 000000000..6d1acfb3d --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/FitnessHolderFragment.kt @@ -0,0 +1,71 @@ +package com.pennapps.labs.pennmobile + +import android.os.Bundle +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 +import com.pennapps.labs.pennmobile.components.collapsingtoolbar.ToolbarBehavior +import com.pennapps.labs.pennmobile.utils.Utils + +import kotlinx.android.synthetic.main.fragment_fitness_holder.pager +import kotlinx.android.synthetic.main.fragment_fitness_holder.tabLayout + +class FitnessHolderFragment: Fragment() { + private lateinit var mActivity : MainActivity + private lateinit var mView : View + private lateinit var pagerAdapter : FitnessPagerAdapter + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + mActivity = activity as MainActivity + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + super.onCreateView(inflater, container, savedInstanceState) + return inflater.inflate(R.layout.fragment_fitness_holder, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + mView = view + // initialize app bar and swipe refresh + initAppBar() + + pagerAdapter = FitnessPagerAdapter(this) + pager?.adapter = pagerAdapter + pager.isUserInputEnabled = false + TabLayoutMediator(tabLayout, pager) { tab, position -> + if (position == 0) { + tab.text = "Pottruck" + } else { + tab.text = "Other Facilities" + } + }.attach() + } + + /** + * 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() + } +} \ No newline at end of file diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt index 0084f86e8..1de149df3 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt @@ -134,7 +134,7 @@ class MainActivity : AppCompatActivity() { fragment = HomeFragment() } "Dining" -> fragment = DiningHolderFragment() - "PCA" -> fragment = PennCourseAlertHolderFragment() + "PCA" -> fragment = FitnessHolderFragment() "GSR" -> fragment = GsrTabbedFragment() "Laundry" -> fragment = LaundryFragment() "More" -> fragment = MoreFragment() diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertCreateAlertFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertCreateAlertFragment.kt index 248d75830..5919e2b00 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertCreateAlertFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/PennCourseAlertCreateAlertFragment.kt @@ -59,7 +59,6 @@ class PennCourseAlertCreateAlertFragment : Fragment() { // hideInternetErrorBar(view) } - val sp = PreferenceManager.getDefaultSharedPreferences(activity) val pennKey = sp.getString(getString(R.string.pennkey), null) val bearerToken = "Bearer " + sp.getString(getString(R.string.access_token), "").toString() @@ -80,9 +79,10 @@ class PennCourseAlertCreateAlertFragment : Fragment() { viewModel.userInfo.observe(viewLifecycleOwner, Observer { val formattedPhoneNumber = viewModel.userInfo.value?.profile?.phone?.drop(2) val email = viewModel.userInfo.value?.profile?.email + phoneNumberEditText.text = - Editable.Factory.getInstance().newEditable(formattedPhoneNumber) - emailEditText.text = Editable.Factory.getInstance().newEditable(email) + Editable.Factory.getInstance().newEditable(formattedPhoneNumber?: "") + emailEditText.text = Editable.Factory.getInstance().newEditable(email?: "") }) val alertButton = view.findViewById