Commit e74f9910 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

added callback for photo on load and failded; progressbar;

parent e0531ec9
package com.biganto.visual.roompark.conductor.dialogs.change_handler
import android.content.pm.ActivityInfo
import android.graphics.Bitmap
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ProgressBar
import androidx.annotation.LayoutRes
import androidx.core.os.bundleOf
import androidx.recyclerview.widget.RecyclerView
import com.biganto.visual.roompark.R
import com.bluelinelabs.conductor.Controller
import com.bumptech.glide.Glide
import com.bumptech.glide.load.DataSource
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import com.github.chrisbanes.photoview.PhotoView
import com.google.android.material.snackbar.Snackbar
/**
......@@ -33,17 +40,41 @@ class PhotoDialogController : Controller {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
val view = inflater.inflate(getLayoutId(), container, false)
val progress = view.findViewById<ProgressBar>(R.id.photo_load_progress_bar)
progress.visibility = View.VISIBLE
activity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
args.getString(PHOTO_URL_KEY)?.let {
val photoView = view.findViewById<PhotoView>(R.id.photo_frame)
Glide.with(photoView)
.asBitmap()
.load(it)
// .thumbnail(model.resolutionList.lowelest()?.let { thumb ->
// Glide.with(photoPreview).load(thumb.url).diskCacheStrategy(DiskCacheStrategy.ALL)
// .centerCrop()
// })
.diskCacheStrategy(DiskCacheStrategy.ALL)
.addListener(object :RequestListener<Bitmap>{
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Bitmap>?,
isFirstResource: Boolean
): Boolean {
progress.visibility = View.INVISIBLE
Snackbar.make(view,"Ошибка при загрузке!",Snackbar.LENGTH_SHORT)
return false
}
override fun onResourceReady(
resource: Bitmap?,
model: Any?,
target: Target<Bitmap>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
progress.visibility = View.INVISIBLE
return false
}
})
.into(photoView)
}
return view
......
......@@ -9,4 +9,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/photo_load_progress_bar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:indeterminate="true"
android:layout_gravity="center" />
</RelativeLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment