Skip to content

Instantly share code, notes, and snippets.

View MuratVarol's full-sized avatar
🏠
Working from home

Murat VAROL MuratVarol

🏠
Working from home
  • Oyak Securities
  • Istanbul
View GitHub Profile
import com.google.gson.JsonParseException
import com.sample.app.internal.util.Failure
import com.squareup.moshi.JsonDataException
import io.reactivex.Single
import io.reactivex.android.schedulers.AndroidSchedulers
/**
* Singleton class for handling API requests and responses
abstract class BaseViewHolder(val itemBinding: ViewDataBinding) :
RecyclerView.ViewHolder(itemBinding.root) {
abstract fun bindData(position: Int)
}
open class BaseRecyclerAdapter<T>(
private var modelList: List<T>,
private val itemLayoutId: Int,
private val viewModel: ViewModel?
) : RecyclerView.Adapter<BaseViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
val layoutInflater: LayoutInflater = LayoutInflater.from(parent.context)
val binding: ViewDataBinding =
DataBindingUtil.inflate(layoutInflater, itemLayoutId, parent, false)
class AdapterBuilder<ModelType>(
private val itemList: List<ModelType>,
private val layoutId: Int,
private val viewModel: ViewModel?
) {
fun build(): BaseRecyclerAdapter<ModelType> {
val baseAdapter = BaseRecyclerAdapter(itemList, layoutId, viewModel)
baseAdapter.updateData(itemList)
return baseAdapter
@BindingAdapter(
value = [
"itemList",
"itemLayoutId",
"viewModel"
],
requireAll = false
)
fun RecyclerView.bindRecyclerView(
itemList: List<Nothing>?,
{
"error": {
"code": 0,
"message": "string"
},
"result": {
"totalPagesCount": 0,
"page": 0,
"countPerPage": 0,
"feeds": [
{
"error": null,
"result": {
"data": {
"pipeTypes": [
{
"description": "TS EN 10255 Orta Seri Su Boruları",
"values": [
{
"Product": "30-01063",
{
"error": null,
"result": {
"data": {
"pipeTypes": [
{
"description": "TS EN 10255 Orta Seri Su Boruları",
"values": [
{
"Product": "30-01063",
{
"error": null,
"result": {
"data": {
"pipeTypes": [
{
"description": "TS EN 10255 Orta Seri Su Boruları",
"values": [
{
"Product": "30-01063",
{
"error": null,
"result": {
"name": "string",
"surname": "string",
"email": "[email protected]",
"companyName": null,
"phone": "11223344551"
},
"success": true