Skip to content

Commit a6b9cbb

Browse files
committed
ensure proper note being focused at viewpager
1 parent 27c815e commit a6b9cbb

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class MainActivity : SimpleActivity() {
202202

203203
override fun onNewIntent(intent: Intent) {
204204
super.onNewIntent(intent)
205-
view_pager.currentItem = getWantedNoteIndex()
205+
view_pager.currentItem = getWantedNoteIndex(null)
206206
}
207207

208208
private fun storeStateVariables() {
@@ -247,15 +247,15 @@ class MainActivity : SimpleActivity() {
247247
}
248248
}
249249

250-
private fun initViewPager() {
250+
private fun initViewPager(wantedNoteId: Long? = null) {
251251
NotesHelper(this).getNotes {
252252
mNotes = it
253253
invalidateOptionsMenu()
254254
mCurrentNote = mNotes[0]
255255
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes, this)
256256
view_pager.apply {
257257
adapter = mAdapter
258-
currentItem = getWantedNoteIndex()
258+
currentItem = getWantedNoteIndex(wantedNoteId)
259259

260260
onPageChangeListener {
261261
mCurrentNote = mNotes[it]
@@ -269,10 +269,10 @@ class MainActivity : SimpleActivity() {
269269
}
270270
}
271271

272-
private fun getWantedNoteIndex(): Int {
272+
private fun getWantedNoteIndex(secondaryWantedNoteId: Long?): Int {
273273
var wantedNoteId = intent.getLongExtra(OPEN_NOTE_ID, -1)
274274
if (wantedNoteId == -1L) {
275-
wantedNoteId = config.currentNoteId
275+
wantedNoteId = secondaryWantedNoteId ?: config.currentNoteId
276276
}
277277
return getNoteIndexWithId(wantedNoteId)
278278
}
@@ -286,7 +286,7 @@ class MainActivity : SimpleActivity() {
286286
private fun displayRenameDialog() {
287287
RenameNoteDialog(this, mCurrentNote) {
288288
mCurrentNote = it
289-
initViewPager()
289+
initViewPager(mCurrentNote.id)
290290
}
291291
}
292292

@@ -308,7 +308,7 @@ class MainActivity : SimpleActivity() {
308308
NotesHelper(this).insertOrUpdateNote(note) {
309309
val newNoteId = it
310310
showSaveButton = false
311-
initViewPager()
311+
initViewPager(newNoteId)
312312
updateSelectedNote(newNoteId)
313313
view_pager.onGlobalLayout {
314314
mAdapter?.focusEditText(getNoteIndexWithId(newNoteId))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ class NoteFragment : androidx.fragment.app.Fragment() {
190190
private fun saveNoteValue(note: Note) {
191191
if (note.path.isEmpty()) {
192192
NotesHelper(activity!!).insertOrUpdateNote(note) {
193-
(activity as MainActivity).noteSavedSuccessfully(note.title)
193+
(activity as? MainActivity)?.noteSavedSuccessfully(note.title)
194194
}
195195
} else {
196196
val currentText = getCurrentNoteViewText()
197197
if (currentText != null) {
198-
(activity as MainActivity).exportNoteValueToFile(note.path, currentText, true)
198+
(activity as? MainActivity)?.exportNoteValueToFile(note.path, currentText, true)
199199
}
200200
}
201201
}

0 commit comments

Comments
 (0)