Convert EditPagerAdapter to Kotlin
This commit is contained in:
parent
a4d9a9b9d7
commit
93ae39fdf4
2 changed files with 52 additions and 68 deletions
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue