Skip to content

Commit

Permalink
Merge branch 'develop' into feature/#558-apply-calladapter
Browse files Browse the repository at this point in the history
  • Loading branch information
hxeyexn committed Jan 11, 2025
2 parents 8c99e4b + c6f9efe commit 3dca2c4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ interface CommentApiService {
private const val COMMENTS_URI = "/comments"
private const val STACCATO_ID = "momentId"
private const val COMMENT_ID = "commentId"
private const val COMMENTS_URI_WITH_COMMENT_ID = "$COMMENTS_URI/v2/{$COMMENT_ID}"
private const val COMMENTS_URI_WITH_COMMENT_ID = "$COMMENTS_URI/{$COMMENT_ID}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.annotation.RequiresApi
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.gms.location.Priority
Expand All @@ -34,7 +33,6 @@ import com.on.staccato.presentation.main.viewmodel.SharedViewModel
import com.on.staccato.presentation.memory.MemoryFragment.Companion.MEMORY_ID_KEY
import com.on.staccato.presentation.staccato.StaccatoFragment.Companion.STACCATO_ID_KEY
import com.on.staccato.presentation.staccatocreation.adapter.AttachedPhotoItemTouchHelperCallback
import com.on.staccato.presentation.staccatocreation.adapter.ItemDragListener
import com.on.staccato.presentation.staccatocreation.adapter.PhotoAttachAdapter
import com.on.staccato.presentation.staccatocreation.dialog.MemorySelectionFragment
import com.on.staccato.presentation.staccatocreation.dialog.VisitedAtSelectionFragment
Expand Down Expand Up @@ -243,18 +241,7 @@ class StaccatoCreationActivity :

private fun initAdapter() {
photoAttachAdapter =
PhotoAttachAdapter(
object : ItemDragListener {
override fun onStartDrag(viewHolder: RecyclerView.ViewHolder) {
itemTouchHelper.startDrag(viewHolder)
}

override fun onStopDrag(list: List<AttachedPhotoUiModel>) {
viewModel.setUrisWithNewOrder(list)
}
},
viewModel,
)
PhotoAttachAdapter(viewModel) { viewModel.setUrisWithNewOrder(it) }
binding.rvPhotoAttach.adapter = photoAttachAdapter
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import androidx.recyclerview.widget.RecyclerView
class AttachedPhotoItemTouchHelperCallback(
private val moveListener: ItemMoveListener,
) : ItemTouchHelper.Callback() {
override fun isLongPressDragEnabled(): Boolean {
return true
}

override fun getMovementFlags(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
): Int {
return makeFlag(
ItemTouchHelper.ACTION_STATE_DRAG,
ItemTouchHelper.DOWN or ItemTouchHelper.UP or ItemTouchHelper.START or ItemTouchHelper.END,
)
return if (viewHolder is PhotoAttachViewHolder.AttachedPhotoViewHolder) {
makeFlag(
ItemTouchHelper.ACTION_STATE_DRAG,
ItemTouchHelper.DOWN or ItemTouchHelper.UP or ItemTouchHelper.START or ItemTouchHelper.END,
)
} else {
ItemTouchHelper.ACTION_STATE_IDLE
}
}

override fun onMove(
Expand All @@ -40,25 +40,27 @@ class AttachedPhotoItemTouchHelperCallback(
viewHolder: RecyclerView.ViewHolder?,
actionState: Int,
) {
super.onSelectedChanged(viewHolder, actionState)
when (actionState) {
ItemTouchHelper.ACTION_STATE_DRAG -> {
if (viewHolder != null) {
(viewHolder as PhotoAttachViewHolder.AttachedPhotoViewHolder).startMoving()
if (viewHolder is PhotoAttachViewHolder.AttachedPhotoViewHolder) {
viewHolder.startMoving()
}
}

ItemTouchHelper.ACTION_STATE_IDLE -> {
moveListener.onStopDrag()
}
}
super.onSelectedChanged(viewHolder, actionState)
}

override fun clearView(
recyclerView: RecyclerView,
viewHolder: RecyclerView.ViewHolder,
) {
(viewHolder as PhotoAttachViewHolder.AttachedPhotoViewHolder).stopMoving()
if (viewHolder is PhotoAttachViewHolder.AttachedPhotoViewHolder) {
viewHolder.stopMoving()
}
}

override fun onSwiped(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.on.staccato.presentation.staccatocreation.adapter

import androidx.recyclerview.widget.RecyclerView
import com.on.staccato.presentation.staccatocreation.model.AttachedPhotoUiModel

interface ItemDragListener {
fun onStartDrag(viewHolder: RecyclerView.ViewHolder)

fun interface ItemDragListener {
fun onStopDrag(list: List<AttachedPhotoUiModel>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.on.staccato.presentation.common.AttachedPhotoHandler
import com.on.staccato.presentation.staccatocreation.model.AttachedPhotoUiModel

class PhotoAttachAdapter(
private val dragListener: ItemDragListener,
private val attachedPhotoHandler: AttachedPhotoHandler,
private val dragListener: ItemDragListener,
) :
ItemMoveListener, ListAdapter<AttachedPhotoUiModel, PhotoAttachViewHolder>(diffUtil) {
init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.annotation.RequiresApi
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.gms.location.Priority
Expand All @@ -37,7 +36,6 @@ import com.on.staccato.presentation.staccato.StaccatoFragment.Companion.STACCATO
import com.on.staccato.presentation.staccatocreation.CurrentLocationHandler
import com.on.staccato.presentation.staccatocreation.OnUrisSelectedListener
import com.on.staccato.presentation.staccatocreation.adapter.AttachedPhotoItemTouchHelperCallback
import com.on.staccato.presentation.staccatocreation.adapter.ItemDragListener
import com.on.staccato.presentation.staccatocreation.adapter.PhotoAttachAdapter
import com.on.staccato.presentation.staccatocreation.dialog.MemorySelectionFragment
import com.on.staccato.presentation.staccatocreation.dialog.VisitedAtSelectionFragment
Expand Down Expand Up @@ -237,18 +235,7 @@ class StaccatoUpdateActivity :

private fun initAdapter() {
photoAttachAdapter =
PhotoAttachAdapter(
object : ItemDragListener {
override fun onStartDrag(viewHolder: RecyclerView.ViewHolder) {
itemTouchHelper.startDrag(viewHolder)
}

override fun onStopDrag(list: List<AttachedPhotoUiModel>) {
viewModel.setUrisWithNewOrder(list)
}
},
viewModel,
)
PhotoAttachAdapter(viewModel) { viewModel.setUrisWithNewOrder(it) }
binding.rvPhotoAttach.adapter = photoAttachAdapter
}

Expand Down

0 comments on commit 3dca2c4

Please sign in to comment.