From a079577ca21e16dd4b424eea28498f7b56a297df Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Mon, 22 Feb 2021 00:47:34 +0100 Subject: API's now being called with an ID as a parameter. --- .../main/java/xyz/adjutor/aniki/manga/MangaApi.kt | 5 ++- .../aniki/topmanga/DetailTopMangaActivity.kt | 47 +++++++++++----------- 2 files changed, 27 insertions(+), 25 deletions(-) (limited to 'app/src/main/java/xyz') 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 77304bb..419d510 100644 --- a/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt +++ b/app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt @@ -2,10 +2,11 @@ package xyz.adjutor.aniki.manga import retrofit2.Call import retrofit2.http.GET +import retrofit2.http.Path interface MangaApi { - @GET("v3/manga/1") - fun getMangaData(): Call + @GET("v3/manga/{id}") + fun getMangaData(@Path("id") id: String): Call } \ No newline at end of file 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 152fe4a..b222a99 100644 --- a/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt +++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt @@ -23,35 +23,34 @@ import xyz.adjutor.aniki.manga.RestMangaResponse class DetailTopMangaActivity : AppCompatActivity() { - var base_url = "https://api.jikan.moe/" - val gson = GsonBuilder() + private var baseUrl = "https://api.jikan.moe/" + private val gson = GsonBuilder() .setLenient() .create() - var manga: RestMangaResponse? = null - private val mangaId = "themangaid" - private val mangaTitle = "themangatitle" - private val mangaRank = "themangarank" - private val mangaScore = "themangascore" - private val mangaImageUrl = "themangaimageurl" + private val intentMangaId = "themangaid" + private val intentMangaTitle = "themangatitle" + private val intentMangaRank = "themangarank" + private val intentMangaScore = "themangascore" + private val intentMangaImageUrl = "themangaimageurl" - private val mangaVolumes = "themangavolumes" - private val mangaStartDate = "themangastartdate" - private val mangaEndDate = "themangaenddate" + private val intentMangaVolumes = "themangavolumes" + private val intentMangaStartDate = "themangastartdate" + private val intentMangaEndDate = "themangaenddate" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_detail_top_manga) - val mangaId = intent.getStringExtra(mangaId) - val mangaTitle = intent.getStringExtra(mangaTitle) - val mangaRank = intent.getStringExtra(mangaRank) - val mangaScore = intent.getStringExtra(mangaScore) - val mangaImage = intent.getStringExtra(mangaImageUrl) + val mangaId = intent.getStringExtra(intentMangaId) + val mangaTitle = intent.getStringExtra(intentMangaTitle) + val mangaRank = intent.getStringExtra(intentMangaRank) + val mangaScore = intent.getStringExtra(intentMangaScore) + val mangaImage = intent.getStringExtra(intentMangaImageUrl) - val mangaVolumes = intent.getStringExtra(mangaVolumes) - val mangaStartDate = intent.getStringExtra(mangaStartDate) - val mangaEndDate = intent.getStringExtra(mangaEndDate) + val mangaVolumes = intent.getStringExtra(intentMangaVolumes) + val mangaStartDate = intent.getStringExtra(intentMangaStartDate) + val mangaEndDate = intent.getStringExtra(intentMangaEndDate) val tvId: TextView = findViewById(R.id.tv_detail_id) val tvTitle: TextView = findViewById(R.id.tv_detail_title) @@ -73,14 +72,16 @@ class DetailTopMangaActivity : AppCompatActivity() { .apply(RequestOptions().override(400)) .into(ivImage) + //not used in the recyclerview tvVolumes.text = mangaVolumes tvStartDate.text = mangaStartDate tvEndDate.text = mangaEndDate - makeApiCall(base_url) + //taking the API's fields I want and displaying them + makeApiCall(baseUrl, mangaId.toString()) } - private fun makeApiCall(BASE_URL: String) { + private fun makeApiCall(BASE_URL: String, mangaId: String) { val retrofit = Retrofit.Builder() .baseUrl(BASE_URL) @@ -88,13 +89,13 @@ class DetailTopMangaActivity : AppCompatActivity() { .build() val service = retrofit.create(MangaApi::class.java) - val call = service.getMangaData() + val call = service.getMangaData(mangaId) call.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { 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 + val manga = response.body() //getting the RestMangaResponse fields showDetail(manga!!) } else { -- cgit v1.2.3