aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/xyz/adjutor/aniki
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2021-02-22 00:00:12 +0100
committerClyhtsuriva <aimeric@adjutor.xyz>2021-02-22 00:00:12 +0100
commit56f69f774bc2a7ef645169f85b89934255c29cf9 (patch)
treef6a41952dc69088d6d9c68b25887c5960ce5cd74 /app/src/main/java/xyz/adjutor/aniki
parent94ab3bbeb21049ac1be128ee00dbae1570346123 (diff)
API call and display on DetailTopMangaActivity.kt
Still need to find a way to call with the right ID. Rn, using the id 1 of monster as a "placeholder"
Diffstat (limited to 'app/src/main/java/xyz/adjutor/aniki')
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt58
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt4
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/manga/RestMangaResponse.kt (renamed from app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt)2
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt2
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt72
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt4
6 files changed, 70 insertions, 72 deletions
diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt
deleted file mode 100644
index ad753e2..0000000
--- a/app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt
+++ /dev/null
@@ -1,58 +0,0 @@
-@file:Suppress("DEPRECATION")
-
-package xyz.adjutor.aniki.manga
-
-import android.content.Intent
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import android.widget.ImageView
-import android.widget.TextView
-import androidx.cardview.widget.CardView
-import androidx.recyclerview.widget.RecyclerView
-import com.bumptech.glide.Glide
-import com.bumptech.glide.request.RequestOptions
-import xyz.adjutor.aniki.R
-import xyz.adjutor.aniki.topmanga.DetailTopMangaActivity
-
-class MangaAdapter(val mangaList: List<Manga>) :
- RecyclerView.Adapter<MangaAdapter.MangaViewHolder>() {
-
- // Describes an item view and its place within the RecyclerView
- class MangaViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
- val mangaTitle: TextView = itemView.findViewById(R.id.tv_title)
- val mangaRank: TextView = itemView.findViewById(R.id.tv_rank)
- val mangaScore: TextView = itemView.findViewById(R.id.tv_score)
- val mangaImage: ImageView = itemView.findViewById(R.id.iv_image)
- val cardview: CardView = itemView.findViewById(R.id.cv_cardView)
-
- }
-
- // 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) {
- val currentManga: Manga = mangaList[position]
- holder.mangaTitle.text = currentManga.title
- holder.mangaRank.text = currentManga.rank.toString()
- holder.mangaScore.text = currentManga.score.toString()
- val image: String = currentManga.image_url.toString()
- Glide
- .with(holder.itemView.context)
- .load(image)
- .apply(RequestOptions().override(400))
- .into(holder.mangaImage)
- }
-}
-
diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt b/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt
index 7692836..77304bb 100644
--- a/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt
@@ -5,7 +5,7 @@ import retrofit2.http.GET
interface MangaApi {
- @GET("v3/manga")
- fun getMangaData(): Call<Manga>
+ @GET("v3/manga/1")
+ fun getMangaData(): Call<RestMangaResponse>
} \ No newline at end of file
diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt b/app/src/main/java/xyz/adjutor/aniki/manga/RestMangaResponse.kt
index baba9f5..7a4aff9 100644
--- a/app/src/main/java/xyz/adjutor/aniki/manga/Manga.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/manga/RestMangaResponse.kt
@@ -2,7 +2,7 @@ package xyz.adjutor.aniki.manga
import com.google.gson.annotations.SerializedName
-class Manga{ //only kept the infos I didnt have and that were interresting to me.
+class RestMangaResponse{ //only kept the infos I didnt have and that were interresting to me.
@SerializedName("chapters")
var chapters: Int? = null
diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt
index 4953939..d38adb2 100644
--- a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt
@@ -1,5 +1,3 @@
-@file:Suppress("DEPRECATION")
-
package xyz.adjutor.aniki.topanime
import android.view.LayoutInflater
diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt
index 27f602a..152fe4a 100644
--- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt
@@ -1,16 +1,34 @@
package xyz.adjutor.aniki.topmanga
+import android.content.Context
import android.os.Bundle
+import android.view.View
import android.widget.ImageView
import android.widget.TextView
+import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
-import com.google.android.material.snackbar.Snackbar
+import com.google.gson.GsonBuilder
+import retrofit2.Call
+import retrofit2.Callback
+import retrofit2.Response
+import retrofit2.Retrofit
+import retrofit2.converter.gson.GsonConverterFactory
import xyz.adjutor.aniki.R
+import xyz.adjutor.aniki.manga.MangaApi
+import xyz.adjutor.aniki.manga.RestMangaResponse
class DetailTopMangaActivity : AppCompatActivity() {
+ var base_url = "https://api.jikan.moe/"
+ val gson = GsonBuilder()
+ .setLenient()
+ .create()
+ var manga: RestMangaResponse? = null
+
private val mangaId = "themangaid"
private val mangaTitle = "themangatitle"
private val mangaRank = "themangarank"
@@ -45,11 +63,6 @@ class DetailTopMangaActivity : AppCompatActivity() {
val tvStartDate: TextView = findViewById(R.id.tv_start_date)
val tvEndDate: TextView = findViewById(R.id.tv_end_date)
- //elements from Manga
- val tvChapters: TextView = findViewById(R.id.tv_chapters)
- val tvSynopsis: TextView = findViewById(R.id.tv_synopsis)
- val tvBackground: TextView = findViewById(R.id.tv_background)
-
tvId.text = mangaId
tvTitle.text = mangaTitle
tvRank.text = mangaRank
@@ -63,5 +76,52 @@ class DetailTopMangaActivity : AppCompatActivity() {
tvVolumes.text = mangaVolumes
tvStartDate.text = mangaStartDate
tvEndDate.text = mangaEndDate
+
+ makeApiCall(base_url)
+ }
+
+ private fun makeApiCall(BASE_URL: String) {
+
+ val retrofit = Retrofit.Builder()
+ .baseUrl(BASE_URL)
+ .addConverterFactory(GsonConverterFactory.create(gson))
+ .build()
+
+ val service = retrofit.create(MangaApi::class.java)
+ val call = service.getMangaData()
+
+ call.enqueue(object : Callback<RestMangaResponse> {
+ override fun onResponse(call: Call<RestMangaResponse>, response: Response<RestMangaResponse>) {
+ if(response.isSuccessful && response.body() != null){ //if the code returned is >= 200 and < 300 AND the the body ain't empty
+
+ manga = response.body() //getting the RestMangaResponse fields
+ showDetail(manga!!)
+
+ } else {
+ showError("API ERROR : is not successful")
+ }
+ }
+
+ override fun onFailure(call: Call<RestMangaResponse>, t: Throwable) {
+ showError("API ERROR : onFailure")
+ }
+
+ })
+ }
+
+ private fun showDetail(manga: RestMangaResponse) {
+ //elements from RestMangaResponse
+ val tvChapters: TextView = findViewById(R.id.tv_chapters)
+ val tvSynopsis: TextView = findViewById(R.id.tv_synopsis)
+ val tvBackground: TextView = findViewById(R.id.tv_background)
+
+ tvChapters.text = manga.chapters.toString()
+ tvSynopsis.text = manga.synopsis.toString()
+ tvBackground.text = manga.background.toString()
+
+ }
+
+ fun showError(text: String) {
+ Toast.makeText(this, text, Toast.LENGTH_LONG).show()
}
} \ No newline at end of file
diff --git a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt
index 7a32dd5..c2b3567 100644
--- a/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt
@@ -1,5 +1,3 @@
-@file:Suppress("DEPRECATION")
-
package xyz.adjutor.aniki.topmanga
import android.content.Intent
@@ -53,7 +51,7 @@ class TopMangaAdapter(val mangaList: List<TopManga>) :
.apply(RequestOptions().override(400))
.into(holder.mangaImage)
- //to go to the detail page of the selected manga
+ //when you click on a selected cardview, some datas are sent to the other activity
holder.cardview.setOnClickListener {
val currentMangaId = "themangaid"
val currentMangaTitle = "themangatitle"