@ -15,9 +15,10 @@ import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
import kotlinx.android.synthetic.main.activity_image_viewer.*
import sushi.hardcore.droidfs.ConstValues
import sushi.hardcore.droidfs.R
import sushi.hardcore.droidfs.util.MiscUtils
import sushi.hardcore.droidfs.explorers.ExplorerElement
import sushi.hardcore.droidfs.util.MiscUtils
import sushi.hardcore.droidfs.util.PathUtils
import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder
import sushi.hardcore.droidfs.widgets.ZoomableImageView
import java.io.File
import java.security.MessageDigest
@ -28,6 +29,7 @@ class ImageViewer: FileViewerActivity() {
private const val hideDelay : Long = 3000
private const val MIN _SWIPE _DISTANCE = 150
}
private lateinit var fileName : String
private lateinit var glideImage : RequestBuilder < Drawable >
private var x1 = 0F
private var x2 = 0F
@ -43,44 +45,56 @@ class ImageViewer: FileViewerActivity() {
action _bar . visibility = View . GONE
}
override fun viewFile ( ) {
val imageBuff = loadWholeFile ( filePath )
if ( imageBuff != null ) {
setContentView ( R . layout . activity _image _viewer )
image _viewer . setOnInteractionListener ( object : ZoomableImageView . OnInteractionListener {
override fun onSingleTap ( event : MotionEvent ? ) {
handler . removeCallbacks ( hideUI )
if ( action _buttons . visibility == View . GONE ) {
action _buttons . visibility = View . VISIBLE
action _bar . visibility = View . VISIBLE
handler . postDelayed ( hideUI , hideDelay )
} else {
hideUI . run ( )
}
setContentView ( R . layout . activity _image _viewer )
image _viewer . setOnInteractionListener ( object : ZoomableImageView . OnInteractionListener {
override fun onSingleTap ( event : MotionEvent ? ) {
handler . removeCallbacks ( hideUI )
if ( action _buttons . visibility == View . GONE ) {
action _buttons . visibility = View . VISIBLE
action _bar . visibility = View . VISIBLE
handler . postDelayed ( hideUI , hideDelay )
} else {
hideUI . run ( )
}
override fun onTouch ( event : MotionEvent ? ) {
if ( ! image _viewer . isZoomed ) {
when ( event ?. action ) {
MotionEvent . ACTION _DOWN -> {
x1 = event . x
}
MotionEvent . ACTION _UP -> {
x2 = event . x
val deltaX = x2 - x1
if ( abs ( deltaX ) > MIN _SWIPE _DISTANCE ) {
swipeImage ( deltaX )
}
}
override fun onTouch ( event : MotionEvent ? ) {
if ( ! image _viewer . isZoomed ) {
when ( event ?. action ) {
MotionEvent . ACTION _DOWN -> {
x1 = event . x
}
MotionEvent . ACTION _UP -> {
x2 = event . x
val deltaX = x2 - x1
if ( abs ( deltaX ) > MIN _SWIPE _DISTANCE ) {
swipeImage ( deltaX )
}
}
}
}
} )
glideImage = Glide . with ( this ) . load ( imageBuff )
}
} )
loadImage ( )
handler . postDelayed ( hideUI , hideDelay )
}
private fun loadImage ( ) {
loadWholeFile ( filePath ) ?. let {
glideImage = Glide . with ( this ) . load ( it )
glideImage . into ( image _viewer )
text _filename . text = File ( filePath ) . name
handler . postDelayed ( hideUI , hideDelay )
fileName = File ( filePath ) . name
text _filename . text = fileName
rotationAngle = 0F
}
}
override fun onUserInteraction ( ) {
super . onUserInteraction ( )
handler . removeCallbacks ( hideUI )
handler . postDelayed ( hideUI , hideDelay )
}
private fun swipeImage ( deltaX : Float ) {
if ( ! wasMapped ) {
for ( e in gocryptfsVolume . recursiveMapFiles ( PathUtils . getParentPath ( filePath ) ) ) {
@ -103,26 +117,61 @@ class ImageViewer: FileViewerActivity() {
} else {
MiscUtils . decrementIndex ( currentMappedImageIndex , mappedImages )
}
loadWholeFile ( mappedImages [ currentMappedImageIndex ] . fullPath ) ?. let {
glideImage = Glide . with ( applicationContext ) . load ( it )
glideImage . into ( image _viewer )
text _filename . text = File ( mappedImages [ currentMappedImageIndex ] . fullPath ) . name
rotationAngle = 0F
}
filePath = mappedImages [ currentMappedImageIndex ] . fullPath
loadImage ( )
}
fun onClickDelete ( view : View ) {
ColoredAlertDialogBuilder ( this )
. keepFullScreen ( )
. setTitle ( R . string . warning )
. setPositiveButton ( R . string . ok ) { _ , _ ->
if ( gocryptfsVolume . removeFile ( filePath ) ) {
currentMappedImageIndex = MiscUtils . decrementIndex ( currentMappedImageIndex , mappedImages )
mappedImages . clear ( )
wasMapped = false
swipeImage ( - 1F )
} else {
ColoredAlertDialogBuilder ( this )
. keepFullScreen ( )
. setTitle ( R . string . error )
. setMessage ( getString ( R . string . remove _failed , fileName ) )
. setPositiveButton ( R . string . ok , null )
. show ( )
}
}
. setNegativeButton ( R . string . cancel , null )
. setMessage ( getString ( R . string . single _delete _confirm , fileName ) )
. show ( )
}
fun onClickSlideshow ( view : View ) {
if ( ! slideshowActive ) {
slideshowActive = true
Thread {
Thread . sleep ( ConstValues . slideshow _delay )
while ( slideshowActive ) {
runOnUiThread { swipeImage ( - 1F ) }
Thread . sleep ( ConstValues . slideshow _delay )
}
} . start ( )
hideUI . run ( )
Toast . makeText ( this , R . string . slideshow _started , Toast . LENGTH _SHORT ) . show ( )
} else {
stopSlideshow ( )
}
}
private fun stopSlideshow ( ) {
slideshowActive = false
Toast . makeText ( this , R . string . slideshow _stopped , Toast . LENGTH _SHORT ) . show ( )
}
override fun onBackPressed ( ) {
if ( slideshowActive ) {
stopSlideshow ( )
} else {
slideshowActive = false
Toast . makeText ( this , R . string . slideshow _stopped , Toast . LENGTH _SHORT ) . show ( )
super . onBackPressed ( )
}
}