aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2021-03-02 12:05:27 +0100
committerClyhtsuriva <aimeric@adjutor.xyz>2021-03-02 12:05:27 +0100
commit81a89af9aa3c35a991eced93eeaa5066804e3ee5 (patch)
tree2c63470f6d7ddf20ede498ea3e4edf181e83ddd8 /app/src
parent6d5df6250d4c060840b64d7441525f85146fb87b (diff)
Search working for mangas.
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/xyz/adjutor/aniki/manga/search/SearchMangaPage.kt28
-rw-r--r--app/src/main/res/layout/search_manga_page.xml29
-rw-r--r--app/src/main/res/values/strings.xml1
3 files changed, 30 insertions, 28 deletions
diff --git a/app/src/main/java/xyz/adjutor/aniki/manga/search/SearchMangaPage.kt b/app/src/main/java/xyz/adjutor/aniki/manga/search/SearchMangaPage.kt
index 6310dfc..40f9633 100644
--- a/app/src/main/java/xyz/adjutor/aniki/manga/search/SearchMangaPage.kt
+++ b/app/src/main/java/xyz/adjutor/aniki/manga/search/SearchMangaPage.kt
@@ -1,7 +1,5 @@
package xyz.adjutor.aniki.manga.search
-import android.content.Context
-import android.content.SharedPreferences
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
@@ -11,8 +9,8 @@ import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
-import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.snackbar.Snackbar
+import com.google.android.material.textfield.TextInputEditText
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import retrofit2.Call
@@ -24,7 +22,6 @@ import xyz.adjutor.aniki.R
class SearchMangaPage : Fragment() {
- private lateinit var sharedPreferences: SharedPreferences
val gson: Gson = GsonBuilder()
.setLenient()
.create()
@@ -37,11 +34,6 @@ class SearchMangaPage : Fragment() {
// Inflate the layout for this fragment
val view = inflater.inflate(R.layout.search_manga_page, container, false)
- sharedPreferences = view.context.getSharedPreferences("sp_manga", Context.MODE_PRIVATE)
-
-
- makeApiCall(view, baseUrl)
-
return view
}
@@ -54,18 +46,10 @@ class SearchMangaPage : Fragment() {
findNavController().navigate(R.id.action_SearchMangaPage_to_HomePage)
}
- fun updateList() {
- makeApiCall(view, baseUrl)
- Snackbar.make(requireView(), "Data refreshed", Snackbar.LENGTH_LONG)
- .setAction("Action", null).show()
+ view.findViewById<Button>(R.id.button_query).setOnClickListener{
+ val userInput = view.findViewById<TextInputEditText>(R.id.tiet_query).text.toString()
+ makeApiCall(view, baseUrl, userInput)
}
-
- val swipeRefresh: SwipeRefreshLayout = view.findViewById(R.id.swiperefresh)
- swipeRefresh.setOnRefreshListener {
- updateList()
- swipeRefresh.isRefreshing = false
- }
-
}
//display the recyclerview
@@ -77,7 +61,7 @@ class SearchMangaPage : Fragment() {
(recyclerView.adapter as SearchMangaAdapter).notifyDataSetChanged()
}
- private fun makeApiCall(view: View, BASE_URL: String) {
+ private fun makeApiCall(view: View, BASE_URL: String, query: String) {
val retrofit = Retrofit.Builder()
.baseUrl(BASE_URL)
@@ -85,7 +69,7 @@ class SearchMangaPage : Fragment() {
.build()
val service = retrofit.create(SearchMangaApi::class.java)
- val call = service.getSearchMangaData("fate") //fate is an exemple, we'll have to replace it by the user input.
+ val call = service.getSearchMangaData(q = query) //fate is an exemple, we'll have to replace it by the user input.
call.enqueue(object : Callback<SearchMangaResponse> {
override fun onResponse(
diff --git a/app/src/main/res/layout/search_manga_page.xml b/app/src/main/res/layout/search_manga_page.xml
index a6de772..1470311 100644
--- a/app/src/main/res/layout/search_manga_page.xml
+++ b/app/src/main/res/layout/search_manga_page.xml
@@ -7,10 +7,27 @@
android:background="@color/very_dark_purple"
tools:context=".manga.search.SearchMangaPage">
- <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
- android:id="@+id/swiperefresh"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
+
+ <com.google.android.material.textfield.TextInputEditText
+ android:id="@+id/tiet_query"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:textStyle="bold"
+ app:layout_constraintBottom_toTopOf="@id/recycler_view"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintEnd_toStartOf="@id/button_query"/>
+
+ <Button
+ android:id="@+id/button_query"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintBottom_toTopOf="@id/recycler_view"
+ app:layout_constraintStart_toEndOf="@id/tiet_query"
+ android:text="@string/search"
+ />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
@@ -20,9 +37,8 @@
app:layout_constraintBottom_toTopOf="@+id/button_home"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/tiet_query"
tools:listitem="@layout/item_layout" />
- </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<Button
android:id="@+id/button_home"
@@ -33,4 +49,5 @@
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/values/strings.xml b/app/src/main/res/values/strings.xml
index 87630b3..d7f7838 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -37,5 +37,6 @@
<string name="episodes">0000</string>
<string name="search_manga_page_label">Search Manga Page</string>
<string name="search_manga">Search Manga</string>
+ <string name="search">Search in the database</string>
</resources> \ No newline at end of file