Commit 9f75c250 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

photo screen viewer

parent 127391e9
...@@ -10,11 +10,15 @@ import androidx.recyclerview.widget.LinearLayoutManager ...@@ -10,11 +10,15 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView import butterknife.BindView
import com.biganto.visual.roompark.R import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.conductor.dialogs.change_handler.DialogChangeHandler
import com.biganto.visual.roompark.conductor.dialogs.change_handler.PhotoDialogController
import com.biganto.visual.roompark.domain.model.PhotoResolutionModel import com.biganto.visual.roompark.domain.model.PhotoResolutionModel
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyclerAdapter import com.biganto.visual.roompark.presentation.screen.settings.util.CommonRecyclerAdapter
import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder import com.biganto.visual.roompark.presentation.screen.settings.util.CommonViewHolder
import com.bluelinelabs.conductor.Controller import com.bluelinelabs.conductor.Controller
import com.bluelinelabs.conductor.RouterTransaction
import com.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
import io.reactivex.disposables.CompositeDisposable
import timber.log.Timber import timber.log.Timber
...@@ -38,6 +42,13 @@ class ChooseResolutionDialogController : Controller { ...@@ -38,6 +42,13 @@ class ChooseResolutionDialogController : Controller {
lateinit var recyclerView : RecyclerView lateinit var recyclerView : RecyclerView
private val detachDisposable = CompositeDisposable()
override fun onDetach(view: View) {
detachDisposable.clear()
super.onDetach(view)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
val view = inflater.inflate(getLayoutId(), container, false) val view = inflater.inflate(getLayoutId(), container, false)
...@@ -51,12 +62,18 @@ class ChooseResolutionDialogController : Controller { ...@@ -51,12 +62,18 @@ class ChooseResolutionDialogController : Controller {
) )
args.getParcelableArrayList<PhotoResolutionModel>(PHOTOS_KEY)?.let { args.getParcelableArrayList<PhotoResolutionModel>(PHOTOS_KEY)?.let {
Timber.d("items; $it")
Timber.d("recyclerView; $recyclerView")
(recyclerView.adapter as PhotoSizeAdapter).setItems(it) (recyclerView.adapter as PhotoSizeAdapter).setItems(it)
(recyclerView.adapter as PhotoSizeAdapter).notifyDataSetChanged()
} }
detachDisposable.add(
(recyclerView.adapter as PhotoSizeAdapter).onItemClicked.subscribe {
Timber.d("gonna shit : $it")
router.replaceTopController(RouterTransaction.with(PhotoDialogController(it.url))
.popChangeHandler(DialogChangeHandler())
.pushChangeHandler(DialogChangeHandler())
)
})
view.findViewById<View>(R.id.cancel_button).setOnClickListener { handleBack() } view.findViewById<View>(R.id.cancel_button).setOnClickListener { handleBack() }
return view return view
......
package com.biganto.visual.roompark.conductor.dialogs.change_handler
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
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.engine.DiskCacheStrategy
import com.github.chrisbanes.photoview.PhotoView
/**
* Created by Vladislav Bogdashkin on 09.04.2019.
*/
internal const val PHOTO_URL_KEY = "CHHOSE_PHOTO_LIST_KEY"
class PhotoDialogController : Controller {
constructor(args: Bundle) : super(args)
constructor(photoUrl: String) : super(bundleOf(PHOTO_URL_KEY to photoUrl))
lateinit var recyclerView : RecyclerView
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
val view = inflater.inflate(getLayoutId(), container, false)
args.getString(PHOTO_URL_KEY)?.let {
val photoView = view.findViewById<PhotoView>(R.id.photo_frame)
Glide.with(photoView)
.load(it)
// .thumbnail(model.resolutionList.lowelest()?.let { thumb ->
// Glide.with(photoPreview).load(thumb.url).diskCacheStrategy(DiskCacheStrategy.ALL)
// .centerCrop()
// })
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(photoView)
}
return view
}
@LayoutRes
fun getLayoutId() = R.layout.photo_viewer
override fun handleBack(): Boolean {
return router.popCurrentController()
}
}
...@@ -84,8 +84,9 @@ class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView) ...@@ -84,8 +84,9 @@ class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView)
@BindView(R.id.photo_preview_imageview) lateinit var photoPreview: RoundedImageView @BindView(R.id.photo_preview_imageview) lateinit var photoPreview: RoundedImageView
override fun onViewBound(model: PhotoModel) { override fun onViewBound(model: PhotoModel) {
model.resolutionList.lowelest()?.let { model.resolutionList.lowlest()?.let {
Glide.with(itemView) Glide.with(itemView)
.asBitmap()
.load(it.url) .load(it.url)
.centerCrop() .centerCrop()
.fitCenter() .fitCenter()
...@@ -93,5 +94,5 @@ class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView) ...@@ -93,5 +94,5 @@ class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView)
}} }}
} }
fun List<PhotoResolutionModel>.lowelest() = fun List<PhotoResolutionModel>.lowlest() =
this.minBy { it.resWidth * it.resHeight } this.minBy { it.resWidth * it.resHeight }
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<com.github.chrisbanes.photoview.PhotoView
android:id="@+id/photo_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</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