Commit 4ad06ff2 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

customized feeds tab layout

parent 95b43e29
...@@ -13,105 +13,126 @@ import javax.inject.Inject ...@@ -13,105 +13,126 @@ import javax.inject.Inject
*/ */
class FeedsInteractor @Inject constructor( class FeedsInteractor @Inject constructor(
){ ) {
fun fetchTopFeeds():Single<FeedsHeaderModel> fun fetchTopFeeds(): Single<FeedsHeaderModel> = Single.just(testFeeds)
= Single.just(testFeeds)
fun fetchArticles(feedId:Int):Single<ArticlesPreviewModel> fun fetchArticles(feedId: Int): Single<ArticlesPreviewModel> = Single.just(
= Single.just(when(feedId) { when (feedId) {
1-> testNewsArticles 1 -> testNewsArticles
2-> testBlogsArticles 2 -> testBlogsArticles
3-> testDevArticles 3 -> testDevArticles
else -> error("unknown feedId") else -> error("unknown feedId")
}) }
)
private companion object {
private companion object{
private const val sampleUrl: String =
private const val sampleUrl:String = "https://room-park.ru/assets/news_articles/preview/00/00/00/109-8c9b72.jpeg" "https://room-park.ru/assets/news_articles/preview/00/00/00/109-8c9b72.jpeg"
private const val sampleUrlB = "https://room-park.ru/assets/news_articles/preview/00/00/00/104-2b4eff.jpeg" private const val sampleUrlB =
private const val sampleUrlDev = "https://room-park.ru/assets/news_articles/preview/00/00/00/96-a972cd.jpeg" "https://room-park.ru/assets/news_articles/preview/00/00/00/104-2b4eff.jpeg"
private const val sampleUrlDev =
val testFeeds = FeedsHeaderModel( "https://room-park.ru/assets/news_articles/preview/00/00/00/96-a972cd.jpeg"
listOf(
FeedModel(1, "НОВОСТИ"), val testFeeds = FeedsHeaderModel(
FeedModel(2, "БЛОГИ"), listOf(
FeedModel(2, "БЛОГ СТРОИТЕЛЬСТВА") FeedModel(1, "НОВОСТИ"),
) FeedModel(2, "БЛОГИ"),
FeedModel(2, "БЛОГ СТРОИТЕЛЬСТВА")
)
)
val testNewsArticles = ArticlesPreviewModel(
1,
listOf(
ArticlePreviewModel(
1
, Date()
, "Первая новость"
, "Самый очаровательной анонс в мире"
, sampleUrl
, false
),
ArticlePreviewModel(
1
, Date()
, "Первая новость"
, "Самый очаровательной анонс в мире"
, sampleUrl
, false
),
ArticlePreviewModel(
1
, Date()
, "Первая новость"
, "Самый очаровательной анонс в мире"
, sampleUrl
, false
) )
)
val testNewsArticles = ArticlesPreviewModel(1, )
listOf(
ArticlePreviewModel(1 val testBlogsArticles = ArticlesPreviewModel(
, Date() 2,
,"Первая новость" listOf(
,"Самый очаровательной анонс в мире" ArticlePreviewModel(
,sampleUrl 1
, false), , Date()
ArticlePreviewModel(1 , "Первая новость"
, Date() , "Самый очаровательной анонс в мире"
,"Первая новость" , sampleUrlB
,"Самый очаровательной анонс в мире" , false
,sampleUrl ),
, false), ArticlePreviewModel(
ArticlePreviewModel(1 1
, Date() , Date()
,"Первая новость" , "НОВЫЙ ОФИС ПРОДАЖ ЖК «РУМЯНЦЕВО-ПАРК»"
,"Самый очаровательной анонс в мире" , "Самый очаровательной анонс в мире"
,sampleUrl , sampleUrlB
, false) , false
) ),
ArticlePreviewModel(
1
, Date()
, "В «РУМЯНЦЕВО-ПАРК» ПРИСТУПИЛИ К МОНТАЖУ ОКОННЫХ БЛОКОВ"
, "Самый очаровательной анонс в мире"
, sampleUrlB
, false
) )
)
val testBlogsArticles = ArticlesPreviewModel(2, )
listOf(
ArticlePreviewModel(1 val testDevArticles = ArticlesPreviewModel(
, Date() 3,
,"Первая новость" listOf(
,"Самый очаровательной анонс в мире" ArticlePreviewModel(
,sampleUrlB 1
, false), , Date()
ArticlePreviewModel(1 , "Ход1"
, Date() , "Самый очаровательной анонс в мире"
,"НОВЫЙ ОФИС ПРОДАЖ ЖК «РУМЯНЦЕВО-ПАРК»" , sampleUrlDev
,"Самый очаровательной анонс в мире" , false
,sampleUrlB ),
, false), ArticlePreviewModel(
ArticlePreviewModel(1 1
, Date() , Date()
,"В «РУМЯНЦЕВО-ПАРК» ПРИСТУПИЛИ К МОНТАЖУ ОКОННЫХ БЛОКОВ" , "Ход2"
,"Самый очаровательной анонс в мире" , "Самый очаровательной анонс в мире"
,sampleUrlB , sampleUrlDev
, false) , false
) ),
) ArticlePreviewModel(
1
val testDevArticles = ArticlesPreviewModel(3, , Date()
listOf( , "Ход3"
ArticlePreviewModel(1 , "Самый очаровательной анонс в мире"
, Date() , sampleUrlDev
,"Ход1" , false
,"Самый очаровательной анонс в мире"
, sampleUrlDev
, false),
ArticlePreviewModel(1
, Date()
,"Ход2"
,"Самый очаровательной анонс в мире"
,sampleUrlDev
, false),
ArticlePreviewModel(1
, Date()
,"Ход3"
,"Самый очаровательной анонс в мире"
,sampleUrlDev
, false)
)
) )
} )
)
} }
} }
......
...@@ -75,7 +75,6 @@ class AuthScreenController : ...@@ -75,7 +75,6 @@ class AuthScreenController :
is AuthScreenViewState.SignedIn -> render(viewState) is AuthScreenViewState.SignedIn -> render(viewState)
is AuthScreenViewState.SignInError -> render(viewState) is AuthScreenViewState.SignInError -> render(viewState)
} }
} }
......
package com.biganto.visual.roompark.presentation.screen.feeds package com.biganto.visual.roompark.presentation.screen.feeds
import android.view.View import android.view.View
import android.widget.TextView
import butterknife.BindView
import com.biganto.visual.roompark.R import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.presentation.screen.feeds.utils.FeedsPagerAdapter
import com.google.android.material.tabs.TabLayout
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
...@@ -22,6 +26,11 @@ class FeedsScreenController : ...@@ -22,6 +26,11 @@ class FeedsScreenController :
getComponent() getComponent()
} }
@BindView(R.id.feedsTabs)
lateinit var feedsTabs:TabLayout
val feedsAdapter = FeedsPagerAdapter()
@Inject @Inject
override lateinit var injectedPresenter: FeedsScreenPresenter override lateinit var injectedPresenter: FeedsScreenPresenter
...@@ -35,6 +44,7 @@ class FeedsScreenController : ...@@ -35,6 +44,7 @@ class FeedsScreenController :
Timber.d("Render state $viewState") Timber.d("Render state $viewState")
when(viewState){ when(viewState){
is FeedsScreenViewState.Idle -> render(viewState) is FeedsScreenViewState.Idle -> render(viewState)
is FeedsScreenViewState.FeedsPages -> render(viewState)
} }
} }
...@@ -42,6 +52,25 @@ class FeedsScreenController : ...@@ -42,6 +52,25 @@ class FeedsScreenController :
} }
private fun render(viewState: FeedsScreenViewState.FeedsPages){
feedsTabs.removeAllTabs()
viewState.items.forEach {feed ->
val tab = feedsTabs.newTab()
.setCustomView(R.layout.feeds_tab_view)
tab.customView
?.let {
it.findViewById<TextView>(R.id.tab_title)?.text = feed.title
it.findViewById<TextView>(R.id.tab_divider)?.visibility =
if (viewState.items.indexOf(feed) == viewState.items.size - 1) View.GONE
else View.VISIBLE
}
feedsTabs.addTab(tab)
}
}
private fun getComponent() = DaggerFeedsScreenComponent.factory() private fun getComponent() = DaggerFeedsScreenComponent.factory()
.create(RoomParkApplication.component,activity as RoomParkMainActivity) .create(RoomParkApplication.component,activity as RoomParkMainActivity)
.inject(this) .inject(this)
......
...@@ -20,7 +20,11 @@ class FeedsScreenPresenter @Inject constructor( ...@@ -20,7 +20,11 @@ class FeedsScreenPresenter @Inject constructor(
override fun bindIntents() { override fun bindIntents() {
val fetchFeeds = interactor.fetchTopFeeds()
.map {FeedsScreenViewState.FeedsPages(it.feeds.toList()) }
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(fetchFeeds)
.doOnError{ Timber.e(it)} .doOnError{ Timber.e(it)}
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
......
package com.biganto.visual.roompark.presentation.screen.feeds package com.biganto.visual.roompark.presentation.screen.feeds
import com.biganto.visual.roompark.conductor.BigantoBaseViewState import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.FeedModel
/** /**
* Created by Vladislav Bogdashkin on 30.09.2019. * Created by Vladislav Bogdashkin on 30.09.2019.
...@@ -9,4 +10,5 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState ...@@ -9,4 +10,5 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState
sealed class FeedsScreenViewState : BigantoBaseViewState() { sealed class FeedsScreenViewState : BigantoBaseViewState() {
class Idle : FeedsScreenViewState() class Idle : FeedsScreenViewState()
class FeedsPages(val items:List<FeedModel>) : FeedsScreenViewState()
} }
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.feeds.utils
import android.view.View
import androidx.viewpager.widget.PagerAdapter
import com.biganto.visual.roompark.domain.model.FeedModel
import timber.log.Timber
/**
* Created by Vladislav Bogdashkin on 14.10.2019.
*/
class FeedsPagerAdapter: PagerAdapter() {
public fun updateData(items:List<FeedModel>){
if (list.size>0) Timber.w("View pager list is not empty!")
list.clear()
list.addAll(items)
notifyDataSetChanged()
}
private val list:MutableList<FeedModel> = mutableListOf()
override fun isViewFromObject(view: View, `object`: Any): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getCount(): Int = list.size
override fun getPageTitle(position: Int): CharSequence? = list[position].title
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@color/colorInvertedText" />
<item android:state_focused="true" android:color="@color/colorOpacityBackgroundInv" />
<item android:state_pressed="true" android:color="@color/colorOpacityBackgroundInv" />
<item android:color="@color/colorOpacityBackgroundInv" />
</selector>
\ No newline at end of file
...@@ -9,14 +9,26 @@ ...@@ -9,14 +9,26 @@
android:orientation="vertical" android:orientation="vertical"
android:paddingStart="16dp"> android:paddingStart="16dp">
<androidx.viewpager.widget.ViewPager <com.google.android.material.tabs.TabLayout
android:id="@+id/viewPager" android:id="@+id/feedsTabs"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#00000000"
app:tabMaxWidth="@dimen/feeds_tab_max_width"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tabMode="scrollable" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/feedsRecyclerView"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
tools:listitem="@layout/feed_direct_viewholder"
app:layout_constraintBottom_toTopOf="@+id/feeds_divider" app:layout_constraintBottom_toTopOf="@+id/feeds_divider"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></androidx.viewpager.widget.ViewPager> app:layout_constraintTop_toBottomOf="@+id/feedsTabs" />
<include <include
android:id="@+id/feeds_divider" android:id="@+id/feeds_divider"
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tab_title"
style="@style/Header_TextView.TabItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tab_divider"
style="@style/Header_TextView.TabItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="@id/tab_title"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="@string/feeds_tab_divider"
android:textColor="@color/colorInvertedNoticeText"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/tab_title"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
<string name="can_not_download_all_tours_error">Can\'t download tours!</string> <string name="can_not_download_all_tours_error">Can\'t download tours!</string>
<string name="auth_data_requirments_failed">Login at least %d symbols <string name="auth_data_requirments_failed">Login at least %d symbols
\nPassword at least %d symbols</string> \nPassword at least %d symbols</string>
<string name="feeds_tab_divider">/</string>
<!--endregion--> <!--endregion-->
</resources> </resources>
...@@ -222,6 +222,10 @@ ...@@ -222,6 +222,10 @@
<item name="android:textColor">@color/colorInvertedText</item> <item name="android:textColor">@color/colorInvertedText</item>
</style> </style>
<style name="Header_TextView.TabItem">
<item name="android:textColor">@color/tab_item_selector</item>
</style>
<style name="Flat_Input_TextView" parent="Base.Widget.AppCompat.TextView.AcromMediumTextView"> <style name="Flat_Input_TextView" parent="Base.Widget.AppCompat.TextView.AcromMediumTextView">
<item name="android:textSize">@dimen/super_size</item> <item name="android:textSize">@dimen/super_size</item>
</style> </style>
......
...@@ -8,4 +8,6 @@ ...@@ -8,4 +8,6 @@
<dimen name="bottom_gradient_height">3dp</dimen> <dimen name="bottom_gradient_height">3dp</dimen>
<dimen name="ceil_grid_padding">8dp</dimen> <dimen name="ceil_grid_padding">8dp</dimen>
<dimen name="feeds_tab_max_width">999dp</dimen>
</resources> </resources>
\ 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