Commit 68e88c00 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

added abstract CommonAdapter<CommonViewHolder>

added adapter for pushes
parent c4e3681f
...@@ -119,6 +119,7 @@ dependencies { ...@@ -119,6 +119,7 @@ dependencies {
implementation "com.jakewharton.rxbinding3:rxbinding-recyclerview:$rxBindingVersion" implementation "com.jakewharton.rxbinding3:rxbinding-recyclerview:$rxBindingVersion"
implementation "com.jakewharton.rxbinding3:rxbinding-material:$rxBindingVersion" implementation "com.jakewharton.rxbinding3:rxbinding-material:$rxBindingVersion"
//Tests //Tests
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'
......
package com.biganto.visual.roompark.domain.interactor package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.CachedDataModel
import com.biganto.visual.roompark.domain.model.PushSwitchModel
import com.biganto.visual.roompark.domain.model.SettingsModel
import io.reactivex.Observable
import javax.inject.Inject import javax.inject.Inject
/** /**
...@@ -8,4 +12,37 @@ import javax.inject.Inject ...@@ -8,4 +12,37 @@ import javax.inject.Inject
class SettingsInteractor @Inject constructor( class SettingsInteractor @Inject constructor(
){ ){
fun fetchSettings(): Observable<SettingsModel> = Observable.just(sampleSettings)
companion object{
val sampleSettings = SettingsModel(
arrayListOf(
PushSwitchModel("Новости",1,"zsldfj",true),
PushSwitchModel("Блог",2,"zsldfj",false),
PushSwitchModel("Ход Строительства Дом №1",3,"zsldfj",true),
PushSwitchModel("Сделка кв №451",4,"zsldfj",true),
PushSwitchModel("Сделка кв №452",5,"zsldfj",true)
),
arrayListOf(
CachedDataModel("Скачать карточки моих\n" +
"квартир из избранного\n" +
"и сделок",8415456588L,900),
CachedDataModel("Скачать виртуальные туры \n" +
"моих квартир из избранного\n" +
"и сделок ",656853321588L,999)
),
arrayListOf(
CachedDataModel("Всего скачано",2834264238L,1),
CachedDataModel("Карточки квартир",6434268L,2),
CachedDataModel("Виртуальные туры",1782234268L,3),
CachedDataModel("Новости и заметки",4323438L,4),
CachedDataModel("Фотографии",164444L,5)
)
)
}
} }
...@@ -7,8 +7,8 @@ package com.biganto.visual.roompark.domain.model ...@@ -7,8 +7,8 @@ package com.biganto.visual.roompark.domain.model
data class PushSwitchModel( data class PushSwitchModel(
val title:String, val title:String,
val pushId:String,
val innerId:Int, val innerId:Int,
val pushId:String,
val switchState: Boolean val switchState: Boolean
) )
......
...@@ -87,7 +87,13 @@ class DealViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { ...@@ -87,7 +87,13 @@ class DealViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
dealPayed.text = deal.dealPayout.toRubly() dealPayed.text = deal.dealPayout.toRubly()
dealSumToPay.text = deal.dealToPay.toRubly() dealSumToPay.text = deal.dealToPay.toRubly()
createStatusView(statusLayout,statusContainer,deal.statusList,deal.statusNo,false) createStatusView(
statusLayout,
statusContainer,
deal.statusList,
deal.statusNo,
false
)
} }
private fun renderCommonInfo(info:DealPreviewModel){ private fun renderCommonInfo(info:DealPreviewModel){
......
package com.biganto.visual.roompark.presentation.screen.settings package com.biganto.visual.roompark.presentation.screen.settings
import android.view.View import android.view.View
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
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.settings.util.PushListAdapter
import com.google.android.material.textview.MaterialTextView
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
...@@ -25,9 +31,33 @@ class SettingsScreenController : ...@@ -25,9 +31,33 @@ class SettingsScreenController :
@Inject @Inject
override lateinit var injectedPresenter: SettingsScreenPresenter override lateinit var injectedPresenter: SettingsScreenPresenter
@BindView(R.id.pushRecyclerView)
lateinit var pushRecycler:RecyclerView
@BindView(R.id.cachedRecyclerView)
lateinit var cachedRecycler:RecyclerView
@BindView(R.id.downloadToursText)
lateinit var toursDownloaderTitle:MaterialTextView
@BindView(R.id.downloadFlatCardsText)
lateinit var flatDownloaderTitle:MaterialTextView
@BindView(R.id.downloadToursIcon)
lateinit var toursDownloaderButton:ImageView
@BindView(R.id.downloadFlatCardsIcon)
lateinit var flatDownloaderButton:ImageView
override fun onViewBound(v: View) { override fun onViewBound(v: View) {
pushRecycler.isNestedScrollingEnabled = true
pushRecycler.layoutManager =
LinearLayoutManager(activity, RecyclerView.VERTICAL, false)
pushRecycler.adapter = PushListAdapter()
pushRecycler.itemAnimator = null
} }
override fun render(viewState: SettingsScreenViewState) { override fun render(viewState: SettingsScreenViewState) {
...@@ -35,6 +65,7 @@ class SettingsScreenController : ...@@ -35,6 +65,7 @@ class SettingsScreenController :
Timber.d("Render state $viewState") Timber.d("Render state $viewState")
when(viewState){ when(viewState){
is SettingsScreenViewState.Idle -> render(viewState) is SettingsScreenViewState.Idle -> render(viewState)
is SettingsScreenViewState.LoadSettingsList -> render(viewState)
} }
} }
...@@ -42,11 +73,15 @@ class SettingsScreenController : ...@@ -42,11 +73,15 @@ class SettingsScreenController :
} }
private fun render(viewState: SettingsScreenViewState.LoadSettingsList){
(pushRecycler.adapter as PushListAdapter).setItems(viewState.settings.pushItems)
}
private fun getComponent() = DaggerSettingsScreenComponent.factory() private fun getComponent() = DaggerSettingsScreenComponent.factory()
.create(RoomParkApplication.component,activity as RoomParkMainActivity) .create(RoomParkApplication.component,activity as RoomParkMainActivity)
.inject(this) .inject(this)
override fun getLayoutId(): Int = R.layout.favorites_screen override fun getLayoutId(): Int = R.layout.settings_screen
} }
\ No newline at end of file
...@@ -20,7 +20,11 @@ class SettingsScreenPresenter @Inject constructor( ...@@ -20,7 +20,11 @@ class SettingsScreenPresenter @Inject constructor(
override fun bindIntents() { override fun bindIntents() {
val fetchSettings = interactor.fetchSettings()
.map { SettingsScreenViewState.LoadSettingsList(it) }
val state = restoreStateObservable val state = restoreStateObservable
.mergeWith(fetchSettings)
.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.settings package com.biganto.visual.roompark.presentation.screen.settings
import com.biganto.visual.roompark.conductor.BigantoBaseViewState import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.SettingsModel
/** /**
* 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 SettingsScreenViewState : BigantoBaseViewState() { sealed class SettingsScreenViewState : BigantoBaseViewState() {
class Idle : SettingsScreenViewState() class Idle : SettingsScreenViewState()
class LoadSettingsList(val settings:SettingsModel) : SettingsScreenViewState()
} }
\ No newline at end of file
package com.biganto.visual.roompark.presentation.screen.settings.util
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView
import butterknife.ButterKnife
import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.domain.model.PushSwitchModel
import com.google.android.material.switchmaterial.SwitchMaterial
import com.google.android.material.textview.MaterialTextView
import timber.log.Timber
import kotlin.reflect.KClass
import kotlin.reflect.full.valueParameters
import kotlin.reflect.jvm.javaType
/**
* Created by Vladislav Bogdashkin on 16.10.2019.
*/
abstract class CommonRecyclerAdapter<VH:CommonViewHolder<M>,M> : RecyclerView.Adapter<VH>() {
private var list: MutableList<M> = mutableListOf()
fun setItems(list:List<M>){
this.list.clear()
this.list.addAll(list)
notifyDataSetChanged()
}
protected abstract val vhKlazz : KClass<VH>
@LayoutRes
protected abstract fun getVhLayout() : Int
private fun inflateViewHolder(parent:ViewGroup): View =
LayoutInflater.from(parent.context)
.inflate(getVhLayout(), parent, false)
private fun getViewHolderInstance(klazz:KClass<VH>, view:View):VH =
klazz.constructors.first{ it.valueParameters[0].type.javaType == View::class.java}.call(view)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH =
getViewHolderInstance(vhKlazz,inflateViewHolder(parent))
override fun getItemCount(): Int = list.size
override fun onBindViewHolder(holder: VH, position: Int) {
holder.bindModel(list[position])
}
}
abstract class CommonViewHolder<M>(itemView: View): RecyclerView.ViewHolder(itemView) {
abstract fun onViewBound(model: M)
fun bindModel(model: M){
ButterKnife.bind(this, itemView)
onViewBound(model)
}
}
class PushListAdapter : CommonRecyclerAdapter<PushViewHolder,PushSwitchModel>() {
override val vhKlazz: KClass<PushViewHolder>
get() = PushViewHolder::class
override fun getVhLayout(): Int = R.layout.bell_switcher_with_text_viewholder
}
class PushViewHolder(itemView: View) : CommonViewHolder<PushSwitchModel>(itemView) {
@BindView(R.id.bellSwitcherTitle)
lateinit var bellTitle:MaterialTextView
@BindView(R.id.bellSwitch)
lateinit var switcher:ViewGroup
override fun onViewBound(model: PushSwitchModel) {
Timber.d("model is : $model")
bellTitle.text = model.title
switcher.findViewById<SwitchMaterial>(R.id.switch1).isChecked = model.switchState
}
}
...@@ -33,8 +33,6 @@ class FindFlatScreenController : ...@@ -33,8 +33,6 @@ class FindFlatScreenController :
override fun getFlat(): Observable<TourRequestModel> = override fun getFlat(): Observable<TourRequestModel> =
flatNumberEditor.keys { it.keyCode == KeyEvent.KEYCODE_ENTER } flatNumberEditor.keys { it.keyCode == KeyEvent.KEYCODE_ENTER }
.doOnNext { flatNumberEditor.hideKeyboard() } .doOnNext { flatNumberEditor.hideKeyboard() }
.doOnNext{Timber.d(" key code is : ${it.keyCode}")}
.doOnNext{Timber.d(" KeyEvent.FLAG_EDITOR_ACTION : ${KeyEvent.FLAG_EDITOR_ACTION}")}
.map { .map {
TourRequestModel( TourRequestModel(
estateTabs[flatTabs.selectedTabPosition].building estateTabs[flatTabs.selectedTabPosition].building
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
android:weightSum="1"> android:weightSum="1">
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/bellSwitcherTitle"
style="@style/Common_Text.Default" style="@style/Common_Text.Default"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="match_parent"
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
android:text="блабла" /> android:text="блабла" />
<include <include
android:id="@+id/bellSwitch"
layout="@layout/bell_switch_view" layout="@layout/bell_switch_view"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
android:text="PUSH УВЕДОМЛЕНИЯ" /> android:text="PUSH УВЕДОМЛЕНИЯ" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/pushRecyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
...@@ -41,6 +42,7 @@ ...@@ -41,6 +42,7 @@
android:weightSum="1"> android:weightSum="1">
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/downloadFlatCardsText"
style="@style/Common_Text.Default" style="@style/Common_Text.Default"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -52,10 +54,11 @@ ...@@ -52,10 +54,11 @@
и сделок (4 MB)" /> и сделок (4 MB)" />
<ImageView <ImageView
android:src="@drawable/ic_flat" android:id="@+id/downloadFlatCardsIcon"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_gravity="end|center_vertical" android:layout_gravity="end|center_vertical"
android:src="@drawable/ic_flat"
android:weightSum="1" /> android:weightSum="1" />
</LinearLayout> </LinearLayout>
...@@ -71,6 +74,7 @@ ...@@ -71,6 +74,7 @@
android:weightSum="1"> android:weightSum="1">
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/downloadToursText"
style="@style/Common_Text.Default" style="@style/Common_Text.Default"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -82,10 +86,11 @@ ...@@ -82,10 +86,11 @@
и сделок (477 MB)" /> и сделок (477 MB)" />
<ImageView <ImageView
android:src="@drawable/ic_flat" android:id="@+id/downloadToursIcon"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_gravity="end|center_vertical" android:layout_gravity="end|center_vertical"
android:src="@drawable/ic_flat"
android:weightSum="1" /> android:weightSum="1" />
</LinearLayout> </LinearLayout>
...@@ -102,6 +107,7 @@ ...@@ -102,6 +107,7 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/cachedRecyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
......
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