aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2021-02-17 08:00:07 +0100
committerClyhtsuriva <aimeric@adjutor.xyz>2021-02-17 08:00:07 +0100
commitd49771c90315897e0fe6eb8d4034e36853bf6650 (patch)
tree394125738b1ff504026528fcd9adbbc2cc5ae078 /app/src
parent7288d5ae154f895d71727acc92828aa555e8108b (diff)
Trying to mimic the Flower exemple from google.
Diffstat (limited to 'app/src')
-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
-rw-r--r--app/src/main/res/layout/item_layout.xml34
-rw-r--r--app/src/main/res/layout/row_layout.xml47
-rw-r--r--app/src/main/res/layout/top_manga_page.xml9
-rw-r--r--app/src/main/res/values/strings.xml21
8 files changed, 98 insertions, 120 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
diff --git a/app/src/main/res/layout/item_layout.xml b/app/src/main/res/layout/item_layout.xml
index e03e874..c4b662c 100644
--- a/app/src/main/res/layout/item_layout.xml
+++ b/app/src/main/res/layout/item_layout.xml
@@ -2,6 +2,7 @@
<androidx.cardview.widget.CardView
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:id="@+id/cv_cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -10,10 +11,10 @@
android:focusable="true"
android:foreground="?selectableItemBackground"
app:cardCornerRadius="10dp"
+ app:cardBackgroundColor="@color/black"
>
- <RelativeLayout
- android:id="@+id/rl_wrapper"
+ <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
@@ -23,30 +24,25 @@
android:id="@+id/iv_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_margin="10dp"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
android:src="@mipmap/ic_launcher_round"
android:contentDescription="@string/rv_image" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_alignTop="@id/iv_image"
- android:layout_alignBottom="@id/iv_image"
- android:layout_toEndOf="@id/iv_image"
- android:orientation="vertical"
- >
-
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_marginStart="10dp"
+ app:layout_constraintStart_toEndOf="@id/iv_image"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintBottom_toBottomOf="parent"
android:text="@string/rv_title"
android:textColor="@color/strong_pink"
- android:textSize="20sp"/>
+ android:textSize="30sp"/>
- <TextView
+ <!--TextView
android:id="@+id/tv_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -54,10 +50,8 @@
android:text="@string/rv_description"
android:textColor="@color/slightly_desaturated_magenta"
android:textSize="20sp"
- />
-
- </LinearLayout>
+ /-->
- </RelativeLayout>
+ </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView> \ No newline at end of file
diff --git a/app/src/main/res/layout/row_layout.xml b/app/src/main/res/layout/row_layout.xml
deleted file mode 100644
index 1c74476..0000000
--- a/app/src/main/res/layout/row_layout.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="?android:attr/listPreferredItemHeight"
- android:layout_marginStart="?android:attr/listPreferredItemPaddingLeft"
- android:layout_marginEnd="?android:attr/listPreferredItemPaddingRight"
- android:gravity="center_vertical"
- android:padding="6dip">
-
-<ImageView
- android:id="@+id/icon"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:layout_alignParentBottom="true"
- android:layout_alignParentTop="true"
- android:layout_marginEnd="6dip"
- android:contentDescription="@string/rv_image"
- android:src="@mipmap/ic_launcher"
- tools:ignore="MissingConstraints" />
-
-<TextView
- android:id="@+id/secondLine"
- android:layout_height="26dip"
- android:ellipsize="marquee"
- android:text="@string/rv_description"
- android:textSize="12sp"
- app:layout_constraintStart_toEndOf="@id/icon"
- app:layout_constraintTop_toBottomOf="@id/firstLine"
- android:layout_width="0dp" />
-
-<TextView
- android:id="@+id/firstLine"
- android:layout_height="wrap_content"
- android:layout_toEndOf="@id/icon"
- android:gravity="center_vertical"
- android:text="@string/rv_title"
- android:textSize="16sp"
- app:layout_constraintStart_toEndOf="@id/icon"
- app:layout_constraintEnd_toEndOf="parent"
- android:layout_width="0dp"
- tools:ignore="MissingConstraints" />
-
-
-</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/app/src/main/res/layout/top_manga_page.xml b/app/src/main/res/layout/top_manga_page.xml
index f8d2510..4a807f1 100644
--- a/app/src/main/res/layout/top_manga_page.xml
+++ b/app/src/main/res/layout/top_manga_page.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<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"
@@ -11,10 +12,10 @@
android:id="@+id/recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/home"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/item_layout" />
<Button
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index a16e804..41bd064 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,7 +1,6 @@
<resources>
<string name="app_name">Aniki</string>
<string name="action_settings">Settings</string>
- <!-- Strings used for fragments for navigation -->
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
<string name="info">Infos about the developper of the app.</string>
@@ -16,4 +15,24 @@
<string name="rv_title">Title</string>
<string name="rv_description">This is a description</string>
<string name="rv_image">image</string>
+ <string name="manga_image_content_description">Image of manga</string>
+
+ <string-array name="manga_array">
+ <item>Dragon Ball</item>
+ <item>Naruto</item>
+ <item>Fairy Tail</item>
+ <item>Shokugeki no Souma</item>
+ <item>Ajin</item>
+ <item>Komi-san no Komyushu</item>
+ <item>Hunter x Hunter</item>
+ <item>Detective Conan</item>
+ <item>Swortd Art Online</item>
+ <item>Scumbag Loser</item>
+ <item>Ana Satsujin</item>
+ <item>Samurai Deeper Kyou</item>
+ <item>Sebsei, Ore ni Kamawazu Itte Kudasai!!</item>
+ </string-array>
+
+ <string name="manga1_name">Dragon Ball</string>
+
</resources> \ No newline at end of file