-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added dining marker and interactive dining graphs
- Loading branch information
Showing
4 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/DiningMarkerView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.pennapps.labs.pennmobile.classes | ||
|
||
import android.content.Context | ||
import android.graphics.Canvas | ||
import android.util.Log | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import com.github.mikephil.charting.components.MarkerView | ||
import com.pennapps.labs.pennmobile.R | ||
import com.github.mikephil.charting.data.Entry | ||
import com.github.mikephil.charting.highlight.Highlight | ||
import com.github.mikephil.charting.utils.MPPointF | ||
import com.pennapps.labs.pennmobile.adapters.DiningInsightsCardAdapter | ||
import kotlinx.android.synthetic.main.dining_spent_card.view.view | ||
import java.text.SimpleDateFormat | ||
import java.util.Date | ||
import kotlin.math.roundToInt | ||
|
||
class DiningMarkerView(context: Context, layoutResource: Int) : MarkerView(context, layoutResource) { | ||
|
||
companion object { | ||
private const val DINING_DOLLARS_PREDICTIONS = 2 | ||
private const val DINING_SWIPES_PREDICTIONS = 3 | ||
} | ||
private val textView: TextView = findViewById(R.id.dining_marker_text) | ||
private val point: ImageView = findViewById(R.id.dining_marker_point) | ||
private var xValue: Float = 0.0F | ||
private var yValue: Float = 0.0F | ||
private var typeId: Int = 0 | ||
|
||
// Callback method to update the marker content | ||
override fun refreshContent(entry: Entry, highlight: Highlight) { | ||
xValue = entry.x | ||
yValue = entry.y | ||
//convert entry.x to date | ||
val daysFromStart = xValue.roundToInt() | ||
val sdf = SimpleDateFormat("MMM. dd") | ||
val date = DiningInsightsCardAdapter.Utils.addDaysToDateMMMdd(DiningInsightsCardAdapter.START_DAY_OF_SEMESTER, daysFromStart) | ||
|
||
var diningData = String.format("%.2f", yValue) | ||
if (typeId == DINING_SWIPES_PREDICTIONS) { | ||
diningData = yValue.toInt().toString() | ||
} | ||
if (typeId == DINING_DOLLARS_PREDICTIONS) { | ||
diningData = "\$" + diningData | ||
} | ||
textView.text = buildString { | ||
append(date) | ||
append("\n") | ||
append(diningData) | ||
} | ||
if(typeId == DINING_SWIPES_PREDICTIONS) { | ||
textView.setTextColor(context.getColor(R.color.diningBlue)) | ||
point.setColorFilter(context.getColor(R.color.diningBlue)) | ||
} | ||
else { | ||
textView.setTextColor(context.getColor(R.color.diningGreen)) | ||
point.setColorFilter(context.getColor(R.color.diningGreen)) | ||
} | ||
} | ||
|
||
fun setGraphType(typeId: Int) { | ||
this.typeId = typeId | ||
} | ||
// This is used to reposition the marker | ||
override fun getOffset(): MPPointF { | ||
return MPPointF(0.0F, (-height / 6).toFloat()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
android:padding="0dp"> | ||
|
||
<ImageView | ||
android:id="@+id/dining_marker_point" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:src="@drawable/dining_insights_circle" | ||
/> | ||
|
||
<TextView | ||
android:id="@+id/dining_marker_text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:fontFamily="@font/gilroy_bold" | ||
android:text="@string/dining_graph_point" | ||
android:textColor="@android:color/black" | ||
android:textSize="14sp" /> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters