diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt index 9f207d18..b8908038 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt index 25f225e9..48f884cb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt @@ -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 { diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt index 0c0caaea..9d7785fe 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt index 22e471f4..bb5be80d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Config.kt @@ -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() diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt index c879c2ee..7406cb06 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/helpers/Constants.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/views/MyHorizontalScrollView.kt b/app/src/main/kotlin/com/simplemobiletools/notes/views/MyHorizontalScrollView.kt new file mode 100644 index 00000000..30b8fbe9 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/notes/views/MyHorizontalScrollView.kt @@ -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) + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 18e180bb..be9a3c51 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -12,4 +12,5 @@ android:layout_gravity="top" android:paddingLeft="@dimen/activity_margin" android:paddingRight="@dimen/activity_margin"/> + </com.simplemobiletools.commons.views.MyViewPager> diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 60483eba..0882f0f1 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -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" diff --git a/app/src/main/res/layout/fragment_note.xml b/app/src/main/res/layout/fragment_note.xml index 1f68f6ae..ef39270e 100644 --- a/app/src/main/res/layout/fragment_note.xml +++ b/app/src/main/res/layout/fragment_note.xml @@ -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> diff --git a/app/src/main/res/layout/note_view_horiz_scrollable.xml b/app/src/main/res/layout/note_view_horiz_scrollable.xml new file mode 100644 index 00000000..514c6a5d --- /dev/null +++ b/app/src/main/res/layout/note_view_horiz_scrollable.xml @@ -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> diff --git a/app/src/main/res/layout/note_view_static.xml b/app/src/main/res/layout/note_view_static.xml new file mode 100644 index 00000000..2c562a4a --- /dev/null +++ b/app/src/main/res/layout/note_view_static.xml @@ -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"/>