-
Notifications
You must be signed in to change notification settings - Fork 2
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
[feat] 핑글 개최 프로세스 - 장소 선택 뷰 구현 #37
Changes from 20 commits
3417f13
5c8f7dd
053a598
68a8e56
08c53af
dfb7a0f
815c1e2
36332af
d975e51
c598133
ba4dc80
bdcee6c
1a8b49a
312d332
288e043
aac44a1
8f9356b
c484743
e7c3b1b
417be24
1ef9e9c
0de4aa0
c5fda8a
7665ea7
8516f45
baa55ae
67eb4ee
ec2721f
cae1696
5e3b28c
a8005a7
9163fd6
a845dbe
3b80cab
e9d9591
cdadf8f
15e0cae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.sopt.pingle.presentation.model | ||
|
||
data class PlanLocationModel( | ||
val location: String, | ||
val address: String, | ||
val x: Double, | ||
val y: Double, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.sopt.pingle.presentation.ui.plan | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import org.sopt.pingle.R | ||
import org.sopt.pingle.databinding.ActivityPlanLocationBinding | ||
|
||
class PlanLocationActivity : AppCompatActivity() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 바인딩 액티비티 사용해주세요. 그리고 나중에 다은이 피알 머지되면 다은이가 만든 액티비티 사용해주세용 |
||
private lateinit var binding: ActivityPlanLocationBinding | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
binding = ActivityPlanLocationBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
supportFragmentManager.beginTransaction() | ||
.add(R.id.fragment_test, PlanLocationFragment()) | ||
.commit() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.sopt.pingle.presentation.ui.plan | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.sopt.pingle.databinding.ItemPlanLocationBinding | ||
import org.sopt.pingle.presentation.model.PlanLocationModel | ||
|
||
class PlanLocationAdapter : | ||
ListAdapter<PlanLocationModel, PlanLocationAdapter.PlanLocationViewHolder>( | ||
PlanLocationDiffCallback(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 확장함수로 DiffCallback 만들어 두었으니 그거 사용하시면 됩니다. 따로 만들 필요 없어요. |
||
) { | ||
private var planLocationList: List<PlanLocationModel> = emptyList() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. listAdapter로 만들면 따로 만들어줄 필요 없어요 |
||
private var selectedPosition: Int = -1 | ||
private lateinit var itemClickListener: ItemClickListener | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlanLocationViewHolder = | ||
PlanLocationViewHolder( | ||
ItemPlanLocationBinding.inflate(LayoutInflater.from(parent.context), parent, false), | ||
) | ||
|
||
override fun onBindViewHolder(holder: PlanLocationViewHolder, position: Int) { | ||
holder.onBind(getItem(position), position) | ||
} | ||
|
||
inner class PlanLocationViewHolder( | ||
private val binding: ItemPlanLocationBinding, | ||
) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun onBind(item: PlanLocationModel, position: Int) { | ||
binding.planLocationItem = item | ||
val planLocationItem = binding.planLocationItem | ||
planLocationItem?.isSelected = position == selectedPosition | ||
|
||
binding.root.setOnClickListener { | ||
selectedPosition = position | ||
itemClickListener.onClick(it, item) | ||
} | ||
} | ||
} | ||
|
||
interface ItemClickListener { | ||
fun onClick(view: View, item: PlanLocationModel) | ||
} | ||
|
||
fun setItemClickListener(itemClickListener: ItemClickListener) { | ||
this.itemClickListener = itemClickListener | ||
} | ||
} | ||
|
||
/*fun moveItem(fromPosition: Int, toPosition: Int) { | ||
val newList = currentList.toMutableList() | ||
Collections.swap(newList, fromPosition, toPosition) | ||
submitList(newList) | ||
} | ||
|
||
fun removeItem(position: Int) { | ||
val newList = currentList.toMutableList() | ||
newList.removeAt(position) | ||
submitList(newList) | ||
}*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.sopt.pingle.presentation.ui.plan | ||
|
||
import androidx.recyclerview.widget.DiffUtil | ||
import org.sopt.pingle.presentation.model.PlanLocationModel | ||
|
||
class PlanLocationDiffCallback : DiffUtil.ItemCallback<PlanLocationModel>() { | ||
|
||
// Referential equality를 갖는지 판정 | ||
override fun areItemsTheSame(oldItem: PlanLocationModel, newItem: PlanLocationModel): Boolean { | ||
return oldItem === newItem | ||
} | ||
|
||
// Structural equality를 갖는지 판정 | ||
override fun areContentsTheSame( | ||
oldItem: PlanLocationModel, | ||
newItem: PlanLocationModel, | ||
): Boolean { | ||
return oldItem == newItem | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.sopt.pingle.presentation.ui.plan | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.fragment.app.viewModels | ||
import androidx.recyclerview.widget.DividerItemDecoration | ||
import org.sopt.pingle.R | ||
import org.sopt.pingle.databinding.FragmentPlanLocationBinding | ||
import org.sopt.pingle.presentation.model.PlanLocationModel | ||
import org.sopt.pingle.util.base.BindingFragment | ||
|
||
class PlanLocationFragment : | ||
BindingFragment<FragmentPlanLocationBinding>(R.layout.fragment_plan_location) { | ||
private val planLocationViewModel by viewModels<PlanLocationViewModel>() | ||
private val planLocationAdapter: PlanLocationAdapter by lazy { | ||
PlanLocationAdapter() | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
initLayout() | ||
} | ||
|
||
private fun initLayout() { | ||
binding.rvPlanLocationList.apply { | ||
addItemDecoration( | ||
DividerItemDecoration( | ||
requireContext(), | ||
DividerItemDecoration.HORIZONTAL, | ||
), | ||
) | ||
this.layoutManager = layoutManager | ||
adapter = planLocationAdapter | ||
} | ||
|
||
planLocationAdapter.submitList(planLocationViewModel.mockPlanLocationList) | ||
planLocationAdapter.setItemClickListener(object : PlanLocationAdapter.ItemClickListener { | ||
override fun onClick(view: View, item: PlanLocationModel) { | ||
// TODO click | ||
} | ||
}) | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
binding.rvPlanLocationList.adapter = null | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.sopt.pingle.presentation.ui.plan | ||
|
||
/*import android.view.View | ||
import android.widget.AdapterView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.sopt.pingle.R | ||
import org.sopt.pingle.databinding.ItemPlanLocationBinding | ||
import org.sopt.pingle.presentation.model.PlanLocationModel | ||
|
||
interface ItemClickListener { | ||
fun onClick(view: View, item: PlanLocationModel) | ||
} | ||
class PlanLocationViewHolder( | ||
private val binding: ItemPlanLocationBinding, | ||
private var selectedPosition: Int, | ||
private var itemClickListener: ItemClickListener | ||
) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
|
||
fun onBind(item: PlanLocationModel, position: Int, selectedPosition: Int) { | ||
binding.planLocationItem = item | ||
|
||
binding.root.setOnClickListener { | ||
binding.imvPlanLocationCheck.setImageResource(R.drawable.ic_all_check_selected_24) | ||
binding.imvPlanLocationCheck.isSelected = position == selectedPosition | ||
|
||
binding.imvPlanLocationCheck.setOnClickListener { | ||
this.selectedPosition = position | ||
itemClickListener.onClick(it, item) | ||
} | ||
} | ||
|
||
*//*if (selectedPosition == this.adapterPosition) { | ||
planLocationList[adapterPosition].isSelected = true | ||
binding.imvPlanLocationCheck.setImageResource(R.drawable.ic_all_check_selected_24) | ||
} else { | ||
planLocationList[adapterPosition].isSelected = false | ||
binding.imvPlanLocationCheck.setImageResource(R.drawable.ic_all_check_default_24) | ||
} | ||
|
||
if (onItemClickListener != null) { | ||
binding.root.setOnClickListener { | ||
onItemClickListener?.onItemClick(item, adapterPosition) | ||
if (selectedPosition != adapterPosition) { | ||
val previousSelectedPosition = selectedPosition | ||
selectedPosition = adapterPosition | ||
adapter.updateItem(previousSelectedPosition) | ||
adapter.updateItem(selectedPosition) | ||
} | ||
} | ||
}*//* | ||
} | ||
}*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.sopt.pingle.presentation.ui.plan | ||
|
||
import androidx.lifecycle.ViewModel | ||
import org.sopt.pingle.presentation.model.PlanLocationModel | ||
|
||
class PlanLocationViewModel : ViewModel() { | ||
val mockPlanLocationList = listOf<PlanLocationModel>( | ||
PlanLocationModel( | ||
location = "하얀집", | ||
address = "서울 중구 퇴계로6길 12", | ||
x = 123.5, | ||
y = 56.7, | ||
), | ||
PlanLocationModel( | ||
location = "하얀집2호점", | ||
address = "서울 중구 퇴계로6길 12", | ||
x = 123.5, | ||
y = 56.7, | ||
), | ||
PlanLocationModel( | ||
location = "하얀집3호점", | ||
address = "서울 중구 퇴계로6길 12", | ||
x = 123.5, | ||
y = 56.7, | ||
), | ||
PlanLocationModel( | ||
location = "하얀집 싫어싫어싫어", | ||
address = "서울 중구 퇴계로6길 12", | ||
x = 123.5, | ||
y = 56.7, | ||
), | ||
PlanLocationModel( | ||
location = "하얀집 좋아좋아좋아", | ||
address = "서울 중구 퇴계로6길 12", | ||
x = 123.5, | ||
y = 56.7, | ||
), | ||
PlanLocationModel( | ||
location = "하얀집웅시러", | ||
address = "서울 중구 퇴계로6길 12", | ||
x = 123.5, | ||
y = 56.7, | ||
), | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.sopt.pingle.presentation.ui.plan | ||
|
||
import androidx.lifecycle.ViewModel | ||
import org.sopt.pingle.presentation.model.PlanModel | ||
|
||
class PlanViewModel : ViewModel() { | ||
val mockPlanList = listOf<PlanModel>( | ||
PlanModel( | ||
category = "others", | ||
name = "개빡세게 공부", | ||
date = "2024년 1월 18일", | ||
startAt = "오후 05:00", | ||
endAt = "오후 10:00", | ||
x = 15.8, | ||
y = 192.4, | ||
address = "서울 중구 퇴계로6길 12", | ||
location = "하얀집", | ||
), | ||
) | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 변경하신 이유가 있나요,,?? 없다면 되돌려 주세요 ㅜㅜ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
domain 레이어에 적어주면 됩니다.