From 848c8bf1ba4f0f3ecf2eeae0b9be2d6a664db2b4 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Tue, 2 Mar 2021 10:46:48 +0100 Subject: Creating the APIs and the responses. --- .../xyz/adjutor/aniki/manga/topmanga/TopMangaPage.kt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'app/src/main/java/xyz/adjutor/aniki/manga/topmanga/TopMangaPage.kt') 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 ce9b1c6..b35bcdd 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 @@ -26,7 +26,7 @@ import java.lang.reflect.Type class TopMangaPage : Fragment() { - var sharedPreferences: SharedPreferences? = null + private lateinit var sharedPreferences: SharedPreferences val gson: Gson = GsonBuilder() .setLenient() .create() @@ -53,7 +53,7 @@ class TopMangaPage : Fragment() { private fun getDataFromCache(): List? { //the value of the mangaList json, if nothing is found, return null - val jsonManga: String? = sharedPreferences?.getString("jsonMangaList", null) + val jsonManga: String? = sharedPreferences.getString("jsonMangaList", null) //if it's null, well, return null return if (jsonManga == null) { @@ -92,6 +92,7 @@ class TopMangaPage : Fragment() { recyclerView.setHasFixedSize(true) recyclerView.layoutManager = LinearLayoutManager(view.context) recyclerView.adapter = TopMangaAdapter(mangaList) + (recyclerView.adapter as TopMangaAdapter).notifyDataSetChanged() } private fun makeApiCall(view: View, BASE_URL: String) { @@ -104,10 +105,10 @@ class TopMangaPage : Fragment() { val service = retrofit.create(TopMangaApi::class.java) val call = service.getTopMangaData() - call.enqueue(object : Callback { + call.enqueue(object : Callback { override fun onResponse( - call: Call, - response: Response + call: Call, + response: Response ) { if (response.isSuccessful && response.body() != null) { //if the code returned is >= 200 and < 300 AND the the body ain't empty @@ -124,7 +125,7 @@ class TopMangaPage : Fragment() { } } - override fun onFailure(call: Call, t: Throwable) { + override fun onFailure(call: Call, t: Throwable) { showError() } @@ -135,9 +136,9 @@ class TopMangaPage : Fragment() { val jsonString: String = gson.toJson(mangaList) sharedPreferences - ?.edit() - ?.putString("jsonMangaList", jsonString) - ?.apply() + .edit() + .putString("jsonMangaList", jsonString) + .apply() } private fun showError() { -- cgit v1.2.3