From 7288d5ae154f895d71727acc92828aa555e8108b Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Tue, 16 Feb 2021 11:37:58 +0100 Subject: Starting to work on recycler view feature --- app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt | 45 ++++++++++++++++ .../main/java/xyz/adjutor/aniki/MainActivity.kt | 1 + .../main/java/xyz/adjutor/aniki/TopMangaPage.kt | 1 + app/src/main/res/layout/activity_main.xml | 3 +- app/src/main/res/layout/item_layout.xml | 63 ++++++++++++++++++++++ app/src/main/res/layout/row_layout.xml | 47 ++++++++++++++++ app/src/main/res/layout/top_manga_page.xml | 21 ++++---- app/src/main/res/values/strings.xml | 3 ++ 8 files changed, 173 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt create mode 100644 app/src/main/res/layout/item_layout.xml create mode 100644 app/src/main/res/layout/row_layout.xml (limited to 'app/src/main') diff --git a/app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt new file mode 100644 index 0000000..74ba9c4 --- /dev/null +++ b/app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt @@ -0,0 +1,45 @@ +package xyz.adjutor.aniki + +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView + +class ListAdapter(private val dataSet: Array) : + RecyclerView.Adapter() { + + /** + * Provide a reference to the type of views that you are using + * (custom ViewHolder). + */ + class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + // Define click listener for the ViewHolder's View. + val firstLine: TextView = view.findViewById(R.id.firstLine) + val secondLine: TextView = view.findViewById(R.id.secondLine) + + } + + // Create new views (invoked by the layout manager) + override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder { + // Create a new view, which defines the UI of the list item + val view = LayoutInflater.from(viewGroup.context) + .inflate(R.layout.row_layout, viewGroup, false) + + return ViewHolder(view) + } + + // Replace the contents of a view (invoked by the layout manager) + override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) { + + // Get element from your dataset at this position and replace the + // contents of the view with that element + viewHolder.firstLine.text = dataSet[position] + viewHolder.secondLine.text = dataSet[position] + } + + // Return the size of your dataset (invoked by the layout manager) + override fun getItemCount() = dataSet.size + +} + diff --git a/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt b/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt index 4ccae64..3ae1bf2 100644 --- a/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt @@ -6,6 +6,7 @@ import com.google.android.material.snackbar.Snackbar import androidx.appcompat.app.AppCompatActivity import android.view.Menu import android.view.MenuItem +import androidx.recyclerview.widget.RecyclerView class MainActivity : AppCompatActivity() { diff --git a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt index c64b9fe..a59e038 100644 --- a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt +++ b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt @@ -27,5 +27,6 @@ class TopMangaPage : Fragment() { view.findViewById