Skip to content

Commit 3b4d89c

Browse files
committed
fix #160, allow disabling line wrap
1 parent 7f15b8c commit 3b4d89c

File tree

11 files changed

+122
-29
lines changed

11 files changed

+122
-29
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
4343
private var noteViewWithTextSelected: MyEditText? = null
4444
private var wasInit = false
4545
private var storedUseEnglish = false
46+
private var storedEnableLineWrap = true
4647
private var showSaveButton = false
4748
private var saveNoteButton: MenuItem? = null
4849

@@ -86,6 +87,10 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
8687
return
8788
}
8889

90+
if (storedEnableLineWrap != config.enableLineWrap) {
91+
initViewPager()
92+
}
93+
8994
invalidateOptionsMenu()
9095
pager_title_strip.apply {
9196
setTextSize(TypedValue.COMPLEX_UNIT_PX, getTextSize())
@@ -165,7 +170,10 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
165170
}
166171

167172
private fun storeStateVariables() {
168-
storedUseEnglish = config.useEnglish
173+
config.apply {
174+
storedUseEnglish = useEnglish
175+
storedEnableLineWrap = enableLineWrap
176+
}
169177
}
170178

171179
private fun handleText(text: String) {
@@ -206,8 +214,9 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
206214
mNotes = dbHelper.getNotes()
207215
mCurrentNote = mNotes[0]
208216
var wantedNoteId = intent.getIntExtra(OPEN_NOTE_ID, -1)
209-
if (wantedNoteId == -1)
217+
if (wantedNoteId == -1) {
210218
wantedNoteId = config.currentNoteId
219+
}
211220

212221
val itemIndex = getNoteIndexWithId(wantedNoteId)
213222

app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class SettingsActivity : SimpleActivity() {
4040
setupShowKeyboard()
4141
setupShowNotePicker()
4242
setupShowWordCount()
43+
setupEnableLineWrap()
4344
setupFontSize()
4445
setupGravity()
4546
setupWidgetNote()
@@ -120,6 +121,14 @@ class SettingsActivity : SimpleActivity() {
120121
}
121122
}
122123

124+
private fun setupEnableLineWrap() {
125+
settings_enable_line_wrap.isChecked = config.enableLineWrap
126+
settings_enable_line_wrap_holder.setOnClickListener {
127+
settings_enable_line_wrap.toggle()
128+
config.enableLineWrap = settings_enable_line_wrap.isChecked
129+
}
130+
}
131+
123132
private fun setupFontSize() {
124133
settings_font_size.text = getFontSizeText()
125134
settings_font_size_holder.setOnClickListener {

app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import android.view.View
1414
import android.view.ViewGroup
1515
import com.simplemobiletools.commons.extensions.beGone
1616
import com.simplemobiletools.commons.extensions.beVisible
17+
import com.simplemobiletools.commons.extensions.onGlobalLayout
1718
import com.simplemobiletools.notes.R
1819
import com.simplemobiletools.notes.activities.MainActivity
1920
import com.simplemobiletools.notes.extensions.*
@@ -24,21 +25,24 @@ import com.simplemobiletools.notes.helpers.NOTE_ID
2425
import com.simplemobiletools.notes.models.Note
2526
import kotlinx.android.synthetic.main.fragment_note.*
2627
import kotlinx.android.synthetic.main.fragment_note.view.*
28+
import kotlinx.android.synthetic.main.note_view_horiz_scrollable.view.*
2729
import java.io.File
2830

2931
class NoteFragment : Fragment() {
3032
private var noteId = 0
3133
lateinit var note: Note
3234
lateinit var view: ViewGroup
33-
lateinit var mDb: DBHelper
35+
private lateinit var db: DBHelper
3436

3537
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
3638
view = inflater.inflate(R.layout.fragment_note, container, false) as ViewGroup
3739
noteId = arguments!!.getInt(NOTE_ID)
38-
mDb = context!!.dbHelper
39-
note = mDb.getNote(noteId) ?: return view
40+
db = context!!.dbHelper
41+
note = db.getNote(noteId) ?: return view
4042
retainInstance = true
4143

44+
val layoutToInflate = if (context!!.config.enableLineWrap) R.layout.note_view_static else R.layout.note_view_horiz_scrollable
45+
inflater.inflate(layoutToInflate, view.notes_relative_layout, true)
4246
if (context!!.config.clickableLinks) {
4347
view.notes_view.apply {
4448
linksClickable = true
@@ -47,6 +51,10 @@ class NoteFragment : Fragment() {
4751
}
4852
}
4953

54+
view.notes_horizontal_scrollview?.onGlobalLayout {
55+
view.notes_view.minWidth = view.notes_horizontal_scrollview.width
56+
}
57+
5058
return view
5159
}
5260

@@ -133,7 +141,7 @@ class NoteFragment : Fragment() {
133141

134142
private fun saveNoteValue(note: Note) {
135143
if (note.path.isEmpty()) {
136-
mDb.updateNoteValue(note)
144+
db.updateNoteValue(note)
137145
(activity as MainActivity).noteSavedSuccessfully(note.title)
138146
} else {
139147
(activity as MainActivity).exportNoteValueToFile(note.path, getCurrentNoteViewText(), true)

app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ class Config(context: Context) : BaseConfig(context) {
5757
get() = prefs.getBoolean(CURSOR_PLACEMENT, true)
5858
set(placement) = prefs.edit().putBoolean(CURSOR_PLACEMENT, placement).apply()
5959

60+
var enableLineWrap: Boolean
61+
get() = prefs.getBoolean(ENABLE_LINE_WRAP, true)
62+
set(enableLineWrap) = prefs.edit().putBoolean(ENABLE_LINE_WRAP, enableLineWrap).apply()
63+
6064
var lastUsedExtension: String
6165
get() = prefs.getString(LAST_USED_EXTENSION, "txt")
6266
set(lastUsedExtension) = prefs.edit().putString(LAST_USED_EXTENSION, lastUsedExtension).apply()

app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const val GRAVITY = "gravity"
1818
const val CURSOR_PLACEMENT = "cursor_placement"
1919
const val LAST_USED_EXTENSION = "last_used_extension"
2020
const val LAST_USED_SAVE_PATH = "last_used_save_path"
21+
const val ENABLE_LINE_WRAP = "enable_line_wrap"
2122

2223
// gravity
2324
const val GRAVITY_LEFT = 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.simplemobiletools.notes.views
2+
3+
import android.content.Context
4+
import android.util.AttributeSet
5+
import android.view.MotionEvent
6+
import android.widget.HorizontalScrollView
7+
8+
class MyHorizontalScrollView : HorizontalScrollView {
9+
constructor(context: Context) : super(context)
10+
11+
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
12+
13+
override fun onTouchEvent(ev: MotionEvent): Boolean {
14+
parent.requestDisallowInterceptTouchEvent(false)
15+
return super.onTouchEvent(ev)
16+
}
17+
}

app/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
android:layout_gravity="top"
1313
android:paddingLeft="@dimen/activity_margin"
1414
android:paddingRight="@dimen/activity_margin"/>
15+
1516
</com.simplemobiletools.commons.views.MyViewPager>

app/src/main/res/layout/activity_settings.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,26 @@
225225

226226
</RelativeLayout>
227227

228+
<RelativeLayout
229+
android:id="@+id/settings_enable_line_wrap_holder"
230+
android:layout_width="match_parent"
231+
android:layout_height="wrap_content"
232+
android:layout_marginTop="@dimen/medium_margin"
233+
android:background="?attr/selectableItemBackground"
234+
android:padding="@dimen/activity_margin">
235+
236+
<com.simplemobiletools.commons.views.MySwitchCompat
237+
android:id="@+id/settings_enable_line_wrap"
238+
android:layout_width="match_parent"
239+
android:layout_height="wrap_content"
240+
android:background="@null"
241+
android:clickable="false"
242+
android:paddingLeft="@dimen/medium_margin"
243+
android:paddingStart="@dimen/medium_margin"
244+
android:text="@string/enable_line_wrap"/>
245+
246+
</RelativeLayout>
247+
228248
<RelativeLayout
229249
android:id="@+id/settings_font_size_holder"
230250
android:layout_width="match_parent"

app/src/main/res/layout/fragment_note.xml

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<RelativeLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:tools="http://schemas.android.com/tools"
5-
android:id="@+id/note_Fragment_holder"
5+
android:id="@+id/note_fragment_holder"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent">
88

@@ -17,28 +17,17 @@
1717
android:layout_width="match_parent"
1818
android:layout_height="wrap_content">
1919

20-
<com.simplemobiletools.commons.views.MyEditText
21-
android:id="@+id/notes_view"
22-
android:layout_width="match_parent"
23-
android:layout_height="match_parent"
24-
android:background="@null"
25-
android:freezesText="true"
26-
android:gravity="top"
27-
android:inputType="textCapSentences|textMultiLine"
28-
android:padding="@dimen/activity_margin"
29-
android:textCursorDrawable="@null"/>
30-
31-
<com.simplemobiletools.commons.views.MyTextView
32-
android:id="@+id/notes_counter"
33-
android:layout_width="wrap_content"
34-
android:layout_height="wrap_content"
35-
android:layout_alignParentBottom="true"
36-
android:layout_alignParentEnd="true"
37-
android:layout_alignParentRight="true"
38-
android:padding="@dimen/small_margin"
39-
android:textStyle="italic"
40-
tools:text="123"/>
41-
4220
</RelativeLayout>
4321
</ScrollView>
22+
23+
<com.simplemobiletools.commons.views.MyTextView
24+
android:id="@+id/notes_counter"
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:layout_alignParentBottom="true"
28+
android:layout_alignParentEnd="true"
29+
android:layout_alignParentRight="true"
30+
android:padding="@dimen/small_margin"
31+
android:textStyle="italic"
32+
tools:text="123"/>
4433
</RelativeLayout>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.simplemobiletools.notes.views.MyHorizontalScrollView
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:id="@+id/notes_horizontal_scrollview"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
android:scrollbarSize="5dp"
8+
android:scrollbars="horizontal">
9+
10+
<com.simplemobiletools.commons.views.MyEditText
11+
android:id="@+id/notes_view"
12+
android:layout_width="match_parent"
13+
android:layout_height="match_parent"
14+
android:background="@null"
15+
android:freezesText="true"
16+
android:gravity="top"
17+
android:inputType="textCapSentences|textMultiLine"
18+
android:padding="@dimen/activity_margin"
19+
android:scrollbars="vertical"
20+
android:textCursorDrawable="@null"/>
21+
22+
</com.simplemobiletools.notes.views.MyHorizontalScrollView>

0 commit comments

Comments
 (0)