Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Feat: Added battery percentage click.
Browse files Browse the repository at this point in the history
also closes #503
  • Loading branch information
CreativeCodeCat committed May 25, 2024
1 parent 4025d83 commit f2ef47f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import android.view.View.OnTouchListener
import kotlin.math.abs

internal open class ViewSwipeTouchListener(c: Context?, v: View) : OnTouchListener {
private val gestureDetector: GestureDetector
private val gestureDetector: GestureDetector = GestureDetector(c, GestureListener(v))

@SuppressLint("ClickableViewAccessibility")
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
Expand Down Expand Up @@ -76,8 +76,4 @@ internal open class ViewSwipeTouchListener(c: Context?, v: View) : OnTouchListen
open fun onLongClick(view: View) {}
open fun onDoubleClick() {}
open fun onClick(view: View) {}

init {
gestureDetector = GestureDetector(c, GestureListener(v))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ class HomeFragment : Fragment(), View.OnClickListener, View.OnLongClickListener
viewModel.resetDefaultLauncherApp(requireContext())
}

R.id.batteryLayout -> {
openBatteryUsage()
}

else -> {
try { // Launch app
val appLocation = view.id
Expand All @@ -262,6 +266,11 @@ class HomeFragment : Fragment(), View.OnClickListener, View.OnLongClickListener
}
}

private fun openBatteryUsage() {
val batteryUsageIntent = Intent(Intent.ACTION_POWER_USAGE_SUMMARY)
startActivity(batteryUsageIntent)
}

override fun onLongClick(view: View): Boolean {
if (prefs.homeLocked) return true

Expand All @@ -280,6 +289,7 @@ class HomeFragment : Fragment(), View.OnClickListener, View.OnLongClickListener
binding.date.setOnClickListener(this)
binding.setTotalScreenTime.setOnClickListener(this)
binding.setDefaultLauncher.setOnClickListener(this)
binding.batteryLayout.setOnClickListener(this)
}

@RequiresApi(Build.VERSION_CODES.Q)
Expand Down

0 comments on commit f2ef47f

Please sign in to comment.