mirror of
				https://github.com/SimpleMobileTools/Simple-Notes.git
				synced 2025-06-05 17:00:23 +02:00 
			
		
		
		
	fix #80, prevent crashes at rotating with some dialog open
This commit is contained in:
		| @@ -59,7 +59,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener { | ||||
|  | ||||
|         val itemIndex = getNoteIndexWithId(wantedNoteId) | ||||
|  | ||||
|         mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes) | ||||
|         mAdapter = NotesPagerAdapter(supportFragmentManager, mNotes, applicationContext) | ||||
|         view_pager.apply { | ||||
|             adapter = mAdapter | ||||
|             currentItem = itemIndex | ||||
|   | ||||
| @@ -1,15 +1,19 @@ | ||||
| package com.simplemobiletools.notes.adapters | ||||
|  | ||||
| import android.content.Context | ||||
| import android.os.Bundle | ||||
| import android.support.v4.app.Fragment | ||||
| import android.support.v4.app.FragmentManager | ||||
| import android.support.v4.app.FragmentStatePagerAdapter | ||||
| import android.util.SparseArray | ||||
| import android.view.ViewGroup | ||||
| import com.simplemobiletools.commons.extensions.toast | ||||
| import com.simplemobiletools.notes.R | ||||
| import com.simplemobiletools.notes.fragments.NoteFragment | ||||
| import com.simplemobiletools.notes.helpers.NOTE_ID | ||||
| import com.simplemobiletools.notes.models.Note | ||||
|  | ||||
| class NotesPagerAdapter(fm: FragmentManager, private val notes: List<Note>) : FragmentStatePagerAdapter(fm) { | ||||
| class NotesPagerAdapter(fm: FragmentManager, val notes: List<Note>, val context: Context) : FragmentStatePagerAdapter(fm) { | ||||
|     var fragments: SparseArray<NoteFragment> = SparseArray(5) | ||||
|  | ||||
|     override fun getCount() = notes.size | ||||
| @@ -35,4 +39,12 @@ class NotesPagerAdapter(fm: FragmentManager, private val notes: List<Note>) : Fr | ||||
|     fun saveCurrentNote(position: Int) = fragments[position]?.saveText() | ||||
|  | ||||
|     fun showKeyboard(position: Int) = fragments[position]?.showKeyboard() | ||||
|  | ||||
|     override fun finishUpdate(container: ViewGroup?) { | ||||
|         try { | ||||
|             super.finishUpdate(container) | ||||
|         } catch (e: Exception) { | ||||
|             context.toast(R.string.unknown_error_occurred) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user