From 93ae39fdf4e3aabefa3424791546f2cf7f8b636d Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Sun, 4 Aug 2019 18:00:07 -0700 Subject: [PATCH] Convert EditPagerAdapter to Kotlin --- .../view/adapter/EditPagerAdapter.java | 68 ------------------- .../view/adapter/EditPagerAdapter.kt | 52 ++++++++++++++ 2 files changed, 52 insertions(+), 68 deletions(-) delete mode 100644 app/src/main/java/com/wbrawner/simplemarkdown/view/adapter/EditPagerAdapter.java create mode 100644 app/src/main/java/com/wbrawner/simplemarkdown/view/adapter/EditPagerAdapter.kt diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/adapter/EditPagerAdapter.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/adapter/EditPagerAdapter.java deleted file mode 100644 index 3e07ce1..0000000 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/adapter/EditPagerAdapter.java +++ /dev/null @@ -1,68 +0,0 @@ -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; - -public class EditPagerAdapter extends FragmentPagerAdapter { - public static final int FRAGMENT_EDIT = 0; - public static final int FRAGMENT_PREVIEW = 1; - public static final int NUM_PAGES = 2; - - private Context mContext; - - public EditPagerAdapter(FragmentManager fm, Context context) { - super(fm); - mContext = context; - } - - @Override - public Fragment getItem(int position) { - switch (position) { - case FRAGMENT_EDIT: - return new EditFragment(); - case FRAGMENT_PREVIEW: - return new PreviewFragment(); - } - return null; - } - - @Override - public int getCount() { - return NUM_PAGES; - } - - @Override - public CharSequence getPageTitle(int position) { - int stringId = 0; - switch (position) { - case FRAGMENT_EDIT: - stringId = R.string.action_edit; - break; - case FRAGMENT_PREVIEW: - stringId = R.string.action_preview; - break; - } - return mContext.getString(stringId); - } - - @Override - public float getPageWidth(int position) { - if (mContext.getResources().getConfiguration().orientation - == Configuration.ORIENTATION_LANDSCAPE) { - return 0.5f; - } - return super.getPageWidth(position); - } -} 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 new file mode 100644 index 0000000..42f5b55 --- /dev/null +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/adapter/EditPagerAdapter.kt @@ -0,0 +1,52 @@ +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) { + + override fun getItem(position: Int): Fragment { + when (position) { + FRAGMENT_EDIT -> return EditFragment() + FRAGMENT_PREVIEW -> return PreviewFragment() + } + return null + } + + override fun getCount(): Int { + return NUM_PAGES + } + + override fun getPageTitle(position: Int): CharSequence? { + var stringId = 0 + when (position) { + FRAGMENT_EDIT -> stringId = R.string.action_edit + FRAGMENT_PREVIEW -> stringId = R.string.action_preview + } + return mContext.getString(stringId) + } + + override fun getPageWidth(position: Int): Float { + return if (mContext.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) { + 0.5f + } else super.getPageWidth(position) + } + + companion object { + val FRAGMENT_EDIT = 0 + val FRAGMENT_PREVIEW = 1 + val NUM_PAGES = 2 + } +}