aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2021-02-18 19:42:15 +0100
committerClyhtsuriva <aimeric@adjutor.xyz>2021-02-18 19:42:15 +0100
commitf4d8a9c6fa8f805a9dedb626ef343aa37943c079 (patch)
tree2b461dc110c29f5d87aeb7dab3b301736f8845b7 /app/src/main
parent017ed2bebc74a8d9d8f8165dbab8faaee53572eb (diff)
Implementing API calls for the top mangas.feature/api_server_call
Test and Debug with snackbar : ok Adding internet access. Removing useless News class.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/AndroidManifest.xml2
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/News.kt7
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt15
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/TopManga.kt30
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/TopMangaApi.kt11
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt51
6 files changed, 109 insertions, 7 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 68bca97..105fdfd 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="xyz.adjutor.aniki">
+ <uses-permission android:name="android.permission.INTERNET"/>
+
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
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 d38a556..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..8cd5f2b
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/RestTopMangaResponse.kt
@@ -0,0 +1,15 @@
+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 = ArrayList<TopManga>()
+} \ 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..acedf56
--- /dev/null
+++ b/app/src/main/java/xyz/adjutor/aniki/TopManga.kt
@@ -0,0 +1,30 @@
+package xyz.adjutor.aniki
+
+import com.google.gson.annotations.SerializedName
+
+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/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
index ac585c7..9496053 100644
--- a/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/TopMangaPage.kt
@@ -9,6 +9,13 @@ 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() {
@@ -22,6 +29,10 @@ class TopMangaPage : Fragment() {
// Retrieves data from mangasource
val mangaList = MangaSource(view.context).getMangaList()
+
+ makeApiCall(base_url)
+
+
val recyclerView: RecyclerView = view.findViewById(R.id.recycler_view)
recyclerView.setHasFixedSize(true)
recyclerView.layoutManager = LinearLayoutManager(view.context)
@@ -37,4 +48,44 @@ class TopMangaPage : Fragment() {
}
}
+
+ fun makeApiCall(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()
+ Snackbar.make(requireView(), "HA? YOU THOUGHT IT WAS AN ERROR !? BUT IT WAS I, API !", Snackbar.LENGTH_LONG)
+ .setAction("Action", null).show()
+ } else {
+ showError()
+ }
+ }
+
+ 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/"
+ }
+
} \ No newline at end of file