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

customized feeds tab layout

parent 95b43e29
......@@ -13,27 +13,28 @@ import javax.inject.Inject
*/
class FeedsInteractor @Inject constructor(
){
) {
fun fetchTopFeeds():Single<FeedsHeaderModel>
= Single.just(testFeeds)
fun fetchTopFeeds(): Single<FeedsHeaderModel> = Single.just(testFeeds)
fun fetchArticles(feedId:Int):Single<ArticlesPreviewModel>
= Single.just(when(feedId) {
1-> testNewsArticles
2-> testBlogsArticles
3-> testDevArticles
fun fetchArticles(feedId: Int): Single<ArticlesPreviewModel> = Single.just(
when (feedId) {
1 -> testNewsArticles
2 -> testBlogsArticles
3 -> testDevArticles
else -> error("unknown feedId")
})
}
)
private companion object{
private companion object {
private const val sampleUrl:String = "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 sampleUrlDev = "https://room-park.ru/assets/news_articles/preview/00/00/00/96-a972cd.jpeg"
private const val sampleUrl: String =
"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 sampleUrlDev =
"https://room-park.ru/assets/news_articles/preview/00/00/00/96-a972cd.jpeg"
val testFeeds = FeedsHeaderModel(
listOf(
......@@ -43,75 +44,95 @@ class FeedsInteractor @Inject constructor(
)
)
val testNewsArticles = ArticlesPreviewModel(1,
val testNewsArticles = ArticlesPreviewModel(
1,
listOf(
ArticlePreviewModel(1
ArticlePreviewModel(
1
, Date()
,"Первая новость"
,"Самый очаровательной анонс в мире"
,sampleUrl
, false),
ArticlePreviewModel(1
, "Первая новость"
, "Самый очаровательной анонс в мире"
, sampleUrl
, false
),
ArticlePreviewModel(
1
, Date()
,"Первая новость"
,"Самый очаровательной анонс в мире"
,sampleUrl
, false),
ArticlePreviewModel(1
, "Первая новость"
, "Самый очаровательной анонс в мире"
, sampleUrl
, false
),
ArticlePreviewModel(
1
, Date()
,"Первая новость"
,"Самый очаровательной анонс в мире"
,sampleUrl
, false)
, "Первая новость"
, "Самый очаровательной анонс в мире"
, sampleUrl
, false
)
)
)
val testBlogsArticles = ArticlesPreviewModel(2,
val testBlogsArticles = ArticlesPreviewModel(
2,
listOf(
ArticlePreviewModel(1
ArticlePreviewModel(
1
, Date()
,"Первая новость"
,"Самый очаровательной анонс в мире"
,sampleUrlB
, false),
ArticlePreviewModel(1
, "Первая новость"
, "Самый очаровательной анонс в мире"
, sampleUrlB
, false
),
ArticlePreviewModel(
1
, Date()
,"НОВЫЙ ОФИС ПРОДАЖ ЖК «РУМЯНЦЕВО-ПАРК»"
,"Самый очаровательной анонс в мире"
,sampleUrlB
, false),
ArticlePreviewModel(1
, "НОВЫЙ ОФИС ПРОДАЖ ЖК «РУМЯНЦЕВО-ПАРК»"
, "Самый очаровательной анонс в мире"
, sampleUrlB
, false
),
ArticlePreviewModel(
1
, Date()
,"В «РУМЯНЦЕВО-ПАРК» ПРИСТУПИЛИ К МОНТАЖУ ОКОННЫХ БЛОКОВ"
,"Самый очаровательной анонс в мире"
,sampleUrlB
, false)
, "В «РУМЯНЦЕВО-ПАРК» ПРИСТУПИЛИ К МОНТАЖУ ОКОННЫХ БЛОКОВ"
, "Самый очаровательной анонс в мире"
, sampleUrlB
, false
)
)
)
val testDevArticles = ArticlesPreviewModel(3,
val testDevArticles = ArticlesPreviewModel(
3,
listOf(
ArticlePreviewModel(1
ArticlePreviewModel(
1
, Date()
,"Ход1"
,"Самый очаровательной анонс в мире"
, "Ход1"
, "Самый очаровательной анонс в мире"
, sampleUrlDev
, false),
ArticlePreviewModel(1
, false
),
ArticlePreviewModel(
1
, Date()
,"Ход2"
,"Самый очаровательной анонс в мире"
,sampleUrlDev
, false),
ArticlePreviewModel(1
, "Ход2"
, "Самый очаровательной анонс в мире"
, sampleUrlDev
, false
),
ArticlePreviewModel(
1
, Date()
,"Ход3"
,"Самый очаровательной анонс в мире"
,sampleUrlDev
, false)
, "Ход3"
, "Самый очаровательной анонс в мире"
, sampleUrlDev
, false
)
)
)
}
}
}
......
......@@ -75,7 +75,6 @@ class AuthScreenController :
is AuthScreenViewState.SignedIn -> render(viewState)
is AuthScreenViewState.SignInError -> render(viewState)
}
}
......
package com.biganto.visual.roompark.presentation.screen.feeds
import android.view.View
import android.widget.TextView
import butterknife.BindView
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.feeds.utils.FeedsPagerAdapter
import com.google.android.material.tabs.TabLayout
import timber.log.Timber
import javax.inject.Inject
......@@ -22,6 +26,11 @@ class FeedsScreenController :
getComponent()
}
@BindView(R.id.feedsTabs)
lateinit var feedsTabs:TabLayout
val feedsAdapter = FeedsPagerAdapter()
@Inject
override lateinit var injectedPresenter: FeedsScreenPresenter
......@@ -35,6 +44,7 @@ class FeedsScreenController :
Timber.d("Render state $viewState")
when(viewState){
is FeedsScreenViewState.Idle -> render(viewState)
is FeedsScreenViewState.FeedsPages -> render(viewState)
}
}
......@@ -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()
.create(RoomParkApplication.component,activity as RoomParkMainActivity)
.inject(this)
......
......@@ -20,7 +20,11 @@ class FeedsScreenPresenter @Inject constructor(
override fun bindIntents() {
val fetchFeeds = interactor.fetchTopFeeds()
.map {FeedsScreenViewState.FeedsPages(it.feeds.toList()) }
val state = restoreStateObservable
.mergeWith(fetchFeeds)
.doOnError{ Timber.e(it)}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
......
package com.biganto.visual.roompark.presentation.screen.feeds
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.FeedModel
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -9,4 +10,5 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState
sealed class FeedsScreenViewState : BigantoBaseViewState() {
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 @@
android:orientation="vertical"
android:paddingStart="16dp">
<androidx.viewpager.widget.ViewPager
android:id="@+id/viewPager"
<com.google.android.material.tabs.TabLayout
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_height="0dp"
tools:listitem="@layout/feed_direct_viewholder"
app:layout_constraintBottom_toTopOf="@+id/feeds_divider"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></androidx.viewpager.widget.ViewPager>
app:layout_constraintTop_toBottomOf="@+id/feedsTabs" />
<include
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 @@
<string name="can_not_download_all_tours_error">Can\'t download tours!</string>
<string name="auth_data_requirments_failed">Login at least %d symbols
\nPassword at least %d symbols</string>
<string name="feeds_tab_divider">/</string>
<!--endregion-->
</resources>
......@@ -222,6 +222,10 @@
<item name="android:textColor">@color/colorInvertedText</item>
</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">
<item name="android:textSize">@dimen/super_size</item>
</style>
......
......@@ -8,4 +8,6 @@
<dimen name="bottom_gradient_height">3dp</dimen>
<dimen name="ceil_grid_padding">8dp</dimen>
<dimen name="feeds_tab_max_width">999dp</dimen>
</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