@@ -15,6 +15,7 @@ import com.pennapps.labs.pennmobile.adapters.DiningInsightsCardAdapter
1515import com.pennapps.labs.pennmobile.api.CampusExpress
1616import com.pennapps.labs.pennmobile.api.CampusExpressNetworkManager
1717import com.pennapps.labs.pennmobile.classes.DiningBalances
18+ import com.pennapps.labs.pennmobile.classes.DiningBalancesList
1819import com.pennapps.labs.pennmobile.classes.DiningInsightCell
1920import com.pennapps.labs.pennmobile.classes.DollarsSpentCell
2021import kotlinx.android.synthetic.main.fragment_dining.*
@@ -23,14 +24,15 @@ import kotlinx.android.synthetic.main.fragment_dining_insights.*
2324import kotlinx.android.synthetic.main.fragment_dining_insights.view.*
2425import kotlinx.android.synthetic.main.fragment_gsr.*
2526import kotlinx.android.synthetic.main.fragment_home.view.*
27+ import java.time.LocalDateTime
28+ import java.time.format.DateTimeFormatter
2629import java.util.*
2730import kotlin.collections.ArrayList
2831
2932
3033/* *
31- * A simple [Fragment] subclass.
32- * Use the [DiningInsightsFragment.newInstance] factory method to
33- * create an instance of this fragment.
34+ * Dining Insights Fragment
35+ * Created by Julius Snipes
3436 */
3537class DiningInsightsFragment : Fragment () {
3638
@@ -60,8 +62,14 @@ class DiningInsightsFragment : Fragment() {
6062 networkManager = CampusExpressNetworkManager (mActivity)
6163 val diningBalance = DollarsSpentCell ()
6264 diningBalance.type = " dining_balance"
65+ val diningDollarsPredictionsCell = DiningInsightCell ()
66+ diningDollarsPredictionsCell.type = " dining_dollars_predictions"
67+ val diningSwipesPredictionsCell = DiningInsightCell ()
68+ diningSwipesPredictionsCell.type = " dining_swipes_predictions"
6369 cells = ArrayList ()
6470 cells.add(diningBalance)
71+ cells.add(diningDollarsPredictionsCell)
72+ cells.add(diningSwipesPredictionsCell)
6573 insightsrv = view.insightsrv
6674 insightsrv.adapter = DiningInsightsCardAdapter (cells)
6775 val networkManager = CampusExpressNetworkManager (mActivity)
@@ -97,6 +105,7 @@ class DiningInsightsFragment : Fragment() {
97105 super .onResume()
98106 }
99107
108+ @RequiresApi(Build .VERSION_CODES .O )
100109 private fun refresh () {
101110 val accessToken = networkManager.getAccessToken()
102111 if (accessToken == " " ) {
@@ -116,6 +125,7 @@ class DiningInsightsFragment : Fragment() {
116125
117126
118127
128+ @RequiresApi(Build .VERSION_CODES .O )
119129 private fun getInsights (accessToken : String? ) {
120130 if (! isOnline(context)) {
121131 internetConnectionDiningInsights?.setBackgroundColor(resources.getColor(R .color.darkRedBackground))
@@ -140,6 +150,23 @@ class DiningInsightsFragment : Fragment() {
140150 dining_insights_refresh?.isRefreshing = false
141151 }
142152 })
153+ val current = LocalDateTime .now()
154+ val formatter = DateTimeFormatter .ofPattern(" yyyy-MM-dd" )
155+ val formattedCurrentDate = current.format(formatter)
156+ mCampusExpress.getPastDiningBalances(bearerToken, DiningInsightsCardAdapter .START_DAY_OF_SEMESTER , formattedCurrentDate).subscribe( { t: DiningBalancesList ? ->
157+ activity?.runOnUiThread {
158+ cells[1 ].diningBalancesList = t
159+ cells[2 ].diningBalancesList = t
160+ (insightsrv.adapter as DiningInsightsCardAdapter ).notifyItemChanged(1 )
161+ (insightsrv.adapter as DiningInsightsCardAdapter ).notifyItemChanged(2 )
162+ dining_insights_refresh?.isRefreshing = false
163+ } },
164+ { throwable ->
165+ activity?.runOnUiThread {
166+ Log .e(" DiningInsightsFragment" , " Error getting balances" , throwable)
167+ dining_insights_refresh?.isRefreshing = false
168+ }
169+ })
143170
144171 }
145172
0 commit comments