mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-21 18:57:24 +02:00
ensure proper note being focused at viewpager
This commit is contained in:
parent
27c815ec3f
commit
a6b9cbba9b
app/src/main/kotlin/com/simplemobiletools/notes/pro
@ -202,7 +202,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
super.onNewIntent(intent)
|
super.onNewIntent(intent)
|
||||||
view_pager.currentItem = getWantedNoteIndex()
|
view_pager.currentItem = getWantedNoteIndex(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun storeStateVariables() {
|
private fun storeStateVariables() {
|
||||||
@ -247,7 +247,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initViewPager() {
|
private fun initViewPager(wantedNoteId: Long? = null) {
|
||||||
NotesHelper(this).getNotes {
|
NotesHelper(this).getNotes {
|
||||||
mNotes = it
|
mNotes = it
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
@ -255,7 +255,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes, this)
|
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes, this)
|
||||||
view_pager.apply {
|
view_pager.apply {
|
||||||
adapter = mAdapter
|
adapter = mAdapter
|
||||||
currentItem = getWantedNoteIndex()
|
currentItem = getWantedNoteIndex(wantedNoteId)
|
||||||
|
|
||||||
onPageChangeListener {
|
onPageChangeListener {
|
||||||
mCurrentNote = mNotes[it]
|
mCurrentNote = mNotes[it]
|
||||||
@ -269,10 +269,10 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getWantedNoteIndex(): Int {
|
private fun getWantedNoteIndex(secondaryWantedNoteId: Long?): Int {
|
||||||
var wantedNoteId = intent.getLongExtra(OPEN_NOTE_ID, -1)
|
var wantedNoteId = intent.getLongExtra(OPEN_NOTE_ID, -1)
|
||||||
if (wantedNoteId == -1L) {
|
if (wantedNoteId == -1L) {
|
||||||
wantedNoteId = config.currentNoteId
|
wantedNoteId = secondaryWantedNoteId ?: config.currentNoteId
|
||||||
}
|
}
|
||||||
return getNoteIndexWithId(wantedNoteId)
|
return getNoteIndexWithId(wantedNoteId)
|
||||||
}
|
}
|
||||||
@ -286,7 +286,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
private fun displayRenameDialog() {
|
private fun displayRenameDialog() {
|
||||||
RenameNoteDialog(this, mCurrentNote) {
|
RenameNoteDialog(this, mCurrentNote) {
|
||||||
mCurrentNote = it
|
mCurrentNote = it
|
||||||
initViewPager()
|
initViewPager(mCurrentNote.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +308,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
NotesHelper(this).insertOrUpdateNote(note) {
|
NotesHelper(this).insertOrUpdateNote(note) {
|
||||||
val newNoteId = it
|
val newNoteId = it
|
||||||
showSaveButton = false
|
showSaveButton = false
|
||||||
initViewPager()
|
initViewPager(newNoteId)
|
||||||
updateSelectedNote(newNoteId)
|
updateSelectedNote(newNoteId)
|
||||||
view_pager.onGlobalLayout {
|
view_pager.onGlobalLayout {
|
||||||
mAdapter?.focusEditText(getNoteIndexWithId(newNoteId))
|
mAdapter?.focusEditText(getNoteIndexWithId(newNoteId))
|
||||||
|
@ -190,12 +190,12 @@ class NoteFragment : androidx.fragment.app.Fragment() {
|
|||||||
private fun saveNoteValue(note: Note) {
|
private fun saveNoteValue(note: Note) {
|
||||||
if (note.path.isEmpty()) {
|
if (note.path.isEmpty()) {
|
||||||
NotesHelper(activity!!).insertOrUpdateNote(note) {
|
NotesHelper(activity!!).insertOrUpdateNote(note) {
|
||||||
(activity as MainActivity).noteSavedSuccessfully(note.title)
|
(activity as? MainActivity)?.noteSavedSuccessfully(note.title)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val currentText = getCurrentNoteViewText()
|
val currentText = getCurrentNoteViewText()
|
||||||
if (currentText != null) {
|
if (currentText != null) {
|
||||||
(activity as MainActivity).exportNoteValueToFile(note.path, currentText, true)
|
(activity as? MainActivity)?.exportNoteValueToFile(note.path, currentText, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user