Commit 36611c57 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

added restore feeds model

parent f6587b74
......@@ -69,20 +69,27 @@ class RoomParkMainActivity(
override fun hideAll() {
appBar.visibility=Toolbar.INVISIBLE
bottomNavigation.visibility = BottomNavigationView.GONE
bottomShadow.visibility = View.GONE
Timber.e(" lay params : ${appBar.layoutParams.javaClass}")
val params:CoordinatorLayout.LayoutParams = conductor_container.layoutParams as CoordinatorLayout.LayoutParams
params.behavior = null
conductor_container.requestLayout()
}
override fun hide() {
bottomNavigation.visibility = BottomNavigationView.GONE
bottomShadow.visibility = View.GONE
}
override fun show() {
bottomNavigation.visibility = Toolbar.VISIBLE
bottomShadow.visibility = View.VISIBLE
}
override fun showAll() {
appBar.setExpanded(true,false)
collapsingToolbarLayout.visibility= View.VISIBLE
bottomNavigation.visibility = Toolbar.VISIBLE
bottomShadow.visibility = View.VISIBLE
appBar.visibility= View.VISIBLE
topAppBar.visibility = View.VISIBLE
......@@ -96,4 +103,12 @@ class RoomParkMainActivity(
val behavior = params.behavior as DragControlAppBarLayoutBehaviour
behavior.allowDrag=allow
}
override fun onBackPressed() {
if (router.handleBack()) {
Timber.d("In stack : " + router.backstackSize)
} else {
super.onBackPressed()
}
}
}
......@@ -31,4 +31,6 @@ interface IConductorActivity{
interface IBottomNavigation{
val bottomNavigation : BottomNavigationView
fun hide()
fun show()
}
......@@ -6,7 +6,7 @@ import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.presentation.screen.home.HomeController
import com.biganto.visual.roompark.presentation.screen.home.home_routing.HomeBottomNavigationController
import com.bluelinelabs.conductor.RouterTransaction
import com.google.android.material.button.MaterialButton
import com.google.android.material.snackbar.Snackbar
......@@ -89,7 +89,7 @@ class AuthScreenController :
}
private fun render(viewState: AuthScreenViewState.SignedIn){
router.setRoot(RouterTransaction.with(HomeController()))
router.setRoot(RouterTransaction.with(HomeBottomNavigationController()))
// snacky.showSnackBar("lul")
}
......
......@@ -59,7 +59,7 @@ class DealsScreenController :
override fun onViewBound(v: View) {
// setToolbar()
setToolbar()
bindRecycler()
}
......
......@@ -60,7 +60,7 @@ class FavoritesScreenController :
}
override fun onViewBound(v: View) {
// setToolbar()
setToolbar()
bindRecycler()
}
......
......@@ -101,7 +101,7 @@ class ArticlesScreenController :
override fun handleBack(): Boolean {
Timber.d("handle back in class ")
router.popController(this)
return super.handleBack()
return true
}
......
......@@ -97,6 +97,7 @@ class FeedsScreenController :
override lateinit var injectedPresenter: FeedsScreenPresenter
override fun onViewBound(v: View) {
toolBar.hideAll()
bindRecycler()
feedsBlockView.findViewById<MaterialTextView>(R.id.to_feed_articles).clicks()
.map{ feedsTabs.getTabAt(feedsTabs.selectedTabPosition)}
......@@ -121,6 +122,7 @@ class FeedsScreenController :
is FeedsScreenViewState.AlbumsPages -> render(viewState)
is FeedsScreenViewState.CamsList -> render(viewState)
is FeedsScreenViewState.GetFeedArticlesPreview -> render(viewState)
is FeedsScreenViewState.RestoreView -> render(viewState)
}
}
......@@ -163,6 +165,30 @@ class FeedsScreenController :
(camsRecyclerView.adapter as CamsListAdapter).setItems(viewState.items)
}
private fun render(viewState: FeedsScreenViewState.RestoreView){
(camsRecyclerView.adapter as CamsListAdapter).setItems(viewState.restore.cams)
(feedsRecyclerView.adapter as ArticlesPreviewAdapter).setItems(viewState.restore.articles)
(devProgressRecyclerView.adapter as AlbumsPreviewAdapter).setItems(viewState.restore.albums)
feedsTabs.removeAllTabs()
viewState.restore.feeds.forEach {feed ->
val tab = feedsTabs.newTab()
.setCustomView(R.layout.feeds_tab_view)
.setTag(feed.feedId)
tab.customView
?.let {
it.findViewById<TextView>(R.id.tab_title)?.text = feed.title
it.findViewById<TextView>(R.id.tab_divider)?.visibility =
if (viewState.restore.feeds.indexOf(feed) == viewState.restore.feeds.size - 1) View.GONE
else View.VISIBLE
}
feedsTabs.addTab(tab)
}
storedFeedsList = viewState.restore.feeds
}
private fun getComponent() = DaggerFeedsScreenComponent.factory()
.create(RoomParkApplication.component,activity as RoomParkMainActivity)
.inject(this)
......
......@@ -17,21 +17,45 @@ class FeedsScreenPresenter @Inject constructor(
)
: BigantoBasePresenter<FeedsScreen, FeedsScreenViewState>() {
private val restoreModel = RestoreModel(
arrayListOf(),
arrayListOf(),
arrayListOf(),
arrayListOf())
override fun attachView(view: FeedsScreen) {
Timber.d("AttachView ")
restoreStateObservable.accept(FeedsScreenViewState.RestoreView(restoreModel))
super.attachView(view)
}
override fun bindIntents() {
val fetchCams = interactor.fetchCams()
.map {FeedsScreenViewState.CamsList(it.items) }
.map {
restoreModel.cams = it.items
FeedsScreenViewState.CamsList(it.items)
}
val fetchAlbums = interactor.fetchAlbums()
.map {FeedsScreenViewState.AlbumsPages(it) }
.map {
restoreModel.albums = it
FeedsScreenViewState.AlbumsPages(it)
}
val fetchFeeds = interactor.fetchTopFeeds()
.map {FeedsScreenViewState.FeedsPages(it.feeds.toList()) }
.map {
restoreModel.feeds = it.feeds
FeedsScreenViewState.FeedsPages(it.feeds.toList())
}
val getFeedArticlesPreview = intent(FeedsScreen::feedsTabSelected)
.flatMapSingle { interactor.fetchArticles(it) }
.map { FeedsScreenViewState.GetFeedArticlesPreview(it.articles.toList()) }
.map {
restoreModel.articles = it.articles
FeedsScreenViewState.GetFeedArticlesPreview(it.articles.toList())
}
val state = restoreStateObservable
.mergeWith(fetchFeeds)
......
......@@ -18,4 +18,13 @@ sealed class FeedsScreenViewState : BigantoBaseViewState() {
class CamsList(val items:List<WebCamModel>) : FeedsScreenViewState()
class GetFeedArticlesPreview(val items:List<ArticlePreviewModel>) : FeedsScreenViewState()
class RestoreView(val restore:RestoreModel) : FeedsScreenViewState()
}
data class RestoreModel(
var feeds:List<FeedModel>,
var albums:List<AlbumPreviewModel>,
var cams:List<WebCamModel>,
var articles:List<ArticlePreviewModel>
)
\ No newline at end of file
......@@ -8,6 +8,7 @@ import com.biganto.visual.roompark.di.dagger.AppComponent
import com.biganto.visual.roompark.di.dagger.AuthContractModule
import com.biganto.visual.roompark.di.dagger.PerScreen
import com.biganto.visual.roompark.domain.contract.AuthContract
import com.biganto.visual.roompark.presentation.screen.home.home_routing.HomeBottomNavigationController
import dagger.Binds
import dagger.BindsInstance
import dagger.Component
......@@ -34,6 +35,7 @@ interface HomeScreenComponent {
val presenter: HomeScreenPresenter
fun inject(controller: HomeController)
fun inject(controller: HomeBottomNavigationController)
}
@Module
......
package com.biganto.visual.roompark.presentation.screen.home.home_routing
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.annotation.IdRes
import androidx.annotation.NonNull
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.IBottomNavigation
import com.biganto.visual.roompark.base.ICollapsingToolBar
import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.presentation.screen.deals.DealsScreenController
import com.biganto.visual.roompark.presentation.screen.favorites.FavoritesScreenController
import com.biganto.visual.roompark.presentation.screen.feeds.FeedsScreenController
import com.biganto.visual.roompark.presentation.screen.home.DaggerHomeScreenComponent
import com.biganto.visual.roompark.presentation.screen.home.HomeScreenPresenter
import com.biganto.visual.roompark.presentation.screen.home.HomeScreenViewState
import com.biganto.visual.roompark.presentation.screen.settings.SettingsScreenController
import com.biganto.visual.roompark.presentation.screen.to_flat.FindFlatScreenController
import com.bluelinelabs.conductor.Controller
import com.google.android.material.bottomnavigation.BottomNavigationView
import timber.log.Timber
import javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 14.02.2019.
*/
const val OPEN_CHILD_CONTROLLER_KEY="OPEN_HOME_SCREEN_CHILD_CONTROLLER_ID"
fun toPageBundle(@IdRes menuItemId:Int): Bundle {
val b = Bundle()
b.putInt(OPEN_CHILD_CONTROLLER_KEY, menuItemId)
return b
}
class HomeBottomNavigationController(@IdRes toPage: Int = R.id.tab_feeds)
: BottomNavigationController(toPageBundle(toPage)) {
override fun injectDependencies() {
getComponent()
}
override fun getStartupMenuId(): Int =
args.getInt(OPEN_CHILD_CONTROLLER_KEY, R.id.tab_feeds)
@Inject
lateinit var tb: ICollapsingToolBar
@Inject
lateinit var bottomNavigation: IBottomNavigation
@Inject
override lateinit var injectedPresenter: HomeScreenPresenter
fun getComponent() = DaggerHomeScreenComponent
.factory()
.create(RoomParkApplication.component,activity as RoomParkMainActivity)
.inject(this)
override fun render(viewState: HomeScreenViewState) {
when(viewState){
is HomeScreenViewState.Idle -> render(viewState)
is HomeScreenViewState.ToScreen -> render(viewState)
}
}
private fun render(viewState: HomeScreenViewState.Idle){
}
private fun render(viewState: HomeScreenViewState.ToScreen){
// snacky.showSnackBar("lul")
}
override fun getLayoutId() = R.layout.tab_routing_screen_view
override val tag: String
get() = "BottomNavigationImpl"
override fun onViewBound(@NonNull view: View) {
bottomNavigation.show()
Timber.d(" onViewBound: ${this::class}")
bottomNavigationView = ((activity as RoomParkMainActivity) as IBottomNavigation).bottomNavigation
bottomNavigationView.visibility = BottomNavigationView.VISIBLE
controllerContainer = view.findViewById(R.id.tabContainer)
bottomNavigationView.setOnNavigationItemSelectedListener { item ->
navigateTo(getControllerFor(item.itemId), false)
true
}
router.backstack.clear()
val toScreen = args.getInt(OPEN_CHILD_CONTROLLER_KEY, R.id.tab_feeds)
}
override fun getControllerFor(menuItemId: Int): Controller = when (menuItemId) {
R.id.tab_feeds -> FeedsScreenController()
R.id.tab_favorites -> FavoritesScreenController()
R.id.tab_deals -> DealsScreenController()
R.id.tab_look_flat -> FindFlatScreenController()
R.id.tab_settings -> SettingsScreenController()
else -> FeedsScreenController()
}
override fun isSupportedController(controller: Controller): Boolean {
return true
}
override fun getIdForController(controller: Controller): Int {
return when (controller) {
is FeedsScreenController -> R.id.tab_feeds
is FavoritesScreenController -> R.id.tab_favorites
is DealsScreenController -> R.id.tab_deals
is FindFlatScreenController -> R.id.tab_look_flat
is SettingsScreenController -> R.id.tab_settings
else -> 0
}
}
override fun handleBack(): Boolean {
/*
* The childRouter should handleBack,
* as this BottomNavigationController doesn't have a back step sensible to the user.
*/
Timber.d("in back stack ")
val childRouter = getChildRouter(currentlySelectedItemId)
Timber.d("in back stack - ${childRouter?.backstackSize}")
if (childRouter != null) {
val backStackSizeCondition = childRouter.backstackSize < 0
val backStackResult = childRouter.handleBack()
if (backStackResult
&& backStackSizeCondition
)
navigateTo(getControllerFor(R.id.tab_feeds), false)
return backStackResult
} else {
Log.e(TAG, "handleBack called with getChildRouter(currentlySelectedItemId) == null.",
IllegalStateException(
"handleBack called with getChildRouter(currentlySelectedItemId) == null."))
}
return false
}
}
......@@ -71,7 +71,7 @@ class SettingsScreenController :
}
override fun onViewBound(v: View) {
// setToolbar()
setToolbar()
pushRecycler.isNestedScrollingEnabled = true
pushRecycler.layoutManager =
LinearLayoutManager(activity, RecyclerView.VERTICAL, false)
......
......@@ -72,14 +72,14 @@ class FindFlatScreenController :
@Inject
override lateinit var injectedPresenter: FindFlatScreenPresenter
val estateTabs = arrayListOf(
private val estateTabs = arrayListOf(
EstateTabModel("Д1",1),
EstateTabModel("Д2",2),
EstateTabModel("Д3",3)
)
override fun onViewBound(v: View) {
// setToolbar()
setToolbar()
estateTabs.forEach {estate ->
val tab = flatTabs.newTab()
.setCustomView(R.layout.to_flat_tab_view)
......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
xmlns:android="http://schemas.android.com/apk/res/android">
<!--<com.biganto.visual.androidplayer.presentation.screen.home_routing.NonSwipeableViewPager-->
<!--android:id="@+id/tabsContainerViewPager"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent" />-->
<com.bluelinelabs.conductor.ChangeHandlerFrameLayout
android:id="@+id/tabContainer"
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
\ No newline at end of file
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