Skip to content

Instantly share code, notes, and snippets.

@LionZXY
Created July 12, 2017 17:32
Show Gist options
  • Save LionZXY/3e8c6a6021a79b3b16563fe36ef33abc to your computer and use it in GitHub Desktop.
Save LionZXY/3e8c6a6021a79b3b16563fe36ef33abc to your computer and use it in GitHub Desktop.
package com.togezzer.android.ui.questions.view
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.arellomobile.mvp.MvpAppCompatFragment
import com.arellomobile.mvp.presenter.InjectPresenter
import com.togezzer.android.R
import com.togezzer.android.ui.questions.presenter.QuestionPresenter
import com.togezzer.android.utils.inflate
import kotlinx.android.synthetic.main.fragment_question.*
class QuestionFragment : MvpAppCompatFragment(), IQuestionView {
companion object {
val PAGE_COUNT = 3
val PAGE_NEW = 0
val PAGE_OTHER = 1
val PAGE_PERSONAL = 2
}
@InjectPresenter
lateinit var presenter: QuestionPresenter
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return container?.inflate(R.layout.fragment_question)
}
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewpager.adapter = MyFragmentPagerAdapter(fragmentManager)
}
private inner class MyFragmentPagerAdapter(fm: FragmentManager) : FragmentPagerAdapter(fm) {
override fun getItem(position: Int): Fragment {
return QuestionListFragment()
}
override fun getCount(): Int {
return PAGE_COUNT
}
override fun getPageTitle(position: Int): CharSequence = when (position) {
PAGE_NEW -> resources.getString(R.string.question_tab_new)
PAGE_OTHER -> resources.getString(R.string.question_tab_others)
PAGE_PERSONAL -> resources.getString(R.string.question_tab_personal)
else -> String()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment