Skip to content

Commit

Permalink
24
Browse files Browse the repository at this point in the history
24
  • Loading branch information
umerov1999 committed Apr 27, 2023
1 parent 617ad81 commit b26e549
Show file tree
Hide file tree
Showing 61 changed files with 1,292 additions and 490 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class SinglePhotoActivity : NoMainActivity(), PlaceProvider, AppStyleable {

}).build()
)

ret.photo.setOnLongClickListener {
doSaveOnDrive(true)
true
Expand Down Expand Up @@ -304,6 +303,7 @@ class SinglePhotoActivity : NoMainActivity(), PlaceProvider, AppStyleable {
}

private fun loadImage(url: String?) {
PicassoInstance.with().cancelRequest(photo)
mLoadingNow = true
resolveProgressVisibility(true)
PicassoInstance.with()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class GifPagerActivity : AbsDocumentPreviewActivity<GifPagerPresenter, IGifPager
LayoutInflater.from(container.context)
.inflate(R.layout.content_gif_page, container, false)
)
ret.mGifView.orientationLocked = TouchImageView.OrientationLocked.HORIZONTAL
ret.mGifView.setOnTouchListener { view: View, event: MotionEvent ->
if (event.pointerCount >= 2 || view.canScrollHorizontally(1) && view.canScrollHorizontally(
-1
Expand Down Expand Up @@ -325,4 +326,4 @@ class GifPagerActivity : AbsDocumentPreviewActivity<GifPagerPresenter, IGifPager
return args
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface IPhotoPagerView : IMvpView, IErrorView, IToastView {
fun setButtonsBarVisible(visible: Boolean)
fun setToolbarVisible(visible: Boolean)
fun rebindPhotoAt(position: Int)
fun rebindPhotoAtPartial(position: Int)
fun closeOnly()
fun returnInfo(position: Int, parcelNativePtr: Long)
fun returnOnlyPos(position: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,23 @@ import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.graphics.Color
import android.graphics.Matrix
import android.os.Bundle
import android.util.SparseIntArray
import android.view.*
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import androidx.annotation.ColorInt
import androidx.annotation.IdRes
import androidx.annotation.LayoutRes
import androidx.appcompat.widget.PopupMenu
import androidx.appcompat.widget.Toolbar
import androidx.core.view.MenuProvider
import androidx.core.view.doOnPreDraw
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
Expand Down Expand Up @@ -317,6 +323,10 @@ class PhotoPagerActivity : BaseMvpActivity<PhotoPagerPresenter, IPhotoPagerView>
}
mButtonWithUser = findViewById(R.id.with_user_button)
mButtonWithUser?.setOnClickListener { presenter?.fireWithUserClick() }
mButtonWithUser?.setOnLongClickListener {
presenter?.fireWithUserLongClick()
true
}
mButtonComments = findViewById(R.id.comments_button)
mButtonComments?.setOnClickListener { presenter?.fireCommentsButtonClick() }
buttonShare = findViewById(R.id.share_button)
Expand Down Expand Up @@ -674,6 +684,10 @@ class PhotoPagerActivity : BaseMvpActivity<PhotoPagerPresenter, IPhotoPagerView>
mToolbar?.visibility = if (visible) View.VISIBLE else View.GONE
}

override fun rebindPhotoAtPartial(position: Int) {
mPagerAdapter?.notifyItemChanged(position)
}

override fun rebindPhotoAt(position: Int) {
mPagerAdapter?.notifyItemChanged(position)
if (bShowPhotosLine && mAdapterRecycler.getSize() > 1) {
Expand Down Expand Up @@ -761,13 +775,94 @@ class PhotoPagerActivity : BaseMvpActivity<PhotoPagerPresenter, IPhotoPagerView>
val reload: FloatingActionButton
private val mPicassoLoadCallback: WeakPicassoLoadCallback
val photo: TouchImageView
val tagsPlaceholder: FrameLayout
val progress: RLottieImageView
var animationDispose: Disposable = Disposable.disposed()
private var mAnimationLoaded = false
private var mLoadingNow = false
private var tagCleared = true
private var currentPhoto: Photo? = null

fun clearTags() {
if (tagCleared) {
return
}
tagsPlaceholder.removeAllViews()
tagsPlaceholder.visibility = View.GONE
tagCleared = true
}

fun addTags() {
if (!tagCleared) {
return
}
val currPhoto = currentPhoto ?: return
if (!currPhoto.showPhotoTags || currPhoto.photoTags.isNullOrEmpty()) {
return
}
val tags = currPhoto.photoTags
val stateValues = photo.getStateValues() ?: return
if (stateValues.viewWidth <= 0 || stateValues.viewHeight <= 0 || stateValues.bitmapWidth <= 0 || stateValues.bitmapHeight <= 0) {
return
}
val scaleX: Double = stateValues.matrix[Matrix.MSCALE_X].toDouble()
val bitmapWidth: Double = stateValues.bitmapWidth.toDouble()
val preScaledBitmapWidth = scaleX * bitmapWidth / 100.0
val scaleY: Double = stateValues.matrix[Matrix.MSCALE_Y].toDouble()
val bitmapHeight: Double = stateValues.bitmapHeight.toDouble()
val preScaledBitmapHeight = scaleY * bitmapHeight / 100.0
val transX: Double = stateValues.matrix[Matrix.MTRANS_X].toDouble()
val transY: Double = stateValues.matrix[Matrix.MTRANS_Y].toDouble()

var has = false
for (i in tags.orEmpty()) {
val leftMargin = transX + i.getX() * preScaledBitmapWidth
val topMargin = transY + i.getY() * preScaledBitmapHeight
val layoutWidth = ((i.getX2() - i.getX()) * preScaledBitmapWidth)
val layoutHeight = ((i.getY2() - i.getY()) * preScaledBitmapHeight)

if (leftMargin > stateValues.viewWidth || leftMargin < -50.0 || topMargin > stateValues.viewHeight || topMargin < -50.0) {
continue
} else {
val layoutParams = FrameLayout.LayoutParams(-2, -2)
layoutParams.leftMargin = leftMargin.toInt()
layoutParams.topMargin = topMargin.toInt()
val inflate =
layoutInflater.inflate(R.layout.photo_tag_item, null as ViewGroup?)
inflate.findViewById<TextView>(R.id.tv_ph_tag_name)?.let { txt ->
txt.visibility =
if (i.getTaggedName().nonNullNoEmpty()) View.VISIBLE else View.GONE
txt.text = i.getTaggedName()
txt.tag = i
txt.setOnClickListener {
val photoTag = txt.tag as? PhotoTags
if (photoTag != null) {
PlaceFactory.getOwnerWallPlace(
Settings.get().accounts().current, photoTag.getUserId(), null
).tryOpenWith(this@PhotoPagerActivity)
}
}
}
(inflate.findViewById(R.id.iv_ph_tag_border) as ImageView).layoutParams =
LinearLayout.LayoutParams(layoutWidth.toInt(), layoutHeight.toInt())
tagsPlaceholder.addView(inflate, layoutParams)
if (!has) {
has = true
}
}
}
if (has) {
tagCleared = false
tagsPlaceholder.visibility = View.VISIBLE
}
}

fun bindTo(photo_image: Photo) {
clearTags()
photo.resetZoom()
photo.orientationLocked = TouchImageView.OrientationLocked.HORIZONTAL
val size: Int = photoSizeFromPrefs
currentPhoto = photo_image
val url = photo_image.getUrlForSize(size, true)
reload.setOnClickListener {
reload.visibility = View.INVISIBLE
Expand Down Expand Up @@ -829,6 +924,7 @@ class PhotoPagerActivity : BaseMvpActivity<PhotoPagerPresenter, IPhotoPagerView>
}

private fun loadImage(url: String) {
PicassoInstance.with().cancelRequest(photo)
mLoadingNow = true
resolveProgressVisibility(true)
PicassoInstance.with()
Expand All @@ -850,6 +946,11 @@ class PhotoPagerActivity : BaseMvpActivity<PhotoPagerPresenter, IPhotoPagerView>
mLoadingNow = false
resolveProgressVisibility(false)
reload.visibility = View.INVISIBLE

clearTags()
photo.doOnPreDraw {
addTags()
}
}

override fun onError(t: Throwable) {
Expand All @@ -865,6 +966,7 @@ class PhotoPagerActivity : BaseMvpActivity<PhotoPagerPresenter, IPhotoPagerView>
photo.doubleTapMaxZoom = 4f
progress = view.findViewById(idOfProgressBar())
reload = view.findViewById(R.id.goto_button)
tagsPlaceholder = view.findViewById(R.id.tags_placeholder)
mPicassoLoadCallback = WeakPicassoLoadCallback(this)
photo.setOnClickListener { presenter?.firePhotoTap() }
}
Expand All @@ -886,12 +988,42 @@ class PhotoPagerActivity : BaseMvpActivity<PhotoPagerPresenter, IPhotoPagerView>
if (rot >= 360f) {
rot = 0f
}
if (rot == 0f) {
ret.clearTags()
ret.addTags()
} else {
ret.clearTags()
}
(ret.photo.drawable as Rotatable).rotate(rot)
ret.photo.fitImageToView()
ret.photo.invalidate()
}
true
}
ret.photo.setOnStateChangeListener(object : TouchImageView.StateListener {
override fun onChangeState(
imageActionState: TouchImageView.ImageActionState,
zoomed: Boolean
) {
when (imageActionState) {
TouchImageView.ImageActionState.NONE -> {
ret.addTags()
}

TouchImageView.ImageActionState.CANT_MOVE, TouchImageView.ImageActionState.MOVE, TouchImageView.ImageActionState.FLING -> {
if (zoomed) {
ret.clearTags()
}
}

TouchImageView.ImageActionState.ZOOM, TouchImageView.ImageActionState.ANIMATE_ZOOM -> {
ret.clearTags()
}

else -> {}
}
}
})
ret.photo.setOnTouchListener { view: View, event: MotionEvent ->
if (event.pointerCount >= 2 || view.canScrollHorizontally(1) && view.canScrollHorizontally(
-1
Expand All @@ -914,10 +1046,12 @@ class PhotoPagerActivity : BaseMvpActivity<PhotoPagerPresenter, IPhotoPagerView>
return ret
}

/*
override fun onViewDetachedFromWindow(holder: PhotoViewHolder) {
super.onViewDetachedFromWindow(holder)
PicassoInstance.with().cancelRequest(holder.photo)
}
*/

override fun onBindViewHolder(holder: PhotoViewHolder, position: Int) {
val photo = mPhotos[position]
Expand Down
Loading

0 comments on commit b26e549

Please sign in to comment.