Commit 3ba27c4e authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

improve mvi behaviour

parent aabbca59
*.iml *.iml
.gradle .gradle
/local.properties /local.properties
/.idea
/.idea/caches /.idea/caches
/.idea/libraries /.idea/libraries
/.idea/modules.xml /.idea/modules.xml
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<dictionary name="bogdashkin"> <dictionary name="bogdashkin">
<words> <words>
<w>Biganto</w> <w>Biganto</w>
<w>snackbar</w>
</words> </words>
</dictionary> </dictionary>
</component> </component>
\ No newline at end of file
...@@ -9,18 +9,22 @@ import android.view.inputmethod.InputMethodManager ...@@ -9,18 +9,22 @@ import android.view.inputmethod.InputMethodManager
import android.widget.Toast import android.widget.Toast
import androidx.annotation.LayoutRes import androidx.annotation.LayoutRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.appcompat.app.ActionBar
import androidx.appcompat.app.AppCompatActivity
import butterknife.ButterKnife import butterknife.ButterKnife
import com.biganto.visual.roompark.R import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.ICollapsingToolBar
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.mosby.mvi.BigantoMviController import com.biganto.visual.roompark.conductor.mosby.mvi.BigantoMviController
import com.biganto.visual.roompark.di.dagger.PerScreen
import com.biganto.visual.roompark.view_utils.snackbar.ISnackBarProvider import com.biganto.visual.roompark.view_utils.snackbar.ISnackBarProvider
import com.hannesdorfmann.mosby3.mvi.MviBasePresenter import com.hannesdorfmann.mosby3.mvi.MviBasePresenter
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import javax.inject.Inject
/** /**
* Created by Vladislav Bogdashkin on 28.05.2018. * Created by Vladislav Bogdashkin on 28.05.2018.
*/ */
@PerScreen
abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseContract<VS>,P : MviBasePresenter<V,VS>> abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseContract<VS>,P : MviBasePresenter<V,VS>>
: BigantoMviController<V, P> { : BigantoMviController<V, P> {
...@@ -38,22 +42,12 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon ...@@ -38,22 +42,12 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon
@StringRes @StringRes
protected abstract fun getToolbarTitleId(): Int protected abstract fun getToolbarTitleId(): Int
protected abstract fun showBottomAppBar(): Boolean
// protected lateinit var toolBars:TopBottomActionBarsSupported
protected lateinit var snackbar: ISnackBarProvider
private fun setToolbarTitle() { @Inject
// if the Activity happens to be non-AppCompatActivity or it does not have ActionBar, simply do not set the title private lateinit var roomParkActivity:RoomParkMainActivity
(activity as? AppCompatActivity)?.supportActionBar?.apply {
title = resources?.getString(getToolbarTitleId())
setDisplayHomeAsUpEnabled(router.backstackSize > 1)
}
}
//TODO(injection) protected val toolBar: ICollapsingToolBar = roomParkActivity
private fun bottomToolbar() : ActionBar?=(activity as? AppCompatActivity)?.supportActionBar protected val snackbar: ISnackBarProvider = roomParkActivity.snackbarProvider
override fun onDetach(view: View) { override fun onDetach(view: View) {
detachDisposable.clear() detachDisposable.clear()
...@@ -64,19 +58,13 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon ...@@ -64,19 +58,13 @@ abstract class BigantoBaseController<VS : BigantoBaseViewState,V: BigantoBaseCon
val view = inflater.inflate(getLayoutId(), container, false) val view = inflater.inflate(getLayoutId(), container, false)
// instantiate the view // instantiate the view
ButterKnife.bind(this, view) ButterKnife.bind(this, view)
// toolBars=(activity as TopBottomActionBarsSupported)
snackbar = activity as ISnackBarProvider
//TODO(remove duplicated code:)
if (showBottomAppBar())
bottomToolbar()?.show()
if (!showBottomAppBar())
bottomToolbar()?.hide()
return view return view
} }
protected fun View.hideKeyboard() { protected fun View.hideKeyboard() {
val inputMethodManager = applicationContext?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager val inputMethodManager = applicationContext
?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(this.windowToken, 0) inputMethodManager.hideSoftInputFromWindow(this.windowToken, 0)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment