diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/adapter/EditPagerAdapter.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/adapter/EditPagerAdapter.kt index 42f5b55..6e1dc60 100644 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/adapter/EditPagerAdapter.kt +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/adapter/EditPagerAdapter.kt @@ -1,28 +1,22 @@ package com.wbrawner.simplemarkdown.view.adapter -/** - * Created by billy on 7/29/2017. - */ - import android.content.Context import android.content.res.Configuration - import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentPagerAdapter - import com.wbrawner.simplemarkdown.R import com.wbrawner.simplemarkdown.view.fragment.EditFragment import com.wbrawner.simplemarkdown.view.fragment.PreviewFragment -class EditPagerAdapter(fm: FragmentManager, private val mContext: Context) : FragmentPagerAdapter(fm) { +class EditPagerAdapter(fm: FragmentManager, private val context: Context) : FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { override fun getItem(position: Int): Fragment { - when (position) { - FRAGMENT_EDIT -> return EditFragment() - FRAGMENT_PREVIEW -> return PreviewFragment() + return when (position) { + FRAGMENT_EDIT -> EditFragment() + FRAGMENT_PREVIEW -> PreviewFragment() + else -> throw IllegalStateException("Attempting to get fragment for invalid page number") } - return null } override fun getCount(): Int { @@ -35,18 +29,20 @@ class EditPagerAdapter(fm: FragmentManager, private val mContext: Context) : Fra FRAGMENT_EDIT -> stringId = R.string.action_edit FRAGMENT_PREVIEW -> stringId = R.string.action_preview } - return mContext.getString(stringId) + return context.getString(stringId) } override fun getPageWidth(position: Int): Float { - return if (mContext.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { + return if (context.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { 0.5f - } else super.getPageWidth(position) + } else { + super.getPageWidth(position) + } } companion object { - val FRAGMENT_EDIT = 0 - val FRAGMENT_PREVIEW = 1 - val NUM_PAGES = 2 + const val FRAGMENT_EDIT = 0 + const val FRAGMENT_PREVIEW = 1 + const val NUM_PAGES = 2 } }