Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fail) 공통으로 사용되는 MusicAdapter, UI #144

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/android-pull-request-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
echo "$DEBUG_KEYSTORE" | base64 -d > debug.keystore
echo "$KEYSTORE_PROPERTIES" > keystore.properties
echo "$LOCAL_PROPERTIES" > local.properties
./gradlew testDebugUnitTest --stacktrace
./gradlew debugUnitTest --stacktrace

- name: Publish Test Results
if: always()
Expand Down
16 changes: 10 additions & 6 deletions android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ plugins {
alias(libs.plugins.navigation.safe.args) apply false
}

tasks.register<Test>("test") {
useJUnitPlatform()
reports {
junitXml.required.set(false)
}
systemProperty("gradle.build.dir", project.buildDir)

tasks.register<Exec>("domainUnitTest") {
commandLine = listOf("gradle", "core:domain:test")
}


tasks.register<Exec>("debugUnitTest") {
dependsOn("domainUnitTest")
commandLine = listOf("gradle", "testDebugUnitTest")
}


true // Needed to make the Suppress annotation work for the plugins block
8 changes: 8 additions & 0 deletions android/core/domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

tasks.getByName<Test>("test") {
useJUnitPlatform()
reports {
junitXml.required.set(false)
}
systemProperty("gradle.build.dir", project.buildDir)
}

dependencies {
testImplementation(libs.junit)
testImplementation(libs.kotest.runner)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.ohdodok.catchytape.core.domain.signup
package com.ohdodok.catchytape.core.domain

import io.kotest.core.config.AbstractProjectConfig
import io.kotest.core.extensions.Extension
import io.kotest.extensions.junitxml.JunitXmlReporter

class TestConfig : AbstractProjectConfig() {
class KoTestConfig : AbstractProjectConfig() {

override fun extensions(): List<Extension> = listOf(
JunitXmlReporter(
includeContainers = false, // don't write out status for all tests
useTestPathAsName = true, // use the full test path (ie, includes parent test names)
outputDir = "test-results/excludeContainers"
outputDir = "../build/test-results"
)
)
}
2 changes: 2 additions & 0 deletions android/core/ui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ dependencies {

api(libs.navigation.fragment.ktx)
api(libs.navigation.ui.ktx)

implementation(project(":core:domain"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ohdodok.catchytape.core.ui

import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView


@BindingAdapter("submitData")
fun <T, VH : RecyclerView.ViewHolder> RecyclerView.bindItems(items: List<T>) {
val adapter = this.adapter ?: return
val listAdapter: ListAdapter<T, VH> = adapter as ListAdapter<T, VH>
listAdapter.submitList(items)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.ohdodok.catchytape.core.ui

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.ohdodok.catchytape.core.domain.model.Music
import com.ohdodok.catchytape.core.ui.databinding.ItemMusicHorizontalBinding
import com.ohdodok.catchytape.core.ui.databinding.ItemMusicVerticalBinding


class MusicAdapter(private val orientation: Orientation) :
ListAdapter<Music, RecyclerView.ViewHolder>(MusicDiffUtil) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return when (orientation) {
Orientation.Horizontal -> HorizontalViewHolder.from(parent)
Orientation.Vertical -> VerticalViewHolder.from(parent)
}
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (orientation) {
Orientation.Horizontal -> (holder as HorizontalViewHolder).bind(currentList[position])
Orientation.Vertical -> (holder as VerticalViewHolder).bind(currentList[position])
}
}


class HorizontalViewHolder private constructor(private val binding: ItemMusicHorizontalBinding) :
RecyclerView.ViewHolder(binding.root) {

fun bind(item: Music) {
binding.music = item
}

companion object {
fun from(parent: ViewGroup) = HorizontalViewHolder(
ItemMusicHorizontalBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
}
}

class VerticalViewHolder private constructor(private val binding: ItemMusicVerticalBinding) :
RecyclerView.ViewHolder(binding.root) {

fun bind(item: Music) {
binding.music = item
}

companion object {
fun from(parent: ViewGroup) = VerticalViewHolder(
ItemMusicVerticalBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
}
}
}

object MusicDiffUtil : DiffUtil.ItemCallback<Music>() {
override fun areItemsTheSame(oldItem: Music, newItem: Music) =
oldItem.id == newItem.id

override fun areContentsTheSame(oldItem: Music, newItem: Music) =
oldItem == newItem
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.ohdodok.catchytape.core.ui

enum class Orientation {
Horizontal, Vertical
}
4 changes: 4 additions & 0 deletions android/core/ui/src/main/res/drawable/ic_more.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<vector android:height="24dp" android:viewportHeight="16"
android:viewportWidth="16" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#ffffff" android:pathData="M8.75,8C8.75,8.148 8.706,8.293 8.624,8.417C8.541,8.54 8.424,8.636 8.287,8.693C8.15,8.75 7.999,8.765 7.854,8.736C7.708,8.707 7.575,8.635 7.47,8.53C7.365,8.425 7.293,8.292 7.264,8.146C7.235,8.001 7.25,7.85 7.307,7.713C7.364,7.576 7.46,7.459 7.583,7.376C7.707,7.294 7.852,7.25 8,7.25C8.199,7.25 8.39,7.329 8.53,7.47C8.671,7.61 8.75,7.801 8.75,8ZM8,4.5C8.148,4.5 8.293,4.456 8.417,4.374C8.54,4.291 8.636,4.174 8.693,4.037C8.75,3.9 8.765,3.749 8.736,3.604C8.707,3.458 8.635,3.325 8.53,3.22C8.425,3.115 8.292,3.043 8.146,3.014C8.001,2.985 7.85,3 7.713,3.057C7.576,3.114 7.459,3.21 7.376,3.333C7.294,3.457 7.25,3.602 7.25,3.75C7.25,3.949 7.329,4.14 7.47,4.28C7.61,4.421 7.801,4.5 8,4.5ZM8,11.5C7.852,11.5 7.707,11.544 7.583,11.626C7.46,11.709 7.364,11.826 7.307,11.963C7.25,12.1 7.235,12.251 7.264,12.396C7.293,12.542 7.365,12.675 7.47,12.78C7.575,12.885 7.708,12.957 7.854,12.986C7.999,13.014 8.15,13 8.287,12.943C8.424,12.886 8.541,12.79 8.624,12.667C8.706,12.543 8.75,12.398 8.75,12.25C8.75,12.051 8.671,11.86 8.53,11.72C8.39,11.579 8.199,11.5 8,11.5Z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/small"
android:text="@{music.title}"
android:textColor="@color/on_surface"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -42,6 +43,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/extra_small"
android:text="@{music.artist}"
android:textColor="@color/on_surface_variant"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
62 changes: 62 additions & 0 deletions android/core/ui/src/main/res/layout/item_music_vertical.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<layout 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">

<data>

<variable
name="music"
type="com.ohdodok.catchytape.core.domain.model.Music" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/medium">

<ImageView
android:id="@+id/iv_thumbnail"
android:layout_width="@dimen/music_vertical_img"
android:layout_height="@dimen/music_vertical_img"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:background="@color/on_surface" />

<TextView
android:id="@+id/tv_title"
style="@style/BodyMedium"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/medium"
android:layout_marginTop="@dimen/small"
android:text="@{music.title}"
android:textColor="@color/on_surface"
app:layout_constraintStart_toEndOf="@+id/iv_thumbnail"
app:layout_constraintTop_toTopOf="parent"
tools:text="어떨것같애" />

<TextView
android:id="@+id/tv_artist"
style="@style/BodySmall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/medium"
android:text="@{music.artist}"
android:textColor="@color/on_surface_variant"
app:layout_constraintStart_toEndOf="@+id/iv_thumbnail"
app:layout_constraintTop_toBottomOf="@id/tv_title"
tools:text="MEENOI" />

<ImageView
android:id="@+id/iv_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_more"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
1 change: 1 addition & 0 deletions android/core/ui/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<dimen name="extra_large">32dp</dimen>

<dimen name="music_horizontal_img">120dp</dimen>
<dimen name="music_vertical_img">56dp</dimen>
<dimen name="login_icon_margin_vertical">168dp</dimen>

<dimen name="btn_height">50dp</dimen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import androidx.fragment.app.viewModels
import androidx.navigation.NavDeepLinkRequest
import androidx.navigation.fragment.findNavController
import com.ohdodok.catchytape.core.ui.BaseFragment
import com.ohdodok.catchytape.core.ui.MusicAdapter
import com.ohdodok.catchytape.core.ui.Orientation
import com.ohdodok.catchytape.feature.home.databinding.FragmentHomeBinding
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -18,9 +20,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewModel = viewModel
binding.rvRecentlyAddedSong.adapter = MusicHorizontalAdapter()


binding.rvRecentlyAddedSong.adapter = MusicAdapter(Orientation.Horizontal)

binding.ibUpload.setOnClickListener {
val request = NavDeepLinkRequest.Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ohdodok.catchytape.feature.home

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ohdodok.catchytape.core.domain.model.Music
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -12,13 +13,21 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update

data class HomeUiState(
val recentlyUploadedMusics: List<Unit> = emptyList()
val recentlyUploadedMusics: List<Music> = emptyList()
)

class HomeViewModel constructor(
// todo : DI로 주입하는 코드로 변경
private val getMusicUseCase: GetMusicUseCase = GetMusicUseCase {
flow { emit(listOf()) }
flow {
emit(
listOf(
Music("1", "title1", "artist1", ""),
Music("2", "title2", "artist2", ""),
Music("3", "title3", "artist3", "")
) // 화면 확인용 Dummy data 입니다.
)
}
},
) : ViewModel() {

Expand All @@ -44,5 +53,5 @@ class HomeViewModel constructor(

// todo : domain layer로 이동
fun interface GetMusicUseCase {
operator fun invoke(): Flow<List<Unit>>
operator fun invoke(): Flow<List<Music>>
}

This file was deleted.

2 changes: 2 additions & 0 deletions android/feature/home/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@
android:id="@+id/rv_recently_added_song"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/small"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="@id/tv_recently_added_song"
app:layout_constraintStart_toStartOf="@id/tv_recently_added_song"
app:layout_constraintTop_toBottomOf="@id/tv_recently_added_song"
app:submitData="@{viewModel.uiState.recentlyUploadedMusics}"
tools:listitem="@layout/item_music_horizontal" />

</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down