mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-13 06:52:03 +02:00
couple correections to viewpager
This commit is contained in:
parent
b3bca97c6a
commit
215883014c
app/src/main
kotlin/com/simplemobiletools/notes
res
@ -2,6 +2,7 @@ package com.simplemobiletools.notes.activities
|
|||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.support.v4.view.ViewPager
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
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.activity_main.*
|
||||||
import kotlinx.android.synthetic.main.fragment_note.*
|
import kotlinx.android.synthetic.main.fragment_note.*
|
||||||
|
|
||||||
class MainActivity : SimpleActivity() {
|
class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||||
lateinit var mCurrentNote: Note
|
lateinit var mCurrentNote: Note
|
||||||
lateinit var mAdapter: NotesPagerAdapter
|
lateinit var mAdapter: NotesPagerAdapter
|
||||||
lateinit var mDb: DBHelper
|
lateinit var mDb: DBHelper
|
||||||
@ -38,6 +39,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes)
|
mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes)
|
||||||
view_pager.apply {
|
view_pager.apply {
|
||||||
adapter = mAdapter
|
adapter = mAdapter
|
||||||
|
addOnPageChangeListener(this@MainActivity)
|
||||||
}
|
}
|
||||||
|
|
||||||
notes_fab.setOnClickListener { displayNewNoteDialog() }
|
notes_fab.setOnClickListener { displayNewNoteDialog() }
|
||||||
@ -52,11 +54,6 @@ class MainActivity : SimpleActivity() {
|
|||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
super.onPause()
|
|
||||||
mAdapter.saveNote(mCurrentNote.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
config.isFirstRun = false
|
config.isFirstRun = false
|
||||||
@ -125,11 +122,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSelectedNote(id: Int) {
|
private fun updateSelectedNote(id: Int) {
|
||||||
mNotes = mDb.getNotes()
|
|
||||||
config.currentNoteId = id
|
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() {
|
fun displayNewNoteDialog() {
|
||||||
@ -185,4 +178,15 @@ class MainActivity : SimpleActivity() {
|
|||||||
startActivity(Intent.createChooser(this, shareTitle))
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,4 @@ class NotesPagerAdapter(fm: FragmentManager, private val notes: List<Note>) : Fr
|
|||||||
fragments.put(position, fragment)
|
fragments.put(position, fragment)
|
||||||
return fragment
|
return fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveNote(pos: Int) {
|
|
||||||
fragments.get(pos)?.saveText()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,7 @@
|
|||||||
<com.simplemobiletools.notes.views.MyViewPager
|
<com.simplemobiletools.notes.views.MyViewPager
|
||||||
android:id="@+id/view_pager"
|
android:id="@+id/view_pager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"/>
|
||||||
android:layout_marginTop="@dimen/activity_margin"/>
|
|
||||||
|
|
||||||
<android.support.design.widget.FloatingActionButton
|
<android.support.design.widget.FloatingActionButton
|
||||||
android:id="@+id/notes_fab"
|
android:id="@+id/notes_fab"
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:id="@+id/note_Fragment_holder"
|
android:id="@+id/note_Fragment_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent"
|
||||||
|
android:paddingTop="@dimen/activity_margin">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/current_note_title"
|
android:id="@+id/current_note_title"
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
|
|
||||||
Pode abrir a aplicação e aceder à sua nota através de um toque no widget.
|
Pode abrir a aplicação e aceder à sua nota através de um toque no widget.
|
||||||
|
|
||||||
Não contém anúncios nem permissões desnecessárias. Disponibiliza um tema escuro e é totalmente 'open source'.
|
Não contém anúncios nem permissões desnecessárias. Disponibiliza um tema escuro e é totalmente \'open source\'.
|
||||||
|
|
||||||
Esta aplicação é apenas parte de um conjunto mais vasto de aplicações. Saiba mais em http://www.simplemobiletools.com
|
Esta aplicação é apenas parte de um conjunto mais vasto de aplicações. Saiba mais em http://www.simplemobiletools.com
|
||||||
</string>
|
</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user