fix #120, make sure the proper note is shown at clicking a widget

This commit is contained in:
tibbi
2018-09-12 18:54:10 +02:00
parent 67a3a5e811
commit f52aa7f245
2 changed files with 17 additions and 9 deletions

View File

@ -193,6 +193,11 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
view_pager.currentItem = getWantedNoteIndex()
}
private fun storeStateVariables() {
config.apply {
storedEnableLineWrap = enableLineWrap
@ -236,17 +241,10 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
private fun initViewPager() {
mNotes = dbHelper.getNotes()
mCurrentNote = mNotes[0]
var wantedNoteId = intent.getIntExtra(OPEN_NOTE_ID, -1)
if (wantedNoteId == -1) {
wantedNoteId = config.currentNoteId
}
val itemIndex = getNoteIndexWithId(wantedNoteId)
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes, this)
view_pager.apply {
adapter = mAdapter
currentItem = itemIndex
currentItem = getWantedNoteIndex()
addOnPageChangeListener(this@MainActivity)
}
@ -255,6 +253,14 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
}
}
private fun getWantedNoteIndex(): Int {
var wantedNoteId = intent.getIntExtra(OPEN_NOTE_ID, -1)
if (wantedNoteId == -1) {
wantedNoteId = config.currentNoteId
}
return getNoteIndexWithId(wantedNoteId)
}
private fun currentNotesView() = if (view_pager == null) {
null
} else {