mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-03-01 09:37:48 +01:00
fix OpenNoteDialog
This commit is contained in:
parent
7be53dd1f3
commit
5967b74c3e
@ -44,14 +44,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
|||||||
fun initViewPager() {
|
fun initViewPager() {
|
||||||
mNotes = mDb.getNotes()
|
mNotes = mDb.getNotes()
|
||||||
mCurrentNote = mNotes[0]
|
mCurrentNote = mNotes[0]
|
||||||
var itemIndex = 0
|
val itemIndex = getNoteIndexWithId(config.currentNoteId)
|
||||||
for (i in 0..mNotes.count() - 1) {
|
|
||||||
if (mNotes[i].id == config.currentNoteId) {
|
|
||||||
mCurrentNote = mNotes[i]
|
|
||||||
itemIndex = i
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes)
|
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes)
|
||||||
view_pager.apply {
|
view_pager.apply {
|
||||||
@ -127,11 +120,9 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
|||||||
|
|
||||||
private fun updateSelectedNote(id: Int) {
|
private fun updateSelectedNote(id: Int) {
|
||||||
config.currentNoteId = id
|
config.currentNoteId = id
|
||||||
|
val index = getNoteIndexWithId(id)
|
||||||
for (i in 0..mNotes.count() - 1) {
|
view_pager.currentItem = index
|
||||||
view_pager.currentItem = i
|
mCurrentNote = mNotes[index]
|
||||||
mCurrentNote = mNotes[i]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun displayNewNoteDialog() {
|
fun displayNewNoteDialog() {
|
||||||
@ -172,6 +163,16 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getNoteIndexWithId(id: Int): Int {
|
||||||
|
for (i in 0..mNotes.count() - 1) {
|
||||||
|
if (mNotes[i].id == id) {
|
||||||
|
mCurrentNote = mNotes[i]
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
private fun shareText() {
|
private fun shareText() {
|
||||||
val text = notes_view.value
|
val text = notes_view.value
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
|
@ -12,6 +12,7 @@ import kotlinx.android.synthetic.main.dialog_radio_group.view.*
|
|||||||
|
|
||||||
class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> Unit) : RadioGroup.OnCheckedChangeListener {
|
class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> Unit) : RadioGroup.OnCheckedChangeListener {
|
||||||
val dialog: AlertDialog?
|
val dialog: AlertDialog?
|
||||||
|
var wasInit = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val config = Config.newInstance(activity)
|
val config = Config.newInstance(activity)
|
||||||
@ -36,10 +37,13 @@ class OpenNoteDialog(val activity: Activity, val callback: (checkedId: Int) -> U
|
|||||||
.create()
|
.create()
|
||||||
|
|
||||||
dialog!!.show()
|
dialog!!.show()
|
||||||
|
wasInit = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCheckedChanged(group: RadioGroup, checkedId: Int) {
|
override fun onCheckedChanged(group: RadioGroup, checkedId: Int) {
|
||||||
callback.invoke(checkedId)
|
if (wasInit) {
|
||||||
dialog?.dismiss()
|
callback.invoke(checkedId)
|
||||||
|
dialog?.dismiss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user