diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 88a89f7c..a8788fdb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,3 +11,10 @@ repos: hooks: - id: pretty-format-kotlin args: [ --autofix, --ktlint-version=1.4.1 ] +- repo: local + hooks: + - id: check-debug-enabled + name: Check debug enabled + entry: val DEBUG = true + language: pygrep + files: '.+\.kt' diff --git a/app/src/main/java/com/github/damontecres/stashapp/StashDataGridFragment.kt b/app/src/main/java/com/github/damontecres/stashapp/StashDataGridFragment.kt index 7ab61495..ef2a5793 100644 --- a/app/src/main/java/com/github/damontecres/stashapp/StashDataGridFragment.kt +++ b/app/src/main/java/com/github/damontecres/stashapp/StashDataGridFragment.kt @@ -86,6 +86,7 @@ class StashDataGridFragment : private var remoteButtonPaging: Boolean = true // State + private var previousPosition = -1 private var selectedPosition = -1 private var onBackPressedCallback: OnBackPressedCallback? = null @@ -157,7 +158,8 @@ class StashDataGridFragment : private fun onSelectedOrJump(position: Int) { if (position != selectedPosition) { - if (DEBUG) Log.v(TAG, "gridOnItemSelected=$position") + if (DEBUG) Log.v(TAG, "newPosition=$position, previousPosition=$previousPosition") + previousPosition = selectedPosition selectedPosition = position viewModel.position = position positionTextView.text = formatNumber(position + 1, false) @@ -522,6 +524,23 @@ class StashDataGridFragment : } } + override fun onKeyLongPress( + keyCode: Int, + event: KeyEvent, + ): Boolean { + if (keyCode == KeyEvent.KEYCODE_BACK) { + if (DEBUG) Log.d(TAG, "Long press back, maybe $selectedPosition=>$previousPosition") + if (previousPosition >= 0 && + previousPosition != selectedPosition && + requireActivity().currentFocus is StashImageCardView + ) { + jumpTo(previousPosition) + return true + } + } + return super.onKeyLongPress(keyCode, event) + } + override fun onKeyUp( keyCode: Int, event: KeyEvent, @@ -573,7 +592,7 @@ class StashDataGridFragment : companion object { private const val TAG = "StashDataGridFragment" - private const val DEBUG = true + private const val DEBUG = false } inner class VerticalGridItemBridgeAdapter : ItemBridgeAdapter() {