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

검색 - 키워드 입력 #266

Merged
merged 5 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dependencies {
implementation(project(":feature:player"))
implementation(project(":feature:playlist"))
implementation(project(":feature:mypage"))
implementation(project(":feature:search"))
implementation(project(":core:data"))
implementation(project(":core:domain"))

Expand Down
13 changes: 13 additions & 0 deletions android/app/src/main/res/drawable/ic_search.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M21,21L15,15M3,10C3,10.919 3.181,11.83 3.533,12.679C3.885,13.528 4.4,14.3 5.05,14.95C5.7,15.6 6.472,16.115 7.321,16.467C8.17,16.819 9.081,17 10,17C10.919,17 11.83,16.819 12.679,16.467C13.528,16.115 14.3,15.6 14.95,14.95C15.6,14.3 16.115,13.528 16.467,12.679C16.819,11.83 17,10.919 17,10C17,9.081 16.819,8.17 16.467,7.321C16.115,6.472 15.6,5.7 14.95,5.05C14.3,4.4 13.528,3.885 12.679,3.533C11.83,3.181 10.919,3 10,3C9.081,3 8.17,3.181 7.321,3.533C6.472,3.885 5.7,4.4 5.05,5.05C4.4,5.7 3.885,6.472 3.533,7.321C3.181,8.17 3,9.081 3,10Z"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="@color/on_surface"
android:strokeLineCap="round"/>
</vector>
6 changes: 5 additions & 1 deletion android/app/src/main/res/menu/bottom_navigation_items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
android:icon="@drawable/home_tab_selector"
android:title="@string/home" />

<item
android:id="@id/search_nav_graph"
android:icon="@drawable/ic_search"
android:title="@string/search" />

<item
android:id="@id/playlist_nav_graph"
android:icon="@drawable/playlist_tab_selector"
android:title="@string/playlist" />


<item
android:id="@id/my_page_nav_graph"
android:icon="@drawable/my_page_tab_selector"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<include app:graph="@navigation/player_navigation" />
<include app:graph="@navigation/playlist_navigation" />
<include app:graph="@navigation/my_page_navigation" />
<include app:graph="@navigation/search_navigation" />

</navigation>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="22dp" />
</shape>
1 change: 1 addition & 0 deletions android/feature/search/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
30 changes: 30 additions & 0 deletions android/feature/search/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
id("catchytape.android.feature")
}

android {
namespace = "com.ohdodok.catchytape.feature.search"

defaultConfig {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
kotlinOptions {
jvmTarget = "17"
}
}

dependencies {

}
Empty file.
21 changes: 21 additions & 0 deletions android/feature/search/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
4 changes: 4 additions & 0 deletions android/feature/search/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.ohdodok.catchytape.feature.search

import android.os.Bundle
import android.view.View
import androidx.fragment.app.viewModels
import com.ohdodok.catchytape.core.ui.BaseFragment
import com.ohdodok.catchytape.feature.search.databinding.FragmentSearchBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class SearchFragment : BaseFragment<FragmentSearchBinding>(R.layout.fragment_search) {

private val viewModel: SearchViewModel by viewModels()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewModel = viewModel
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ohdodok.catchytape.feature.search

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import javax.inject.Inject

data class SearchUiState(
val keyword: String = "",
)

@HiltViewModel
class SearchViewModel @Inject constructor(

) : ViewModel() {

private val _uiState = MutableStateFlow(SearchUiState())
val uiState: StateFlow<SearchUiState> = _uiState.asStateFlow()

fun updateKeyword(newKeyword: String) {
_uiState.update { it.copy(keyword = newKeyword) }
}
}
31 changes: 31 additions & 0 deletions android/feature/search/src/main/res/layout/fragment_search.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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">

<data>

<variable
name="viewModel"
type="com.ohdodok.catchytape.feature.search.SearchViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<EditText
Copy link
Collaborator

@2taezeat 2taezeat Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

검색 UI 구현할때,
com.google.android.material.search.SearchView 을 쓰지 않은 이유가 있으신가요? (궁금해서 여쭤봅니다)

https://github.com/material-components/material-components-android/blob/master/docs/components/Search.md

Copy link
Member Author

@HamBP HamBP Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SearchView보다 EditText를 커스텀하는 게 더 쉬울 거라 생각했어

android:layout_width="0dp"
android:layout_height="44dp"
android:layout_margin="@dimen/margin_horizontal"
android:background="@drawable/search_bar_background"
android:backgroundTint="@color/surface_bright"
android:hint="@string/input_keyword"
android:text="@{viewModel.uiState.keyword}"
android:onTextChanged="@{(text, s, b, c) -> viewModel.updateKeyword(text.toString())}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

텍스트가 바뀌면 viewmodel에 업데이트 하고 또 viewmodel에서 업데이트 된 텍스트를 text에 넣는 것 같은데, 위에 android:text="@{viewModel.uiState.keyword}" 는 없어도 될 것 같슴다

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ViewModel에서 text를 조작하는 경우를 고려한 코드긴 한데, 일단 제거하고 올릴게!
혹시나 테스트 해봤는데 무한 루프는 안 생기는 거 같아

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아항 그런 의도의 코드였군요 !

android:paddingHorizontal="@dimen/margin_horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/search_nav_graph"
app:startDestination="@id/search_fragment">

<fragment
android:id="@+id/search_fragment"
android:name="com.ohdodok.catchytape.feature.search.SearchFragment"
android:label="search"
tools:layout="@layout/fragment_search" />

</navigation>
4 changes: 4 additions & 0 deletions android/feature/search/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="input_keyword">검색어를 입력하세요.</string>
</resources>
1 change: 1 addition & 0 deletions android/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ include(":feature:upload")
include(":feature:player")
include(":feature:playlist")
include(":feature:mypage")
include(":feature:search")