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

인증글 작성하기 버그 수정, 운동 내역 단일 선택 기능 버그 수정, 전체적인 UI 수정 #79

Merged
merged 5 commits into from
Dec 7, 2022
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.whyranoid.presentation.community.runningpost

import android.content.res.ColorStateList
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
Expand All @@ -16,6 +17,7 @@ class CommunityRunningHistoryAdapter(private val selectRunningHistoryListener: R
ListAdapter<RunningHistoryUiModel, CommunityRunningHistoryViewHolder>(
MyRunningHistoryDiffCallback()
) {

override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
Expand All @@ -26,7 +28,7 @@ class CommunityRunningHistoryAdapter(private val selectRunningHistoryListener: R
}

override fun onBindViewHolder(holder: CommunityRunningHistoryViewHolder, position: Int) {
holder.bind(getItem(position))
holder.bind(getItem(position), position)
}
}

Expand All @@ -36,30 +38,49 @@ class CommunityRunningHistoryViewHolder(
) : RecyclerView.ViewHolder(view) {
private val binding = ItemRunningHistoryBinding.bind(view)

fun bind(runningHistory: RunningHistoryUiModel) {
fun bind(runningHistory: RunningHistoryUiModel, itemPosition: Int) {
// 아이템이 선택된 개체인지 확인

binding.runningHistory = runningHistory
val isSelected = listener.checkRunningHistoryId(itemPosition)

binding.root.setBackgroundColor(Color.TRANSPARENT)
if (isSelected) {
binding.root.setBackgroundResource(R.drawable.background_rounded)
binding.root.backgroundTintList = ColorStateList.valueOf(
ContextCompat.getColor(
binding.root.context,
R.color.mogakrun_secondary
)
)
} else {
// 선택되어 있지 않던 아이템이면
binding.root.setBackgroundColor(Color.TRANSPARENT)
}

binding.root.setOnClickListener {
val isSelected = listener.checkRunningHistoryId(runningHistory)
val isAlreadySelected = listener.checkRunningHistoryId(itemPosition)

// 이미 선택되어 있던 아이템이면
if (isSelected) {
// 이미 선택되어 있던 아이템을 누른 경우
if (isAlreadySelected) {
listener.unSelectRunningHistory()
it.setBackgroundColor(Color.TRANSPARENT)
} else {
// 선택되어 있지 않던 아이템이면
listener.selectRunningHistory(runningHistory)
it.setBackgroundColor(
// 선택되어 있지 않던 아이템을 누른 경우
listener.selectRunningHistory(runningHistory, itemPosition)
binding.root.setBackgroundResource(R.drawable.background_rounded)
binding.root.backgroundTintList = ColorStateList.valueOf(
ContextCompat.getColor(
binding.root.context,
R.color.gray
R.color.mogakrun_secondary
)
)
}
}
}
}

interface RunningHistoryItemListener {
fun checkRunningHistoryId(itemPosition: Int): Boolean
Copy link
Member

Choose a reason for hiding this comment

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

인터페이스로 하나만 선택하기 기능 잘 구현하신 것 같아요!

fun selectRunningHistory(runningHistory: RunningHistoryUiModel, itemPosition: Int)
fun unSelectRunningHistory()
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CreateRunningPostViewModel @Inject constructor(

val createPostButtonEnableState: StateFlow<Boolean>
get() = runningPostContent.map { content ->
content != null
content.isNullOrBlank().not()
}.stateIn(
initialValue = false,
started = SharingStarted.WhileSubscribed(5000),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ internal class SelectRunningHistoryFragment :
true
}
R.id.warning_select_running_history_button -> {
Snackbar.make(binding.root, getString(R.string.community_select_running_history_snack_bar), Snackbar.LENGTH_SHORT).show()
Snackbar.make(
binding.root,
getString(R.string.community_select_running_history_snack_bar),
Snackbar.LENGTH_SHORT
).show()
true
}
else -> {
Expand All @@ -107,14 +111,27 @@ internal class SelectRunningHistoryFragment :
}
}

override fun checkRunningHistoryId(runningHistory: RunningHistoryUiModel): Boolean =
viewModel.getSelectedRunningHistory()?.historyId == runningHistory.historyId
override fun checkRunningHistoryId(itemPosition: Int): Boolean {
// 아무것도 선택이 되지 않은 상황이거나 선택한 운동내역이 이미 선택되어있는 운동내역과 다를 때 false 반환 -> 일반 배경색
// true 반환 -> 선택된 배경색
return (viewModel.selectedItemPosition.value == NOTHING_SELECTED_ITEM_POSITION || viewModel.selectedItemPosition.value != itemPosition).not()
}

override fun selectRunningHistory(runningHistory: RunningHistoryUiModel) {
override fun selectRunningHistory(runningHistory: RunningHistoryUiModel, itemPosition: Int) {
// 현재 선택되어 있는 아이템의 position을 가져옴
val currentSelectedItemPosition = viewModel.selectedItemPosition.value
viewModel.setSelectedRunningHistory(runningHistory)
viewModel.setSelectedItemPosition(itemPosition)
// 이전에 선택되어 있던 아이템에게 배경색을 다시 불러오도록 명령
runningHistoryAdapter.notifyItemChanged(currentSelectedItemPosition)
}

override fun unSelectRunningHistory() {
viewModel.setSelectedRunningHistory(null)
viewModel.setSelectedItemPosition(NOTHING_SELECTED_ITEM_POSITION)
}

companion object {
private const val NOTHING_SELECTED_ITEM_POSITION = -1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ class SelectRunningHistoryViewModel @Inject constructor(private val getRunningHi
val runningHistoryListState: StateFlow<UiState<List<RunningHistoryUiModel>>>
get() = _runningHistoryListState.asStateFlow()

// TODO 인증글 작성 넘어가도록 하는 더미데이터 -> 인증글 작성 로직이 완료되면 삭제하겠습니다
private val _selectedRunningHistory = MutableStateFlow<RunningHistoryUiModel?>(RunningHistoryUiModel("seungmin_history_id", 8995875L, 2452, 24524L, 134L, 124.0, 23.0))
private val _selectedRunningHistory = MutableStateFlow<RunningHistoryUiModel?>(null)
val selectedRunningHistory: StateFlow<RunningHistoryUiModel?>
get() = _selectedRunningHistory.asStateFlow()

private val _selectedItemPosition = MutableStateFlow(NOTHING_SELECTED_ITEM_POSITION)
val selectedItemPosition: StateFlow<Int>
get() = _selectedItemPosition.asStateFlow()

private fun getRunningHistoryList() {
viewModelScope.launch {
_runningHistoryListState.value = UiState.Loading
Expand All @@ -53,4 +56,12 @@ class SelectRunningHistoryViewModel @Inject constructor(private val getRunningHi
fun setSelectedRunningHistory(runningHistoryUiModel: RunningHistoryUiModel?) {
_selectedRunningHistory.value = runningHistoryUiModel
}

fun setSelectedItemPosition(itemPosition: Int) {
_selectedItemPosition.value = itemPosition
}

companion object {
private const val NOTHING_SELECTED_ITEM_POSITION = -1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class CalendarDayBinder(
container.binding.root.background =
ContextCompat.getDrawable(
calendarView.context,
R.drawable.calendar_kong
R.drawable.kong
)
}
}
Expand Down
Binary file removed presentation/src/main/res/drawable/calendar_kong.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="10dp"
android:shape="rectangle" >
<solid android:color="@color/mogakrun_primary" />
<corners
android:topLeftRadius="12dp"
android:topRightRadius="12dp" />
</shape>
2 changes: 1 addition & 1 deletion presentation/src/main/res/drawable/done_outline_icon.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#ACD182"
<vector android:height="24dp" android:tint="@color/gray"
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="M19.77,5.03l1.4,1.4L8.43,19.17l-5.6,-5.6 1.4,-1.4 4.2,4.2L19.77,5.03m0,-2.83L8.43,13.54l-4.2,-4.2L0,13.57 8.43,22 24,6.43 19.77,2.2z"/>
Expand Down
2 changes: 1 addition & 1 deletion presentation/src/main/res/drawable/done_solid_icon.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#ACD182"
<vector android:height="24dp" android:tint="?attr/colorOnPrimary"
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="M9,16.2L4.8,12l-1.4,1.4L9,19 21,7l-1.4,-1.4L9,16.2z"/>
Expand Down
2 changes: 1 addition & 1 deletion presentation/src/main/res/drawable/plus_button.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<vector android:height="24dp" android:tint="#ACD182"
<vector android:height="24dp" android:tint="?attr/colorOnPrimary"
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="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
Expand Down
8 changes: 5 additions & 3 deletions presentation/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
app:itemTextColor="@drawable/bottom_navigation_color_selector"
app:itemIconTint="@drawable/bottom_navigation_color_selector"
style="@style/Widget.MaterialComponents.BottomNavigationView.Colored"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:itemIconTint="@drawable/bottom_navigation_color_selector"
app:itemTextAppearanceActive="@style/MoGakRunText.Regular.Small"
app:itemTextAppearanceInactive="@style/MoGakRunText.Regular.Small"
app:itemTextColor="@drawable/bottom_navigation_color_selector"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_navigation_menu" />

</androidx.constraintlayout.widget.ConstraintLayout>
Expand Down
12 changes: 9 additions & 3 deletions presentation/src/main/res/layout/activity_running.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/running_history_label_start_running_time"
android:textAppearance="@style/MoGakRunText.Regular.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Expand All @@ -96,6 +97,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/running_total_time"
android:textAppearance="@style/MoGakRunText.Regular.Small"
app:layout_constraintStart_toStartOf="@id/view_vertical_partition_line"
app:layout_constraintTop_toTopOf="parent" />

Expand All @@ -113,6 +115,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/running_history_label_running_distance"
android:textAppearance="@style/MoGakRunText.Regular.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/view_horizontal_partition_line" />

Expand All @@ -121,7 +124,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="44dp"
android:layout_marginEnd="32dp"
app:layout_constraintEnd_toStartOf="@id/view_vertical_partition_line"
app:layout_constraintTop_toBottomOf="@id/view_horizontal_partition_line"
tools:text="11.7km" />
Expand All @@ -132,6 +135,7 @@
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/running_history_label_running_pace"
android:textAppearance="@style/MoGakRunText.Regular.Small"
app:layout_constraintStart_toStartOf="@id/view_vertical_partition_line"
app:layout_constraintTop_toBottomOf="@id/view_horizontal_partition_line" />

Expand All @@ -140,7 +144,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginEnd="44dp"
android:layout_marginEnd="28dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/view_horizontal_partition_line"
tools:text="6.3km/h" />
Expand All @@ -154,6 +158,7 @@
android:layout_margin="12dp"
android:onClick="@{() -> vm.onCheckingPauseOrResume()}"
android:text="@string/running_pause_or_resume"
android:textAppearance="@style/MoGakRunText.Regular.Small"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/btn_finish"
app:layout_constraintStart_toStartOf="parent" />
Expand All @@ -165,6 +170,7 @@
android:layout_margin="12dp"
android:onClick="@{() -> vm.onFinishButtonClicked()}"
android:text="@string/running_finish"
android:textAppearance="@style/MoGakRunText.Regular.Small"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/btn_pause_or_resume" />
Expand All @@ -173,8 +179,8 @@
android:id="@+id/frame_progress_running"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:alpha="0.8"
android:background="@color/black"
android:translationZ="@{vm.runningState instanceof RunningState.NotRunning ? 10f : 0f }"
android:visibility="@{vm.runningState instanceof RunningState.NotRunning ? View.VISIBLE : View.GONE }">

Expand Down
4 changes: 4 additions & 0 deletions presentation/src/main/res/layout/dialog_edit_nick_name.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/my_run_edit_nick_name_dialog_description"
android:textAppearance="@style/MoGakRunText.Bold.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -27,10 +28,13 @@
android:layout_marginHorizontal="20dp"
android:layout_marginTop="20dp"
android:autofillHints="name"
android:background="@drawable/community_create_running_post_edit_text_background"
android:hint="@string/my_run_edit_nick_name_dialog_hint"
android:inputType="textPersonName"
android:maxLength="20"
android:maxLines="1"
android:padding="12dp"
android:textAppearance="@style/MoGakRunText.Bold.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_dialog_description" />
Expand Down
9 changes: 5 additions & 4 deletions presentation/src/main/res/layout/fragment_community.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/mogakrun_background"
app:titleTextAppearance="@style/MoGakRunText.Bold.Medium"
app:title="@string/text_community" />
app:title="@string/text_community"
app:titleTextAppearance="@style/MoGakRunText.Bold.Medium" />

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

Expand All @@ -35,10 +35,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/mogakrun_background"
app:tabIndicatorColor="@color/mogakrun_on_primary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_bar">
app:layout_constraintTop_toBottomOf="@id/app_bar"
app:tabIndicatorColor="@color/mogakrun_on_primary"
app:tabTextAppearance="@style/MoGakRunText.Regular.Small">

</com.google.android.material.tabs.TabLayout>

Expand Down
Loading