mirror of
https://github.com/IllusionMan1212/NPS-Browser.git
synced 2026-10-24 02:12:37 +00:00
Handle recyclerview touches and add single app activity
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package com.illusionware.npsbrowser
|
||||
|
||||
import android.content.Context
|
||||
import android.view.GestureDetector
|
||||
import android.view.GestureDetector.SimpleOnGestureListener
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.RecyclerView.OnItemTouchListener
|
||||
|
||||
class RecyclerTouchListener(context: Context?, recyclerView: RecyclerView,
|
||||
private val clickListener: ClickListener?) : OnItemTouchListener {
|
||||
interface ClickListener {
|
||||
fun onClick(view: View?, position: Int)
|
||||
fun onLongClick(view: View?, recyclerView: RecyclerView?, position: Int)
|
||||
}
|
||||
|
||||
private val gestureDetector: GestureDetector
|
||||
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
|
||||
val child = rv.findChildViewUnder(e.x, e.y)
|
||||
if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
|
||||
clickListener.onClick(child, rv.getChildAdapterPosition(child))
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {}
|
||||
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {}
|
||||
|
||||
init {
|
||||
gestureDetector = GestureDetector(context, object : SimpleOnGestureListener() {
|
||||
override fun onSingleTapUp(e: MotionEvent): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onLongPress(e: MotionEvent) {
|
||||
val child = recyclerView.findChildViewUnder(e.x, e.y)
|
||||
if (child != null && clickListener != null) {
|
||||
clickListener.onLongClick(child, recyclerView, recyclerView.getChildAdapterPosition(child))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.illusionware.npsbrowser.AppData
|
||||
@@ -31,6 +30,20 @@ class AppsListActivity : AppCompatActivity() {
|
||||
recyclerView.apply {
|
||||
layoutManager = LinearLayoutManager(applicationContext)
|
||||
adapter = viewAdapter
|
||||
|
||||
recyclerView.addOnItemTouchListener(RecyclerTouchListener(applicationContext, recyclerView, object : RecyclerTouchListener.ClickListener {
|
||||
override fun onClick(view: View?, position: Int) {
|
||||
val myIntent = Intent(context, SingleAppActivity::class.java)
|
||||
SingleAppActivity.app = apps[position]
|
||||
|
||||
startActivity(myIntent)
|
||||
}
|
||||
|
||||
override fun onLongClick(view: View?, recyclerView: RecyclerView?, position: Int) {
|
||||
Toast.makeText(applicationContext, "TODO: Long Click ", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.illusionware.npsbrowser.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.illusionware.npsbrowser.AppData
|
||||
import com.illusionware.npsbrowser.databinding.ActivitySingleGameBinding
|
||||
|
||||
class SingleAppActivity: AppCompatActivity() {
|
||||
companion object {
|
||||
lateinit var app : AppData
|
||||
}
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val binding = ActivitySingleGameBinding.inflate(layoutInflater);
|
||||
setContentView(binding.root)
|
||||
|
||||
binding.titleID.text = app.TitleID
|
||||
binding.gameTitle.text = app.Title;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user