parent
9fe135e17e
commit
05afd66d73
@ -0,0 +1,38 @@ |
||||
package net.pokeranalytics.android.ui.view |
||||
|
||||
import android.content.Context |
||||
import android.util.AttributeSet |
||||
import android.view.ContextMenu |
||||
import android.view.View |
||||
import androidx.recyclerview.widget.RecyclerView |
||||
import timber.log.Timber |
||||
|
||||
|
||||
class ContextMenuRecyclerView : RecyclerView { |
||||
|
||||
constructor(context: Context, attributeSet: AttributeSet?, defStyle: Int) : super(context, attributeSet, defStyle) |
||||
constructor(context: Context, attributeSet: AttributeSet?) : super(context, attributeSet) |
||||
constructor(context: Context) : super(context) |
||||
|
||||
private var mContextMenuInfo: RecyclerViewContextMenuInfo? = null |
||||
|
||||
override fun getContextMenuInfo(): ContextMenu.ContextMenuInfo? { |
||||
return mContextMenuInfo |
||||
} |
||||
|
||||
override fun showContextMenuForChild(originalView: View): Boolean { |
||||
val longPressPosition = getChildAdapterPosition(originalView) |
||||
Timber.d("longPressPosition = $longPressPosition") |
||||
if (longPressPosition >= 0) { |
||||
val longPressId = adapter!!.getItemId(longPressPosition) |
||||
Timber.d("longPressId = $longPressId") |
||||
mContextMenuInfo = RecyclerViewContextMenuInfo(longPressPosition, longPressId) |
||||
return super.showContextMenuForChild(originalView) |
||||
} |
||||
return false |
||||
} |
||||
|
||||
class RecyclerViewContextMenuInfo(val position: Int, val id: Long) : ContextMenu.ContextMenuInfo |
||||
|
||||
} |
||||
|
||||
@ -0,0 +1,8 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto"> |
||||
|
||||
<item android:id="@+id/duplicate" android:title="@string/duplicate" android:icon="@drawable/picto_gear" app:showAsAction="always|withText" /> |
||||
|
||||
</menu> |
||||
Loading…
Reference in new issue