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

[mod] 핑글 개최 프로세스 - 장소 선택 뷰 수정 #64

Merged
merged 6 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
Expand Up @@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.stateIn
import org.sopt.pingle.domain.model.PlanLocationEntity
import org.sopt.pingle.presentation.type.CategoryType
import org.sopt.pingle.presentation.type.PlanType

Expand All @@ -33,17 +34,10 @@ class PlanViewModel : ViewModel() {
(currentPage == 2 && planOpenChattingLink.isNotBlank())
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false)

private val _location = MutableStateFlow<String?>(null)
val location get() = _location.asStateFlow()
// val isPlanBtnEnabled = MutableStateFlow(true)

private val _x = MutableStateFlow<Double?>(null)
val locationX get() = _x.asStateFlow()

private val _y = MutableStateFlow<Double?>(null)
val locationY get() = _y.asStateFlow()

private val _address = MutableStateFlow<String?>(null)
val address get() = _address.asStateFlow()
private val _selectedLocation = MutableStateFlow<PlanLocationEntity?>(null)
val selectedLocation get() = _selectedLocation.asStateFlow()

// TODO 뷰 연결 시 버튼 활성/비활성화 로직 isPlanBtnEnabled에 추가
private val _selectedCategory = MutableStateFlow<CategoryType?>(null)
Expand All @@ -65,13 +59,79 @@ class PlanViewModel : ViewModel() {
_selectedTimeType.value = timeType
}

fun setPlanLocation(location: String, locationX: Double, locationY: Double, address: String) {
_location.value = location
_x.value = locationX
_y.value = locationY
_address.value = address
private fun setPlanLocation(position: Int) {
_selectedLocation.value = mockPlanLocationList[position]
// _selectedLocation.value = planLocationList[position]
}

companion object {
const val FIRST_PAGE_POSITION = 0
}

private val _planLocationList = MutableStateFlow<List<PlanLocationEntity>>(emptyList())
private val planLocationList get() = _planLocationList.asStateFlow()

private var oldPosition = -1
fun updatePlanLocationList(position: Int) {
if (oldPosition == -1 && oldPosition != position) {
setIsSelected(true, position)
setPlanLocation(position)
} else if (oldPosition == position) {
setIsSelected(false, oldPosition)
} else {
setIsSelected(true, position)
setPlanLocation(position)
setIsSelected(false, oldPosition)
}
oldPosition = position
}

fun checkIsNull(): Boolean {
return mockPlanLocationList.isEmpty()
// TODO return planLocationList.value.isEmpty()
}

private fun setIsSelected(value: Boolean, position: Int) {
mockPlanLocationList[position].isSelected.set(value)
// TODO 서버에서 받아올 리스트에 저장.. planLocationList.value[position].isSelected.set(value)
}

val mockPlanLocationList = listOf<PlanLocationEntity>(
PlanLocationEntity(
location = "하얀집",
address = "서울 중구 퇴계로6길 12",
x = 123.5,
y = 56.7,
),
PlanLocationEntity(
location = "하얀집2호점",
address = "서울 중구 퇴계로6길 12",
x = 123.5,
y = 56.7,
),
PlanLocationEntity(
location = "하얀집3호점",
address = "서울 중구 퇴계로6길 12",
x = 123.5,
y = 56.7,
),
PlanLocationEntity(
location = "하얀집 싫어싫어싫어",
address = "서울 중구 퇴계로6길 12",
x = 123.5,
y = 56.7,
),
PlanLocationEntity(
location = "하얀집 좋아좋아좋아",
address = "서울 중구 퇴계로6길 12",
x = 123.5,
y = 56.7,
),
PlanLocationEntity(
location = "하얀집웅시러",
address = "서울 중구 퇴계로6길 12",
x = 123.5,
y = 56.7,
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import org.sopt.pingle.R
import org.sopt.pingle.databinding.FragmentPlanLocationBinding
import org.sopt.pingle.presentation.ui.main.plan.PlanViewModel
import org.sopt.pingle.util.base.BindingFragment
import org.sopt.pingle.util.context.hideKeyboard

class PlanLocationFragment :
BindingFragment<FragmentPlanLocationBinding>(R.layout.fragment_plan_location) {
private val planLocationViewModel by viewModels<PlanLocationViewModel>()
private val planLocationViewModel by viewModels<PlanViewModel>()
private val planLocationAdapter: PlanLocationAdapter by lazy {
PlanLocationAdapter(::deleteOldPosition)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

initLayout()
addListeners()
}
Expand Down Expand Up @@ -48,7 +50,7 @@ class PlanLocationFragment :
return@OnKeyListener true
}
false
}
},
)
}

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/fragment_plan_location.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
<EditText
android:id="@+id/et_plan_location_search"
android:layout_width="0dp"
android:maxLines="1"
android:inputType="text"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing24"
android:background="@drawable/shape_border_radius_8"
android:backgroundTint="@color/g_10"
android:hint="@string/plan_location_hint"
android:inputType="text"
android:maxLines="1"
android:paddingVertical="@dimen/spacing10"
android:background="@drawable/shape_border_radius_8"
android:paddingStart="@dimen/spacing16"
android:textAppearance="@style/TextAppearance.Pingle.Body.Semi.14"
android:textColor="@color/white"
Expand Down Expand Up @@ -103,13 +103,13 @@
android:id="@+id/rv_plan_location_list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="21dp"
android:visibility="invisible"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/layout_plan_location_search"
android:layout_marginTop="21dp"
tools:listitem="@layout/item_plan_location" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
6 changes: 3 additions & 3 deletions app/src/main/res/layout/item_plan_location.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@

<ImageView
android:id="@+id/iv_plan_location_check"
android:layout_width="1dp"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/spacing14"
android:src="@{planLocationItem.isSelected ? @drawable/ic_all_check_selected_24 : @drawable/ic_all_check_default_24}"
android:src="@{planLocationItem.isSelected ? @drawable/ic_all_check_selected_24 : @drawable/ic_all_check_default_24, default=@drawable/ic_all_check_default_24}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down
Loading