Fix EditPagerAdapter oddities from autoconversion
This commit is contained in:
parent
93ae39fdf4
commit
09809cada9
1 changed files with 13 additions and 17 deletions
|
@ -1,28 +1,22 @@
|
||||||
package com.wbrawner.simplemarkdown.view.adapter
|
package com.wbrawner.simplemarkdown.view.adapter
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by billy on 7/29/2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.fragment.app.FragmentPagerAdapter
|
import androidx.fragment.app.FragmentPagerAdapter
|
||||||
|
|
||||||
import com.wbrawner.simplemarkdown.R
|
import com.wbrawner.simplemarkdown.R
|
||||||
import com.wbrawner.simplemarkdown.view.fragment.EditFragment
|
import com.wbrawner.simplemarkdown.view.fragment.EditFragment
|
||||||
import com.wbrawner.simplemarkdown.view.fragment.PreviewFragment
|
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 {
|
override fun getItem(position: Int): Fragment {
|
||||||
when (position) {
|
return when (position) {
|
||||||
FRAGMENT_EDIT -> return EditFragment()
|
FRAGMENT_EDIT -> EditFragment()
|
||||||
FRAGMENT_PREVIEW -> return PreviewFragment()
|
FRAGMENT_PREVIEW -> PreviewFragment()
|
||||||
|
else -> throw IllegalStateException("Attempting to get fragment for invalid page number")
|
||||||
}
|
}
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCount(): Int {
|
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_EDIT -> stringId = R.string.action_edit
|
||||||
FRAGMENT_PREVIEW -> stringId = R.string.action_preview
|
FRAGMENT_PREVIEW -> stringId = R.string.action_preview
|
||||||
}
|
}
|
||||||
return mContext.getString(stringId)
|
return context.getString(stringId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPageWidth(position: Int): Float {
|
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
|
0.5f
|
||||||
} else super.getPageWidth(position)
|
} else {
|
||||||
|
super.getPageWidth(position)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val FRAGMENT_EDIT = 0
|
const val FRAGMENT_EDIT = 0
|
||||||
val FRAGMENT_PREVIEW = 1
|
const val FRAGMENT_PREVIEW = 1
|
||||||
val NUM_PAGES = 2
|
const val NUM_PAGES = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue