Skip to content

Commit

Permalink
delete torrent from long click
Browse files Browse the repository at this point in the history
  • Loading branch information
arranlomas committed Nov 3, 2017
1 parent c676ff4 commit cec5ae1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
package com.shwifty.tex.views.all.list

import android.support.v7.widget.PopupMenu
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import com.pawegio.kandroid.inflateLayout
import com.schiwfty.kotlinfilebrowser.onLongClick
import com.schiwfty.torrentwrapper.models.TorrentInfo
import com.shwifty.tex.R
import com.shwifty.tex.utils.onClick

/**
* Created by arran on 19/04/2017.
*/
class AllTorrentsAdapter(val itemClickListener: (View, Int, Int) -> Unit) : RecyclerView.Adapter<AllTorrentsCardHolder>() {
class AllTorrentsAdapter(val itemClickListener: (View, Int, Int) -> Unit, val onDeleteClick: (View, Int, Int) -> Unit) : RecyclerView.Adapter<AllTorrentsCardHolder>() {
var torrentFiles: List<TorrentInfo> = mutableListOf()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AllTorrentsCardHolder {
val itemView = parent.context.inflateLayout(R.layout.list_item_torrent_all, parent, false)
val holder = AllTorrentsCardHolder(itemView)
holder.onClick (itemClickListener)
holder.onClick(itemClickListener)
holder.onLongClick { view, position, type ->
val popup = PopupMenu(itemView.context, itemView)
popup.menuInflater.inflate(R.menu.popup_view_torrent, popup.menu)
popup.setOnMenuItemClickListener {
when (it.itemId) {
R.id.menu_item_delete -> onDeleteClick(view, position, type)
}
true
}
popup.show()
}
return holder
}

Expand Down
10 changes: 9 additions & 1 deletion app/src/main/java/com/shwifty/tex/views/all/mvp/AllFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ class AllFragment : BaseFragment(), AllContract.View {
val torrentFile = filesAdapter.torrentFiles[position]
MainEventHandler.showTorrentInfo(torrentFile)
}
val filesAdapter = AllTorrentsAdapter(itemOnClick)

val onDeleteItem: (View, Int, Int) -> Unit = { _, position, _ ->
val torrentFile = filesAdapter.torrentFiles[position]
Trickl.dialogManager.showDeleteTorrentDialog(context, torrentFile, {
showError(R.string.error_deleting_torrent)
})
}

val filesAdapter = AllTorrentsAdapter(itemOnClick, onDeleteItem)

companion object {
fun newInstance(): Fragment {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/menu/popup_view_torrent.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_item_delete"
android:title="@string/delete"/>
</menu>

0 comments on commit cec5ae1

Please sign in to comment.