11package com.simplemobiletools.notes.pro.fragments
22
3+ import android.annotation.SuppressLint
34import android.content.Context
45import android.graphics.Typeface
56import android.os.Bundle
@@ -10,6 +11,7 @@ import android.text.style.UnderlineSpan
1011import android.text.util.Linkify
1112import android.util.TypedValue
1213import android.view.LayoutInflater
14+ import android.view.MotionEvent
1315import android.view.View
1416import android.view.ViewGroup
1517import 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