From 215883014cdab57590320365b79d8480a099f10c Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 26 Nov 2016 19:45:23 +0100 Subject: [PATCH] couple correections to viewpager --- .../notes/activities/MainActivity.kt | 24 +++++++++++-------- .../notes/adapters/NotesPagerAdapter.kt | 4 ---- app/src/main/res/layout/activity_main.xml | 3 +-- app/src/main/res/layout/fragment_note.xml | 3 ++- app/src/main/res/values-pt-rPT/strings.xml | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt index 2e301369..a89cdb68 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.notes.activities import android.content.Intent import android.os.Bundle +import android.support.v4.view.ViewPager import android.view.Menu import android.view.MenuItem import android.view.View @@ -21,7 +22,7 @@ import com.simplemobiletools.notes.models.Note import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.fragment_note.* -class MainActivity : SimpleActivity() { +class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { lateinit var mCurrentNote: Note lateinit var mAdapter: NotesPagerAdapter lateinit var mDb: DBHelper @@ -38,6 +39,7 @@ class MainActivity : SimpleActivity() { mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes) view_pager.apply { adapter = mAdapter + addOnPageChangeListener(this@MainActivity) } notes_fab.setOnClickListener { displayNewNoteDialog() } @@ -52,11 +54,6 @@ class MainActivity : SimpleActivity() { invalidateOptionsMenu() } - override fun onPause() { - super.onPause() - mAdapter.saveNote(mCurrentNote.id) - } - override fun onDestroy() { super.onDestroy() config.isFirstRun = false @@ -125,11 +122,7 @@ class MainActivity : SimpleActivity() { } private fun updateSelectedNote(id: Int) { - mNotes = mDb.getNotes() config.currentNoteId = id - notes_view.setText(mCurrentNote.value) - current_note_title.text = mCurrentNote.title - current_note_title.visibility = if (mNotes.size <= 1) View.GONE else View.VISIBLE } fun displayNewNoteDialog() { @@ -185,4 +178,15 @@ class MainActivity : SimpleActivity() { startActivity(Intent.createChooser(this, shareTitle)) } } + + override fun onPageScrollStateChanged(state: Int) { + } + + override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { + } + + override fun onPageSelected(position: Int) { + mCurrentNote = mNotes[position] + config.currentNoteId = mCurrentNote.id + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt index eb9c653b..b2c1ebee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/adapters/NotesPagerAdapter.kt @@ -31,8 +31,4 @@ class NotesPagerAdapter(fm: FragmentManager, private val notes: List) : Fr fragments.put(position, fragment) return fragment } - - fun saveNote(pos: Int) { - fragments.get(pos)?.saveText() - } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 1f92ff0f..0d52fd43 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -9,8 +9,7 @@ + android:layout_height="match_parent"/> + android:layout_height="match_parent" + android:paddingTop="@dimen/activity_margin">