Skip to content

Commit

Permalink
Implement visual difference for public and private repos in list
Browse files Browse the repository at this point in the history
Closes #25
  • Loading branch information
alexandr7035 committed Sep 10, 2021
1 parent 192f92d commit 4e9aad4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import android.graphics.drawable.GradientDrawable
import android.text.format.DateFormat
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.alexandr7035.gitstat.R
import com.alexandr7035.gitstat.data.local.model.RepositoryEntity
import com.alexandr7035.gitstat.databinding.ViewRepositoryBinding

Expand Down Expand Up @@ -34,11 +36,31 @@ class RepositoriesAdapter(private val languagesColors: Map<String, Map<String, S
holder.binding.language.text = items[position].language
holder.binding.stars.text = items[position].stars.toString()

holder.binding.repoVisibility.text = when (items[position].isPrivate) {
true -> "Private"
else -> "Public"
when (items[position].isPrivate) {
true -> {
holder.binding.repoVisibility.text = "Private"
holder.binding.repoVisibility.setTextColor(ContextCompat.getColor(
holder.itemView.context,
R.color.white
))

holder.binding.repoVisibility.background = ContextCompat.getDrawable(
holder.itemView.context,
R.drawable.background_repo_visibilily_private)
}
else -> {
holder.binding.repoVisibility.text = "Public"
holder.binding.repoVisibility.setTextColor(ContextCompat.getColor(
holder.itemView.context,
R.color.black
))
holder.binding.repoVisibility.background = ContextCompat.getDrawable(
holder.itemView.context,
R.drawable.background_repo_visibilily)
}
}


val stringColor = when(languagesColors[holder.binding.language.text]) {
null -> colorUnknownLanguage
else -> languagesColors[holder.binding.language.text]!!["color"]
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/drawable/background_repo_visibilily_private.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid
android:color="@color/black"/>

<stroke
android:width="1dp"
android:color="@color/black"/>
<corners
android:radius="20dp"/>

</shape>
17 changes: 12 additions & 5 deletions app/src/main/res/layout/view_repository.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
android:textColor="@color/black"
android:textSize="22sp"
android:textStyle="bold"
android:layout_marginBottom="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/languageView"
tools:text="GitStat" />


Expand All @@ -28,9 +30,12 @@
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:background="@drawable/background_repo_visibilily"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:paddingStart="7dp"
android:paddingTop="3dp"
android:paddingEnd="7dp"
android:paddingBottom="3dp"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/languageView"
tools:text="Private" />
Expand All @@ -41,9 +46,9 @@
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_marginTop="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/repoName">
app:layout_constraintTop_toTopOf="@id/repoVisibility"
app:layout_constraintBottom_toBottomOf="@id/repoVisibility">

<View
android:id="@+id/languageColorView"
Expand Down Expand Up @@ -89,8 +94,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/repoVisibility"
app:layout_constraintBottom_toBottomOf="@id/repoVisibility"
tools:text="2017-02-21" />


Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
<color name="gray_400">#444444</color>
<color name="gray_300">#595959</color>
<color name="gray_200">#898989</color>
<color name="gray_100">#B1B1B1</color>

</resources>

0 comments on commit 4e9aad4

Please sign in to comment.