Implement image viewing with static member
This commit is contained in:
parent
dec94b0011
commit
36af732a9f
|
@ -12,6 +12,11 @@ data class BooruImage (
|
||||||
var file_url: String,
|
var file_url: String,
|
||||||
var preview_url: String,
|
var preview_url: String,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
fun clone(): BooruImage {
|
||||||
|
return BooruImage(id, rating, tags, file_url, preview_url)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@Throws(JSONException::class)
|
@Throws(JSONException::class)
|
||||||
fun imageFromJson(json: JSONObject): BooruImage {
|
fun imageFromJson(json: JSONObject): BooruImage {
|
||||||
|
|
|
@ -54,14 +54,18 @@ class ImageGridFragment(val images: List<BooruImage>) : Fragment() {
|
||||||
.placeholder(ContextCompat.getDrawable(context, R.drawable.ic_launcher_foreground))
|
.placeholder(ContextCompat.getDrawable(context, R.drawable.ic_launcher_foreground))
|
||||||
.into(holder.imageview)
|
.into(holder.imageview)
|
||||||
|
|
||||||
|
holder.image = imageList[position]
|
||||||
holder.imageview.setOnClickListener(holder)
|
holder.imageview.setOnClickListener(holder)
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
|
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
|
||||||
var imageview: ImageView = itemView.findViewById(R.id.image)
|
var imageview: ImageView = itemView.findViewById(R.id.image)
|
||||||
|
lateinit var image: BooruImage
|
||||||
|
|
||||||
override fun onClick(view: View?) {
|
override fun onClick(view: View?) {
|
||||||
val intent = Intent(view?.context, ImageViewerActivity::class.java)
|
val intent = Intent(view?.context, ImageViewerActivity::class.java)
|
||||||
|
ImageViewerActivity.image = this.image
|
||||||
|
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,27 @@ package com.example.testes
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.bumptech.glide.Glide
|
||||||
import com.example.testes.databinding.ActivityImageViewerBinding
|
import com.example.testes.databinding.ActivityImageViewerBinding
|
||||||
import com.example.testes.databinding.ActivityMainBinding
|
import com.example.testes.databinding.ActivityMainBinding
|
||||||
|
|
||||||
class ImageViewerActivity : AppCompatActivity() {
|
class ImageViewerActivity : AppCompatActivity() {
|
||||||
lateinit var binding: ActivityImageViewerBinding
|
lateinit var binding: ActivityImageViewerBinding
|
||||||
|
lateinit var local_image: BooruImage
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
lateinit var image: BooruImage
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityImageViewerBinding.inflate(layoutInflater)
|
binding = ActivityImageViewerBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
local_image = image.clone()
|
||||||
|
Glide.with(this)
|
||||||
|
.load(local_image.file_url)
|
||||||
|
.placeholder(ContextCompat.getDrawable(this, R.drawable.ic_launcher_foreground))
|
||||||
|
.into(binding.image)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -76,6 +76,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
private fun loadGrid(images: List<BooruImage>) {
|
private fun loadGrid(images: List<BooruImage>) {
|
||||||
val fragmentTransaction = supportFragmentManager.beginTransaction()
|
val fragmentTransaction = supportFragmentManager.beginTransaction()
|
||||||
fragmentTransaction.replace(R.id.imageGridRecV, ImageGridFragment(images))
|
fragmentTransaction.replace(R.id.imageGridRecV, ImageGridFragment(images))
|
||||||
|
fragmentTransaction.addToBackStack(null)
|
||||||
fragmentTransaction.commit()
|
fragmentTransaction.commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
tools:context=".ImageViewerActivity">
|
tools:context=".ImageViewerActivity">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
android:id="@+id/image"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:src="@mipmap/ic_launcher"
|
android:src="@mipmap/ic_launcher"
|
||||||
|
|
Loading…
Reference in New Issue