forked from github/wulkanowy-mirror
Add navigate up to login view (#547)
This commit is contained in:

committed by
Mikołaj Pich

parent
7cf7977cc6
commit
cb9c35d772
@ -3,6 +3,7 @@ package io.github.wulkanowy.ui.modules.login
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.ui.base.BaseActivity
|
||||
@ -23,22 +24,28 @@ class LoginActivity : BaseActivity<LoginPresenter>(), LoginView {
|
||||
lateinit var loginAdapter: BaseFragmentPagerAdapter
|
||||
|
||||
companion object {
|
||||
|
||||
fun getStartIntent(context: Context) = Intent(context, LoginActivity::class.java)
|
||||
}
|
||||
|
||||
override val currentViewIndex: Int
|
||||
get() = loginViewpager.currentItem
|
||||
override val currentViewIndex get() = loginViewpager.currentItem
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_login)
|
||||
setSupportActionBar(loginToolbar)
|
||||
messageContainer = loginContainer
|
||||
|
||||
presenter.onAttachView(this)
|
||||
}
|
||||
|
||||
override fun initAdapter() {
|
||||
loginAdapter.apply {
|
||||
override fun initView() {
|
||||
with(requireNotNull(supportActionBar)) {
|
||||
setDisplayHomeAsUpEnabled(true)
|
||||
setDisplayShowTitleEnabled(false)
|
||||
}
|
||||
|
||||
with(loginAdapter) {
|
||||
containerId = loginViewpager.id
|
||||
addFragments(listOf(
|
||||
LoginFormFragment.newInstance(),
|
||||
@ -47,19 +54,24 @@ class LoginActivity : BaseActivity<LoginPresenter>(), LoginView {
|
||||
))
|
||||
}
|
||||
|
||||
loginViewpager.run {
|
||||
with(loginViewpager) {
|
||||
offscreenPageLimit = 2
|
||||
adapter = loginAdapter
|
||||
setOnSelectPageListener { presenter.onViewSelected(it) }
|
||||
setOnSelectPageListener(presenter::onViewSelected)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (item.itemId == android.R.id.home) onBackPressed()
|
||||
return true
|
||||
}
|
||||
|
||||
override fun switchView(index: Int) {
|
||||
loginViewpager.setCurrentItem(index, false)
|
||||
}
|
||||
|
||||
override fun showActionBar(show: Boolean) {
|
||||
supportActionBar?.apply { if (show) show() else hide() }
|
||||
supportActionBar?.run { if (show) show() else hide() }
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
|
@ -16,8 +16,8 @@ class LoginPresenter @Inject constructor(
|
||||
|
||||
override fun onAttachView(view: LoginView) {
|
||||
super.onAttachView(view)
|
||||
view.run {
|
||||
initAdapter()
|
||||
with(view) {
|
||||
initView()
|
||||
showActionBar(false)
|
||||
}
|
||||
Timber.i("Login view was initialized")
|
||||
@ -48,8 +48,8 @@ class LoginPresenter @Inject constructor(
|
||||
fun onViewSelected(index: Int) {
|
||||
view?.apply {
|
||||
when (index) {
|
||||
0, 1 -> showActionBar(false)
|
||||
2 -> showActionBar(true)
|
||||
0 -> showActionBar(false)
|
||||
1, 2 -> showActionBar(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ interface LoginView : BaseView {
|
||||
|
||||
val currentViewIndex: Int
|
||||
|
||||
fun initAdapter()
|
||||
fun initView()
|
||||
|
||||
fun switchView(index: Int)
|
||||
|
||||
|
Reference in New Issue
Block a user