From 4742a5855d94a203a9de987ebd54f29496dfe47d Mon Sep 17 00:00:00 2001 From: Julius Snipes Date: Fri, 18 Mar 2022 20:26:00 -0400 Subject: [PATCH 01/23] Added dining insights fragment. Can currently see a mock dining dollars and swipes. --- .../labs/pennmobile/DiningFragment.kt | 2 + .../labs/pennmobile/DiningHolderFragment.kt | 32 +++ .../labs/pennmobile/DiningInsightsFragment.kt | 27 +++ .../pennapps/labs/pennmobile/MainActivity.kt | 2 +- .../pennmobile/adapters/DiningPagerAdapter.kt | 37 +++ .../res/drawable/dining_insights_circle.xml | 24 ++ .../drawable/dining_insights_rectangle.xml | 30 +++ .../drawable/ic_baseline_people_alt_24.xml | 23 ++ .../res/layout/fragment_dining_holder.xml | 13 ++ .../res/layout/fragment_dining_insights.xml | 211 ++++++++++++++++++ PennMobile/src/main/res/values/strings.xml | 5 + PennMobile/src/main/res/values/styles.xml | 20 ++ 12 files changed, 425 insertions(+), 1 deletion(-) create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInsightsFragment.kt create mode 100644 PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningPagerAdapter.kt create mode 100644 PennMobile/src/main/res/drawable/dining_insights_circle.xml create mode 100644 PennMobile/src/main/res/drawable/dining_insights_rectangle.xml create mode 100644 PennMobile/src/main/res/drawable/ic_baseline_people_alt_24.xml create mode 100644 PennMobile/src/main/res/layout/fragment_dining_holder.xml create mode 100644 PennMobile/src/main/res/layout/fragment_dining_insights.xml diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt index bf59f932..56f694f2 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningFragment.kt @@ -2,6 +2,7 @@ package com.pennapps.labs.pennmobile import android.os.Build import android.os.Bundle +import android.util.Log import android.view.* import android.view.View import android.widget.LinearLayout @@ -152,6 +153,7 @@ class DiningFragment : Fragment() { view?.let { displaySnack(it, "Just Updated") } } }, { + Log.e("DiningFragment", "Error getting dining halls", it); mActivity.runOnUiThread { loadingPanel?.visibility = View.GONE internetConnectionDining?.setBackgroundColor(resources.getColor(R.color.darkRedBackground)) diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt new file mode 100644 index 00000000..e0e6b24f --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt @@ -0,0 +1,32 @@ +package com.pennapps.labs.pennmobile + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.pennapps.labs.pennmobile.adapters.DiningPagerAdapter +import kotlinx.android.synthetic.main.fragment_dining_holder.* + +class DiningHolderFragment : Fragment() { + + lateinit var pagerAdapter: DiningPagerAdapter + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_dining_holder, container, false) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val fragmentManager = childFragmentManager; + pagerAdapter = DiningPagerAdapter(fragmentManager, lifecycle) + pager?.setAdapter(pagerAdapter) + } +} \ No newline at end of file diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInsightsFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInsightsFragment.kt new file mode 100644 index 00000000..4c6aca3d --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInsightsFragment.kt @@ -0,0 +1,27 @@ +package com.pennapps.labs.pennmobile + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup + + +/** + * A simple [Fragment] subclass. + * Use the [DiningInsightsFragment.newInstance] factory method to + * create an instance of this fragment. + */ +class DiningInsightsFragment : Fragment() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + } + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle?): View? { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_dining_insights, container, false) + } + +} \ 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 57bcee60..3b474115 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/MainActivity.kt @@ -130,7 +130,7 @@ class MainActivity : AppCompatActivity() { "Home" -> if (fragmentManager.backStackEntryCount > 0) { fragment = HomeFragment() } - "Dining" -> fragment = DiningFragment() + "Dining" -> fragment = DiningHolderFragment() "GSR" -> fragment = GsrTabbedFragment() "Laundry" -> fragment = LaundryFragment() "More" -> fragment = MoreFragment() diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningPagerAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningPagerAdapter.kt new file mode 100644 index 00000000..19f3205c --- /dev/null +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/DiningPagerAdapter.kt @@ -0,0 +1,37 @@ +package com.pennapps.labs.pennmobile.adapters + +import androidx.fragment.app.Fragment +import androidx.fragment.app.FragmentManager +import androidx.lifecycle.Lifecycle +import androidx.viewpager2.adapter.FragmentStateAdapter +import com.pennapps.labs.pennmobile.DiningFragment +import com.pennapps.labs.pennmobile.DiningInsightsFragment +import java.util.* + +class DiningPagerAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle?) : FragmentStateAdapter(fragmentManager, lifecycle!!) { + override fun createFragment(position: Int): Fragment { + return BASE_FRAGMENTS[position] + } + + override fun getItemCount(): Int { + return COUNT + } + + override fun getItemId(position: Int): Long { + if (position == HOME_POSITION + && createFragment(position) == BASE_FRAGMENTS[position]) { + return HOME_POSITION.toLong() + } else if (position == INSIGHTS_POSITION + && createFragment(position) == BASE_FRAGMENTS[position]) { + return INSIGHTS_POSITION.toLong() + } + return createFragment(position).hashCode().toLong() + } + + companion object { + private val BASE_FRAGMENTS = Arrays.asList(DiningFragment(), DiningInsightsFragment()) + private const val HOME_POSITION = 0 + private const val INSIGHTS_POSITION = 1 + val COUNT = BASE_FRAGMENTS.size + } +} \ No newline at end of file diff --git a/PennMobile/src/main/res/drawable/dining_insights_circle.xml b/PennMobile/src/main/res/drawable/dining_insights_circle.xml new file mode 100644 index 00000000..9f719ede --- /dev/null +++ b/PennMobile/src/main/res/drawable/dining_insights_circle.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/PennMobile/src/main/res/drawable/dining_insights_rectangle.xml b/PennMobile/src/main/res/drawable/dining_insights_rectangle.xml new file mode 100644 index 00000000..50b89955 --- /dev/null +++ b/PennMobile/src/main/res/drawable/dining_insights_rectangle.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PennMobile/src/main/res/drawable/ic_baseline_people_alt_24.xml b/PennMobile/src/main/res/drawable/ic_baseline_people_alt_24.xml new file mode 100644 index 00000000..58169a9a --- /dev/null +++ b/PennMobile/src/main/res/drawable/ic_baseline_people_alt_24.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/PennMobile/src/main/res/layout/fragment_dining_holder.xml b/PennMobile/src/main/res/layout/fragment_dining_holder.xml new file mode 100644 index 00000000..c3536850 --- /dev/null +++ b/PennMobile/src/main/res/layout/fragment_dining_holder.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/PennMobile/src/main/res/layout/fragment_dining_insights.xml b/PennMobile/src/main/res/layout/fragment_dining_insights.xml new file mode 100644 index 00000000..e8bdf049 --- /dev/null +++ b/PennMobile/src/main/res/layout/fragment_dining_insights.xml @@ -0,0 +1,211 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PennMobile/src/main/res/values/strings.xml b/PennMobile/src/main/res/values/strings.xml index 4368196a..0f531bb3 100644 --- a/PennMobile/src/main/res/values/strings.xml +++ b/PennMobile/src/main/res/values/strings.xml @@ -46,6 +46,11 @@ Order by Residential Hall Order by Open Status Closed today + Dining Balance + Dining Balance + Swipes + Guest Swipes + $ Washers diff --git a/PennMobile/src/main/res/values/styles.xml b/PennMobile/src/main/res/values/styles.xml index b4c73d18..0a0576e5 100644 --- a/PennMobile/src/main/res/values/styles.xml +++ b/PennMobile/src/main/res/values/styles.xml @@ -143,6 +143,26 @@ true + + + + + + + + + + + + +