Implement image main grid prototype
This commit is contained in:
parent
3fb4990709
commit
1b64e7a043
|
@ -5,6 +5,7 @@
|
||||||
<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.33" />
|
||||||
<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.35052083333333334" />
|
||||||
</map>
|
</map>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.example.testes
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ImageView
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
|
class ImageGridAdapter(val imageList: List<BooruImage>) :
|
||||||
|
RecyclerView.Adapter<ImageGridAdapter.ViewHolder>() {
|
||||||
|
|
||||||
|
/* Creates and inflates view and return FlowerViewHolder. */
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
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) {
|
||||||
|
holder.bind(imageList[position])
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||||
|
private val text: TextView = itemView.findViewById(R.id.text)
|
||||||
|
//private val image: ImageView = itemView.findViewById(R.id.image)
|
||||||
|
|
||||||
|
fun bind(image: BooruImage) {
|
||||||
|
text.text = image.url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = imageList.size
|
||||||
|
}
|
|
@ -5,28 +5,13 @@ import androidx.fragment.app.Fragment
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
|
||||||
// TODO: Rename parameter arguments, choose names that match
|
class ImageGridFragment(val images: List<BooruImage>) : Fragment() {
|
||||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
|
||||||
private const val ARG_PARAM1 = "param1"
|
|
||||||
private const val ARG_PARAM2 = "param2"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A simple [Fragment] subclass.
|
|
||||||
* Use the [ImageGridFragment.newInstance] factory method to
|
|
||||||
* create an instance of this fragment.
|
|
||||||
*/
|
|
||||||
class ImageGridFragment : Fragment() {
|
|
||||||
// TODO: Rename and change types of parameters
|
|
||||||
private var param1: String? = null
|
|
||||||
private var param2: String? = null
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
arguments?.let {
|
|
||||||
param1 = it.getString(ARG_PARAM1)
|
|
||||||
param2 = it.getString(ARG_PARAM2)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
|
@ -34,26 +19,12 @@ class ImageGridFragment : Fragment() {
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
return inflater.inflate(R.layout.fragment_image_grid, container, false)
|
val layoutView = inflater.inflate(R.layout.fragment_image_grid, container, false)
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
val recyclerView : RecyclerView = layoutView.findViewById(R.id.imageGridRecV)
|
||||||
/**
|
recyclerView.adapter = ImageGridAdapter(images)
|
||||||
* Use this factory method to create a new instance of
|
recyclerView.layoutManager = GridLayoutManager(layoutView.context, 3)
|
||||||
* this fragment using the provided parameters.
|
|
||||||
*
|
return layoutView
|
||||||
* @param param1 Parameter 1.
|
|
||||||
* @param param2 Parameter 2.
|
|
||||||
* @return A new instance of fragment ImageGridFragment.
|
|
||||||
*/
|
|
||||||
// TODO: Rename and change types and number of parameters
|
|
||||||
@JvmStatic
|
|
||||||
fun newInstance(param1: String, param2: String) =
|
|
||||||
ImageGridFragment().apply {
|
|
||||||
arguments = Bundle().apply {
|
|
||||||
putString(ARG_PARAM1, param1)
|
|
||||||
putString(ARG_PARAM2, param2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@ 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.fragment.app.Fragment
|
||||||
import com.example.testes.databinding.ActivityMainBinding
|
import com.example.testes.databinding.ActivityMainBinding
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
|
@ -17,7 +18,9 @@ class MainActivity : AppCompatActivity() {
|
||||||
try {
|
try {
|
||||||
val array: JSONArray = json.getJSONArray("post")
|
val array: JSONArray = json.getJSONArray("post")
|
||||||
val list = BooruImage.listFromJsonArray(array)
|
val list = BooruImage.listFromJsonArray(array)
|
||||||
Log.i("Image", list[5].toString())
|
loadGrid(list)
|
||||||
|
//Log.i("Image", list.toString())
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (e: JSONException) {
|
catch (e: JSONException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
@ -36,4 +39,11 @@ class MainActivity : AppCompatActivity() {
|
||||||
::imageListFromJson
|
::imageListFromJson
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadGrid(images: List<BooruImage>) {
|
||||||
|
val fragmentTransaction = supportFragmentManager.beginTransaction()
|
||||||
|
fragmentTransaction.add(R.id.imageGridRecV, ImageGridFragment(images))
|
||||||
|
fragmentTransaction.commit()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,9 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivity">
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
<TextView
|
<FrameLayout
|
||||||
android:id="@+id/tvText"
|
android:id="@+id/imageGridRecV"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent" />
|
||||||
android:text="Hello World!"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -3,12 +3,13 @@
|
||||||
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"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
tools:context=".ImageGridFragment">
|
tools:context=".ImageGridFragment">
|
||||||
|
|
||||||
<!-- TODO: Update blank fragment layout -->
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
<TextView
|
android:id="@+id/imageGridRecV"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:text="@string/hello_blank_fragment" />
|
/>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/image"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:src="@mipmap/ic_launcher_round"
|
||||||
|
android:contentDescription="Image"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="HOLAAA"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
android:textAlignment="center"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue