-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from boostcampwm2023/feature/android/174
바텀 재생 바 UI 구성
- Loading branch information
Showing
6 changed files
with
178 additions
and
0 deletions.
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
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
76 changes: 76 additions & 0 deletions
76
...d/feature/player/src/main/java/com/ohdodok/catchytape/feature/player/PlayerControlView.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,76 @@ | ||
package com.ohdodok.catchytape.feature.player | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.widget.ImageButton | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.appcompat.content.res.AppCompatResources | ||
import androidx.constraintlayout.widget.ConstraintLayout | ||
import com.google.android.material.progressindicator.LinearProgressIndicator | ||
import com.ohdodok.catchytape.core.ui.R.* | ||
import com.ohdodok.catchytape.core.ui.bindImg | ||
import kotlin.properties.Delegates | ||
|
||
class PlayerControlView(context: Context, attrs: AttributeSet) : ConstraintLayout(context, attrs) { | ||
|
||
private lateinit var thumbnailUrl: String | ||
private lateinit var title: String | ||
private lateinit var artist: String | ||
private var isPlaying: Boolean by Delegates.notNull() | ||
private var progress: Int by Delegates.notNull() | ||
private var duration: Int by Delegates.notNull() | ||
|
||
init { | ||
initAttrs(attrs) | ||
initView() | ||
} | ||
|
||
private fun initAttrs(attrs: AttributeSet) { | ||
context.theme.obtainStyledAttributes( | ||
attrs, | ||
R.styleable.PlayerBarView, | ||
0, 0 | ||
).apply { | ||
try { | ||
thumbnailUrl = getString(R.styleable.PlayerBarView_thumbnailUrl) ?: "" | ||
title = getString(R.styleable.PlayerBarView_title) ?: "" // 썸네일 | ||
artist = getString(R.styleable.PlayerBarView_artist) ?: "" | ||
isPlaying = getBoolean(R.styleable.PlayerBarView_isPlaying, false) | ||
progress = getInt(R.styleable.PlayerBarView_progress, 0) | ||
duration = getInt(R.styleable.PlayerBarView_duration, 0) | ||
} finally { | ||
recycle() | ||
} | ||
} | ||
} | ||
|
||
private fun initView() { | ||
inflate(context, R.layout.view_player_control, this) | ||
|
||
val thumbnailView: ImageView = findViewById(R.id.iv_thumbnail) | ||
val titleView: TextView = findViewById(R.id.tv_title) | ||
val artistView: TextView = findViewById(R.id.tv_artist) | ||
val playButton: ImageButton = findViewById(R.id.ib_play) | ||
val indicator: LinearProgressIndicator = findViewById(R.id.lpi_player_progress) | ||
|
||
thumbnailView.bindImg(thumbnailUrl) | ||
|
||
titleView.text = title | ||
artistView.text = artist | ||
|
||
val buttonDrawable = | ||
if (isPlaying) AppCompatResources.getDrawable(context, drawable.ic_pause) | ||
else AppCompatResources.getDrawable(context, drawable.ic_play) | ||
playButton.setImageDrawable(buttonDrawable) | ||
|
||
indicator.progress = progress | ||
indicator.max = duration | ||
} | ||
|
||
fun setOnPlayButtonClick(onPlayButtonClick: () -> Unit) { | ||
val playButton: ImageButton = findViewById(R.id.ib_play) | ||
|
||
playButton.setOnClickListener { onPlayButtonClick() } | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
android/feature/player/src/main/res/layout/view_player_control.xml
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,72 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="65dp" | ||
android:background="@color/surface_bright"> | ||
|
||
<ImageView | ||
android:id="@+id/iv_thumbnail" | ||
android:layout_width="40dp" | ||
android:layout_height="40dp" | ||
android:layout_marginStart="@dimen/margin_horizontal" | ||
android:scaleType="centerCrop" | ||
app:layout_constraintBottom_toTopOf="@id/lpi_player_progress" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:background="@color/on_surface_variant" /> | ||
|
||
<TextView | ||
android:id="@+id/tv_title" | ||
style="@style/BodyMedium" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_marginStart="@dimen/medium" | ||
android:ellipsize="end" | ||
android:maxLines="1" | ||
app:layout_constraintBottom_toTopOf="@id/tv_artist" | ||
app:layout_constraintEnd_toStartOf="@id/ib_play" | ||
app:layout_constraintStart_toEndOf="@id/iv_thumbnail" | ||
app:layout_constraintTop_toTopOf="@id/iv_thumbnail" | ||
app:layout_constraintVertical_chainStyle="packed" | ||
tools:text="josee!" /> | ||
|
||
<TextView | ||
android:id="@+id/tv_artist" | ||
style="@style/BodySmall" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:ellipsize="end" | ||
android:maxLines="1" | ||
android:textColor="@color/on_surface_variant" | ||
app:layout_constraintBottom_toBottomOf="@id/iv_thumbnail" | ||
app:layout_constraintStart_toStartOf="@id/tv_title" | ||
app:layout_constraintTop_toBottomOf="@id/tv_title" | ||
tools:text="데이먼스 이어" /> | ||
|
||
<ImageButton | ||
android:id="@+id/ib_play" | ||
android:layout_width="48dp" | ||
android:layout_height="48dp" | ||
android:layout_marginEnd="6dp" | ||
android:background="@android:color/transparent" | ||
android:contentDescription="@string/play" | ||
android:src="@drawable/ic_play" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<com.google.android.material.progressindicator.LinearProgressIndicator | ||
android:id="@+id/lpi_player_progress" | ||
android:layout_width="0dp" | ||
android:layout_height="1dp" | ||
app:indicatorColor="@color/key" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:trackColor="@color/white" | ||
app:trackThickness="1dp" | ||
tools:progress="65" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
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,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<declare-styleable name="PlayerBarView"> | ||
<attr name="thumbnailUrl" format="string" /> | ||
<attr name="title" format="string" /> | ||
<attr name="artist" format="string" /> | ||
<attr name="isPlaying" format="boolean" /> | ||
<attr name="progress" format="integer" /> | ||
<attr name="duration" format="integer" /> | ||
</declare-styleable> | ||
</resources> |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="play">재생하기</string> | ||
</resources> |