mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-01-18 14:28:00 +01:00
adding some rotation related improvements
This commit is contained in:
parent
c1af0bda75
commit
d55c9bb2cb
3 changed files with 22 additions and 18 deletions
|
@ -75,7 +75,7 @@ dependencies {
|
||||||
implementation 'com.squareup.picasso:picasso:2.71828'
|
implementation 'com.squareup.picasso:picasso:2.71828'
|
||||||
implementation 'com.caverock:androidsvg-aar:1.3'
|
implementation 'com.caverock:androidsvg-aar:1.3'
|
||||||
implementation 'com.github.tibbi:gestureviews:985ba285fb'
|
implementation 'com.github.tibbi:gestureviews:985ba285fb'
|
||||||
implementation 'com.github.tibbi:subsampling-scale-image-view:f8559f7f43'
|
implementation 'com.github.tibbi:subsampling-scale-image-view:7be04d9b93'
|
||||||
kapt 'com.github.bumptech.glide:compiler:4.8.0' // keep it here too, not just in Commons, else loading SVGs wont work
|
kapt 'com.github.bumptech.glide:compiler:4.8.0' // keep it here too, not just in Commons, else loading SVGs wont work
|
||||||
|
|
||||||
kapt 'androidx.room:room-compiler:2.0.0'
|
kapt 'androidx.room:room-compiler:2.0.0'
|
||||||
|
|
|
@ -54,7 +54,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
private var mPos = -1
|
private var mPos = -1
|
||||||
private var mShowAll = false
|
private var mShowAll = false
|
||||||
private var mIsSlideshowActive = false
|
private var mIsSlideshowActive = false
|
||||||
private var mRotationDegrees = 0
|
|
||||||
private var mPrevHashcode = 0
|
private var mPrevHashcode = 0
|
||||||
|
|
||||||
private var mSlideshowHandler = Handler()
|
private var mSlideshowHandler = Handler()
|
||||||
|
@ -142,7 +141,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
currentMedium.isFavorite = mFavoritePaths.contains(currentMedium.path)
|
currentMedium.isFavorite = mFavoritePaths.contains(currentMedium.path)
|
||||||
val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0
|
val visibleBottomActions = if (config.bottomActions) config.visibleBottomActions else 0
|
||||||
|
|
||||||
getCurrentPhotoFragment()?.mCurrentRotationDegrees = mRotationDegrees
|
val rotationDegrees = getCurrentPhotoFragment()?.mCurrentRotationDegrees
|
||||||
menu.apply {
|
menu.apply {
|
||||||
findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0
|
findItem(R.id.menu_show_on_map).isVisible = visibleBottomActions and BOTTOM_ACTION_SHOW_ON_MAP == 0
|
||||||
findItem(R.id.menu_slideshow).isVisible = visibleBottomActions and BOTTOM_ACTION_SLIDESHOW == 0
|
findItem(R.id.menu_slideshow).isVisible = visibleBottomActions and BOTTOM_ACTION_SLIDESHOW == 0
|
||||||
|
@ -154,16 +153,16 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
findItem(R.id.menu_rotate).isVisible = currentMedium.isImage() && visibleBottomActions and BOTTOM_ACTION_ROTATE == 0
|
findItem(R.id.menu_rotate).isVisible = currentMedium.isImage() && visibleBottomActions and BOTTOM_ACTION_ROTATE == 0
|
||||||
findItem(R.id.menu_set_as).isVisible = visibleBottomActions and BOTTOM_ACTION_SET_AS == 0
|
findItem(R.id.menu_set_as).isVisible = visibleBottomActions and BOTTOM_ACTION_SET_AS == 0
|
||||||
findItem(R.id.menu_copy_to).isVisible = visibleBottomActions and BOTTOM_ACTION_COPY == 0
|
findItem(R.id.menu_copy_to).isVisible = visibleBottomActions and BOTTOM_ACTION_COPY == 0
|
||||||
findItem(R.id.menu_save_as).isVisible = mRotationDegrees != 0
|
findItem(R.id.menu_save_as).isVisible = rotationDegrees != 0
|
||||||
findItem(R.id.menu_hide).isVisible = !currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
|
findItem(R.id.menu_hide).isVisible = !currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
|
||||||
findItem(R.id.menu_unhide).isVisible = currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
|
findItem(R.id.menu_unhide).isVisible = currentMedium.isHidden() && visibleBottomActions and BOTTOM_ACTION_TOGGLE_VISIBILITY == 0 && !currentMedium.getIsInRecycleBin()
|
||||||
findItem(R.id.menu_add_to_favorites).isVisible = !currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0
|
findItem(R.id.menu_add_to_favorites).isVisible = !currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0
|
||||||
findItem(R.id.menu_remove_from_favorites).isVisible = currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0
|
findItem(R.id.menu_remove_from_favorites).isVisible = currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0
|
||||||
findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(recycleBinPath)
|
findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(recycleBinPath)
|
||||||
findItem(R.id.menu_change_orientation).isVisible = mRotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 0
|
findItem(R.id.menu_change_orientation).isVisible = rotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 0
|
||||||
findItem(R.id.menu_change_orientation).icon = resources.getDrawable(getChangeOrientationIcon())
|
findItem(R.id.menu_change_orientation).icon = resources.getDrawable(getChangeOrientationIcon())
|
||||||
findItem(R.id.menu_rotate).setShowAsAction(
|
findItem(R.id.menu_rotate).setShowAsAction(
|
||||||
if (mRotationDegrees != 0) {
|
if (rotationDegrees != 0) {
|
||||||
MenuItem.SHOW_AS_ACTION_ALWAYS
|
MenuItem.SHOW_AS_ACTION_ALWAYS
|
||||||
} else {
|
} else {
|
||||||
MenuItem.SHOW_AS_ACTION_IF_ROOM
|
MenuItem.SHOW_AS_ACTION_IF_ROOM
|
||||||
|
@ -563,8 +562,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun rotateBy(degrees: Int) {
|
private fun rotateBy(degrees: Int) {
|
||||||
mRotationDegrees = (mRotationDegrees + degrees) % 360
|
getCurrentPhotoFragment()?.rotateImageViewBy(degrees)
|
||||||
getCurrentPhotoFragment()?.rotateImageViewBy(mRotationDegrees)
|
|
||||||
supportInvalidateOptionsMenu()
|
supportInvalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -592,10 +590,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
handleSAFDialog(it) {
|
handleSAFDialog(it) {
|
||||||
toast(R.string.saving)
|
toast(R.string.saving)
|
||||||
Thread {
|
Thread {
|
||||||
saveRotatedImageToFile(currPath, it, mRotationDegrees, true) {
|
val photoFragment = getCurrentPhotoFragment() ?: return@Thread
|
||||||
|
saveRotatedImageToFile(currPath, it, photoFragment.mCurrentRotationDegrees, true) {
|
||||||
toast(R.string.file_saved)
|
toast(R.string.file_saved)
|
||||||
mRotationDegrees = 0
|
|
||||||
getCurrentPhotoFragment()?.mCurrentRotationDegrees = 0
|
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
|
@ -1075,7 +1072,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
if (mPos != position) {
|
if (mPos != position) {
|
||||||
mPos = position
|
mPos = position
|
||||||
updateActionbarTitle()
|
updateActionbarTitle()
|
||||||
mRotationDegrees = 0
|
|
||||||
invalidateOptionsMenu()
|
invalidateOptionsMenu()
|
||||||
scheduleSwipe()
|
scheduleSwipe()
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
)
|
)
|
||||||
|
|
||||||
var mCurrentRotationDegrees = 0
|
var mCurrentRotationDegrees = 0
|
||||||
|
private var mOriginalRotationDegrees = 0
|
||||||
private var mIsFragmentVisible = false
|
private var mIsFragmentVisible = false
|
||||||
private var mIsFullscreen = false
|
private var mIsFullscreen = false
|
||||||
private var mWasInit = false
|
private var mWasInit = false
|
||||||
|
@ -356,7 +357,7 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
.into(mView.gestures_view)
|
.into(mView.gestures_view)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadBitmap(degrees: Int = mCurrentRotationDegrees) {
|
private fun loadBitmap(degrees: Int = mCurrentRotationDegrees, addZoomableView: Boolean = true) {
|
||||||
val options = RequestOptions()
|
val options = RequestOptions()
|
||||||
.signature(mMedium.path.getFileSignature())
|
.signature(mMedium.path.getFileSignature())
|
||||||
.format(DecodeFormat.PREFER_ARGB_8888)
|
.format(DecodeFormat.PREFER_ARGB_8888)
|
||||||
|
@ -374,13 +375,13 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
.listener(object : RequestListener<Drawable> {
|
.listener(object : RequestListener<Drawable> {
|
||||||
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
|
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
tryLoadingWithPicasso(degrees)
|
tryLoadingWithPicasso(degrees, addZoomableView)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
|
||||||
if (mIsFragmentVisible) {
|
if (mIsFragmentVisible && addZoomableView) {
|
||||||
scheduleZoomableView()
|
scheduleZoomableView()
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -388,7 +389,7 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
}).into(mView.gestures_view)
|
}).into(mView.gestures_view)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun tryLoadingWithPicasso(degrees: Int = 0) {
|
private fun tryLoadingWithPicasso(degrees: Int = 0, addZoomableView: Boolean) {
|
||||||
var pathToLoad = if (mMedium.path.startsWith("content://")) mMedium.path else "file://${mMedium.path}"
|
var pathToLoad = if (mMedium.path.startsWith("content://")) mMedium.path else "file://${mMedium.path}"
|
||||||
pathToLoad = pathToLoad.replace("%", "%25").replace("#", "%23")
|
pathToLoad = pathToLoad.replace("%", "%25").replace("#", "%23")
|
||||||
|
|
||||||
|
@ -408,7 +409,7 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
picasso.into(mView.gestures_view, object : Callback {
|
picasso.into(mView.gestures_view, object : Callback {
|
||||||
override fun onSuccess() {
|
override fun onSuccess() {
|
||||||
mView.gestures_view.controller.settings.isZoomEnabled = degrees != 0 || context?.config?.allowZoomingImages == false
|
mView.gestures_view.controller.settings.isZoomEnabled = degrees != 0 || context?.config?.allowZoomingImages == false
|
||||||
if (mIsFragmentVisible) {
|
if (mIsFragmentVisible && addZoomableView) {
|
||||||
scheduleZoomableView()
|
scheduleZoomableView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -476,6 +477,13 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
mIsSubsamplingVisible = false
|
mIsSubsamplingVisible = false
|
||||||
beGone()
|
beGone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onImageRotation(degrees: Int) {
|
||||||
|
if (mCurrentRotationDegrees != degrees) {
|
||||||
|
loadBitmap(degrees, false)
|
||||||
|
}
|
||||||
|
mCurrentRotationDegrees = degrees
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -548,7 +556,7 @@ class PhotoFragment : ViewPagerFragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun rotateImageViewBy(degrees: Int) {
|
fun rotateImageViewBy(degrees: Int) {
|
||||||
mCurrentRotationDegrees = degrees
|
mCurrentRotationDegrees = (mCurrentRotationDegrees + degrees) % 360
|
||||||
mLoadZoomableViewHandler.removeCallbacksAndMessages(null)
|
mLoadZoomableViewHandler.removeCallbacksAndMessages(null)
|
||||||
mIsSubsamplingVisible = false
|
mIsSubsamplingVisible = false
|
||||||
loadBitmap(degrees)
|
loadBitmap(degrees)
|
||||||
|
|
Loading…
Reference in a new issue