0

I have gallery project. I have a recycler view with rest api: ImageView, and 2 Text Views. I want to click small ImageView (this image is from rest api and it's downloaded from Glide) and Open This Image In another fragment with Glide using(Also want to say it's same image as small , but in fullscreen) , but I try to use safeargs with navigation components. I try to put this image in to String value and try to get it in other fragment and load this image in Fullscreen fragment , but it's still not working.


// this is my first fragment with recyclerView

@AndroidEntryPoint
class GalleryListFragment : Fragment() {
    lateinit var adapter:GalleryRecyclerView
private lateinit var binding : FragmentGalleryListBinding
private val viewmodel by viewModels<GalleryViewModel>()

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
      binding = FragmentGalleryListBinding.inflate(inflater)
return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        adapter = GalleryRecyclerView(view)
        binding.listforgallery.layoutManager = LinearLayoutManager(context)
        binding.listforgallery.adapter = adapter
        viewmodel.getPhotosGallery()
        viewmodel.photostate.observe(viewLifecycleOwner) { list ->
            list.body()?.let { adapter.createlistwithphotos(it) }
        }

    }
}

// this a recycler view adapter for this class. Also I try to put Glide image there by key and value

class GalleryRecyclerView@Inject constructor(private val view: View):RecyclerView.Adapter<GalleryRecyclerView.GalleryViewHolder>() {

    var listwithelements =ArrayList<RequestPhotosResponseItem>()
    class GalleryViewHolder(view:View) : RecyclerView.ViewHolder(view)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GalleryViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.gallery_layout,parent,false)
        return GalleryViewHolder(view)
    }

    override fun getItemCount(): Int = listwithelements.size




    override fun onBindViewHolder(holder: GalleryViewHolder, position: Int) {
      holder.itemView.findViewById<TextView>(R.id.author).text = listwithelements[position].user.username
        holder.itemView.findViewById<TextView>(R.id.titleforphoto).text = listwithelements[position].alt_description
        Glide.with(view).load("${listwithelements[position].urls.small}").into(holder.itemView.findViewById(R.id.imageforrest))

holder.itemView.findViewById<ImageView>(R.id.imageforrest).setOnClickListener {
    val image = Glide.with(view).load("${listwithelements[position].urls.regular}")
val action = GalleryListFragmentDirections.actionGalleryListFragmentToPhotoFragment(image.toString())
    view.findNavController().navigate(action)
}

    }
    fun createlistwithphotos(list: List<RequestPhotosResponseItem>){
        listwithelements.addAll(list)
        notifyDataSetChanged()
    }

    }

data class RequestPhotosResponseItem(
    val alt_description: String,
    val blur_hash: String,
    val color: String,
    val created_at: String,
    val current_user_collections: List<Any>,
    val description: String,
    val height: Int,
    val id: String,
    val liked_by_user: Boolean,
    val likes: Int,
    val promoted_at: String,
    val updated_at: String,
    val urls: Urls,
    val user: User,
    val width: Int
) // This is Model class for request

data class Urls(
    val full: String,
    val raw: String,
    var regular: String,
    val small: String,
    val small_s3: String,
    val thumb: String
) // model class for images urls , they're named by size(also want to add that the names are correct.)

// And finally class in which I want to see fullscreen image which was getting from rest api

@AndroidEntryPoint
class FullscreenPhotoFragment : Fragment() {
   private lateinit var binding : FragmentFullscreenPhotoBinding
private val args:FullscreenPhotoFragmentArgs by navArgs()
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
      binding = FragmentFullscreenPhotoBinding.inflate(inflater)


        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
//        binding.button.setOnClickListener {
//            findNavController().navigate(R.id.action_photoFragment_to_galleryListFragment)
//        }
Glide.with(this).load(args.imageURL).into(binding.fullscreenimage)

}




zadgee
  • 21
  • 3
  • What do you consider to be an image? And how are you trying to pass it now? – blackapps Mar 31 '23 at 17:12
  • I mean , that I wanna click small imageview , and navigate to another fragment , in which i want to have this image , but in fullscreen – zadgee Mar 31 '23 at 18:27
  • You did not answer my question. What kind of image are you working with? An ImageView is empty at startup. Where did you fill it with? – blackapps Mar 31 '23 at 18:35
  • @blackapps , I'm working with ImageView, and set OnClickListener on it. And I fill it with Glide. And I wanna click and Navigate to another fragment to see this picture in fullscreen. – zadgee Mar 31 '23 at 18:51
  • Glide is no image. So what you say makes no sense. ImageViews should be filled with an image. – blackapps Mar 31 '23 at 19:17
  • So, how can I open fullscreen photo by clicking imageView? – zadgee Mar 31 '23 at 19:37
  • You need an imageview in your other fragment and you need to make another glide call for it. If you're using fragments then you can pass the image url to the other fragment with navigation safeargs. – Nathan Meade Apr 01 '23 at 04:46
  • @NathanMeade . do you know any documentation, about safeargs? – zadgee Apr 01 '23 at 05:13
  • Yeah just Google navigation safeargs there should be documentation somewhere like the Android developers website – Nathan Meade Apr 01 '23 at 06:04
  • @NathanMeade , thx i'll search docs on devandroid.com – zadgee Apr 01 '23 at 06:37

0 Answers0