fix #160, allow disabling line wrap

This commit is contained in:
tibbi 2018-01-26 22:54:18 +01:00
parent 7f15b8c07a
commit 3b4d89ce97
11 changed files with 122 additions and 29 deletions

View File

@ -43,6 +43,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
private var noteViewWithTextSelected: MyEditText? = null
private var wasInit = false
private var storedUseEnglish = false
private var storedEnableLineWrap = true
private var showSaveButton = false
private var saveNoteButton: MenuItem? = null
@ -86,6 +87,10 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
return
}
if (storedEnableLineWrap != config.enableLineWrap) {
initViewPager()
}
invalidateOptionsMenu()
pager_title_strip.apply {
setTextSize(TypedValue.COMPLEX_UNIT_PX, getTextSize())
@ -165,7 +170,10 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
private fun storeStateVariables() {
storedUseEnglish = config.useEnglish
config.apply {
storedUseEnglish = useEnglish
storedEnableLineWrap = enableLineWrap
}
}
private fun handleText(text: String) {
@ -206,8 +214,9 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
mNotes = dbHelper.getNotes()
mCurrentNote = mNotes[0]
var wantedNoteId = intent.getIntExtra(OPEN_NOTE_ID, -1)
if (wantedNoteId == -1)
if (wantedNoteId == -1) {
wantedNoteId = config.currentNoteId
}
val itemIndex = getNoteIndexWithId(wantedNoteId)

View File

@ -40,6 +40,7 @@ class SettingsActivity : SimpleActivity() {
setupShowKeyboard()
setupShowNotePicker()
setupShowWordCount()
setupEnableLineWrap()
setupFontSize()
setupGravity()
setupWidgetNote()
@ -120,6 +121,14 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupEnableLineWrap() {
settings_enable_line_wrap.isChecked = config.enableLineWrap
settings_enable_line_wrap_holder.setOnClickListener {
settings_enable_line_wrap.toggle()
config.enableLineWrap = settings_enable_line_wrap.isChecked
}
}
private fun setupFontSize() {
settings_font_size.text = getFontSizeText()
settings_font_size_holder.setOnClickListener {

View File

@ -14,6 +14,7 @@ import android.view.View
import android.view.ViewGroup
import com.simplemobiletools.commons.extensions.beGone
import com.simplemobiletools.commons.extensions.beVisible
import com.simplemobiletools.commons.extensions.onGlobalLayout
import com.simplemobiletools.notes.R
import com.simplemobiletools.notes.activities.MainActivity
import com.simplemobiletools.notes.extensions.*
@ -24,21 +25,24 @@ import com.simplemobiletools.notes.helpers.NOTE_ID
import com.simplemobiletools.notes.models.Note
import kotlinx.android.synthetic.main.fragment_note.*
import kotlinx.android.synthetic.main.fragment_note.view.*
import kotlinx.android.synthetic.main.note_view_horiz_scrollable.view.*
import java.io.File
class NoteFragment : Fragment() {
private var noteId = 0
lateinit var note: Note
lateinit var view: ViewGroup
lateinit var mDb: DBHelper
private lateinit var db: DBHelper
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
view = inflater.inflate(R.layout.fragment_note, container, false) as ViewGroup
noteId = arguments!!.getInt(NOTE_ID)
mDb = context!!.dbHelper
note = mDb.getNote(noteId) ?: return view
db = context!!.dbHelper
note = db.getNote(noteId) ?: return view
retainInstance = true
val layoutToInflate = if (context!!.config.enableLineWrap) R.layout.note_view_static else R.layout.note_view_horiz_scrollable
inflater.inflate(layoutToInflate, view.notes_relative_layout, true)
if (context!!.config.clickableLinks) {
view.notes_view.apply {
linksClickable = true
@ -47,6 +51,10 @@ class NoteFragment : Fragment() {
}
}
view.notes_horizontal_scrollview?.onGlobalLayout {
view.notes_view.minWidth = view.notes_horizontal_scrollview.width
}
return view
}
@ -133,7 +141,7 @@ class NoteFragment : Fragment() {
private fun saveNoteValue(note: Note) {
if (note.path.isEmpty()) {
mDb.updateNoteValue(note)
db.updateNoteValue(note)
(activity as MainActivity).noteSavedSuccessfully(note.title)
} else {
(activity as MainActivity).exportNoteValueToFile(note.path, getCurrentNoteViewText(), true)

View File

@ -57,6 +57,10 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(CURSOR_PLACEMENT, true)
set(placement) = prefs.edit().putBoolean(CURSOR_PLACEMENT, placement).apply()
var enableLineWrap: Boolean
get() = prefs.getBoolean(ENABLE_LINE_WRAP, true)
set(enableLineWrap) = prefs.edit().putBoolean(ENABLE_LINE_WRAP, enableLineWrap).apply()
var lastUsedExtension: String
get() = prefs.getString(LAST_USED_EXTENSION, "txt")
set(lastUsedExtension) = prefs.edit().putString(LAST_USED_EXTENSION, lastUsedExtension).apply()

View File

@ -18,6 +18,7 @@ const val GRAVITY = "gravity"
const val CURSOR_PLACEMENT = "cursor_placement"
const val LAST_USED_EXTENSION = "last_used_extension"
const val LAST_USED_SAVE_PATH = "last_used_save_path"
const val ENABLE_LINE_WRAP = "enable_line_wrap"
// gravity
const val GRAVITY_LEFT = 0

View File

@ -0,0 +1,17 @@
package com.simplemobiletools.notes.views
import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import android.widget.HorizontalScrollView
class MyHorizontalScrollView : HorizontalScrollView {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
override fun onTouchEvent(ev: MotionEvent): Boolean {
parent.requestDisallowInterceptTouchEvent(false)
return super.onTouchEvent(ev)
}
}

View File

@ -12,4 +12,5 @@
android:layout_gravity="top"
android:paddingLeft="@dimen/activity_margin"
android:paddingRight="@dimen/activity_margin"/>
</com.simplemobiletools.commons.views.MyViewPager>

View File

@ -225,6 +225,26 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_enable_line_wrap_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_enable_line_wrap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/enable_line_wrap"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_font_size_holder"
android:layout_width="match_parent"

View File

@ -2,7 +2,7 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/note_Fragment_holder"
android:id="@+id/note_fragment_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -17,28 +17,17 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/notes_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:freezesText="true"
android:gravity="top"
android:inputType="textCapSentences|textMultiLine"
android:padding="@dimen/activity_margin"
android:textCursorDrawable="@null"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/notes_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:padding="@dimen/small_margin"
android:textStyle="italic"
tools:text="123"/>
</RelativeLayout>
</ScrollView>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/notes_counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:padding="@dimen/small_margin"
android:textStyle="italic"
tools:text="123"/>
</RelativeLayout>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.notes.views.MyHorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/notes_horizontal_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarSize="5dp"
android:scrollbars="horizontal">
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/notes_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:freezesText="true"
android:gravity="top"
android:inputType="textCapSentences|textMultiLine"
android:padding="@dimen/activity_margin"
android:scrollbars="vertical"
android:textCursorDrawable="@null"/>
</com.simplemobiletools.notes.views.MyHorizontalScrollView>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.commons.views.MyEditText
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/notes_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@null"
android:freezesText="true"
android:gravity="top"
android:inputType="textCapSentences|textMultiLine"
android:padding="@dimen/activity_margin"
android:scrollbars="vertical"
android:textCursorDrawable="@null"/>