mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-22 23:16:12 -06:00
Add navigate up to login view (#547)
This commit is contained in:
parent
7cf7977cc6
commit
cb9c35d772
@ -1,6 +1,9 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<code_scheme name="Project" version="173">
|
||||
<option name="LINE_SEPARATOR" value=" " />
|
||||
<AndroidXmlCodeStyleSettings>
|
||||
<option name="ARRANGEMENT_SETTINGS_MIGRATED_TO_191" value="true" />
|
||||
</AndroidXmlCodeStyleSettings>
|
||||
<JetCodeStyleSettings>
|
||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||
<value>
|
||||
|
@ -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)
|
||||
|
||||
|
@ -1,10 +1,17 @@
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/loginContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.google.android.material.appbar.MaterialToolbar
|
||||
android:id="@+id/loginToolbar"
|
||||
android:background="@android:color/transparent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<com.aurelhubert.ahbottomnavigation.AHBottomNavigationViewPager
|
||||
android:id="@+id/loginViewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
@ -25,7 +25,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="32dp"
|
||||
android:layout_marginLeft="32dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginEnd="32dp"
|
||||
android:layout_marginRight="32dp"
|
||||
android:layout_marginBottom="32dp"
|
||||
|
@ -35,7 +35,7 @@ class LoginPresenterTest {
|
||||
|
||||
@Test
|
||||
fun initViewTest() {
|
||||
verify(loginView).initAdapter()
|
||||
verify(loginView).initView()
|
||||
verify(loginView).showActionBar(false)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user