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

integrated glide

add photo slider
fix photo adapter
semi-working functionaly for photo screen
parent d95a21a3
<component name="ProjectCodeStyleConfiguration"> <component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173"> <code_scheme name="Project" version="173">
<AndroidXmlCodeStyleSettings>
<option name="ARRANGEMENT_SETTINGS_MIGRATED_TO_191" value="true" />
</AndroidXmlCodeStyleSettings>
<JetCodeStyleSettings> <JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" /> <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings> </JetCodeStyleSettings>
......
...@@ -159,6 +159,11 @@ dependencies { ...@@ -159,6 +159,11 @@ dependencies {
//Photo view //Photo view
implementation "com.github.chrisbanes:PhotoView:$photoViewVersion" implementation "com.github.chrisbanes:PhotoView:$photoViewVersion"
//Glide
implementation "com.github.bumptech.glide:glide:$glideVersion"
annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
//Tests //Tests
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'
......
...@@ -10,8 +10,6 @@ import com.biganto.visual.roompark.base.RoomParkApplication ...@@ -10,8 +10,6 @@ import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.domain.model.AlbumSortedModel import com.biganto.visual.roompark.domain.model.AlbumSortedModel
import com.biganto.visual.roompark.domain.model.PhotoModel import com.biganto.visual.roompark.domain.model.PhotoModel
import com.biganto.visual.roompark.domain.model.PhotoResolutionModel import com.biganto.visual.roompark.domain.model.PhotoResolutionModel
import com.biganto.visual.roompark.presentation.screen.photo.util.PhotosAdapter
import com.biganto.visual.roompark.presentation.screen.photo.util.PhotosViewHolder
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.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView import com.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView
......
...@@ -9,7 +9,8 @@ import com.biganto.visual.roompark.R ...@@ -9,7 +9,8 @@ import com.biganto.visual.roompark.R
import com.biganto.visual.roompark.base.RoomParkApplication import com.biganto.visual.roompark.base.RoomParkApplication
import com.biganto.visual.roompark.base.RoomParkMainActivity import com.biganto.visual.roompark.base.RoomParkMainActivity
import com.biganto.visual.roompark.conductor.BigantoBaseController import com.biganto.visual.roompark.conductor.BigantoBaseController
import com.biganto.visual.roompark.presentation.screen.photo.util.PhotoViewerAdapter import com.biganto.visual.roompark.presentation.screen.photo.util.PhotoPreviewSlider
import com.biganto.visual.roompark.presentation.screen.photo.util.PhotosAdapter
import com.google.android.material.textview.MaterialTextView import com.google.android.material.textview.MaterialTextView
import com.squareup.picasso.Picasso import com.squareup.picasso.Picasso
import timber.log.Timber import timber.log.Timber
...@@ -39,11 +40,26 @@ class PhotoScreenController : ...@@ -39,11 +40,26 @@ class PhotoScreenController :
@BindView(R.id.photo_frame) @BindView(R.id.photo_frame)
lateinit var photoViewPager: ViewPager2 lateinit var photoViewPager: ViewPager2
@BindView(R.id.photosPreviewSlider)
lateinit var slider: PhotoPreviewSlider
private fun bindRecycler() { private fun bindRecycler() {
photoViewPager.isNestedScrollingEnabled = false photoViewPager.isNestedScrollingEnabled = false
photoViewPager.offscreenPageLimit = 2 photoViewPager.offscreenPageLimit = 2
photoViewPager.adapter = PhotoViewerAdapter() photoViewPager.adapter = PhotosAdapter()
setVewPager()
}
private fun setVewPager(){
val ap = PhotosAdapter()
photoViewPager.adapter = ap
photoViewPager.orientation = ViewPager2.ORIENTATION_HORIZONTAL
photoViewPager.offscreenPageLimit = 2
ap.notifyDataSetChanged()
photoViewPager.invalidate()
slider.setUpViewPager(photoViewPager)
} }
override fun onViewBound(v: View) { override fun onViewBound(v: View) {
...@@ -94,11 +110,13 @@ class PhotoScreenController : ...@@ -94,11 +110,13 @@ class PhotoScreenController :
lateinit var picassoAsync:Picasso lateinit var picassoAsync:Picasso
private fun render(viewState: PhotoScreenViewState.PhotoListLoaded) { private fun render(viewState: PhotoScreenViewState.PhotoListLoaded) {
(photoViewPager.adapter as PhotoViewerAdapter).setItems( (photoViewPager.adapter as PhotosAdapter).setItems(
viewState.list.asSequence().sortedBy{it.sort}.toList() viewState.list.asSequence().sortedBy{it.sort}.toList()
) )
photoViewPager.currentItem = (photoViewPager.adapter as PhotoViewerAdapter) photoViewPager.currentItem = viewState.selectedId
.getItemPosition(viewState.selectedId)
slider.visibility= View.VISIBLE
slider.setUpViewPager(photoViewPager)
} }
private fun render(viewState: PhotoScreenViewState.AldumFetched) { private fun render(viewState: PhotoScreenViewState.AldumFetched) {
...@@ -107,7 +125,7 @@ class PhotoScreenController : ...@@ -107,7 +125,7 @@ class PhotoScreenController :
private fun render(viewState: PhotoScreenViewState.PhotoFetched){ private fun render(viewState: PhotoScreenViewState.PhotoFetched){
(photoViewPager.adapter as PhotoViewerAdapter).setItems(arrayListOf(viewState.model)) (photoViewPager.adapter as PhotosAdapter).setItems(arrayListOf(viewState.model))
} }
private fun render(viewState: PhotoScreenViewState.PhotoSelected){ private fun render(viewState: PhotoScreenViewState.PhotoSelected){
// (photoViewPager.adapter as PhotoViewerAdapter).setItems(arrayListOf(viewState.model)) // (photoViewPager.adapter as PhotoViewerAdapter).setItems(arrayListOf(viewState.model))
......
package com.biganto.visual.roompark.presentation.screen.photo.util
import android.content.Context
import android.graphics.SurfaceTexture
import android.util.AttributeSet
import android.view.GestureDetector
import android.view.MotionEvent
import android.view.TextureView
import android.view.View
import androidx.viewpager2.widget.ViewPager2
import kotlinx.android.synthetic.main.photo_page_viewholder.view.*
import timber.log.Timber
/**
* Created by Vladislav Bogdashkin on 22.12.2019.
*/
class PhotoPreviewSlider @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : TextureView(context, attrs, defStyleAttr)
,TextureView.SurfaceTextureListener{
private var texThread: RendererThread?=null
private var adapter: PhotosAdapter? = null
private var vp:ViewPager2? = null
fun setUpViewPager(viewpager:ViewPager2) {
this.adapter = viewpager.adapter as PhotosAdapter
with(viewpager) {
setPageTransformer { page, position ->
setParallaxTransformation(page, position)
}
registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
var actualPosition = 0
override fun onPageScrolled(
position: Int,
positionOffset: Float,
positionOffsetPixels: Int
) {
if (position == actualPosition){
processSliding(positionOffset)
}
else{
processSliding(positionOffset-1)
}
super.onPageScrolled(position, positionOffset, positionOffsetPixels)
}
override fun onPageSelected(position: Int) {
actualPosition = position
texThread?.setIndex(position)
super.onPageSelected(position)
}
})
}
vp = viewpager
}
private fun setParallaxTransformation(page: View, position: Float) {
page.apply {
when {
position < -1 -> // [-Infinity,-1)
// This page is way off-screen to the left.
alpha = 1f
position < -1 -> // [-1,0){
{
}
position <= 1 -> { // [-1,1]
photo_view.translationX = -position * (width / 2)
// slider.processSliding(position)
}
else -> // (1,+Infinity]
{
// This page is way off-screen to the right.
alpha = 1f
}
}
}
}
fun processSliding(_position:Float){
texThread?.setSlidePosition(_position)
}
val gestureDetector = GestureDetector(context, object : GestureDetector.SimpleOnGestureListener(){
override fun onDoubleTap(e: MotionEvent?): Boolean {
Timber.d( "double tap")
return true
}
override fun onScroll(e1: MotionEvent?, e2: MotionEvent?, distanceX: Float, distanceY: Float): Boolean {
mIsScrolling=true
Timber.d( "scroll")
texThread?.perfomDrag(distanceX)
return true
}
override fun onDown(e: MotionEvent?): Boolean {
Timber.d( "down")
return true
}
})
private var mIsScrolling = false
init {
surfaceTextureListener=this
val gestureListener = object : OnTouchListener {
private var gesture: GestureDetector = gestureDetector
override fun onTouch(v: View, event: MotionEvent): Boolean {
Timber.w(" ON TOUCH EVENT!")
val performTouch = gesture.onTouchEvent(event)
if (performTouch) return true
if (event.action == MotionEvent.ACTION_UP) {
if (mIsScrolling) {
Timber.d("OnTouchListener --> onTouch ACTION_UP")
mIsScrolling = false
texThread?.perfomDrag(null,mIsScrolling)
}
}
if (event.action == MotionEvent.ACTION_BUTTON_PRESS)
performClick()
return false
}
}
setOnTouchListener(gestureListener)
}
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
Timber.d("On Size Chagned")
super.onSizeChanged(w, h, oldw, oldh)
}
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture?, width: Int, height: Int) {
print(" onSurfaceTextureSizeChanged")
texThread?.setSize(width,height)
//Ignored
}
override fun onSurfaceTextureUpdated(surface: SurfaceTexture?) {
print(" onSurfaceTextureUpdated")
//Ignored
}
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture?): Boolean {
texThread?.isStopped=true
return true
}
override fun onSurfaceTextureAvailable(surface: SurfaceTexture?, width: Int, height: Int) {
Timber.d("avaliable surf: $surface")
surface?.let {
if (texThread?.isAlive==true)
return
texThread = RendererThread(context,it)
texThread?.setSize(width,height)
texThread?.onChangePage = {ind -> vp?.setCurrentItem(ind,false)}
texThread?.start()
adapter?.let {adapter ->
texThread?.setAdapter(adapter.photosPreviewList)
// texThread?.setIndex(min(_l.size,2))
}?: error("adapter not ready!")
}
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
texThread?.isStopped=true
}
}
...@@ -8,7 +8,8 @@ import com.biganto.visual.roompark.domain.model.PhotoModel ...@@ -8,7 +8,8 @@ import com.biganto.visual.roompark.domain.model.PhotoModel
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.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView import com.github.chrisbanes.photoview.PhotoView
import timber.log.Timber
/** /**
* Created by Vladislav Bogdashkin on 16.10.2019. * Created by Vladislav Bogdashkin on 16.10.2019.
...@@ -16,14 +17,23 @@ import com.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView ...@@ -16,14 +17,23 @@ import com.biganto.visual.roompark.util.view_utils.image_view.RoundedImageView
class PhotosAdapter : CommonRecyclerAdapter<PhotosViewHolder, PhotoModel>() { class PhotosAdapter : CommonRecyclerAdapter<PhotosViewHolder, PhotoModel>() {
val photosPreviewList:List<String> get() {
val ret = list.map { it.resolutionList.lowelest()?.url?: error("No res urls!")}.toList()
Timber.d("$ret")
return ret
}
override val vhKlazz = PhotosViewHolder::class override val vhKlazz = PhotosViewHolder::class
override fun getVhLayout(): Int = R.layout.photo_preview_viewholder override fun getVhLayout(): Int = R.layout.photo_page_viewholder
} }
class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView) { class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView) {
@BindView(R.id.photo_preview_imageview) lateinit var photoPreview: RoundedImageView @BindView(R.id.photo_view) lateinit var photoPreview: PhotoView
private val picassoAsync by lazy { private val picassoAsync by lazy {
return@lazy RoomParkApplication.component.providePicassoAsync() return@lazy RoomParkApplication.component.providePicassoAsync()
...@@ -39,5 +49,5 @@ class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView) ...@@ -39,5 +49,5 @@ class PhotosViewHolder(itemView: View) : CommonViewHolder<PhotoModel>(itemView)
}} }}
} }
fun List<PhotoResolutionModel>.lowelest() = private fun List<PhotoResolutionModel>.lowelest() =
this.minBy { it.resWidth * it.resHeight } this.minBy { it.resWidth * it.resHeight }
\ No newline at end of file
...@@ -67,12 +67,14 @@ ...@@ -67,12 +67,14 @@
app:layout_constraintTop_toTopOf="@+id/guideline2" app:layout_constraintTop_toTopOf="@+id/guideline2"
app:srcCompat="@drawable/iic_full_view" /> app:srcCompat="@drawable/iic_full_view" />
<androidx.recyclerview.widget.RecyclerView <com.biganto.visual.roompark.presentation.screen.photo.util.PhotoPreviewSlider
android:id="@+id/photosPreviewSlider"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:orientation="horizontal" android:orientation="horizontal"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/change_size_button" app:layout_constraintEnd_toStartOf="@+id/change_size_button"
app:layout_constraintStart_toEndOf="@+id/show_full_button" app:layout_constraintStart_toEndOf="@+id/show_full_button"
......
...@@ -26,4 +26,5 @@ ext { ...@@ -26,4 +26,5 @@ ext {
exoPlayerVersion = "2.10.8" exoPlayerVersion = "2.10.8"
photoViewVersion = "2.0.0" photoViewVersion = "2.0.0"
viewPager2Version = "1.0.0" viewPager2Version = "1.0.0"
glideVersion = "4.11.0"
} }
\ 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