diff options
author | Clyhtsuriva <aimeric@adjutor.xyz> | 2021-02-18 21:55:37 +0100 |
---|---|---|
committer | Clyhtsuriva <aimeric@adjutor.xyz> | 2021-02-18 21:55:37 +0100 |
commit | eaef2672c25baaf370c72158d5236f40f6fea01f (patch) | |
tree | 658ee831fc5db15dae455d013cf13ec263faa177 /app/src/main/java | |
parent | f4d8a9c6fa8f805a9dedb626ef343aa37943c079 (diff) |
Preparing
Preparing the implementation of the API datas to our recycerview in a fragment.
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt | 12 | ||||
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt | 4 | ||||
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt | 29 |
3 files changed, 25 insertions, 20 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() { |