Center Search
This commit is contained in:
parent
b05857bedf
commit
7f8d8738f8
|
@ -12,15 +12,21 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Testes">
|
||||
<activity
|
||||
android:name=".ImageViewerActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.app.searchable"
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
</activity>
|
||||
</application>
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package com.example.testes
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat.getDrawable
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
|
||||
class ImageGridAdapter(val imageList: List<BooruImage>) :
|
||||
RecyclerView.Adapter<ImageGridAdapter.ViewHolder>() {
|
||||
|
||||
lateinit var context: Context;
|
||||
|
||||
/* Creates and inflates view and return FlowerViewHolder. */
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
context = parent.context;
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.image_grid_item, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
/* Gets current flower and uses it to bind view. */
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
Glide.with(context)
|
||||
.load(imageList[position].preview_url)
|
||||
.placeholder(getDrawable(context, R.drawable.ic_launcher_foreground))
|
||||
.into(holder.imageview)
|
||||
}
|
||||
|
||||
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
var imageview: ImageView = itemView.findViewById(R.id.image)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = imageList.size
|
||||
}
|
|
@ -1,12 +1,16 @@
|
|||
package com.example.testes
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
|
||||
class ImageGridFragment(val images: List<BooruImage>) : Fragment() {
|
||||
|
||||
|
@ -27,4 +31,32 @@ class ImageGridFragment(val images: List<BooruImage>) : Fragment() {
|
|||
|
||||
return layoutView
|
||||
}
|
||||
|
||||
inner class ImageGridAdapter(val imageList: List<BooruImage>) :
|
||||
RecyclerView.Adapter<ImageGridAdapter.ViewHolder>() {
|
||||
|
||||
lateinit var context: Context;
|
||||
|
||||
/* Creates and inflates view and return FlowerViewHolder. */
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
context = parent.context;
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.image_grid_item, parent, false)
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
/* Gets current flower and uses it to bind view. */
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
Glide.with(context)
|
||||
.load(imageList[position].preview_url)
|
||||
.placeholder(ContextCompat.getDrawable(context, R.drawable.ic_launcher_foreground))
|
||||
.into(holder.imageview)
|
||||
}
|
||||
|
||||
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
var imageview: ImageView = itemView.findViewById(R.id.image)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = imageList.size
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.example.testes
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
|
||||
class ImageViewerActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_image_viewer)
|
||||
}
|
||||
}
|
|
@ -1,12 +1,9 @@
|
|||
package com.example.testes
|
||||
|
||||
import android.app.SearchManager
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.example.testes.databinding.ActivityMainBinding
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
|
@ -39,7 +36,7 @@ class MainActivity : AppCompatActivity() {
|
|||
search("")
|
||||
|
||||
binding.search.setOnQueryTextListener(object :
|
||||
android.widget.SearchView.OnQueryTextListener {
|
||||
SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextChange(newText: String): Boolean {
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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"
|
||||
tools:context=".ImageViewerActivity">
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -7,26 +7,20 @@
|
|||
android:orientation="vertical"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<Toolbar
|
||||
<androidx.appcompat.widget.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"
|
||||
>
|
||||
app:contentInsetStart="0dp">
|
||||
|
||||
<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">
|
||||
app:cardCornerRadius="7.5dp">
|
||||
|
||||
|
||||
<SearchView
|
||||
<androidx.appcompat.widget.SearchView
|
||||
android:id="@+id/search"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -38,7 +32,7 @@
|
|||
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
</Toolbar>
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/imageGridRecV"
|
||||
|
|
Loading…
Reference in New Issue