aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2021-03-23 11:19:37 +0100
committerClyhtsuriva <aimeric@adjutor.xyz>2021-03-23 11:19:37 +0100
commita056ae61750af9f4fa4e3538dfaebc73bd13a82f (patch)
tree3008f3643180e237bd735cce7a4ddf72f883acf8
parent436a01b64a3c2500aa8801a72f95dfc40b0b33b7 (diff)
parentbd885788c79cfa37bb2ff02faf4ae2516b87b5dd (diff)
Merge branch 'feature/multiple_top_pages' into develop
-rw-r--r--README.md4
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/anime/topanime/TopAnimeApi.kt5
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/anime/topanime/TopAnimePage.kt36
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/manga/topmanga/TopMangaApi.kt5
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/manga/topmanga/TopMangaPage.kt37
-rw-r--r--app/src/main/res/layout/top_anime_page.xml16
-rw-r--r--app/src/main/res/layout/top_manga_page.xml16
-rw-r--r--app/src/main/res/values/strings.xml2
8 files changed, 104 insertions, 17 deletions
diff --git a/README.md b/README.md
index ad56981..a1f6dcf 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,6 @@
List of elements used in top manga and top anime with a recycler view
-SwipeRefresh used to refresh the list of data.
+SwipeRefresh used to refresh the list of data of the frist page.
+Use the button (prev and next) to navigate with ease through the pages.
Details of a chosen element from the recycler view with an intent object
Title, synopsys and background clickable.
@@ -10,6 +11,7 @@ They display the data in a recycler view similar to the tops.
A feature has been added that hides the keyboard when the query is submitted by the user.
We can also submit the query by clicking the "search" button that replace the "return" one.
Clicking on a searched item also opens a detail page of it.
+I'm not adding the "multiple pages" feature to the search section because I assume the user should use a more precise query if what he's looking for doesn't show up in the first page.
Multiple calls of the REST API from jikan.moe.
Usage of :
diff --git a/app/src/main/java/xyz/adjutor/aniki/anime/topanime/TopAnimeApi.kt b/app/src/main/java/xyz/adjutor/aniki/anime/topanime/TopAnimeApi.kt
index 8e44e77..2e6b1e0 100644
--- a/app/src/main/java/xyz/adjutor/aniki/anime/topanime/TopAnimeApi.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/anime/topanime/TopAnimeApi.kt
@@ -2,10 +2,11 @@ package xyz.adjutor.aniki.anime.topanime
import retrofit2.Call
import retrofit2.http.GET
+import retrofit2.http.Path
interface TopAnimeApi {
- @GET("v3/top/anime")
- fun getTopAnimeData(): Call<TopAnimeResponse>
+ @GET("v3/top/anime/{page}")
+ fun getTopAnimeData(@Path("page") page: Int): Call<TopAnimeResponse>
} \ No newline at end of file
diff --git a/app/src/main/java/xyz/adjutor/aniki/anime/topanime/TopAnimePage.kt b/app/src/main/java/xyz/adjutor/aniki/anime/topanime/TopAnimePage.kt
index d62e5b2..babb7c1 100644
--- a/app/src/main/java/xyz/adjutor/aniki/anime/topanime/TopAnimePage.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/anime/topanime/TopAnimePage.kt
@@ -31,6 +31,7 @@ class TopAnimePage : Fragment() {
.setLenient()
.create()
var baseUrl = "https://api.jikan.moe/" //the api's base url
+ var page: Int = 1
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
@@ -45,10 +46,11 @@ class TopAnimePage : Fragment() {
if (animeList != null) {
showList(view, animeList)
} else {
- makeApiCall(view, baseUrl)
+ makeApiCall(view, baseUrl, 1)
}
return view
+
}
private fun getDataFromCache(): List<TopAnime>? {
@@ -71,16 +73,34 @@ class TopAnimePage : Fragment() {
view.findViewById<Button>(R.id.button_home).setOnClickListener {
findNavController().navigate(R.id.action_TopAnimePage_to_HomePage)
}
+ view.findViewById<Button>(R.id.button_prev).setOnClickListener {
+ if (page > 1) {
+ page -= 1
+ makeApiCall(view, baseUrl, page)
+ Snackbar.make(requireView(), "Page $page has been loaded.", Snackbar.LENGTH_SHORT)
+ .setAction("Action", null).show()
+ } else {
+ Snackbar.make(requireView(), "You're already on page 1.", Snackbar.LENGTH_SHORT)
+ .setAction("Action", null).show()
+ }
+ }
+ view.findViewById<Button>(R.id.button_next).setOnClickListener {
+ page += 1
+ makeApiCall(view, baseUrl, page)
+ Snackbar.make(requireView(), "Page $page has been loaded.", Snackbar.LENGTH_SHORT)
+ .setAction("Action", null).show()
+ }
fun updateList() {
- makeApiCall(view, baseUrl)
- Snackbar.make(requireView(), "Data refreshed", Snackbar.LENGTH_LONG)
+ makeApiCall(view, baseUrl, 1)
+ Snackbar.make(requireView(), "Data refreshed", Snackbar.LENGTH_SHORT)
.setAction("Action", null).show()
}
val swipeRefresh: SwipeRefreshLayout = view.findViewById(R.id.swiperefresh)
swipeRefresh.setOnRefreshListener {
updateList()
+ page = 1
swipeRefresh.isRefreshing = false
}
@@ -95,7 +115,7 @@ class TopAnimePage : Fragment() {
(recyclerView.adapter as TopAnimeAdapter).notifyDataSetChanged()
}
- private fun makeApiCall(view: View, BASE_URL: String) {
+ private fun makeApiCall(view: View, BASE_URL: String, page: Int) {
val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
@@ -103,7 +123,7 @@ class TopAnimePage : Fragment() {
.build()
val service = retrofit.create(TopAnimeApi::class.java)
- val call = service.getTopAnimeData()
+ val call = service.getTopAnimeData(page)
call.enqueue(object : Callback<TopAnimeResponse> {
override fun onResponse(
@@ -142,7 +162,11 @@ class TopAnimePage : Fragment() {
}
private fun showError() {
- Snackbar.make(requireView(), "API ERROR", Snackbar.LENGTH_LONG)
+ Snackbar.make(
+ requireView(),
+ "API ERROR : Verify your internet connection.",
+ Snackbar.LENGTH_LONG
+ )
.setAction("Action", null).show()
}
diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/topmanga/TopMangaApi.kt b/app/src/main/java/xyz/adjutor/aniki/manga/topmanga/TopMangaApi.kt
index 629fe02..2688fab 100644
--- a/app/src/main/java/xyz/adjutor/aniki/manga/topmanga/TopMangaApi.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/manga/topmanga/TopMangaApi.kt
@@ -2,10 +2,11 @@ package xyz.adjutor.aniki.manga.topmanga
import retrofit2.Call
import retrofit2.http.GET
+import retrofit2.http.Path
interface TopMangaApi {
- @GET("v3/top/manga")
- fun getTopMangaData(): Call<TopMangaResponse>
+ @GET("v3/top/manga/{page}")
+ fun getTopMangaData(@Path("page") page: Int): Call<TopMangaResponse>
} \ No newline at end of file
diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/topmanga/TopMangaPage.kt b/app/src/main/java/xyz/adjutor/aniki/manga/topmanga/TopMangaPage.kt
index b35bcdd..9c138a3 100644
--- a/app/src/main/java/xyz/adjutor/aniki/manga/topmanga/TopMangaPage.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/manga/topmanga/TopMangaPage.kt
@@ -31,6 +31,7 @@ class TopMangaPage : Fragment() {
.setLenient()
.create()
private var baseUrl = "https://api.jikan.moe/" //the api's base url
+ var page: Int = 1
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
@@ -45,10 +46,11 @@ class TopMangaPage : Fragment() {
if (mangaList != null) {
showList(view, mangaList)
} else {
- makeApiCall(view, baseUrl)
+ makeApiCall(view, baseUrl, 1)
}
return view
+
}
private fun getDataFromCache(): List<TopManga>? {
@@ -71,16 +73,35 @@ class TopMangaPage : Fragment() {
view.findViewById<Button>(R.id.button_home).setOnClickListener {
findNavController().navigate(R.id.action_TopMangaPage_to_HomePage)
}
+ view.findViewById<Button>(R.id.button_prev).setOnClickListener {
+ if (page > 1) {
+ page -= 1
+ makeApiCall(view, baseUrl, page)
+ Snackbar.make(requireView(), "Page $page has been loaded.", Snackbar.LENGTH_SHORT)
+ .setAction("Action", null).show()
+ } else {
+ Snackbar.make(requireView(), "You're already on page 1.", Snackbar.LENGTH_SHORT)
+ .setAction("Action", null).show()
+ }
+ }
+ view.findViewById<Button>(R.id.button_next).setOnClickListener {
+ page += 1
+ makeApiCall(view, baseUrl, page)
+ Snackbar.make(requireView(), "Page $page has been loaded.", Snackbar.LENGTH_SHORT)
+ .setAction("Action", null).show()
+ }
fun updateList() {
- makeApiCall(view, baseUrl)
- Snackbar.make(requireView(), "Data refreshed", Snackbar.LENGTH_LONG)
+ makeApiCall(view, baseUrl, 1)
+ Snackbar.make(requireView(), "Data refreshed", Snackbar.LENGTH_SHORT)
.setAction("Action", null).show()
}
+ //refresh when swiping down at the top of the page
val swipeRefresh: SwipeRefreshLayout = view.findViewById(R.id.swiperefresh)
swipeRefresh.setOnRefreshListener {
updateList()
+ page = 1
swipeRefresh.isRefreshing = false
}
@@ -95,7 +116,7 @@ class TopMangaPage : Fragment() {
(recyclerView.adapter as TopMangaAdapter).notifyDataSetChanged()
}
- private fun makeApiCall(view: View, BASE_URL: String) {
+ private fun makeApiCall(view: View, BASE_URL: String, page: Int) {
val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
@@ -103,7 +124,7 @@ class TopMangaPage : Fragment() {
.build()
val service = retrofit.create(TopMangaApi::class.java)
- val call = service.getTopMangaData()
+ val call = service.getTopMangaData(page)
call.enqueue(object : Callback<TopMangaResponse> {
override fun onResponse(
@@ -142,7 +163,11 @@ class TopMangaPage : Fragment() {
}
private fun showError() {
- Snackbar.make(requireView(), "API ERROR", Snackbar.LENGTH_LONG)
+ Snackbar.make(
+ requireView(),
+ "API ERROR : Verify your internet connection.",
+ Snackbar.LENGTH_LONG
+ )
.setAction("Action", null).show()
}
diff --git a/app/src/main/res/layout/top_anime_page.xml b/app/src/main/res/layout/top_anime_page.xml
index c7ec862..6797660 100644
--- a/app/src/main/res/layout/top_anime_page.xml
+++ b/app/src/main/res/layout/top_anime_page.xml
@@ -25,6 +25,14 @@
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<Button
+ android:id="@+id/button_prev"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/prev"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toStartOf="@id/button_home" />
+
+ <Button
android:id="@+id/button_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -33,4 +41,12 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
+ <Button
+ android:id="@+id/button_next"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/next"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toEndOf="@id/button_home" />
+
</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 f3d0db3..2f4a9f1 100644
--- a/app/src/main/res/layout/top_manga_page.xml
+++ b/app/src/main/res/layout/top_manga_page.xml
@@ -25,6 +25,14 @@
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<Button
+ android:id="@+id/button_prev"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/prev"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toStartOf="@id/button_home" />
+
+ <Button
android:id="@+id/button_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@@ -33,4 +41,12 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
+ <Button
+ android:id="@+id/button_next"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/next"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toEndOf="@id/button_home" />
+
</androidx.constraintlayout.widget.ConstraintLayout> \ 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 0c56edc..861a440 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -42,5 +42,7 @@
<string name="search_anime">Search Anime</string>
<string name="search_anime_page_label">Search Anime Page</string>
<string name="hint_query">Your query …</string>
+ <string name="prev">PREV</string>
+ <string name="next">NEXT</string>
</resources> \ No newline at end of file