List versioned files in a repository
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
package fr.uca.iut.clfreville2.teaiswarm
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import fr.uca.iut.clfreville2.teaiswarm.model.VersionedFile
|
||||||
|
|
||||||
|
class FileListAdapter(private val dataSet: List<VersionedFile>, private val onClick: (VersionedFile) -> Unit) :
|
||||||
|
RecyclerView.Adapter<FileListAdapter.ViewHolder>() {
|
||||||
|
|
||||||
|
class ViewHolder(view: View, private val onClick: (VersionedFile) -> Unit) : RecyclerView.ViewHolder(view) {
|
||||||
|
private val fileNameView: TextView
|
||||||
|
private var currentFile: VersionedFile? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
fileNameView = view.findViewById(R.id.repository_name)
|
||||||
|
itemView.setOnClickListener {
|
||||||
|
currentFile?.let {
|
||||||
|
onClick(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bind(file: VersionedFile) {
|
||||||
|
fileNameView.text = file.fileName
|
||||||
|
currentFile = file
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
val view = LayoutInflater.from(viewGroup.context)
|
||||||
|
.inflate(R.layout.repository_row_item, viewGroup, false)
|
||||||
|
|
||||||
|
return ViewHolder(view, onClick)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
holder.bind(dataSet[position])
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount() = dataSet.size
|
||||||
|
}
|
@@ -3,10 +3,13 @@ package fr.uca.iut.clfreville2.teaiswarm
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import fr.uca.iut.clfreville2.teaiswarm.model.VersionedFile
|
||||||
|
|
||||||
class RepositoryDetailActivity : AppCompatActivity() {
|
class RepositoryDetailActivity : AppCompatActivity() {
|
||||||
|
|
||||||
private lateinit var repositoryName: TextView
|
private lateinit var repositoryName: TextView
|
||||||
|
private lateinit var versionedFiles: RecyclerView
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -23,5 +26,20 @@ class RepositoryDetailActivity : AppCompatActivity() {
|
|||||||
currentRepositoryName?.let {
|
currentRepositoryName?.let {
|
||||||
repositoryName.text = currentRepositoryName
|
repositoryName.text = currentRepositoryName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
versionedFiles = findViewById(R.id.versioned_files_view)
|
||||||
|
versionedFiles.adapter = FileListAdapter(
|
||||||
|
listOf(
|
||||||
|
"cli",
|
||||||
|
"doc",
|
||||||
|
"sql",
|
||||||
|
"test",
|
||||||
|
"web",
|
||||||
|
".drone.yml",
|
||||||
|
".gitignore",
|
||||||
|
"CONVENTIONS.md",
|
||||||
|
"README.md"
|
||||||
|
).map { VersionedFile(it) }
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,3 @@
|
|||||||
|
package fr.uca.iut.clfreville2.teaiswarm.model
|
||||||
|
|
||||||
|
data class VersionedFile(val fileName: String)
|
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout 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_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
@@ -19,4 +20,10 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/repository_description"
|
android:text="@string/repository_description"
|
||||||
android:padding="16dp" />
|
android:padding="16dp" />
|
||||||
</LinearLayout>
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/versioned_files_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layoutManager="LinearLayoutManager"/>
|
||||||
|
</LinearLayout>
|
||||||
|
Reference in New Issue
Block a user