aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/xyz/adjutor/aniki
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/xyz/adjutor/aniki')
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt45
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt40
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/MangaSource.kt11
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt11
4 files changed, 59 insertions, 48 deletions
diff --git a/app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt
deleted file mode 100644
index 74ba9c4..0000000
--- a/app/src/main/java/xyz/adjutor/aniki/ListAdapter.kt
+++ /dev/null
@@ -1,45 +0,0 @@
-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<String>) :
- RecyclerView.Adapter<ListAdapter.ViewHolder>() {
-
- /**
- * 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/MangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt
new file mode 100644
index 0000000..8e1c8f2
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt
@@ -0,0 +1,40 @@
+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
+import java.util.ArrayList
+
+class MangaAdapter(val mangaList: Array<String>) :
+ RecyclerView.Adapter<MangaAdapter.MangaViewHolder>() {
+
+ // Describes an item view and its place within the RecyclerView
+ class MangaViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
+ private val mangaTextView: TextView = itemView.findViewById(R.id.tv_title)
+
+ fun bind(word: String) {
+ mangaTextView.text = word
+ }
+ }
+
+ // Returns a new ViewHolder
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MangaViewHolder {
+ val view = LayoutInflater.from(parent.context)
+ .inflate(R.layout.item_layout, parent, false)
+
+ return MangaViewHolder(view)
+ }
+
+ // Returns size of data list
+ override fun getItemCount(): Int {
+ return mangaList.size
+ }
+
+ // Displays data at a certain position
+ override fun onBindViewHolder(holder: MangaViewHolder, position: Int) {
+ holder.bind(mangaList[position])
+ }
+}
+
diff --git a/app/src/main/java/xyz/adjutor/aniki/MangaSource.kt b/app/src/main/java/xyz/adjutor/aniki/MangaSource.kt
new file mode 100644
index 0000000..86e46e2
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/MangaSource.kt
@@ -0,0 +1,11 @@
+package xyz.adjutor.aniki
+
+import android.content.Context
+
+class MangaSource(val context: Context) {
+ fun getMangaList(): Array<String> {
+
+ // Return manga list from string resources
+ return context.resources.getStringArray(R.array.manga_array)
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt
index a59e038..32d3ce6 100644
--- a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt
@@ -6,11 +6,10 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
+import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.fragment.findNavController
+import androidx.recyclerview.widget.RecyclerView
-/**
- * A simple [Fragment] subclass as the second destination in the navigation.
- */
class TopMangaPage : Fragment() {
override fun onCreateView(
@@ -28,5 +27,11 @@ class TopMangaPage : Fragment() {
findNavController().navigate(R.id.action_TopMangaPage_to_HomePage)
}
+ // Retrieves data from mangasource
+ val mangaList = MangaSource(requireActivity().applicationContext).getMangaList()
+
+ val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view)
+ recyclerView.adapter = MangaAdapter(mangaList)
+
}
} \ No newline at end of file