Improve search structure, LinearLayout

This commit is contained in:
Dusk 2022-02-22 20:47:15 +01:00
parent b0a05c50ae
commit b05857bedf
3 changed files with 24 additions and 14 deletions

View File

@ -3,7 +3,7 @@
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="app/src/main/res/layout/activity_main.xml" value="0.33" />
<entry key="app/src/main/res/layout/activity_main.xml" value="0.2" />
<entry key="app/src/main/res/layout/fragment_image_grid.xml" value="0.2515625" />
<entry key="app/src/main/res/layout/image_grid_item.xml" value="0.35260416666666666" />
</map>

View File

@ -36,7 +36,7 @@ class MainActivity : AppCompatActivity() {
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
val url = "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&limit=18"
search(assemblePostsUrl("izumi_konata"))
search("")
binding.search.setOnQueryTextListener(object :
android.widget.SearchView.OnQueryTextListener {
@ -45,7 +45,7 @@ class MainActivity : AppCompatActivity() {
}
override fun onQueryTextSubmit(query: String): Boolean {
search(assemblePostsUrl(query))
search(query)
// task HERE
return false
}
@ -53,13 +53,23 @@ class MainActivity : AppCompatActivity() {
)
}
private fun search(url: String) {
private fun search(query: String?) {
if (query.isNullOrBlank() || query == "*") {
Request.getRequest(
this,
"https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&limit=18",
::imageListFromJson
)
}
else {
val url: String = assemblePostsUrl(query)
Request.getRequest(
this,
url,
::imageListFromJson
)
Log.i("ocko", url)
}
}
private fun assemblePostsUrl(query: String): String{

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Toolbar
@ -39,12 +40,11 @@
</Toolbar>
<FrameLayout
android:id="@+id/imageGridRecV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/mainToolbar"/>
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.appcompat.widget.LinearLayoutCompat>