package it.danieleverducci.openweddingapp.ui.gallery

import android.os.Bundle
import android.os.PersistableBundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.github.chrisbanes.photoview.PhotoView
import com.squareup.picasso.Picasso
import it.danieleverducci.openweddingapp.R
import java.io.File
import java.security.InvalidParameterException

class GalleryFullscreenViewerActivity: AppCompatActivity() {
    companion object {
        val EXTRAS_IMGURL = "imgurl"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_galleryfullscreenviewer)

        val imgUrl = intent.extras?.getString(EXTRAS_IMGURL)
        if (imgUrl == null) {
            throw InvalidParameterException("No image url specified")
        }

        val imageView = findViewById<PhotoView>(R.id.image)
        imageView.systemUiVisibility =
            View.SYSTEM_UI_FLAG_IMMERSIVE or
                    View.SYSTEM_UI_FLAG_FULLSCREEN or
                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        if (imgUrl.startsWith("http")) {
            Picasso.get()
                .load(imgUrl)
                .error(R.drawable.placeholder)
                .into(imageView);
        } else {
            Picasso.get()
                .load(File(imgUrl))
                .error(R.drawable.placeholder)
                .into(imageView);
        }

        findViewById<View>(R.id.close_button).setOnClickListener {
            finish()
        }
    }
}