diff options
Diffstat (limited to 'app/src/main/java/xyz/adjutor')
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt | 33 | ||||
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/MangaSource.kt | 11 | ||||
-rw-r--r-- | app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt | 19 |
3 files changed, 39 insertions, 24 deletions
diff --git a/app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt index f378c65..3116062 100644 --- a/app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt +++ b/app/src/main/java/xyz/adjutor/aniki/MangaAdapter.kt @@ -1,5 +1,12 @@ +@file:Suppress("DEPRECATION") + package xyz.adjutor.aniki +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 @@ -34,9 +41,29 @@ class MangaAdapter(val mangaList: List<TopManga>) : // Displays data at a certain position override fun onBindViewHolder(holder: MangaViewHolder, position: Int) { val currentManga: TopManga = mangaList[position] - holder.mangaTitle.text = currentManga.title //use specific json data - holder.mangaRank.text = currentManga.rank.toString() //replace by the actual rank - //holder.mangaImage.setImageResource(mangaList[position]) //replace by the manga image + holder.mangaTitle.text = currentManga.title + holder.mangaRank.text = currentManga.rank.toString() + DownloadImageFromInternet(holder.mangaImage).execute(currentManga.image_url) + } + + @SuppressLint("StaticFieldLeak") + private inner class DownloadImageFromInternet(var imageView: ImageView) : AsyncTask<String, Void, Bitmap?>() { + 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) + } } } diff --git a/app/src/main/java/xyz/adjutor/aniki/MangaSource.kt b/app/src/main/java/xyz/adjutor/aniki/MangaSource.kt deleted file mode 100644 index 86e46e2..0000000 --- a/app/src/main/java/xyz/adjutor/aniki/MangaSource.kt +++ /dev/null @@ -1,11 +0,0 @@ -package xyz.adjutor.aniki - -import android.content.Context - -class MangaSource(val context: Context) { - fun getMangaList(): Array<String> { - - // Return manga list from string resources - return context.resources.getStringArray(R.array.manga_array) - } -}
\ No newline at end of file diff --git a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt index 45e714a..ee8a510 100644 --- a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt +++ b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt @@ -48,27 +48,26 @@ class TopMangaPage : Fragment() { } fun makeApiCall(view: View, BASE_URL: String) { + val gson = GsonBuilder() .setLenient() .create() + val retrofit = Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create(gson)) .build() + val service = retrofit.create(TopMangaApi::class.java) val call = service.getTopMangaData() + call.enqueue(object : Callback<RestTopMangaResponse> { override fun onResponse(call: Call<RestTopMangaResponse>, response: Response<RestTopMangaResponse>) { - if(response.isSuccessful && response.body() != null){ - val topMangaResponse = response.body()!!.getResults() - Snackbar.make(requireView(), "HA? YOU THOUGHT IT WAS AN ERROR !? BUT IT WAS I, API !", Snackbar.LENGTH_LONG) - .setAction("Action", null).show() - // Retrieves data from mangasource - //val mangaList = MangaSource(view.context).getMangaList() - val mangaList=topMangaResponse - showList(view, mangaList) + if(response.isSuccessful && response.body() != null){ //if the code returned is >= 200 and < 300 AND the the body ain't empty + val mangaList = response.body()!!.getResults() //getting the "top" field containing our list of TopMangas + showList(view, mangaList) // calling the method in charge of displaying on the recyclerview } else { - showError() + showError() //a snackbar } } @@ -85,7 +84,7 @@ class TopMangaPage : Fragment() { } companion object { - var base_url = "https://api.jikan.moe/" + var base_url = "https://api.jikan.moe/" //the api's base url } }
\ No newline at end of file |