diff options
Diffstat (limited to 'app')
16 files changed, 295 insertions, 33 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() { diff --git a/app/src/main/res/layout/home_page.xml b/app/src/main/res/layout/home_page.xml index 68d9f81..564d7da 100644 --- a/app/src/main/res/layout/home_page.xml +++ b/app/src/main/res/layout/home_page.xml @@ -30,6 +30,17 @@ app:layout_constraintTop_toBottomOf="@id/tv_title" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toStartOf="@id/button_top_anime" + /> + + <Button + android:id="@+id/button_top_anime" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/top_anime" + app:layout_constraintTop_toBottomOf="@id/tv_title" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintStart_toEndOf="@id/button_top_manga" app:layout_constraintEnd_toEndOf="parent" /> diff --git a/app/src/main/res/layout/top_anime_page.xml b/app/src/main/res/layout/top_anime_page.xml new file mode 100644 index 0000000..4b6a58f --- /dev/null +++ b/app/src/main/res/layout/top_anime_page.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".topanime.TopAnimePage" + android:background="@color/very_dark_purple"> + + <androidx.recyclerview.widget.RecyclerView + android:id="@+id/recycler_view" + android:layout_width="0dp" + android:layout_height="0dp" + app:layout_constraintBottom_toTopOf="@+id/button_home" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:listitem="@layout/item_layout" /> + + <Button + android:id="@+id/button_home" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/home" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + /> + +</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/top_manga_page.xml b/app/src/main/res/layout/top_manga_page.xml index ba19596..95c9161 100644 --- a/app/src/main/res/layout/top_manga_page.xml +++ b/app/src/main/res/layout/top_manga_page.xml @@ -5,7 +5,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".TopMangaPage" + tools:context=".topmanga.TopMangaPage" android:background="@color/very_dark_purple"> <androidx.recyclerview.widget.RecyclerView diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index d8d3b26..132de49 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -12,41 +12,17 @@ tools:layout="@layout/home_page"> <action - android:id="@+id/action_HomePage_to_NewsPage" - app:destination="@id/NewsPage" /> - <action - android:id="@+id/action_HomePage_to_ArticlePage" - app:destination="@id/ArticlePage" /> - <action android:id="@+id/action_HomePage_to_TopMangaPage" app:destination="@id/TopMangaPage" /> - </fragment> - - <fragment - android:id="@+id/NewsPage" - android:name="xyz.adjutor.aniki.NewsPage" - android:label="@string/news_page_label" - tools:layout="@layout/news_page"> - <action - android:id="@+id/action_NewsPage_to_HomePage" - app:destination="@id/HomePage" /> - </fragment> + android:id="@+id/action_HomePage_to_TopAnimePage" + app:destination="@id/TopAnimePage" /> - <fragment - android:id="@+id/ArticlePage" - android:name="xyz.adjutor.aniki.ArticlePage" - android:label="@string/article_page_label" - tools:layout="@layout/article_page"> - - <action - android:id="@+id/action_ArticlePage_to_HomePage" - app:destination="@id/HomePage" /> </fragment> <fragment android:id="@+id/TopMangaPage" - android:name="xyz.adjutor.aniki.TopMangaPage" + android:name="xyz.adjutor.aniki.topmanga.TopMangaPage" android:label="@string/top_manga_page_label" tools:layout="@layout/top_manga_page"> @@ -54,5 +30,15 @@ android:id="@+id/action_TopMangaPage_to_HomePage" app:destination="@id/HomePage" /> </fragment> + <fragment + android:id="@+id/TopAnimePage" + android:name="xyz.adjutor.aniki.topanime.TopAnimePage" + android:label="@string/top_anime_page_label" + tools:layout="@layout/top_anime_page"> + + <action + android:id="@+id/action_TopAnimePage_to_HomePage" + app:destination="@id/HomePage" /> + </fragment> </navigation>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5301008..403a883 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -16,6 +16,8 @@ <string name="rv_rank">0</string> <string name="rv_image">image</string> <string name="manga_image_content_description">Image of manga</string> + <string name="top_anime_page_label">Top Anime Page</string> + <string name="top_anime">Top Anime</string> <string-array name="manga_array"> <item>Dragon Ball</item> |