summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2021-02-18 21:55:37 +0100
committerClyhtsuriva <aimeric@adjutor.xyz>2021-02-18 21:55:37 +0100
commiteaef2672c25baaf370c72158d5236f40f6fea01f (patch)
tree658ee831fc5db15dae455d013cf13ec263faa177 /app/src/main
parentf4d8a9c6fa8f805a9dedb626ef343aa37943c079 (diff)
Preparing
Preparing the implementation of the API datas to our recycerview in a fragment.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt12
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt4
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt29
-rw-r--r--app/src/main/res/layout/item_layout.xml33
-rw-r--r--app/src/main/res/values/strings.xml2
5 files changed, 48 insertions, 32 deletions
diff --git a/app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt
index 8e1c8f2..9f7a373 100644
--- a/app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt
@@ -3,6 +3,7 @@ package xyz.adjutor.aniki
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import java.util.ArrayList
@@ -12,11 +13,10 @@ class MangaAdapter(val mangaList: Array<String>) :
// 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)
+ val mangaTitle: TextView = itemView.findViewById(R.id.tv_title)
+ val mangaRank: TextView = itemView.findViewById(R.id.tv_rank)
+ val mangaImage: ImageView = itemView.findViewById(R.id.iv_image)
- fun bind(word: String) {
- mangaTextView.text = word
- }
}
// Returns a new ViewHolder
@@ -34,7 +34,9 @@ class MangaAdapter(val mangaList: Array<String>) :
// Displays data at a certain position
override fun onBindViewHolder(holder: MangaViewHolder, position: Int) {
- holder.bind(mangaList[position])
+ holder.mangaTitle.text = mangaList[position] //use specific json data
+ holder.mangaRank.text = position.toString() //replace by the actual rank
+ //holder.mangaImage.setImageResource(mangaList[position]) //replace by the manga image
}
}
diff --git a/app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt b/app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt
index 8cd5f2b..46b3bd3 100644
--- a/app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt
@@ -12,4 +12,8 @@ class RestTopMangaResponse {
var request_cached_expiry: Int? = null
@SerializedName("top")
var top = ArrayList<TopManga>()
+
+ fun getResults(): ArrayList<TopManga> {
+ return top
+ }
} \ 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 9496053..729ff6f 100644
--- a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt
@@ -26,17 +26,8 @@ class TopMangaPage : Fragment() {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.top_manga_page, container, false)
- // Retrieves data from mangasource
- val mangaList = MangaSource(view.context).getMangaList()
+ makeApiCall(view, base_url)
-
- makeApiCall(base_url)
-
-
- val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view)
- recyclerView.setHasFixedSize(true)
- recyclerView.layoutManager = LinearLayoutManager(view.context)
- recyclerView.adapter = MangaAdapter(mangaList)
return view
}
@@ -49,7 +40,14 @@ class TopMangaPage : Fragment() {
}
- fun makeApiCall(BASE_URL: String) {
+ fun showList(view: View, mangaList: Array<String> ){
+ val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view)
+ recyclerView.setHasFixedSize(true)
+ recyclerView.layoutManager = LinearLayoutManager(view.context)
+ recyclerView.adapter = MangaAdapter(mangaList)
+ }
+
+ fun makeApiCall(view: View, BASE_URL: String) {
val gson = GsonBuilder()
.setLenient()
.create()
@@ -62,9 +60,12 @@ class TopMangaPage : Fragment() {
call.enqueue(object : Callback<RestTopMangaResponse> {
override fun onResponse(call: Call<RestTopMangaResponse>, response: Response<RestTopMangaResponse>) {
if(response.isSuccessful && response.body() != null){
- val topMangaResponse = response.body()
+ val topMangaResponse = response.body()!!.getResults()
Snackbar.make(requireView(), "HA? YOU THOUGHT IT WAS AN ERROR !? BUT IT WAS I, API !", Snackbar.LENGTH_LONG)
.setAction("Action", null).show()
+ // Retrieves data from mangasource
+ val mangaList = MangaSource(view.context).getMangaList()
+ showList(view, mangaList)
} else {
showError()
}
@@ -74,9 +75,7 @@ class TopMangaPage : Fragment() {
showError()
}
-
- }
- )
+ })
}
private fun showError() {
diff --git a/app/src/main/res/layout/item_layout.xml b/app/src/main/res/layout/item_layout.xml
index 8500bc7..eb65d60 100644
--- a/app/src/main/res/layout/item_layout.xml
+++ b/app/src/main/res/layout/item_layout.xml
@@ -29,17 +29,28 @@
android:src="@mipmap/ic_launcher_round"
android:contentDescription="@string/rv_image" />
- <TextView
- android:id="@+id/tv_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- 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"/>
+ <TextView
+ android:id="@+id/tv_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ 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="30sp"/>
+
+ <TextView
+ android:id="@+id/tv_rank"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@color/very_dark_purple"
+ android:text="@string/rv_rank"
+ android:textColor="@color/slightly_desaturated_magenta"
+ android:textSize="20sp"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index ccd2ae8..5301008 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -13,7 +13,7 @@
<string name="article_page_label">Article Page</string>
<string name="top_manga_page_label">Top Manga Page</string>
<string name="rv_title">Title</string>
- <string name="rv_description">This is a description</string>
+ <string name="rv_rank">0</string>
<string name="rv_image">image</string>
<string name="manga_image_content_description">Image of manga</string>