Skip to content

Commit

Permalink
swipe to delete player fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
VolgoAK committed Sep 4, 2019
1 parent 3b9ee95 commit 3c9f5b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.os.Bundle
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.Observer
import com.example.sergey.shlypa2.R
import com.example.sergey.shlypa2.RvAdapter
Expand Down Expand Up @@ -99,7 +98,7 @@ class PlayersActivity : AppCompatActivity(), RenameDialogFragment.RenameDialogLi
supportFragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
.commit()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.takusemba.spotlight.Spotlight
import com.theartofdev.edmodo.cropper.CropImage
import com.theartofdev.edmodo.cropper.CropImageView
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.IFlexible
import kotlinx.android.synthetic.main.fragment_players.*
import org.koin.androidx.viewmodel.ext.android.sharedViewModel
import timber.log.Timber
Expand All @@ -49,7 +50,7 @@ class PlayersFragment : androidx.fragment.app.Fragment(),


val viewModel by sharedViewModel<PlayersViewModel>()
private val playersAdapter = FlexibleAdapter(emptyList(), this)
private lateinit var playersAdapter: FlexibleAdapter<IFlexible<*>>

companion object {
const val SHOW_SPOTLIGHT = "spotlight_show"
Expand Down Expand Up @@ -78,13 +79,18 @@ class PlayersFragment : androidx.fragment.app.Fragment(),
}

private fun initViews() {
rvPlayers.layoutManager = LinearLayoutManager(requireContext()).apply {
stackFromEnd = true
reverseLayout = true
}
playersAdapter = FlexibleAdapter(emptyList(), this)

rvPlayers.adapter = playersAdapter
with(rvPlayers) {
layoutManager = LinearLayoutManager(requireContext()).apply {
stackFromEnd = true
reverseLayout = true
}
adapter = playersAdapter
}
// set swipe enabled only allowed after attaching to recycler view
playersAdapter.isSwipeEnabled = true

civPlayerAvatar.setOnClickListener {
viewModel.onChangeAvatarClicked()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ open class ItemPlayer(val player: Player)

override fun getLayoutRes() = R.layout.holder_player

override fun isSwipeable() = true

class ViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?)
: FlexibleViewHolder(view, adapter) {
val tvName: TextView = itemView.tvPlayerName
Expand Down

0 comments on commit 3c9f5b5

Please sign in to comment.