mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
commit
bc863d2e27
@ -1,7 +1,6 @@
|
|||||||
package com.github.libretube.ui.activities
|
package com.github.libretube.ui.activities
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.graphics.Bitmap
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
@ -9,7 +8,6 @@ import androidx.core.view.isVisible
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.github.libretube.constants.IntentData
|
import com.github.libretube.constants.IntentData
|
||||||
import com.github.libretube.databinding.ActivityZoomableImageBinding
|
import com.github.libretube.databinding.ActivityZoomableImageBinding
|
||||||
import com.github.libretube.extensions.parcelableExtra
|
|
||||||
import com.github.libretube.helpers.ImageHelper
|
import com.github.libretube.helpers.ImageHelper
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.github.libretube.ui.fragments
|
package com.github.libretube.ui.fragments
|
||||||
|
|
||||||
import android.content.Intent
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
@ -30,7 +29,6 @@ import com.github.libretube.helpers.ImageHelper
|
|||||||
import com.github.libretube.helpers.NavigationHelper
|
import com.github.libretube.helpers.NavigationHelper
|
||||||
import com.github.libretube.obj.ChannelTabs
|
import com.github.libretube.obj.ChannelTabs
|
||||||
import com.github.libretube.obj.ShareData
|
import com.github.libretube.obj.ShareData
|
||||||
import com.github.libretube.ui.activities.ZoomableImageActivity
|
|
||||||
import com.github.libretube.ui.adapters.SearchAdapter
|
import com.github.libretube.ui.adapters.SearchAdapter
|
||||||
import com.github.libretube.ui.adapters.VideosAdapter
|
import com.github.libretube.ui.adapters.VideosAdapter
|
||||||
import com.github.libretube.ui.dialogs.ShareDialog
|
import com.github.libretube.ui.dialogs.ShareDialog
|
||||||
@ -202,11 +200,17 @@ class ChannelFragment : Fragment() {
|
|||||||
ImageHelper.loadImage(response.avatarUrl, binding.channelImage)
|
ImageHelper.loadImage(response.avatarUrl, binding.channelImage)
|
||||||
|
|
||||||
binding.channelImage.setOnClickListener {
|
binding.channelImage.setOnClickListener {
|
||||||
NavigationHelper.openImagePreview(requireContext(), response.avatarUrl ?: return@setOnClickListener)
|
NavigationHelper.openImagePreview(
|
||||||
|
requireContext(),
|
||||||
|
response.avatarUrl ?: return@setOnClickListener
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.channelBanner.setOnClickListener {
|
binding.channelBanner.setOnClickListener {
|
||||||
NavigationHelper.openImagePreview(requireContext(), response.bannerUrl ?: return@setOnClickListener)
|
NavigationHelper.openImagePreview(
|
||||||
|
requireContext(),
|
||||||
|
response.bannerUrl ?: return@setOnClickListener
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// recyclerview of the videos by the channel
|
// recyclerview of the videos by the channel
|
||||||
|
@ -64,8 +64,8 @@ class ZoomableImageView(context: Context, attr: AttributeSet?) : AppCompatImageV
|
|||||||
mode = ZOOM
|
mode = ZOOM
|
||||||
}
|
}
|
||||||
|
|
||||||
MotionEvent.ACTION_MOVE -> //if the mode is ZOOM or
|
MotionEvent.ACTION_MOVE -> // if the mode is ZOOM or
|
||||||
//if the mode is DRAG and already zoomed
|
// if the mode is DRAG and already zoomed
|
||||||
if (mode == ZOOM || mode == DRAG && saveScale > minScale) {
|
if (mode == ZOOM || mode == DRAG && saveScale > minScale) {
|
||||||
var deltaX = curr.x - last.x // x difference
|
var deltaX = curr.x - last.x // x difference
|
||||||
var deltaY = curr.y - last.y // y difference
|
var deltaY = curr.y - last.y // y difference
|
||||||
@ -73,26 +73,42 @@ class ZoomableImageView(context: Context, attr: AttributeSet?) : AppCompatImageV
|
|||||||
.toFloat() // width after applying current scale
|
.toFloat() // width after applying current scale
|
||||||
val scaleHeight = (origHeight * saveScale).roundToInt()
|
val scaleHeight = (origHeight * saveScale).roundToInt()
|
||||||
.toFloat() // height after applying current scale
|
.toFloat() // height after applying current scale
|
||||||
//if scaleWidth is smaller than the views width
|
// if scaleWidth is smaller than the views width
|
||||||
//in other words if the image width fits in the view
|
// in other words if the image width fits in the view
|
||||||
//limit left and right movement
|
// limit left and right movement
|
||||||
if (scaleWidth < width) {
|
if (scaleWidth < width) {
|
||||||
deltaX = 0f
|
deltaX = 0f
|
||||||
if (y + deltaY > 0) deltaY = -y else if (y + deltaY < -bottom) deltaY =
|
if (y + deltaY > 0) {
|
||||||
-(y + bottom)
|
deltaY = -y
|
||||||
} else if (scaleHeight < height) {
|
} else if (y + deltaY < -bottom) {
|
||||||
deltaY = 0f
|
deltaY =
|
||||||
if (x + deltaX > 0) deltaX = -x else if (x + deltaX < -right) deltaX =
|
|
||||||
-(x + right)
|
|
||||||
} else {
|
|
||||||
if (x + deltaX > 0) deltaX = -x else if (x + deltaX < -right) deltaX =
|
|
||||||
-(x + right)
|
|
||||||
if (y + deltaY > 0) deltaY = -y else if (y + deltaY < -bottom) deltaY =
|
|
||||||
-(y + bottom)
|
-(y + bottom)
|
||||||
}
|
}
|
||||||
//move the image with the matrix
|
} else if (scaleHeight < height) {
|
||||||
|
deltaY = 0f
|
||||||
|
if (x + deltaX > 0) {
|
||||||
|
deltaX = -x
|
||||||
|
} else if (x + deltaX < -right) {
|
||||||
|
deltaX =
|
||||||
|
-(x + right)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (x + deltaX > 0) {
|
||||||
|
deltaX = -x
|
||||||
|
} else if (x + deltaX < -right) {
|
||||||
|
deltaX =
|
||||||
|
-(x + right)
|
||||||
|
}
|
||||||
|
if (y + deltaY > 0) {
|
||||||
|
deltaY = -y
|
||||||
|
} else if (y + deltaY < -bottom) {
|
||||||
|
deltaY =
|
||||||
|
-(y + bottom)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// move the image with the matrix
|
||||||
bitmapMatrix.postTranslate(deltaX, deltaY)
|
bitmapMatrix.postTranslate(deltaX, deltaY)
|
||||||
//set the last touch location to the current
|
// set the last touch location to the current
|
||||||
last[curr.x] = curr.y
|
last[curr.x] = curr.y
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,15 +185,19 @@ class ZoomableImageView(context: Context, attr: AttributeSet?) : AppCompatImageV
|
|||||||
val y = m[Matrix.MTRANS_Y]
|
val y = m[Matrix.MTRANS_Y]
|
||||||
|
|
||||||
if ((origWidth * saveScale).roundToInt() < width) {
|
if ((origWidth * saveScale).roundToInt() < width) {
|
||||||
if (y < -bottom) bitmapMatrix.postTranslate(
|
if (y < -bottom) {
|
||||||
|
bitmapMatrix.postTranslate(
|
||||||
0f,
|
0f,
|
||||||
-(y + bottom)
|
-(y + bottom)
|
||||||
) else if (y > 0) bitmapMatrix.postTranslate(0f, -y)
|
)
|
||||||
|
} else if (y > 0) bitmapMatrix.postTranslate(0f, -y)
|
||||||
} else {
|
} else {
|
||||||
if (x < -right) bitmapMatrix.postTranslate(
|
if (x < -right) {
|
||||||
|
bitmapMatrix.postTranslate(
|
||||||
-(x + right),
|
-(x + right),
|
||||||
0f
|
0f
|
||||||
) else if (x > 0) bitmapMatrix.postTranslate(-x, 0f)
|
)
|
||||||
|
} else if (x > 0) bitmapMatrix.postTranslate(-x, 0f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -187,14 +207,18 @@ class ZoomableImageView(context: Context, attr: AttributeSet?) : AppCompatImageV
|
|||||||
val y = m[Matrix.MTRANS_Y]
|
val y = m[Matrix.MTRANS_Y]
|
||||||
|
|
||||||
if (mScaleFactor < 1) {
|
if (mScaleFactor < 1) {
|
||||||
if (x < -right) bitmapMatrix.postTranslate(
|
if (x < -right) {
|
||||||
|
bitmapMatrix.postTranslate(
|
||||||
-(x + right),
|
-(x + right),
|
||||||
0f
|
0f
|
||||||
) else if (x > 0) bitmapMatrix.postTranslate(-x, 0f)
|
)
|
||||||
if (y < -bottom) bitmapMatrix.postTranslate(
|
} else if (x > 0) bitmapMatrix.postTranslate(-x, 0f)
|
||||||
|
if (y < -bottom) {
|
||||||
|
bitmapMatrix.postTranslate(
|
||||||
0f,
|
0f,
|
||||||
-(y + bottom)
|
-(y + bottom)
|
||||||
) else if (y > 0) bitmapMatrix.postTranslate(0f, -y)
|
)
|
||||||
|
} else if (y > 0) bitmapMatrix.postTranslate(0f, -y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user