aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/xyz/adjutor
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2021-02-19 14:04:59 +0100
committerClyhtsuriva <aimeric@adjutor.xyz>2021-02-19 14:04:59 +0100
commit2aaa50c8303018f89da461750d5577902bc87357 (patch)
tree1d4e58436f7d88c82b588c86fe99fce74ea09de3 /app/src/main/java/xyz/adjutor
parentc519b3f99d5b03f8c52c8d881033c8d5ec6b8b6a (diff)
parentfa849021bf137fc4b245a8c0e7a2a8fc46d574df (diff)
Merge branch 'release/1.0'v1.0.0
Diffstat (limited to 'app/src/main/java/xyz/adjutor')
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/HomePage.kt (renamed from app/src/main/java/xyz/adjutor/aniki/FirstFragment.kt)12
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/MainActivity.kt7
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/News.kt7
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt19
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/SecondFragment.kt31
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/TopManga.kt31
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/TopMangaAdapter.kt69
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/TopMangaApi.kt11
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt92
9 files changed, 226 insertions, 53 deletions
diff --git a/app/src/main/java/xyz/adjutor/aniki/FirstFragment.kt b/app/src/main/java/xyz/adjutor/aniki/HomePage.kt
index 05e5673..b6d45c3 100644
--- a/app/src/main/java/xyz/adjutor/aniki/FirstFragment.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/HomePage.kt
@@ -8,24 +8,20 @@ import android.view.ViewGroup
import android.widget.Button
import androidx.navigation.fragment.findNavController
-/**
- * A simple [Fragment] subclass as the default destination in the navigation.
- */
-class FirstFragment : Fragment() {
+class HomePage : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
- return inflater.inflate(R.layout.fragment_first, container, false)
+ return inflater.inflate(R.layout.home_page, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
-
- view.findViewById<Button>(R.id.button_first).setOnClickListener {
- findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment)
+ view.findViewById<Button>(R.id.button_top_manga).setOnClickListener {
+ findNavController().navigate(R.id.action_HomePage_to_TopMangaPage)
}
}
} \ No newline at end of file
diff --git a/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt b/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt
index f4ded55..50cd24f 100644
--- a/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/MainActivity.kt
@@ -13,13 +13,6 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(findViewById(R.id.toolbar))
-
- findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { view ->
- Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
- .setAction("Action", null).show()
- }
- val industryNews = News(0,"Horror Manga Ajin Ends Nine-Year Serialization","Gamon Sakurai's Ajin (Ajin: Demi-Human) manga ended its nine-year run in the March issue of good! Afternoon on Friday.")
-
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
diff --git a/app/src/main/java/xyz/adjutor/aniki/News.kt b/app/src/main/java/xyz/adjutor/aniki/News.kt
deleted file mode 100644
index dea3516..0000000
--- a/app/src/main/java/xyz/adjutor/aniki/News.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package xyz.adjutor.aniki
-
-data class News (
- val id: Int,
- val title: String,
- val description: String
-) \ 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/RestTopMangaResponse.kt
new file mode 100644
index 0000000..0a7ebc8
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt
@@ -0,0 +1,19 @@
+package xyz.adjutor.aniki
+
+import com.google.gson.annotations.SerializedName
+
+class RestTopMangaResponse {
+
+ @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<TopManga>? = null
+
+ fun getResults(): List<TopManga> {
+ return top!!
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/xyz/adjutor/aniki/SecondFragment.kt b/app/src/main/java/xyz/adjutor/aniki/SecondFragment.kt
deleted file mode 100644
index a994c61..0000000
--- a/app/src/main/java/xyz/adjutor/aniki/SecondFragment.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-package xyz.adjutor.aniki
-
-import android.os.Bundle
-import androidx.fragment.app.Fragment
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import android.widget.Button
-import androidx.navigation.fragment.findNavController
-
-/**
- * A simple [Fragment] subclass as the second destination in the navigation.
- */
-class SecondFragment : Fragment() {
-
- override fun onCreateView(
- inflater: LayoutInflater, container: ViewGroup?,
- savedInstanceState: Bundle?
- ): View? {
- // Inflate the layout for this fragment
- return inflater.inflate(R.layout.fragment_second, container, false)
- }
-
- override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- super.onViewCreated(view, savedInstanceState)
-
- view.findViewById<Button>(R.id.button_second).setOnClickListener {
- findNavController().navigate(R.id.action_SecondFragment_to_FirstFragment)
- }
- }
-} \ No newline at end of file
diff --git a/app/src/main/java/xyz/adjutor/aniki/TopManga.kt b/app/src/main/java/xyz/adjutor/aniki/TopManga.kt
new file mode 100644
index 0000000..9cba192
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/TopManga.kt
@@ -0,0 +1,31 @@
+package xyz.adjutor.aniki
+
+import com.google.gson.annotations.SerializedName
+
+//Content of the top field from the api of top manga
+class TopManga{
+
+ @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("volumes")
+ 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/TopMangaAdapter.kt b/app/src/main/java/xyz/adjutor/aniki/TopMangaAdapter.kt
new file mode 100644
index 0000000..1478111
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/TopMangaAdapter.kt
@@ -0,0 +1,69 @@
+@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
+import android.widget.ImageView
+import android.widget.TextView
+import androidx.recyclerview.widget.RecyclerView
+
+class TopMangaAdapter(val mangaList: List<TopManga>) :
+ RecyclerView.Adapter<TopMangaAdapter.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 mangaImage: ImageView = itemView.findViewById(R.id.iv_image)
+
+ }
+
+ // 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: TopManga = mangaList[position]
+ 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/TopMangaApi.kt b/app/src/main/java/xyz/adjutor/aniki/TopMangaApi.kt
new file mode 100644
index 0000000..b760233
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/TopMangaApi.kt
@@ -0,0 +1,11 @@
+package xyz.adjutor.aniki
+
+import retrofit2.http.GET
+import retrofit2.Call
+
+interface TopMangaApi {
+
+ @GET("v3/top/manga")
+ fun getTopMangaData(): Call<RestTopMangaResponse>
+
+} \ 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
new file mode 100644
index 0000000..6606b6c
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt
@@ -0,0 +1,92 @@
+package xyz.adjutor.aniki
+
+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
+
+class TopMangaPage : Fragment() {
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ // Inflate the layout for this fragment
+ val view = inflater.inflate(R.layout.top_manga_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_TopMangaPage_to_HomePage)
+ }
+
+ }
+
+ //display the recyclerview
+ fun showList(view: View, mangaList: List<TopManga> ){
+ val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view)
+ recyclerView.setHasFixedSize(true)
+ recyclerView.layoutManager = LinearLayoutManager(view.context)
+ recyclerView.adapter = TopMangaAdapter(mangaList)
+ }
+
+ 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){ //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() //a snackbar
+ }
+ }
+
+ override fun onFailure(call: Call<RestTopMangaResponse>, 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