Commit ea9f64ac authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

articles screen

parent 756f4c7b
package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.ArticlesPreviewModel
import io.reactivex.Single
import javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 09.10.2019.
*/
class ArticlesInteractor @Inject constructor(
) {
fun fetchArticles(feedId: Int): Single<ArticlesPreviewModel> = Single.just(
when (feedId) {
1 -> FeedsInteractor.testNewsArticles
2 -> FeedsInteractor.testBlogsArticles
3 -> FeedsInteractor.testDevArticles
else -> error("unknown feedId")
}
)
}
......@@ -28,7 +28,7 @@ class FeedsInteractor @Inject constructor(
fun fetchCams(): Single<WebCamListModel> = Single.just(camsList)
private companion object {
companion object {
private const val sampleUrl: String =
"https://room-park.ru/assets/news_articles/preview/00/00/00/109-8c9b72.jpeg"
......
package com.biganto.visual.roompark.presentation.screen.feed_list
import com.biganto.visual.roompark.conductor.BigantoBaseContract
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
interface ArticlesScreen : BigantoBaseContract<ArticlesScreenViewState> {
}
package com.biganto.visual.roompark.presentation.screen.feed_list
import android.view.View
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
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.feed_list.util.ArticlesAdapter
import com.biganto.visual.roompark.util.view_utils.grid.CeilsDecoration
import timber.log.Timber
import javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
private const val FEED_ID = "DIRECT_FEED_ID_KEY"
class ArticlesScreenController :
BigantoBaseController<ArticlesScreenViewState
, ArticlesScreen
, ArticlesScreenPresenter>
, ArticlesScreen {
constructor()
constructor(feedId:Int):super(bundleOf(FEED_ID to feedId))
override fun injectDependencies() {
getComponent()
}
@Inject
override lateinit var injectedPresenter: ArticlesScreenPresenter
@BindView(R.id.articles_recycler_view)
lateinit var articlesRecyclerView: RecyclerView
private fun setToolbar(){
toolBar.showAll()
toolBar.appBar.setExpanded(false,false)
toolBar.collapsingToolbarLayout.title = "ИЗБРАННОЕ"
toolBar.appBar.setLiftable(true)
toolBar.appBarScrollable(false)
articlesRecyclerView.isNestedScrollingEnabled = false
}
private fun bindRecycler() {
articlesRecyclerView.isNestedScrollingEnabled = true
articlesRecyclerView.layoutManager =
LinearLayoutManager(activity, RecyclerView.VERTICAL, false)
articlesRecyclerView.adapter = ArticlesAdapter()
articlesRecyclerView.itemAnimator = null
if (articlesRecyclerView.itemDecorationCount == 0)
articlesRecyclerView.addItemDecoration(
CeilsDecoration(1
, resources?.getDimensionPixelSize(R.dimen.ceil_grid_padding))
)
}
override fun onViewBound(v: View) {
// setToolbar()
bindRecycler()
}
override fun render(viewState: ArticlesScreenViewState) {
super.render(viewState)
Timber.d("Render state $viewState")
when(viewState){
is ArticlesScreenViewState.Idle -> render(viewState)
is ArticlesScreenViewState.ArticlesLoaded -> render(viewState)
}
}
private fun render(viewState: ArticlesScreenViewState.Idle){
}
private fun render(viewState: ArticlesScreenViewState.ArticlesLoaded) {
(articlesRecyclerView.adapter as ArticlesAdapter).setItems(viewState.items)
}
private fun getComponent() = DaggerArticlesScreenComponent.factory()
.create(2,RoomParkApplication.component,activity as RoomParkMainActivity)
.inject(this)
override fun getLayoutId(): Int = R.layout.feeds_screen
}
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.feed_list
import android.content.Context
import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.di.dagger.AppComponent
import com.biganto.visual.roompark.di.dagger.PerScreen
import dagger.Binds
import dagger.BindsInstance
import dagger.Component
import dagger.Module
import javax.inject.Named
@PerScreen
@Component(
modules = [ArticlesScreenModule::class],
dependencies = [AppComponent::class])
interface ArticlesScreenComponent {
@Component.Factory
interface Factory{
fun create(
@Named("FEED_ID_INT") feed:Int
, appComponent: AppComponent
,@BindsInstance activity: RoomParkMainActivity
): ArticlesScreenComponent
}
val presenter: ArticlesScreenPresenter
fun inject(controller: ArticlesScreenController)
}
@Module
abstract class ArticlesScreenModule{
@PerScreen
@Binds
abstract fun provideContext(activity: RoomParkMainActivity): Context
@PerScreen
@Binds
abstract fun provideFeedId(@Named("FEED_ID_INT") feedId:Int) : Int
}
package com.biganto.visual.roompark.presentation.screen.feed_list
import com.biganto.visual.roompark.conductor.BigantoBasePresenter
import com.biganto.visual.roompark.domain.interactor.ArticlesInteractor
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Named
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
class ArticlesScreenPresenter @Inject constructor(
@Named("FEED_ID_INT") private val feedId:Int,
private val interactor: ArticlesInteractor
)
: BigantoBasePresenter<ArticlesScreen, ArticlesScreenViewState>() {
override fun bindIntents() {
Timber.d("feedId : $feedId")
val prefetchCards = interactor.fetchArticles(1)
.map { ArticlesScreenViewState.ArticlesLoaded(it.articles) }
val state = restoreStateObservable
.mergeWith(prefetchCards)
.doOnError{ Timber.e(it)}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
subscribeViewState(state.cast(ArticlesScreenViewState::class.java), ArticlesScreen::render)
}
}
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.feed_list
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.ArticlePreviewModel
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
sealed class ArticlesScreenViewState : BigantoBaseViewState() {
class Idle : ArticlesScreenViewState()
class ArticlesLoaded(val items: List<ArticlePreviewModel>) : ArticlesScreenViewState()
}
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.feed_list.util
import android.view.View
import com.biganto.visual.roompark.domain.model.ArticlePreviewModel
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyclerAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
/**
* Created by Vladislav Bogdashkin on 16.10.2019.
*/
class ArticlesAdapter() : CommonRecyclerAdapter<ArticleViewHolder, ArticlePreviewModel>() {
override val vhKlazz = ArticleViewHolder::class
override fun getVhLayout(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
class ArticleViewHolder(itemView: View) : CommonViewHolder<ArticlePreviewModel>(itemView) {
override fun onViewBound(model: ArticlePreviewModel) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ class ArticlesPreviewAdapter : RecyclerView.Adapter<ArticlePreviewViewHolder>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ArticlePreviewViewHolder =
ArticlePreviewViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.feed_viewholder, parent, false)
.inflate(R.layout.feed_preview_viewholder, parent, false)
)
override fun getItemCount(): Int = list.size
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorNoticeBackground"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/articles_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:listitem="@layout/feed_direct_viewholder" />
</LinearLayout>
\ No newline at end of file
......@@ -11,6 +11,7 @@
android:id="@+id/imageHolder"
android:layout_width="128dp"
android:layout_height="128dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
......@@ -27,7 +28,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="144dp" />
app:layout_constraintGuide_begin="160dp" />
<FrameLayout
android:id="@+id/feed_read"
......@@ -79,5 +80,16 @@
app:layout_constraintTop_toBottomOf="@+id/feed_title_info_text_view"
app:layout_constraintVertical_bias="0.0" />
<include
layout="@layout/horizontal_divider"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageHolder" />
</androidx.constraintlayout.widget.ConstraintLayout>
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorFeedViewHolderBackground">
<com.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView
android:id="@+id/imageHolder"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@color/colorAccentSecondary"
app:image_corner_radius="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_favorites" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="76dp" />
<FrameLayout
android:id="@+id/feed_read"
android:layout_width="8dp"
android:layout_height="8dp"
android:layout_marginTop="10dp"
android:background="@drawable/new_feed_icon"
android:visibility="visible"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/feed_date_text_view"
style="@style/Feed.Notice"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:includeFontPadding="false"
android:text="22 / 02 / 2019"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/feed_title_info_text_view"
style="@style/Feed_Title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="4dp"
android:includeFontPadding="false"
android:text="В «РУМЯНЦЕВО-ПАРК» ПРИСТУПИЛИ К МОНТАЖУ ОКОННЫХ БЛОКОВ"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toBottomOf="@+id/feed_date_text_view"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
......@@ -29,7 +29,7 @@
app:layout_constraintStart_toStartOf="parent"
tools:itemCount="3"
app:layout_constraintTop_toBottomOf="@+id/feedsTabs"
tools:listitem="@layout/feed_direct_viewholder" />
tools:listitem="@layout/feed_preview_viewholder" />
<include
android:id="@+id/feeds_divider"
......
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