mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 13:57:10 +09:00
show editable blocks in recycler
This commit is contained in:
parent
7c7401ad05
commit
c5018aab96
6 changed files with 43 additions and 8 deletions
|
@ -75,6 +75,7 @@ dependencies {
|
|||
implementation applicationDependencies.dagger
|
||||
implementation applicationDependencies.timber
|
||||
implementation applicationDependencies.gson
|
||||
implementation applicationDependencies.rxRelay
|
||||
|
||||
//Unit/Integration tests dependencies
|
||||
testImplementation unitTestDependencies.junit
|
||||
|
|
|
@ -70,7 +70,7 @@ ext {
|
|||
javaxAnnotation: "javax.annotation:jsr250-api:$javaxAnnotations_version",
|
||||
javaxInject: "javax.inject:javax.inject:$javaxInject_version",
|
||||
gson: "com.google.code.gson:gson:$gson_version",
|
||||
rxRelay: "com.jakewharton.rxrelay2:rxrelay:$rxrelay_version",
|
||||
rxRelay: "com.jakewharton.rxrelay2:rxrelay:$rxrelay_version",
|
||||
retrofit: "com.squareup.retrofit2:converter-gson:$retrofit_version",
|
||||
okhttpLoggingInterceptor: "com.squareup.okhttp3:logging-interceptor:$okhttp_logging_interceptor_version",
|
||||
timber: "com.jakewharton.timber:timber:$timber_version",
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package com.agileburo.anytype.feature_editor.ui
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.agileburo.anytype.core_utils.swap
|
||||
import com.agileburo.anytype.feature_editor.R
|
||||
import com.agileburo.anytype.feature_editor.domain.Block
|
||||
import kotlinx.android.synthetic.main.item_block_editable.view.*
|
||||
import timber.log.Timber
|
||||
|
||||
class EditorAdapter(private val blocks: MutableList<Block>): RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
@ -16,13 +19,17 @@ class EditorAdapter(private val blocks: MutableList<Block>): RecyclerView.Adapte
|
|||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val view = inflater.inflate(R.layout.item_block_editable, parent, false)
|
||||
return ViewHolder.TextHolder(view)
|
||||
}
|
||||
|
||||
override fun getItemCount() = blocks.size
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
|
||||
when (holder) {
|
||||
is ViewHolder.TextHolder -> holder.bind(blocks[position])
|
||||
}
|
||||
}
|
||||
|
||||
fun onItemMoved(fromPosition: Int, toPosition: Int): Boolean {
|
||||
|
@ -37,7 +44,13 @@ class EditorAdapter(private val blocks: MutableList<Block>): RecyclerView.Adapte
|
|||
|
||||
sealed class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
class TextHolder(itemView: View) : ViewHolder(itemView)
|
||||
class TextHolder(itemView: View) : ViewHolder(itemView) {
|
||||
|
||||
fun bind(block : Block) {
|
||||
itemView.tvId.text = "id :${block.id}"
|
||||
itemView.tvContent.text = block.content
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.agileburo.anytype.feature_editor.R
|
||||
import com.agileburo.anytype.feature_editor.disposedBy
|
||||
|
@ -18,8 +19,6 @@ import javax.inject.Inject
|
|||
|
||||
abstract class EditorFragment : Fragment() {
|
||||
|
||||
private lateinit var editorAdapter: EditorAdapter
|
||||
|
||||
@Inject
|
||||
lateinit var factory: EditorViewModelFactory
|
||||
private val viewModel by lazy {
|
||||
|
@ -55,6 +54,7 @@ abstract class EditorFragment : Fragment() {
|
|||
layoutManager = LinearLayoutManager(requireContext())
|
||||
adapter = EditorAdapter(mutableListOf())
|
||||
setHasFixedSize(true)
|
||||
addItemDecoration(DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL))
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
@ -71,7 +71,7 @@ abstract class EditorFragment : Fragment() {
|
|||
is EditorState.Loading -> {
|
||||
}
|
||||
is EditorState.Result -> {
|
||||
editorAdapter.setBlocks(state.blocks)
|
||||
(blockList.adapter as? EditorAdapter)?.setBlocks(state.blocks)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/holo_blue_dark">
|
||||
android:background="@android:color/white">
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/blockList"
|
||||
android:layout_width="0dp"
|
||||
|
|
21
feature_editor/src/main/res/layout/item_block_editable.xml
Normal file
21
feature_editor/src/main/res/layout/item_block_editable.xml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvId"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/tvId"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@android:color/black"/>
|
||||
|
||||
</RelativeLayout>
|
Loading…
Add table
Add a link
Reference in a new issue