Created
October 19, 2021 22:05
-
-
Save natpenguin/bd9b85c5a3c7db8437256362e8450d5a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class DeliveryProgressView(context: Context, attributeSet: AttributeSet) : FrameLayout(context, attributeSet) { | |
private val progressBar: ProgressBar | |
private val notDeliveredCircleImageView: ImageView | |
private val deliveringCircleImageView: ImageView | |
private val deliveredCircleImageView: ImageView | |
init { | |
View.inflate(context, R.layout.delivery_progress_view, this) | |
progressBar = findViewById<ProgressBar>(R.id.progress_bar).apply { | |
progress = 50 | |
max = 100 | |
} | |
notDeliveredCircleImageView = findViewById(R.id.not_delivered_circle) | |
deliveringCircleImageView = findViewById(R.id.delivering_circle) | |
deliveredCircleImageView = findViewById(R.id.delivered_circle) | |
updateStatus() | |
} | |
var deliveryStatus: Int = 0 | |
set(value) { | |
updateStatus() | |
field = value | |
} | |
private fun updateStatus() { | |
when(deliveryStatus) { | |
1 -> { | |
progressBar.progress = 50 | |
notDeliveredCircleImageView.isSelected = false | |
deliveringCircleImageView.isSelected = true | |
deliveredCircleImageView.isSelected = false | |
} | |
2 -> { | |
progressBar.progress = 100 | |
notDeliveredCircleImageView.isSelected = false | |
deliveringCircleImageView.isSelected = false | |
deliveredCircleImageView.isSelected = true | |
} | |
else -> { | |
progressBar.progress = 0 | |
notDeliveredCircleImageView.isSelected = true | |
deliveringCircleImageView.isSelected = false | |
deliveredCircleImageView.isSelected = false | |
} | |
} | |
} | |
} | |
<?xml version="1.0" encoding="utf-8"?> | |
<merge xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:paddingHorizontal="10dp" | |
android:paddingVertical="8dp"> | |
<FrameLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<ProgressBar | |
android:id="@+id/progress_bar" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center_vertical" | |
android:paddingHorizontal="4dp" | |
style="@style/Widget.AppCompat.ProgressBar.Horizontal" | |
android:progress="50" | |
android:max="100" | |
android:progressTint="@color/black" /> | |
<FrameLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<ImageView | |
android:id="@+id/not_delivered_circle" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="start|center_vertical" | |
android:src="@drawable/delivery_progress_view_circle" /> | |
<ImageView | |
android:id="@+id/delivering_circle" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center_horizontal" | |
android:src="@drawable/delivery_progress_view_circle" /> | |
<ImageView | |
android:id="@+id/delivered_circle" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="end|center_vertical" | |
android:src="@drawable/delivery_progress_view_circle" /> | |
</FrameLayout> | |
</FrameLayout> | |
<Space | |
android:layout_width="match_parent" | |
android:layout_height="6dp" /> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:weightSum="3"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:textAlignment="textStart" | |
android:text="TEST1" /> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:textAlignment="center" | |
android:text="TEST2" /> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" | |
android:textAlignment="textEnd" | |
android:text="TEST3" /> | |
</LinearLayout> | |
</LinearLayout> | |
</merge> | |
<?xml version="1.0" encoding="utf-8"?> | |
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item android:state_selected="true"> | |
<shape android:shape="oval"> | |
<solid android:color="#666666"/> | |
<size | |
android:width="30dp" | |
android:height="30dp"/> | |
</shape> | |
</item> | |
<item android:state_selected="false"> | |
<shape android:shape="oval"> | |
<solid android:color="#666666"/> | |
<size | |
android:width="20dp" | |
android:height="20dp"/> | |
</shape> | |
</item> | |
</selector> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment