Skip to content

Commit bb0e66b

Browse files
committed
make swiping between notes easier
1 parent b101a17 commit bb0e66b

File tree

1 file changed

+21
-2
lines changed
  • app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments

1 file changed

+21
-2
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.simplemobiletools.notes.pro.fragments
22

3+
import android.annotation.SuppressLint
34
import android.content.Context
45
import android.graphics.Typeface
56
import android.os.Bundle
@@ -10,6 +11,7 @@ import android.text.style.UnderlineSpan
1011
import android.text.util.Linkify
1112
import android.util.TypedValue
1213
import android.view.LayoutInflater
14+
import android.view.MotionEvent
1315
import android.view.View
1416
import android.view.ViewGroup
1517
import android.view.inputmethod.EditorInfo
@@ -37,12 +39,15 @@ class TextFragment : NoteFragment() {
3739
private var isUndoOrRedo = false
3840
private var skipTextUpdating = false
3941
private var noteId = 0L
42+
private var touchDownX = 0f
43+
private var moveXThreshold = 0 // make sure swiping across notes works well, do not swallow the gestures
4044

4145
lateinit var view: ViewGroup
4246

43-
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
47+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
4448
view = inflater.inflate(R.layout.fragment_text, container, false) as ViewGroup
4549
noteId = requireArguments().getLong(NOTE_ID, 0L)
50+
moveXThreshold = resources.getDimension(R.dimen.activity_margin).toInt()
4651
retainInstance = true
4752

4853
val layoutToInflate = if (config!!.enableLineWrap) R.layout.note_view_static else R.layout.note_view_horiz_scrollable
@@ -112,6 +117,7 @@ class TextFragment : NoteFragment() {
112117
}
113118
}
114119

120+
@SuppressLint("ClickableViewAccessibility")
115121
private fun setupFragment() {
116122
val config = config ?: return
117123
view.text_note_view.apply {
@@ -156,8 +162,21 @@ class TextFragment : NoteFragment() {
156162
}
157163
}
158164

165+
view.text_note_view.setOnTouchListener { v, event ->
166+
when (event.action) {
167+
MotionEvent.ACTION_DOWN -> touchDownX = event.x
168+
MotionEvent.ACTION_MOVE -> {
169+
val diffX = Math.abs(event.x - touchDownX)
170+
if (diffX > moveXThreshold) {
171+
view.requestDisallowInterceptTouchEvent(false)
172+
}
173+
}
174+
}
175+
false
176+
}
177+
159178
if (config.showWordCount) {
160-
view.notes_counter.setTextColor(context!!.getProperTextColor())
179+
view.notes_counter.setTextColor(requireContext().getProperTextColor())
161180
setWordCounter(view.text_note_view.text.toString())
162181
}
163182

0 commit comments

Comments
 (0)