Skip to content

Commit

Permalink
Add capacity circle and last updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
meiron03 committed Sep 17, 2023
1 parent b622263 commit c63a6f9
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.widget.*
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.text.HtmlCompat
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.github.mikephil.charting.charts.BarChart
Expand All @@ -29,6 +30,7 @@ import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.classes.FitnessRoom
import com.pennapps.labs.pennmobile.classes.FitnessRoomUsage
import com.pennapps.labs.pennmobile.classes.RoundedBarChartRenderer
import java.time.Duration
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.ZonedDateTime
Expand All @@ -49,6 +51,10 @@ class FitnessAdapter(private val fitnessRooms: List<FitnessRoom>) :
val progressBar : ProgressBar
val arrowView : ImageView

val lastUpdatedView : TextView
val capacityViewCircle : com.google.android.material.progressindicator.CircularProgressIndicator
val capacityView : TextView

private val extraInfoView : LinearLayout
private val barChart : BarChart

Expand All @@ -63,6 +69,10 @@ class FitnessAdapter(private val fitnessRooms: List<FitnessRoom>) :
hoursView = view.findViewById(R.id.item_fitness_hours)
arrowView = view.findViewById(R.id.fitness_more_indicator)

lastUpdatedView = view.findViewById(R.id.item_pottruck_last_updated)
capacityViewCircle = view.findViewById(R.id.item_pottruck_capacity_circle)
capacityView = view.findViewById(R.id.item_pottruck_capacity)

extraInfoView = view.findViewById(R.id.fitness_list_extra_layout)
progressBar = view.findViewById(R.id.fitness_progress)
barChart = view.findViewById(R.id.barchart_times)
Expand Down Expand Up @@ -105,43 +115,43 @@ class FitnessAdapter(private val fitnessRooms: List<FitnessRoom>) :
labels.add(if (i > 12) "${i - 12}pm" else "${i}am")
}

barChart.xAxis.valueFormatter = IndexAxisValueFormatter(labels);
barChart.xAxis.valueFormatter = IndexAxisValueFormatter(labels)

val set = BarDataSet(entries, "BarDataSet")

set.setDrawValues(false)
set.colors = colors

val data = BarData(set)
data.isHighlightEnabled = false;
data.isHighlightEnabled = false
data.barWidth = 0.5f // set custom bar width
val tf = ResourcesCompat.getFont(context, R.font.sf_pro_display_regular)
barChart.xAxis.typeface = tf

val leftAxis: YAxis = barChart.axisLeft
leftAxis.setDrawGridLines(false)
leftAxis.setDrawAxisLine(false)
leftAxis.setDrawLabels(false);
leftAxis.setDrawLabels(false)

leftAxis.axisMinimum = -0.05f * mxUsage
leftAxis.axisMaximum = mxUsage

val rightAxis: YAxis = barChart.axisRight
rightAxis.setDrawGridLines(false)
rightAxis.setDrawAxisLine(false)
rightAxis.setDrawLabels(false);
rightAxis.setDrawLabels(false)

val xAxis : XAxis = barChart.xAxis
xAxis.setDrawGridLines(false)
xAxis.axisLineWidth = 1f
xAxis.position = XAxis.XAxisPosition.BOTTOM
xAxis.setDrawAxisLine(true)

barChart.legend.isEnabled = false;
barChart.legend.isEnabled = false
barChart.setDrawBorders(false)
barChart.setFitBars(true)
barChart.description.isEnabled = false
barChart.setScaleEnabled(false);
barChart.setScaleEnabled(false)

barChart.renderer = RoundedBarChartRenderer(barChart, barChart.animator,
barChart.viewPortHandler, 50.0f)
Expand All @@ -155,8 +165,8 @@ class FitnessAdapter(private val fitnessRooms: List<FitnessRoom>) :
val view = extraInfoView

if (!extraIsVisible) {
view.visibility = View.VISIBLE;
view.alpha = 0.0f;
view.visibility = View.VISIBLE
view.alpha = 0.0f

view.animate()
.alpha(1.0f)
Expand All @@ -170,11 +180,11 @@ class FitnessAdapter(private val fitnessRooms: List<FitnessRoom>) :
0.5f
)
rotate.duration = 200
rotate.fillAfter = true;
rotate.fillAfter = true
rotate.interpolator = LinearInterpolator()
arrowView.startAnimation(rotate)
} else {
view.visibility = View.GONE;
view.visibility = View.GONE

val rotate = RotateAnimation(
90f,
Expand All @@ -185,7 +195,7 @@ class FitnessAdapter(private val fitnessRooms: List<FitnessRoom>) :
0.5f
)
rotate.duration = 10
rotate.fillAfter = true;
rotate.fillAfter = true
rotate.interpolator = LinearInterpolator()
arrowView.startAnimation(rotate)
}
Expand All @@ -203,7 +213,7 @@ class FitnessAdapter(private val fitnessRooms: List<FitnessRoom>) :
}

override fun onViewAttachedToWindow(holder: ViewHolder) {
// rerotate the image if the extra information panels are open
// re-rotate the image if the extra information panels are open
if (holder.extraIsVisible) {
val rotate = RotateAnimation(
0f,
Expand All @@ -214,7 +224,7 @@ class FitnessAdapter(private val fitnessRooms: List<FitnessRoom>) :
0.5f
)
rotate.duration = 10
rotate.fillAfter = true;
rotate.fillAfter = true
rotate.interpolator = LinearInterpolator()
holder.arrowView.startAnimation(rotate)
}
Expand All @@ -229,7 +239,7 @@ class FitnessAdapter(private val fitnessRooms: List<FitnessRoom>) :
val currentTime = LocalTime.now()

// Sunday -> 0, Monday -> 1, etc.
val dayOfWeek = ZonedDateTime.now().dayOfWeek.value;
val dayOfWeek = ZonedDateTime.now().dayOfWeek.value

// the open and close time lists start with monday
val openTimeString = room.openTimeList?.get((dayOfWeek + 6) % 7)
Expand All @@ -256,7 +266,31 @@ class FitnessAdapter(private val fitnessRooms: List<FitnessRoom>) :
holder.progressBar.visibility = View.INVISIBLE

// get image from url
Glide.with(mContext).load(room.imageURL).into(holder.imageView);
Glide.with(mContext).load(room.imageURL).into(holder.imageView)


// update the capacity
if (room.capacity == null) {
holder.capacityView.text = "N/A"
holder.capacityViewCircle.progress = 0
} else {
val capacityInt = room.capacity!!.toInt()
val capacity = "$capacityInt%"

holder.capacityView.text = capacity
holder.capacityViewCircle.progress = capacityInt
}

// update the time for last updated
val lastUpdateTime = ZonedDateTime.parse(room.lastUpdated)
val duration = Duration.between(lastUpdateTime, ZonedDateTime.now())

val hourDiff = duration.toHours()
val minuteDiff = duration.toMinutes() % 60

val lastUpd = "<b>Last Updated:</b> $hourDiff hours and $minuteDiff minutes ago"

holder.lastUpdatedView.text = HtmlCompat.fromHtml(lastUpd, HtmlCompat.FROM_HTML_MODE_COMPACT)

holder.mainView.bringToFront()
// garbage code starts here ------------------------------------
Expand Down
55 changes: 44 additions & 11 deletions PennMobile/src/main/res/layout/fitness_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,28 +179,61 @@
android:orientation="horizontal">

<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_margin="4dp"
app:cardCornerRadius="8dp"
app:layout_constraintRight_toRightOf="@+id/linear_layout_extras">

<TextView
android:id="@+id/item_pottruck_last_updated"
android:layout_gravity="center"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:padding="8dp"
app:cardCornerRadius="8dp"
app:autoSizeMaxTextSize="13sp"
app:autoSizeMinTextSize="9sp"
app:autoSizeStepGranularity="2sp"
app:autoSizeTextType="uniform"
tools:text="Last Updated: 722 hours and 3 minutes ago"
android:textSize="17sp"
/>

</androidx.cardview.widget.CardView>


<androidx.cardview.widget.CardView
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
app:cardCornerRadius="8dp"
app:layout_constraintRight_toRightOf="@+id/linear_layout_extras">

<!--<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/progress_bar"
app:indicatorSize="70dp"
<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/item_pottruck_capacity_circle"
android:layout_gravity="center"
app:indicatorSize="80dp"
android:progress="70"
app:trackCornerRadius="5dp"
app:trackThickness="7dp"
app:trackColor="#DDD"
app:indicatorColor="@color/blue"
app:indicatorColor="@color/logo_light_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"/>

<TextView
android:id="@+id/item_pottruck_capacity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
-->
android:layout_gravity="center"
tools:text="60%"
android:textSize="18sp"/>
</androidx.cardview.widget.CardView>
</LinearLayout>

Expand Down

0 comments on commit c63a6f9

Please sign in to comment.