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"> <component name="DesignSurface">
<option name="filePathToZoomLevelMap"> <option name="filePathToZoomLevelMap">
<map> <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/fragment_image_grid.xml" value="0.2515625" />
<entry key="app/src/main/res/layout/image_grid_item.xml" value="0.35260416666666666" /> <entry key="app/src/main/res/layout/image_grid_item.xml" value="0.35260416666666666" />
</map> </map>

View File

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

View File

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