summaryrefslogtreecommitdiff
path: root/app/src/main/java/xyz/adjutor
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/xyz/adjutor')
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/HomePage.kt4
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topanime/RestTopAnimeResponse.kt19
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt31
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeAdapter.kt72
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeApi.kt11
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt93
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topmanga/RestTopMangaResponse.kt (renamed from app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt)2
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topmanga/TopManga.kt (renamed from app/src/main/java/xyz/adjutor/aniki/TopManga.kt)2
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt (renamed from app/src/main/java/xyz/adjutor/aniki/TopMangaAdapter.kt)3
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaApi.kt (renamed from app/src/main/java/xyz/adjutor/aniki/TopMangaApi.kt)2
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaPage.kt (renamed from app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt)3
11 files changed, 237 insertions, 5 deletions
diff --git a/app/src/main/java/xyz/adjutor/aniki/HomePage.kt b/app/src/main/java/xyz/adjutor/aniki/HomePage.kt
index b6d45c3..59d7c62 100644
--- a/app/src/main/java/xyz/adjutor/aniki/HomePage.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/HomePage.kt
@@ -20,8 +20,12 @@ class HomePage : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
+
view.findViewById<Button>(R.id.button_top_manga).setOnClickListener {
findNavController().navigate(R.id.action_HomePage_to_TopMangaPage)
}
+ view.findViewById<Button>(R.id.button_top_anime).setOnClickListener {
+ findNavController().navigate(R.id.action_HomePage_to_TopAnimePage)
+ }
}
} \ No newline at end of file
diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/RestTopAnimeResponse.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/RestTopAnimeResponse.kt
new file mode 100644
index 0000000..c711631
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/topanime/RestTopAnimeResponse.kt
@@ -0,0 +1,19 @@
+package xyz.adjutor.aniki.topanime
+
+import com.google.gson.annotations.SerializedName
+
+class RestTopAnimeResponse {
+
+ @SerializedName("request_hash")
+ var request_hash: String? = null
+ @SerializedName("request_cached")
+ var request_cached: Boolean? = null
+ @SerializedName("request_cached_expiry")
+ var request_cached_expiry: Int? = null
+ @SerializedName("top")
+ var top: List<TopAnime>? = null
+
+ fun getResults(): List<TopAnime> {
+ return top!!
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt
new file mode 100644
index 0000000..a428841
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnime.kt
@@ -0,0 +1,31 @@
+package xyz.adjutor.aniki.topanime
+
+import com.google.gson.annotations.SerializedName
+
+//Content of the top field from the api of top manga
+class TopAnime{
+
+ @SerializedName("mal_id")
+ var mal_id: Int? = null
+ @SerializedName("rank")
+ var rank: Int? = null
+ @SerializedName("title")
+ var title: String? = null
+ @SerializedName("url")
+ var url: String? = null
+ @SerializedName("type")
+ var type: String? = null
+ @SerializedName("episodes")
+ var volumes: Int? = null
+ @SerializedName("start_date")
+ var start_date: String? = null
+ @SerializedName("end_date")
+ var end_date: String? = null
+ @SerializedName("members")
+ var members: Int? = null
+ @SerializedName("score")
+ var score: Float? = null
+ @SerializedName("image_url")
+ var image_url: String? = 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
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<TopAnime>) :
+ RecyclerView.Adapter<TopAnimeAdapter.AnimeViewHolder>() {
+
+ // 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<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/topanime/TopAnimeApi.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeApi.kt
new file mode 100644
index 0000000..6d8669c
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimeApi.kt
@@ -0,0 +1,11 @@
+package xyz.adjutor.aniki.topanime
+
+import retrofit2.http.GET
+import retrofit2.Call
+
+interface TopAnimeApi {
+
+ @GET("v3/top/anime")
+ fun getTopAnimeData(): Call<RestTopAnimeResponse>
+
+} \ No newline at end of file
diff --git a/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt
new file mode 100644
index 0000000..9e86191
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/topanime/TopAnimePage.kt
@@ -0,0 +1,93 @@
+package xyz.adjutor.aniki.topanime
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.Button
+import androidx.fragment.app.Fragment
+import androidx.navigation.fragment.findNavController
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+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
+
+class TopAnimePage : Fragment() {
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ // Inflate the layout for this fragment
+ val view = inflater.inflate(R.layout.top_anime_page, container, false)
+
+ makeApiCall(view, base_url)
+
+ return view
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+
+ //button to return to the home page
+ view.findViewById<Button>(R.id.button_home).setOnClickListener {
+ findNavController().navigate(R.id.action_TopAnimePage_to_HomePage)
+ }
+
+ }
+
+ //display the recyclerview
+ fun showList(view: View, animeList: List<TopAnime> ){
+ val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view)
+ recyclerView.setHasFixedSize(true)
+ recyclerView.layoutManager = LinearLayoutManager(view.context)
+ recyclerView.adapter = TopAnimeAdapter(animeList)
+ }
+
+ 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(TopAnimeApi::class.java)
+ val call = service.getTopAnimeData()
+
+ call.enqueue(object : Callback<RestTopAnimeResponse> {
+ override fun onResponse(call: Call<RestTopAnimeResponse>, response: Response<RestTopAnimeResponse>) {
+ if(response.isSuccessful && response.body() != null){ //if the code returned is >= 200 and < 300 AND the the body ain't empty
+ val animeList = response.body()!!.getResults() //getting the "top" field containing our list of TopAnimes
+ showList(view, animeList) // calling the method in charge of displaying on the recyclerview
+ } else {
+ showError() //a snackbar
+ }
+ }
+
+ override fun onFailure(call: Call<RestTopAnimeResponse>, t: Throwable) {
+ showError()
+ }
+
+ })
+ }
+
+ private fun showError() {
+ Snackbar.make(requireView(), "HA? YOU THOUGHT IT WAS AN API !? BUT IT WAS I, ERROR !", Snackbar.LENGTH_LONG)
+ .setAction("Action", null).show()
+ }
+
+ companion object {
+ var base_url = "https://api.jikan.moe/" //the api's base url
+ }
+
+} \ No newline at end of file
diff --git a/app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/RestTopMangaResponse.kt
index 0a7ebc8..897e8a2 100644
--- a/app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/RestTopMangaResponse.kt
@@ -1,4 +1,4 @@
-package xyz.adjutor.aniki
+package xyz.adjutor.aniki.topmanga
import com.google.gson.annotations.SerializedName
diff --git a/app/src/main/java/xyz/adjutor/aniki/TopManga.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopManga.kt
index 9cba192..edf561d 100644
--- a/app/src/main/java/xyz/adjutor/aniki/TopManga.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopManga.kt
@@ -1,4 +1,4 @@
-package xyz.adjutor.aniki
+package xyz.adjutor.aniki.topmanga
import com.google.gson.annotations.SerializedName
diff --git a/app/src/main/java/xyz/adjutor/aniki/TopMangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt
index 1478111..18fd7a0 100644
--- a/app/src/main/java/xyz/adjutor/aniki/TopMangaAdapter.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaAdapter.kt
@@ -1,6 +1,6 @@
@file:Suppress("DEPRECATION")
-package xyz.adjutor.aniki
+package xyz.adjutor.aniki.topmanga
import android.annotation.SuppressLint
import android.graphics.Bitmap
@@ -13,6 +13,7 @@ import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
+import xyz.adjutor.aniki.R
class TopMangaAdapter(val mangaList: List<TopManga>) :
RecyclerView.Adapter<TopMangaAdapter.MangaViewHolder>() {
diff --git a/app/src/main/java/xyz/adjutor/aniki/TopMangaApi.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaApi.kt
index b760233..69c4cdd 100644
--- a/app/src/main/java/xyz/adjutor/aniki/TopMangaApi.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaApi.kt
@@ -1,4 +1,4 @@
-package xyz.adjutor.aniki
+package xyz.adjutor.aniki.topmanga
import retrofit2.http.GET
import retrofit2.Call
diff --git a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaPage.kt
index 6606b6c..e4cd20d 100644
--- a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/topmanga/TopMangaPage.kt
@@ -1,4 +1,4 @@
-package xyz.adjutor.aniki
+package xyz.adjutor.aniki.topmanga
import android.os.Bundle
import android.view.LayoutInflater
@@ -16,6 +16,7 @@ import retrofit2.Callback
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
+import xyz.adjutor.aniki.R
class TopMangaPage : Fragment() {