Skip to content

Commit

Permalink
fix some bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed May 16, 2024
1 parent 7e57aa8 commit b782d1f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 15 additions & 1 deletion app/src/main/java/com/lizongying/mytv/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.lizongying.mytv

import android.os.Bundle
import android.util.Log
import android.view.GestureDetector
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.MotionEvent
Expand Down Expand Up @@ -43,10 +44,13 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {

private lateinit var application: MyTvApplication

private lateinit var gestureDetector: GestureDetector

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
var context = requireContext()
_binding = MenuBinding.inflate(inflater, container, false)

application = requireActivity().applicationContext as MyTvApplication
Expand All @@ -58,9 +62,19 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
hideSelf()
}

gestureDetector = GestureDetector(context, GestureListener())

return binding.root
}

private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
Log.i(TAG, "onSingleTapConfirmed")
hideSelf()
return true
}
}

private fun hideSelf() {
requireActivity().supportFragmentManager.beginTransaction()
.hide(this)
Expand Down Expand Up @@ -137,7 +151,7 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {

itemBinding.items.addOnItemTouchListener(object : RecyclerView.OnItemTouchListener {
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
hideSelf()
gestureDetector.onTouchEvent(e)
return false
}

Expand Down
7 changes: 6 additions & 1 deletion app/src/main/java/com/lizongying/mytv/SP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ object SP {

var time: Boolean
get() = sp.getBoolean(KEY_TIME, true)
set(value) = sp.edit().putBoolean(KEY_TIME, value).apply()
set(value) {
if (value != this.time) {
sp.edit().putBoolean(KEY_TIME, value).apply()
listener?.onSharedPreferenceChanged(KEY_TIME)
}
}

var bootStartup: Boolean
get() = sp.getBoolean(KEY_BOOT_STARTUP, false)
Expand Down

0 comments on commit b782d1f

Please sign in to comment.