forked from github/wulkanowy-mirror
Add navigate up to login view (#547)
This commit is contained in:
parent
7cf7977cc6
commit
cb9c35d772
3
.idea/codeStyles/Project.xml
generated
3
.idea/codeStyles/Project.xml
generated
@ -1,6 +1,9 @@
|
|||||||
<component name="ProjectCodeStyleConfiguration">
|
<component name="ProjectCodeStyleConfiguration">
|
||||||
<code_scheme name="Project" version="173">
|
<code_scheme name="Project" version="173">
|
||||||
<option name="LINE_SEPARATOR" value=" " />
|
<option name="LINE_SEPARATOR" value=" " />
|
||||||
|
<AndroidXmlCodeStyleSettings>
|
||||||
|
<option name="ARRANGEMENT_SETTINGS_MIGRATED_TO_191" value="true" />
|
||||||
|
</AndroidXmlCodeStyleSettings>
|
||||||
<JetCodeStyleSettings>
|
<JetCodeStyleSettings>
|
||||||
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
|
||||||
<value>
|
<value>
|
||||||
|
@ -3,6 +3,7 @@ package io.github.wulkanowy.ui.modules.login
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.MenuItem
|
||||||
import io.github.wulkanowy.R
|
import io.github.wulkanowy.R
|
||||||
import io.github.wulkanowy.data.db.entities.Student
|
import io.github.wulkanowy.data.db.entities.Student
|
||||||
import io.github.wulkanowy.ui.base.BaseActivity
|
import io.github.wulkanowy.ui.base.BaseActivity
|
||||||
@ -23,22 +24,28 @@ class LoginActivity : BaseActivity<LoginPresenter>(), LoginView {
|
|||||||
lateinit var loginAdapter: BaseFragmentPagerAdapter
|
lateinit var loginAdapter: BaseFragmentPagerAdapter
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun getStartIntent(context: Context) = Intent(context, LoginActivity::class.java)
|
fun getStartIntent(context: Context) = Intent(context, LoginActivity::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val currentViewIndex: Int
|
override val currentViewIndex get() = loginViewpager.currentItem
|
||||||
get() = loginViewpager.currentItem
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_login)
|
setContentView(R.layout.activity_login)
|
||||||
|
setSupportActionBar(loginToolbar)
|
||||||
messageContainer = loginContainer
|
messageContainer = loginContainer
|
||||||
|
|
||||||
presenter.onAttachView(this)
|
presenter.onAttachView(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initAdapter() {
|
override fun initView() {
|
||||||
loginAdapter.apply {
|
with(requireNotNull(supportActionBar)) {
|
||||||
|
setDisplayHomeAsUpEnabled(true)
|
||||||
|
setDisplayShowTitleEnabled(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
with(loginAdapter) {
|
||||||
containerId = loginViewpager.id
|
containerId = loginViewpager.id
|
||||||
addFragments(listOf(
|
addFragments(listOf(
|
||||||
LoginFormFragment.newInstance(),
|
LoginFormFragment.newInstance(),
|
||||||
@ -47,19 +54,24 @@ class LoginActivity : BaseActivity<LoginPresenter>(), LoginView {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
loginViewpager.run {
|
with(loginViewpager) {
|
||||||
offscreenPageLimit = 2
|
offscreenPageLimit = 2
|
||||||
adapter = loginAdapter
|
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) {
|
override fun switchView(index: Int) {
|
||||||
loginViewpager.setCurrentItem(index, false)
|
loginViewpager.setCurrentItem(index, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showActionBar(show: Boolean) {
|
override fun showActionBar(show: Boolean) {
|
||||||
supportActionBar?.apply { if (show) show() else hide() }
|
supportActionBar?.run { if (show) show() else hide() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
|
@ -16,8 +16,8 @@ class LoginPresenter @Inject constructor(
|
|||||||
|
|
||||||
override fun onAttachView(view: LoginView) {
|
override fun onAttachView(view: LoginView) {
|
||||||
super.onAttachView(view)
|
super.onAttachView(view)
|
||||||
view.run {
|
with(view) {
|
||||||
initAdapter()
|
initView()
|
||||||
showActionBar(false)
|
showActionBar(false)
|
||||||
}
|
}
|
||||||
Timber.i("Login view was initialized")
|
Timber.i("Login view was initialized")
|
||||||
@ -48,8 +48,8 @@ class LoginPresenter @Inject constructor(
|
|||||||
fun onViewSelected(index: Int) {
|
fun onViewSelected(index: Int) {
|
||||||
view?.apply {
|
view?.apply {
|
||||||
when (index) {
|
when (index) {
|
||||||
0, 1 -> showActionBar(false)
|
0 -> showActionBar(false)
|
||||||
2 -> showActionBar(true)
|
1, 2 -> showActionBar(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ interface LoginView : BaseView {
|
|||||||
|
|
||||||
val currentViewIndex: Int
|
val currentViewIndex: Int
|
||||||
|
|
||||||
fun initAdapter()
|
fun initView()
|
||||||
|
|
||||||
fun switchView(index: Int)
|
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:id="@+id/loginContainer"
|
||||||
android:layout_width="match_parent"
|
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
|
<com.aurelhubert.ahbottomnavigation.AHBottomNavigationViewPager
|
||||||
android:id="@+id/loginViewpager"
|
android:id="@+id/loginViewpager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
</FrameLayout>
|
</LinearLayout>
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="32dp"
|
android:layout_marginStart="32dp"
|
||||||
android:layout_marginLeft="32dp"
|
android:layout_marginLeft="32dp"
|
||||||
android:layout_marginTop="32dp"
|
|
||||||
android:layout_marginEnd="32dp"
|
android:layout_marginEnd="32dp"
|
||||||
android:layout_marginRight="32dp"
|
android:layout_marginRight="32dp"
|
||||||
android:layout_marginBottom="32dp"
|
android:layout_marginBottom="32dp"
|
||||||
|
@ -35,7 +35,7 @@ class LoginPresenterTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun initViewTest() {
|
fun initViewTest() {
|
||||||
verify(loginView).initAdapter()
|
verify(loginView).initView()
|
||||||
verify(loginView).showActionBar(false)
|
verify(loginView).showActionBar(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user