Implement Searches

This commit is contained in:
Dusk 2022-02-19 18:17:15 +01:00
parent 3ad0d9cec0
commit b0a05c50ae
6 changed files with 91 additions and 22 deletions

View File

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="$USER_HOME$/.android/avd/Pixel_3a_XL_API_30.avd" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2022-02-18T22:16:54.747155Z" />
</component>
</project>

View File

@ -17,9 +17,11 @@
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEARCH" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity> </activity>
</application> </application>

View File

@ -1,9 +1,11 @@
package com.example.testes package com.example.testes
import android.app.SearchManager
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.widget.SearchView
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import com.example.testes.databinding.ActivityMainBinding import com.example.testes.databinding.ActivityMainBinding
import org.json.JSONArray import org.json.JSONArray
@ -12,7 +14,6 @@ import org.json.JSONObject
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
private val url = "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&limit=18"
lateinit var binding: ActivityMainBinding lateinit var binding: ActivityMainBinding
private fun imageListFromJson(json: JSONObject) { private fun imageListFromJson(json: JSONObject) {
@ -34,17 +35,55 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
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"
search(assemblePostsUrl("izumi_konata"))
binding.search.setOnQueryTextListener(object :
android.widget.SearchView.OnQueryTextListener {
override fun onQueryTextChange(newText: String): Boolean {
return false
}
override fun onQueryTextSubmit(query: String): Boolean {
search(assemblePostsUrl(query))
// task HERE
return false
}
}
)
}
private fun search(url: String) {
Request.getRequest( Request.getRequest(
this, this,
url, url,
::imageListFromJson ::imageListFromJson
) )
Log.i("ocko", url)
}
private fun assemblePostsUrl(query: String): String{
return "https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&limit=18&tags=$query"
} }
private fun loadGrid(images: List<BooruImage>) { private fun loadGrid(images: List<BooruImage>) {
val fragmentTransaction = supportFragmentManager.beginTransaction() val fragmentTransaction = supportFragmentManager.beginTransaction()
fragmentTransaction.add(R.id.imageGridRecV, ImageGridFragment(images)) fragmentTransaction.replace(R.id.imageGridRecV, ImageGridFragment(images))
fragmentTransaction.commit() fragmentTransaction.commit()
} }
inner class SearchListener(
var callback: (String) -> Unit
) : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query : String): Boolean {
callback(query)
return true
}
override fun onQueryTextChange(query : String): Boolean {
//callback(query)
return true
}
}
} }

View File

@ -6,9 +6,45 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity">
<Toolbar
android:id="@+id/mainToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:background="@color/design_default_color_primary"
>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="7.5dp"
app:cardCornerRadius="7.5dp"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="8dp">
<SearchView
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:iconifiedByDefault="false"
android:queryBackground="@android:color/transparent"
/>
</androidx.cardview.widget.CardView>
</Toolbar>
<FrameLayout <FrameLayout
android:id="@+id/imageGridRecV" android:id="@+id/imageGridRecV"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/mainToolbar"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,5 +1,6 @@
<resources> <resources>
<string name="app_name">Testes</string> <string name="app_name">Boorujelly</string>
<!-- TODO: Remove or change this placeholder text --> <!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string> <string name="hello_blank_fragment">Hello blank fragment</string>
<string name="search_hint">Search</string>
</resources> </resources>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/search_hint"
android:label="@string/app_name"
>
</searchable>