Skip to content

Commit

Permalink
Add a stub for empty contribution years
Browse files Browse the repository at this point in the history
Closes #69
  • Loading branch information
alexandr7035 committed Oct 5, 2021
1 parent df7b426 commit b2d8ad7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,18 @@ class YearCardFragment: Fragment() {
// Update chart
binding?.contributionsChart?.invalidate()

binding?.contributionsCountView?.text = this.days.sumOf { it.count }.toString()
val contributionsCount = this.days.sumOf { it.count }
binding?.contributionsCountView?.text = contributionsCount.toString()

// Show stub if no contributions for this year
if (contributionsCount == 0) {
binding?.emptyPlotStub?.visibility = View.VISIBLE
binding?.contributionsChart?.visibility = View.GONE
}
else {
binding?.emptyPlotStub?.visibility = View.GONE
binding?.contributionsChart?.visibility = View.VISIBLE
}
}


Expand Down
20 changes: 19 additions & 1 deletion app/src/main/res/layout/view_plot_contributions_year.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="200dp"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

Expand Down Expand Up @@ -40,4 +40,22 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/contributionsYear" />

<TextView
android:id="@+id/emptyPlotStub"
android:visibility="gone"
tools:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingEnd="20dp"
android:paddingStart="20dp"
android:text="@string/no_contributions_for_period"
android:textSize="24sp"
android:textColor="@color/gray_300"
android:textStyle="bold"
android:gravity="center_vertical|center_horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="total_contributions">total contributions</string>
<string name="contributions_rate">%1$.2f / d</string>
<string name="no_contributions_for_period">No contributions for this period of time :(</string>

</resources>

0 comments on commit b2d8ad7

Please sign in to comment.