1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

update ui model in adapter and fragment

This commit is contained in:
konstantiniiv 2019-11-18 08:16:12 +03:00
parent d41c8821f1
commit 6570d4400b
7 changed files with 112 additions and 51 deletions

View file

@ -2,20 +2,22 @@ package com.agileburo.anytype.ui.table
import android.os.Bundle
import android.view.View
import android.widget.TextView
import androidx.lifecycle.ViewModelProviders
import com.agileburo.anytype.R
import com.agileburo.anytype.core_utils.ui.ViewState
import com.agileburo.anytype.di.common.componentManager
import com.agileburo.anytype.domain.database.model.DatabaseView
import com.agileburo.anytype.presentation.databaseview.DatabaseViewModel
import com.agileburo.anytype.presentation.databaseview.DatabaseViewModelFactory
import com.agileburo.anytype.presentation.databaseview.models.Table
import com.agileburo.anytype.ui.base.ViewStateFragment
import kotlinx.android.synthetic.main.fragment_table.*
import timber.log.Timber
import javax.inject.Inject
const val TEST_ID = "1"
class DatabaseViewFragment : ViewStateFragment<ViewState<DatabaseView>>(R.layout.fragment_table) {
class DatabaseViewFragment : ViewStateFragment<ViewState<Table>>(R.layout.fragment_table) {
@Inject
lateinit var factory: DatabaseViewModelFactory
@ -32,9 +34,19 @@ class DatabaseViewFragment : ViewStateFragment<ViewState<DatabaseView>>(R.layout
vm.getDatabaseView(id = TEST_ID)
}
override fun render(state: ViewState<DatabaseView>) {
override fun render(state: ViewState<Table>) {
when (state) {
is ViewState.Success -> { Timber.d("Get database : ${state.data.content.view}")}
is ViewState.Init -> {
//Init view
}
is ViewState.Success -> {
Timber.d("Get database : ${state.data}")
}
}
}

View file

@ -5,10 +5,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.agileburo.anytype.R
import com.agileburo.anytype.presentation.table.CellView
import com.agileburo.anytype.presentation.table.ColumnHeaderView
import com.agileburo.anytype.presentation.table.RowHeaderView
import com.agileburo.anytype.ui.table.holder.CellDateViewHolder
import com.agileburo.anytype.presentation.databaseview.models.Cell
import com.agileburo.anytype.presentation.databaseview.models.Column
import com.agileburo.anytype.presentation.databaseview.models.Row
import com.agileburo.anytype.ui.table.holder.CellNameViewHolder
import com.evrencoskun.tableview.adapter.AbstractTableAdapter
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder
@ -18,7 +17,37 @@ private const val DATE_CELL_TYPE = 2
class TableAdapter(context: Context) :
AbstractTableAdapter<ColumnHeaderView, RowHeaderView, CellView>(context) {
AbstractTableAdapter<Column, Row, Cell>(context) {
// -------------- Cell --------------------
override fun getCellItemViewType(position: Int): Int = 0
override fun onCreateCellViewHolder(parent: ViewGroup, viewType: Int): AbstractViewHolder =
LayoutInflater.from(parent.context).run {
CellNameViewHolder(this.inflate(R.layout.item_table_name_cell, parent, false))
// when (viewType) {
// NAME_CELL_TYPE ->
// DATE_CELL_TYPE -> CellDateViewHolder(
// itemView = this.inflate(R.layout.item_table_date_cell, parent, false)
// )
// else -> throw RuntimeException("Unknown cell type")
// }
}
override fun onBindCellViewHolder(
holder: AbstractViewHolder?,
cellItemModel: Any?,
columnPosition: Int,
rowPosition: Int
) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
// -------------- Column --------------------
override fun getColumnHeaderItemViewType(position: Int): Int = 0
override fun onCreateColumnHeaderViewHolder(
parent: ViewGroup?,
@ -35,6 +64,10 @@ class TableAdapter(context: Context) :
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
// -------------- Row --------------------
override fun getRowHeaderItemViewType(position: Int): Int = 0
override fun onBindRowHeaderViewHolder(
holder: AbstractViewHolder?,
rowHeaderItemModel: Any?,
@ -50,41 +83,16 @@ class TableAdapter(context: Context) :
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getCellItemViewType(position: Int): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onCreateCellViewHolder(parent: ViewGroup, viewType: Int): AbstractViewHolder =
LayoutInflater.from(parent.context).run {
when (viewType) {
NAME_CELL_TYPE -> CellNameViewHolder(
itemView = this.inflate(R.layout.item_table_name_cell, parent, false)
)
DATE_CELL_TYPE -> CellDateViewHolder(
itemView = this.inflate(R.layout.item_table_date_cell, parent, false)
)
else -> throw RuntimeException("Unknown cell type")
}
}
override fun onCreateCornerView(): View {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onBindCellViewHolder(
holder: AbstractViewHolder?,
cellItemModel: Any?,
columnPosition: Int,
rowPosition: Int
) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getColumnHeaderItemViewType(position: Int): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getRowHeaderItemViewType(position: Int): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}

View file

@ -1,12 +1,8 @@
package com.agileburo.anytype.ui.table.holder
import android.view.View
import com.agileburo.anytype.presentation.table.CellDateView
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder
class CellDateViewHolder(itemView: View) : AbstractViewHolder(itemView) {
fun bind(cell: CellDateView) {
}
}

View file

@ -1,12 +1,8 @@
package com.agileburo.anytype.ui.table.holder
import android.view.View
import com.agileburo.anytype.presentation.table.CellNameView
import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder
class CellNameViewHolder(itemView: View) : AbstractViewHolder(itemView) {
private fun setCell(cell: CellNameView) {
}
}

View file

@ -0,0 +1,16 @@
<?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="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/button_active"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -1,6 +1,7 @@
<?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:layout_width="match_parent"
android:layout_height="match_parent">
@ -8,12 +9,42 @@
android:id="@+id/tableView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="32dp"
app:column_header_height="@dimen/table_column_header_height"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvViewType"
app:row_header_width="@dimen/table_row_header_width" />
<EditText
android:id="@+id/edtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:ems="10"
android:textSize="21sp"
android:textColor="@color/black"
android:inputType="textPersonName"
android:background="@android:color/transparent"
tools:text="Table name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvViewType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:fontFamily="sans-serif-medium"
android:textColor="@color/black"
android:textSize="16sp"
android:typeface="normal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edtTitle"
tools:text="View type" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -6,18 +6,20 @@ import androidx.lifecycle.viewModelScope
import com.agileburo.anytype.core_utils.ui.ViewState
import com.agileburo.anytype.core_utils.ui.ViewStateViewModel
import com.agileburo.anytype.domain.database.interactor.GetDatabase
import com.agileburo.anytype.domain.database.model.DatabaseView
import com.agileburo.anytype.presentation.databaseview.mapper.toPresentation
import com.agileburo.anytype.presentation.databaseview.models.Table
import timber.log.Timber
class DatabaseViewModel(
private val getDatabase: GetDatabase
) : ViewStateViewModel<ViewState<DatabaseView>>() {
) : ViewStateViewModel<ViewState<Table>>() {
fun getDatabaseView(id: String) {
getDatabase.invoke(viewModelScope, GetDatabase.Params(id)) { result ->
result.either(
fnL = { e -> Timber.e("Error while getting database for id=$id ${e.message}") },
fnR = { stateData.postValue(ViewState.Success(it)) }
fnR = {
stateData.postValue(ViewState.Success(it.toPresentation())) }
)
}
}