mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-13 23:12:02 +02:00
properly handle orientation changes
This commit is contained in:
parent
ed3ad32fa5
commit
b0362dfa1a
@ -6,7 +6,10 @@ import android.support.v4.view.ViewPager
|
||||
import android.text.method.ArrowKeyMovementMethod
|
||||
import android.text.method.LinkMovementMethod
|
||||
import android.util.TypedValue
|
||||
import android.view.*
|
||||
import android.view.ActionMode
|
||||
import android.view.Gravity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
@ -31,7 +34,6 @@ import com.simplemobiletools.notes.helpers.OPEN_NOTE_ID
|
||||
import com.simplemobiletools.notes.helpers.TYPE_NOTE
|
||||
import com.simplemobiletools.notes.models.Note
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import kotlinx.android.synthetic.main.fragment_note.*
|
||||
import java.io.File
|
||||
import java.nio.charset.Charset
|
||||
|
||||
@ -212,7 +214,11 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
hideKeyboard()
|
||||
}
|
||||
|
||||
private fun currentNotesView() = if (view_pager == null) null else mAdapter?.getItem(view_pager.currentItem)?.notes_view
|
||||
private fun currentNotesView() = if (view_pager == null) {
|
||||
null
|
||||
} else {
|
||||
mAdapter?.getCurrentNotesView(view_pager.currentItem)
|
||||
}
|
||||
|
||||
private fun displayRenameDialog() {
|
||||
RenameNoteDialog(this, mDb, mCurrentNote) {
|
||||
@ -241,12 +247,9 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
invalidateOptionsMenu()
|
||||
initViewPager()
|
||||
updateSelectedNote(id)
|
||||
view_pager.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||
override fun onGlobalLayout() {
|
||||
mAdapter?.focusEditText(getNoteIndexWithId(id))
|
||||
view_pager.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
}
|
||||
})
|
||||
view_pager.onGlobalLayout {
|
||||
mAdapter?.focusEditText(getNoteIndexWithId(id))
|
||||
}
|
||||
}
|
||||
|
||||
private fun launchAbout() {
|
||||
|
@ -33,6 +33,8 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
|
||||
|
||||
override fun getPageTitle(position: Int) = notes[position].title
|
||||
|
||||
fun getCurrentNotesView(position: Int) = fragments[position]?.getNotesView()
|
||||
|
||||
fun getCurrentNoteViewText(position: Int) = fragments[position]?.getCurrentNoteViewText()
|
||||
|
||||
fun appendText(position: Int, text: String) = fragments[position]?.getNotesView()?.append(text)
|
||||
@ -48,4 +50,9 @@ class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val activity
|
||||
activity.showErrorToast(e)
|
||||
}
|
||||
}
|
||||
|
||||
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
|
||||
super.destroyItem(container, position, `object`)
|
||||
fragments.removeAt(position)
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ class NoteFragment : Fragment() {
|
||||
noteId = arguments!!.getInt(NOTE_ID)
|
||||
mDb = context!!.dbHelper
|
||||
note = mDb.getNote(noteId) ?: return view
|
||||
retainInstance = true
|
||||
|
||||
if (context!!.config.clickableLinks) {
|
||||
view.notes_view.apply {
|
||||
|
Loading…
x
Reference in New Issue
Block a user