aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/xyz/adjutor/aniki/topmanga
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/topmanga
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/topmanga')
-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
2 files changed, 67 insertions, 9 deletions
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"