diff options
author | Clyhtsuriva <aimeric@adjutor.xyz> | 2021-02-22 00:00:12 +0100 |
---|---|---|
committer | Clyhtsuriva <aimeric@adjutor.xyz> | 2021-02-22 00:00:12 +0100 |
commit | 56f69f774bc2a7ef645169f85b89934255c29cf9 (patch) | |
tree | f6a41952dc69088d6d9c68b25887c5960ce5cd74 /app | |
parent | 94ab3bbeb21049ac1be128ee00dbae1570346123 (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')
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/manga/MangaAdapter.kt | 58 | ||||
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/manga/MangaApi.kt | 4 | ||||
-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.kt | 2 | ||||
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/topmanga/DetailTopMangaActivity.kt | 72 | ||||
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt | 4 | ||||
-rw-r--r-- | app/src/main/res/layout/activity_detail_top_manga.xml | 34 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 16 |
8 files changed, 107 insertions, 85 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" diff --git a/app/src/main/res/layout/activity_detail_top_manga.xml b/app/src/main/res/layout/activity_detail_top_manga.xml index b9a5dd7..ffb9791 100644 --- a/app/src/main/res/layout/activity_detail_top_manga.xml +++ b/app/src/main/res/layout/activity_detail_top_manga.xml @@ -104,9 +104,10 @@ android:id="@+id/cv_more_infos" android:layout_width="match_parent" android:layout_height="wrap_content" - app:layout_constraintTop_toBottomOf="@id/cv_header" android:layout_margin="4sp" - app:cardBackgroundColor="@color/black"> + app:cardBackgroundColor="@color/black" + app:layout_constraintTop_toBottomOf="@id/cv_header"> + <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent" @@ -120,8 +121,9 @@ android:textColor="@color/strong_pink" app:layout_constraintBottom_toBottomOf="@id/tv_volumes" app:layout_constraintEnd_toStartOf="@id/tv_volumes" - app:layout_constraintTop_toTopOf="@id/tv_volumes" - app:layout_constraintStart_toStartOf="parent"/> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="@id/tv_volumes" /> + <TextView android:id="@+id/tv_volumes" android:layout_width="wrap_content" @@ -140,6 +142,7 @@ app:layout_constraintBottom_toBottomOf="@id/tv_chapters" app:layout_constraintEnd_toStartOf="@id/tv_chapters" app:layout_constraintTop_toTopOf="@id/tv_chapters" /> + <TextView android:id="@+id/tv_chapters" android:layout_width="wrap_content" @@ -159,6 +162,7 @@ app:layout_constraintBottom_toBottomOf="@id/tv_start_date" app:layout_constraintEnd_toStartOf="@id/tv_start_date" app:layout_constraintTop_toTopOf="@id/tv_start_date" /> + <TextView android:id="@+id/tv_start_date" android:layout_width="wrap_content" @@ -177,6 +181,7 @@ app:layout_constraintBottom_toBottomOf="@id/tv_end_date" app:layout_constraintEnd_toStartOf="@id/tv_end_date" app:layout_constraintTop_toTopOf="@id/tv_end_date" /> + <TextView android:id="@+id/tv_end_date" android:layout_width="wrap_content" @@ -201,6 +206,14 @@ android:layout_height="match_parent" android:padding="10dp"> + <TextView + android:id="@+id/tv_text_synopsis" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/text_synopsis" + android:textColor="@color/strong_pink" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintStart_toStartOf="parent"/> <TextView android:id="@+id/tv_synopsis" android:layout_width="wrap_content" @@ -210,7 +223,7 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent"/> + app:layout_constraintTop_toBottomOf="@id/tv_text_synopsis"/> </androidx.constraintlayout.widget.ConstraintLayout> </androidx.cardview.widget.CardView> @@ -226,6 +239,15 @@ android:layout_height="match_parent" android:padding="10dp"> + + <TextView + android:id="@+id/tv_text_background" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/text_background" + android:textColor="@color/strong_pink" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintStart_toStartOf="parent"/> <TextView android:id="@+id/tv_background" android:layout_width="wrap_content" @@ -235,7 +257,7 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent"/> + app:layout_constraintTop_toBottomOf="@id/tv_text_background"/> </androidx.constraintlayout.widget.ConstraintLayout> </androidx.cardview.widget.CardView> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 100335d..311e39b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,17 +17,19 @@ <string name="score">00.00</string> <string name="synopsis">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</string> - <string name="text_mal_id">"MAL ID : "</string> - <string name="text_rank">"Rank : "</string> - <string name="text_score">"Score : "</string> + <string name="text_mal_id">"MAL ID "</string> + <string name="text_rank">"Rank "</string> + <string name="text_score">"Score "</string> <string name="volumes">000</string> - <string name="text_volumes">"Volumes : "</string> - <string name="text_chapters">"Chapters: "</string> + <string name="text_volumes">"Volumes "</string> + <string name="text_chapters">"Chapters "</string> <string name="chapters">0000</string> - <string name="text_start_date">"Start date : "</string> - <string name="text_end_date">"End date : "</string> + <string name="text_start_date">"Start date "</string> + <string name="text_end_date">"End date "</string> <string name="start_date">Jan 0000</string> <string name="end_date">Dec 0000</string> <string name="background">Cras molestie turpis at lorem rutrum vehicula. Fusce rutrum, enim sed laoreet semper, tortor quam semper dui, id bibendum lacus quam vitae neque.</string> + <string name="text_synopsis">Synopsis</string> + <string name="text_background">Background</string> </resources>
\ No newline at end of file |