Skip to content

Commit

Permalink
Merge pull request #103 from boostcampwm2023/android/feature/upload
Browse files Browse the repository at this point in the history
음원 파일 업로드 (유저 입력)
  • Loading branch information
2taezeat authored Nov 16, 2023
2 parents e378242 + 16ea13f commit 1bc218b
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 33 deletions.
5 changes: 2 additions & 3 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

Expand All @@ -12,7 +11,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.CatchyTape">
<activity
android:name=".feature.login.LoginActivity"
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_graph"
app:startDestination="@id/login_nav_graph">
app:startDestination="@id/home_nav_graph">

<include app:graph="@navigation/home_navigation" />
<include app:graph="@navigation/login_navigation" />
<include app:graph="@navigation/upload_navigation" />

</navigation>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal class AndroidLibraryPlugin : Plugin<Project> {
with(pluginManager) {
apply("com.android.library")
apply("org.jetbrains.kotlin.android")
apply("kotlin-kapt")
}

extensions.configure<LibraryExtension> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.google.android.material.appbar.MaterialToolbar


abstract class BaseFragment<VB : ViewDataBinding>(
Expand All @@ -31,4 +33,10 @@ abstract class BaseFragment<VB : ViewDataBinding>(
super.onDestroyView()
_binding = null
}

protected fun setupBackStack(toolbar: MaterialToolbar){
toolbar.setNavigationOnClickListener {
findNavController().popBackStack()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.ohdodok.catchytape.core.ui.bindingadapter

import android.widget.AutoCompleteTextView
import androidx.databinding.BindingAdapter


@BindingAdapter("changeSelectedPosition")
fun AutoCompleteTextView.bindPosition(onChange: (Int) -> Unit) {
setOnItemClickListener { _, _, position, _ -> onChange(position) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/on_surface" android:state_enabled="true" />
<item android:color="@color/on_surface_variant" />
</selector>
5 changes: 5 additions & 0 deletions android/core/ui/src/main/res/drawable/ic_cancel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM15.59,7L12,10.59 8.41,7 7,8.41 10.59,12 7,15.59 8.41,17 12,13.41 15.59,17 17,15.59 13.41,12 17,8.41z"/>
</vector>
1 change: 1 addition & 0 deletions android/core/ui/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="genre_items">
<item>장르를 선택해 주세요.</item>
<item>genre1</item>
<item>genre2</item>
<item>genre3</item>
Expand Down
15 changes: 14 additions & 1 deletion android/core/ui/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>

<style name="Base.Theme.CatchyTape" parent="Theme.Material3.DayNight.NoActionBar">
<item name="colorPrimary">@color/primary</item>
Expand Down Expand Up @@ -58,4 +58,17 @@
<item name="android:textCursorDrawable">@color/black</item>
<item name="android:textColorHighlight">@color/key_variant</item>
</style>


<style name="CompleteButton" parent="Widget.AppCompat.Button">
<item name="android:textSize">22sp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:minWidth">0dp</item>
<item name="android:minHeight">0dp</item>
<item name="android:paddingHorizontal">0dp</item>
<item name="android:textColor">@drawable/btn_complete_selector</item>
</style>


</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package com.ohdodok.catchytape.feature.home

import android.os.Bundle
import android.view.View
import androidx.core.net.toUri
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.feature.home.databinding.FragmentHomeBinding
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
private val viewModel: HomeViewModel by viewModels()
Expand All @@ -15,5 +19,14 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {
super.onViewCreated(view, savedInstanceState)
binding.viewModel = viewModel
binding.rvRecentlyAddedSong.adapter = MusicHorizontalAdapter()



binding.ibUpload.setOnClickListener {
val request = NavDeepLinkRequest.Builder
.fromUri("android-app://com.ohdodok.catchytape/upload_fragment".toUri())
.build()
findNavController().navigate(request)
}
}
}
1 change: 1 addition & 0 deletions android/feature/home/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
app:title="@string/home" />

<ImageButton
android:id="@+id/ib_upload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/margin_horizontal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class UploadFragment : BaseFragment<FragmentUploadBinding>(R.layout.fragment_upl
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewModel = viewModel
setupBackStack(binding.tbUploadAppbar)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
package com.ohdodok.catchytape.feature.upload

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

class UploadViewModel : ViewModel() {

val uploadedMusicTitle = MutableStateFlow<String>("")

private val _uploadedMusicGenrePosition = MutableStateFlow(0)
val uploadedMusicGenrePosition = _uploadedMusicGenrePosition.asStateFlow()

private val _isUploadEnable = MutableStateFlow(false)
val isUploadEnable = _isUploadEnable.asStateFlow()

init {
observeMusicTitle()
observeGenrePosition()
}

val onChangePosition: (Int) -> Unit = { position: Int -> _uploadedMusicGenrePosition.value = position }


private fun observeMusicTitle() {
uploadedMusicTitle.onEach {
_isUploadEnable.value = uploadedMusicGenrePosition.value != 0 && it.isNotEmpty()
}.launchIn(viewModelScope)
}


private fun observeGenrePosition() {
uploadedMusicGenrePosition.onEach {
_isUploadEnable.value = it != 0 && uploadedMusicTitle.value.isNotEmpty()
}.launchIn(viewModelScope)
}
}
39 changes: 14 additions & 25 deletions android/feature/upload/src/main/res/layout/fragment_upload.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/tb_upload_appbar"
style="@style/ToolBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -24,16 +25,15 @@
app:navigationIcon="@drawable/ic_arrow_back"
app:title="@string/upload">

<Button
style="@style/BodyMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/btn_complete"
style="@style/CompleteButton"
android:layout_gravity="end|center_vertical"
android:layout_marginEnd="@dimen/margin_horizontal"
android:background="@android:color/transparent"
android:minWidth="0dp"
android:minHeight="0dp"
android:text="@string/complete"
android:textColor="@color/on_surface" />
android:enabled="@{viewModel.isUploadEnable}"
android:text="@string/complete" />


</com.google.android.material.appbar.MaterialToolbar>

Expand Down Expand Up @@ -65,13 +65,17 @@
android:layout_marginHorizontal="@dimen/margin_horizontal"
android:layout_marginTop="@dimen/extra_large"
android:hint="@string/title"
app:endIconDrawable="@drawable/ic_cancel"
app:endIconMode="clear_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cv_upload_thumbnail">

<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:maxLength="10"
android:text="@={viewModel.uploadedMusicTitle}" />

</com.google.android.material.textfield.TextInputLayout>

Expand All @@ -91,26 +95,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
app:changeSelectedPosition="@{viewModel.onChangePosition}"
app:simpleItems="@array/genre_items" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/margin_horizontal"
android:layout_marginTop="@dimen/medium"
android:hint="@string/description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/til_genre">

<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</com.google.android.material.textfield.TextInputLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/upload_navigation"
app:startDestination="@id/upload_navigation">
app:startDestination="@id/upload_fragment">

<fragment
android:id="@+id/upload_navigation"
android:id="@+id/upload_fragment"
android:name="com.ohdodok.catchytape.feature.upload.UploadFragment"
android:label="upload"
tools:layout="@layout/fragment_upload"/>
tools:layout="@layout/fragment_upload">

<deepLink app:uri="android-app://com.ohdodok.catchytape/upload_fragment" />

</fragment>

</navigation>

0 comments on commit 1bc218b

Please sign in to comment.