From 00ac626b27076397b79bcd4bdd934ab861ff05a5 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Fri, 19 Feb 2021 19:46:42 +0100 Subject: Implementing TopAnime Copied the topmanga folder and transformed everything in it into top anime. --- .../xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt (limited to 'app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt') diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt new file mode 100644 index 0000000..a036c15 --- /dev/null +++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt @@ -0,0 +1,72 @@ +@file:Suppress("DEPRECATION") + +package xyz.adjutor.aniki.topanime + +import android.annotation.SuppressLint +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.os.AsyncTask +import android.util.Log +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 xyz.adjutor.aniki.R +import xyz.adjutor.aniki.topanime.TopAnime +import xyz.adjutor.aniki.topanime.TopAnimeAdapter + +class TopAnimeAdapter(val animeList: List) : + RecyclerView.Adapter() { + + // Describes an item view and its place within the RecyclerView + class AnimeViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val animeTitle: TextView = itemView.findViewById(R.id.tv_title) + val animeRank: TextView = itemView.findViewById(R.id.tv_rank) + val animeImage: ImageView = itemView.findViewById(R.id.iv_image) + + } + + // Returns a new ViewHolder + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): AnimeViewHolder { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.item_layout, parent, false) + + return AnimeViewHolder(view) + } + + // Returns size of data list + override fun getItemCount(): Int { + return animeList.size + } + + // Displays data at a certain position + override fun onBindViewHolder(holder: AnimeViewHolder, position: Int) { + val currentAnime: TopAnime = animeList[position] + holder.animeTitle.text = currentAnime.title + holder.animeRank.text = currentAnime.rank.toString() + DownloadImageFromInternet(holder.animeImage).execute(currentAnime.image_url) + } + + @SuppressLint("StaticFieldLeak") + private inner class DownloadImageFromInternet(var imageView: ImageView) : AsyncTask() { + override fun doInBackground(vararg urls: String): Bitmap? { + val imageURL = urls[0] + var image: Bitmap? = null + try { + val `in` = java.net.URL(imageURL).openStream() + image = BitmapFactory.decodeStream(`in`) + } + catch (e: Exception) { + Log.e("Error Message", e.message.toString()) + e.printStackTrace() + } + return image + } + override fun onPostExecute(result: Bitmap?) { + imageView.setImageBitmap(result) + } + } +} + -- cgit v1.2.3