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 {
implementation "com.jakewharton.rxbinding3:rxbinding-recyclerview:$rxBindingVersion"
implementation "com.jakewharton.rxbinding3:rxbinding-material:$rxBindingVersion"
//Tests
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
......
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
/**
......@@ -8,4 +12,37 @@ import javax.inject.Inject
class SettingsInteractor @Inject constructor(
){
}
\ No newline at end of file
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
data class PushSwitchModel(
val title:String,
val pushId:String,
val innerId:Int,
val pushId:String,
val switchState: Boolean
)
......
......@@ -87,7 +87,13 @@ class DealViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
dealPayed.text = deal.dealPayout.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){
......
package com.biganto.visual.roompark.presentation.screen.settings
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.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity
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 javax.inject.Inject
......@@ -12,7 +18,7 @@ import javax.inject.Inject
* Created by Vladislav Bogdashkin on 30.09.2019.
*/
class SettingsScreenController :
class SettingsScreenController :
BigantoBaseController<SettingsScreenViewState
, SettingsScreen
, SettingsScreenPresenter>()
......@@ -25,9 +31,33 @@ class SettingsScreenController :
@Inject
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) {
pushRecycler.isNestedScrollingEnabled = true
pushRecycler.layoutManager =
LinearLayoutManager(activity, RecyclerView.VERTICAL, false)
pushRecycler.adapter = PushListAdapter()
pushRecycler.itemAnimator = null
}
override fun render(viewState: SettingsScreenViewState) {
......@@ -35,6 +65,7 @@ class SettingsScreenController :
Timber.d("Render state $viewState")
when(viewState){
is SettingsScreenViewState.Idle -> render(viewState)
is SettingsScreenViewState.LoadSettingsList -> render(viewState)
}
}
......@@ -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()
.create(RoomParkApplication.component,activity as RoomParkMainActivity)
.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(
override fun bindIntents() {
val fetchSettings = interactor.fetchSettings()
.map { SettingsScreenViewState.LoadSettingsList(it) }
val state = restoreStateObservable
.mergeWith(fetchSettings)
.doOnError{ Timber.e(it)}
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
......
package com.biganto.visual.roompark.presentation.screen.settings
import com.biganto.visual.roompark.conductor.BigantoBaseViewState
import com.biganto.visual.roompark.domain.model.SettingsModel
/**
* Created by Vladislav Bogdashkin on 30.09.2019.
......@@ -9,4 +10,5 @@ import com.biganto.visual.roompark.conductor.BigantoBaseViewState
sealed class SettingsScreenViewState : BigantoBaseViewState() {
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 :
override fun getFlat(): Observable<TourRequestModel> =
flatNumberEditor.keys { it.keyCode == KeyEvent.KEYCODE_ENTER }
.doOnNext { flatNumberEditor.hideKeyboard() }
.doOnNext{Timber.d(" key code is : ${it.keyCode}")}
.doOnNext{Timber.d(" KeyEvent.FLAG_EDITOR_ACTION : ${KeyEvent.FLAG_EDITOR_ACTION}")}
.map {
TourRequestModel(
estateTabs[flatTabs.selectedTabPosition].building
......
......@@ -7,6 +7,7 @@
android:weightSum="1">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/bellSwitcherTitle"
style="@style/Common_Text.Default"
android:layout_width="0dp"
android:layout_height="match_parent"
......@@ -15,6 +16,7 @@
android:text="блабла" />
<include
android:id="@+id/bellSwitch"
layout="@layout/bell_switch_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......
......@@ -16,6 +16,7 @@
android:text="PUSH УВЕДОМЛЕНИЯ" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/pushRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
......@@ -41,6 +42,7 @@
android:weightSum="1">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/downloadFlatCardsText"
style="@style/Common_Text.Default"
android:layout_width="0dp"
android:layout_height="wrap_content"
......@@ -52,10 +54,11 @@
и сделок (4 MB)" />
<ImageView
android:src="@drawable/ic_flat"
android:id="@+id/downloadFlatCardsIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="end|center_vertical"
android:src="@drawable/ic_flat"
android:weightSum="1" />
</LinearLayout>
......@@ -71,6 +74,7 @@
android:weightSum="1">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/downloadToursText"
style="@style/Common_Text.Default"
android:layout_width="0dp"
android:layout_height="wrap_content"
......@@ -82,10 +86,11 @@
и сделок (477 MB)" />
<ImageView
android:src="@drawable/ic_flat"
android:id="@+id/downloadToursIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="end|center_vertical"
android:src="@drawable/ic_flat"
android:weightSum="1" />
</LinearLayout>
......@@ -102,6 +107,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/cachedRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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