Skip to content

Commit a7c8cbf

Browse files
authored
Dining prediction graphs (#557)
* Added dining dollars and dining swipes predictions * Updated imports * Update gradle * Update gradle * Removed unused dependency * Change name of dining hall tab and small change to days in semester * Centered dining analytics graphs * Small style changes to dining graphs
1 parent 04aea39 commit a7c8cbf

15 files changed

Lines changed: 495 additions & 57 deletions

PennMobile/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ buildscript {
66
jcenter()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:4.1.1'
9+
classpath 'com.android.tools.build:gradle:4.1.3'
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
classpath "org.jacoco:org.jacoco.core:0.8.5"
1212
}
@@ -74,6 +74,9 @@ dependencies {
7474
implementation 'com.jakewharton:butterknife:10.2.1'
7575
implementation 'androidx.annotation:annotation:1.1.0'
7676
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
77+
implementation ("androidx.lifecycle:lifecycle-extensions:2.2.0@aar") {
78+
transitive = true
79+
}
7780
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1'
7881
implementation 'com.squareup.retrofit:retrofit:1.9.0'
7982
implementation 'com.squareup.picasso:picasso:2.71828'
@@ -86,14 +89,13 @@ dependencies {
8689
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
8790
testImplementation 'junit:junit:4.13'
8891
androidTestImplementation 'org.testng:testng:7.1.0'
89-
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
92+
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
9093
implementation 'androidx.cardview:cardview:1.0.0'
9194
implementation 'com.github.ahorn:android-rss:master-SNAPSHOT'
9295
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
9396
// official release is several years old and is not thread-safe
9497
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7"
9598
implementation 'com.eightbitlab:supportrenderscriptblur:1.0.2'
96-
implementation 'com.eightbitlab:blurview:1.6.3'
9799
implementation 'androidx.palette:palette-ktx:1.0.0'
98100
implementation 'com.github.searchy2:CustomAlertViewDialogue:2.6.1'
99101
implementation 'com.airbnb.android:lottie:4.2.0'

PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningHolderFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class DiningHolderFragment : Fragment() {
4747
pager.setUserInputEnabled(false)
4848
TabLayoutMediator(tabLayout, pager) { tab, position ->
4949
if (position == 0) {
50-
tab.text = "Dining"
50+
tab.text = "Dining Halls"
5151
} else {
5252
tab.text = "Insights"
5353
}

PennMobile/src/main/java/com/pennapps/labs/pennmobile/DiningInsightsFragment.kt

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.pennapps.labs.pennmobile.adapters.DiningInsightsCardAdapter
1515
import com.pennapps.labs.pennmobile.api.CampusExpress
1616
import com.pennapps.labs.pennmobile.api.CampusExpressNetworkManager
1717
import com.pennapps.labs.pennmobile.classes.DiningBalances
18+
import com.pennapps.labs.pennmobile.classes.DiningBalancesList
1819
import com.pennapps.labs.pennmobile.classes.DiningInsightCell
1920
import com.pennapps.labs.pennmobile.classes.DollarsSpentCell
2021
import kotlinx.android.synthetic.main.fragment_dining.*
@@ -23,14 +24,15 @@ import kotlinx.android.synthetic.main.fragment_dining_insights.*
2324
import kotlinx.android.synthetic.main.fragment_dining_insights.view.*
2425
import kotlinx.android.synthetic.main.fragment_gsr.*
2526
import kotlinx.android.synthetic.main.fragment_home.view.*
27+
import java.time.LocalDateTime
28+
import java.time.format.DateTimeFormatter
2629
import java.util.*
2730
import 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
*/
3537
class 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

Comments
 (0)