Compare commits
5 Commits
88bd746359
...
40bed2db21
Author | SHA1 | Date | |
---|---|---|---|
40bed2db21 | |||
f901495e41 | |||
07f5f8b5d9 | |||
2d5f5a82c9 | |||
b477272d65 |
@ -9,6 +9,8 @@ import android.system.Os
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import sushi.hardcore.droidfs.filesystems.EncryptedVolume
|
import sushi.hardcore.droidfs.filesystems.EncryptedVolume
|
||||||
import sushi.hardcore.droidfs.util.Compat
|
import sushi.hardcore.droidfs.util.Compat
|
||||||
@ -86,7 +88,9 @@ class EncryptedFileProvider(context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun free() {
|
override fun free() {
|
||||||
Wiper.wipe(file)
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
|
Wiper.wipe(file)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,8 +164,10 @@ class EncryptedFileProvider(context: Context) {
|
|||||||
exportedFile: ExportedFile,
|
exportedFile: ExportedFile,
|
||||||
encryptedVolume: EncryptedVolume,
|
encryptedVolume: EncryptedVolume,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val fd = exportedFile.open(ParcelFileDescriptor.MODE_WRITE_ONLY, false).fileDescriptor
|
val pfd = exportedFile.open(ParcelFileDescriptor.MODE_WRITE_ONLY, false)
|
||||||
return encryptedVolume.exportFile(exportedFile.path, FileOutputStream(fd))
|
return encryptedVolume.exportFile(exportedFile.path, FileOutputStream(pfd.fileDescriptor)).also {
|
||||||
|
pfd.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Error {
|
enum class Error {
|
||||||
|
@ -104,7 +104,9 @@ class FileOperationService : Service() {
|
|||||||
activity.lifecycle.addObserver(object : DefaultLifecycleObserver {
|
activity.lifecycle.addObserver(object : DefaultLifecycleObserver {
|
||||||
override fun onDestroy(owner: LifecycleOwner) {
|
override fun onDestroy(owner: LifecycleOwner) {
|
||||||
activity.unbindService(serviceConnection)
|
activity.unbindService(serviceConnection)
|
||||||
service.notificationPermissionHelpers.removeLast()
|
// Could have been more efficient with a LinkedHashMap but the JDK implementation doesn't allow
|
||||||
|
// to access the latest element in O(1) unless using reflection
|
||||||
|
service.notificationPermissionHelpers.removeAll { it.activity == activity }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
activity.bindService(
|
activity.bindService(
|
||||||
|
@ -14,6 +14,8 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.sync.Mutex
|
||||||
|
import kotlinx.coroutines.sync.withLock
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import sushi.hardcore.droidfs.BaseActivity
|
import sushi.hardcore.droidfs.BaseActivity
|
||||||
import sushi.hardcore.droidfs.FileTypes
|
import sushi.hardcore.droidfs.FileTypes
|
||||||
@ -21,7 +23,6 @@ import sushi.hardcore.droidfs.R
|
|||||||
import sushi.hardcore.droidfs.VolumeManagerApp
|
import sushi.hardcore.droidfs.VolumeManagerApp
|
||||||
import sushi.hardcore.droidfs.explorers.ExplorerElement
|
import sushi.hardcore.droidfs.explorers.ExplorerElement
|
||||||
import sushi.hardcore.droidfs.filesystems.EncryptedVolume
|
import sushi.hardcore.droidfs.filesystems.EncryptedVolume
|
||||||
import sushi.hardcore.droidfs.util.IntentUtils
|
|
||||||
import sushi.hardcore.droidfs.util.PathUtils
|
import sushi.hardcore.droidfs.util.PathUtils
|
||||||
import sushi.hardcore.droidfs.util.finishOnClose
|
import sushi.hardcore.droidfs.util.finishOnClose
|
||||||
import sushi.hardcore.droidfs.widgets.CustomAlertDialogBuilder
|
import sushi.hardcore.droidfs.widgets.CustomAlertDialogBuilder
|
||||||
@ -32,9 +33,8 @@ abstract class FileViewerActivity: BaseActivity() {
|
|||||||
private lateinit var originalParentPath: String
|
private lateinit var originalParentPath: String
|
||||||
private lateinit var windowInsetsController: WindowInsetsControllerCompat
|
private lateinit var windowInsetsController: WindowInsetsControllerCompat
|
||||||
private var windowTypeMask = 0
|
private var windowTypeMask = 0
|
||||||
private var foldersFirst = true
|
protected val playlist = mutableListOf<ExplorerElement>()
|
||||||
private var wasMapped = false
|
private val playlistMutex = Mutex()
|
||||||
protected val mappedPlaylist = mutableListOf<ExplorerElement>()
|
|
||||||
protected var currentPlaylistIndex = -1
|
protected var currentPlaylistIndex = -1
|
||||||
private val isLegacyFullscreen = Build.VERSION.SDK_INT <= Build.VERSION_CODES.R
|
private val isLegacyFullscreen = Build.VERSION.SDK_INT <= Build.VERSION_CODES.R
|
||||||
|
|
||||||
@ -46,7 +46,6 @@ abstract class FileViewerActivity: BaseActivity() {
|
|||||||
intent.getIntExtra("volumeId", -1)
|
intent.getIntExtra("volumeId", -1)
|
||||||
)!!
|
)!!
|
||||||
finishOnClose(encryptedVolume)
|
finishOnClose(encryptedVolume)
|
||||||
foldersFirst = sharedPrefs.getBoolean("folders_first", true)
|
|
||||||
windowInsetsController = WindowInsetsControllerCompat(window, window.decorView)
|
windowInsetsController = WindowInsetsControllerCompat(window, window.decorView)
|
||||||
windowInsetsController.addOnControllableInsetsChangedListener { _, typeMask ->
|
windowInsetsController.addOnControllableInsetsChangedListener { _, typeMask ->
|
||||||
windowTypeMask = typeMask
|
windowTypeMask = typeMask
|
||||||
@ -131,48 +130,57 @@ abstract class FileViewerActivity: BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun createPlaylist() {
|
protected suspend fun createPlaylist() {
|
||||||
if (!wasMapped){
|
playlistMutex.withLock {
|
||||||
encryptedVolume.recursiveMapFiles(originalParentPath)?.let { elements ->
|
if (currentPlaylistIndex != -1) {
|
||||||
for (e in elements) {
|
// playlist already initialized
|
||||||
if (e.isRegularFile) {
|
return
|
||||||
if (FileTypes.isExtensionType(getFileType(), e.name) || filePath == e.fullPath) {
|
|
||||||
mappedPlaylist.add(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
val sortOrder = intent.getStringExtra("sortOrder") ?: "name"
|
withContext(Dispatchers.IO) {
|
||||||
ExplorerElement.sortBy(sortOrder, foldersFirst, mappedPlaylist)
|
if (sharedPrefs.getBoolean("map_folders", true)) {
|
||||||
//find current index
|
encryptedVolume.recursiveMapFiles(originalParentPath)
|
||||||
for ((i, e) in mappedPlaylist.withIndex()){
|
} else {
|
||||||
if (filePath == e.fullPath){
|
encryptedVolume.readDir(originalParentPath)
|
||||||
currentPlaylistIndex = i
|
}?.filterTo(playlist) { e ->
|
||||||
break
|
e.isRegularFile && (FileTypes.isExtensionType(getFileType(), e.name) || filePath == e.fullPath)
|
||||||
}
|
}
|
||||||
|
val sortOrder = intent.getStringExtra("sortOrder") ?: "name"
|
||||||
|
val foldersFirst = sharedPrefs.getBoolean("folders_first", true)
|
||||||
|
ExplorerElement.sortBy(sortOrder, foldersFirst, playlist)
|
||||||
|
currentPlaylistIndex = playlist.indexOfFirst { it.fullPath == filePath }
|
||||||
}
|
}
|
||||||
wasMapped = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun playlistNext(forward: Boolean) {
|
private fun updateCurrentItem() {
|
||||||
|
filePath = playlist[currentPlaylistIndex].fullPath
|
||||||
|
}
|
||||||
|
|
||||||
|
protected suspend fun playlistNext(forward: Boolean) {
|
||||||
createPlaylist()
|
createPlaylist()
|
||||||
currentPlaylistIndex = if (forward) {
|
currentPlaylistIndex = if (forward) {
|
||||||
(currentPlaylistIndex+1)%mappedPlaylist.size
|
(currentPlaylistIndex + 1).mod(playlist.size)
|
||||||
} else {
|
} else {
|
||||||
var x = (currentPlaylistIndex-1)%mappedPlaylist.size
|
(currentPlaylistIndex - 1).mod(playlist.size)
|
||||||
if (x < 0) {
|
|
||||||
x += mappedPlaylist.size
|
|
||||||
}
|
|
||||||
x
|
|
||||||
}
|
}
|
||||||
filePath = mappedPlaylist[currentPlaylistIndex].fullPath
|
updateCurrentItem()
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun refreshPlaylist() {
|
protected suspend fun deleteCurrentFile(): Boolean {
|
||||||
mappedPlaylist.clear()
|
createPlaylist() // ensure we know the current position in the playlist
|
||||||
wasMapped = false
|
return if (encryptedVolume.deleteFile(filePath)) {
|
||||||
createPlaylist()
|
playlist.removeAt(currentPlaylistIndex)
|
||||||
|
if (playlist.size != 0) {
|
||||||
|
if (currentPlaylistIndex == playlist.size) {
|
||||||
|
// deleted the last element of the playlist, go back to the first
|
||||||
|
currentPlaylistIndex = 0
|
||||||
|
}
|
||||||
|
updateCurrentItem()
|
||||||
|
}
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun goBackToExplorer() {
|
protected fun goBackToExplorer() {
|
||||||
|
@ -12,10 +12,12 @@ import android.widget.Toast
|
|||||||
import androidx.activity.addCallback
|
import androidx.activity.addCallback
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import com.bumptech.glide.RequestBuilder
|
import com.bumptech.glide.RequestBuilder
|
||||||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool
|
||||||
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
|
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import sushi.hardcore.droidfs.Constants
|
import sushi.hardcore.droidfs.Constants
|
||||||
import sushi.hardcore.droidfs.R
|
import sushi.hardcore.droidfs.R
|
||||||
import sushi.hardcore.droidfs.databinding.ActivityImageViewerBinding
|
import sushi.hardcore.droidfs.databinding.ActivityImageViewerBinding
|
||||||
@ -105,22 +107,21 @@ class ImageViewer: FileViewerActivity() {
|
|||||||
.keepFullScreen()
|
.keepFullScreen()
|
||||||
.setTitle(R.string.warning)
|
.setTitle(R.string.warning)
|
||||||
.setPositiveButton(R.string.ok) { _, _ ->
|
.setPositiveButton(R.string.ok) { _, _ ->
|
||||||
createPlaylist() //be sure the playlist is created before deleting if there is only one image
|
lifecycleScope.launch {
|
||||||
if (encryptedVolume.deleteFile(filePath)) {
|
if (deleteCurrentFile()) {
|
||||||
playlistNext(true)
|
if (playlist.size == 0) { // no more image left
|
||||||
refreshPlaylist()
|
goBackToExplorer()
|
||||||
if (mappedPlaylist.size == 0) { //deleted all images of the playlist
|
} else {
|
||||||
goBackToExplorer()
|
loadImage(true)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
loadImage(true)
|
CustomAlertDialogBuilder(this@ImageViewer, theme)
|
||||||
|
.keepFullScreen()
|
||||||
|
.setTitle(R.string.error)
|
||||||
|
.setMessage(getString(R.string.remove_failed, fileName))
|
||||||
|
.setPositiveButton(R.string.ok, null)
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
CustomAlertDialogBuilder(this, theme)
|
|
||||||
.keepFullScreen()
|
|
||||||
.setTitle(R.string.error)
|
|
||||||
.setMessage(getString(R.string.remove_failed, fileName))
|
|
||||||
.setPositiveButton(R.string.ok, null)
|
|
||||||
.show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.setNegativeButton(R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
@ -198,14 +199,16 @@ class ImageViewer: FileViewerActivity() {
|
|||||||
rotateImage()
|
rotateImage()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun swipeImage(deltaX: Float, slideshowSwipe: Boolean = false){
|
private fun swipeImage(deltaX: Float, slideshowSwipe: Boolean = false) {
|
||||||
playlistNext(deltaX < 0)
|
lifecycleScope.launch {
|
||||||
loadImage(true)
|
playlistNext(deltaX < 0)
|
||||||
if (slideshowActive) {
|
loadImage(true)
|
||||||
if (!slideshowSwipe) { //reset slideshow delay if user swipes
|
if (slideshowActive) {
|
||||||
handler.removeCallbacks(slideshowNext)
|
if (!slideshowSwipe) { // reset slideshow delay if user swipes
|
||||||
|
handler.removeCallbacks(slideshowNext)
|
||||||
|
}
|
||||||
|
handler.postDelayed(slideshowNext, Constants.SLIDESHOW_DELAY)
|
||||||
}
|
}
|
||||||
handler.postDelayed(slideshowNext, Constants.SLIDESHOW_DELAY)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package sushi.hardcore.droidfs.file_viewers
|
|||||||
|
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.annotation.OptIn
|
import androidx.annotation.OptIn
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.media3.common.MediaItem
|
import androidx.media3.common.MediaItem
|
||||||
import androidx.media3.common.PlaybackException
|
import androidx.media3.common.PlaybackException
|
||||||
import androidx.media3.common.Player
|
import androidx.media3.common.Player
|
||||||
@ -11,6 +12,7 @@ import androidx.media3.exoplayer.ExoPlayer
|
|||||||
import androidx.media3.exoplayer.source.MediaSource
|
import androidx.media3.exoplayer.source.MediaSource
|
||||||
import androidx.media3.exoplayer.source.ProgressiveMediaSource
|
import androidx.media3.exoplayer.source.ProgressiveMediaSource
|
||||||
import androidx.media3.extractor.DefaultExtractorsFactory
|
import androidx.media3.extractor.DefaultExtractorsFactory
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import sushi.hardcore.droidfs.Constants
|
import sushi.hardcore.droidfs.Constants
|
||||||
import sushi.hardcore.droidfs.R
|
import sushi.hardcore.droidfs.R
|
||||||
import sushi.hardcore.droidfs.widgets.CustomAlertDialogBuilder
|
import sushi.hardcore.droidfs.widgets.CustomAlertDialogBuilder
|
||||||
@ -39,12 +41,16 @@ abstract class MediaPlayer: FileViewerActivity() {
|
|||||||
private fun initializePlayer(){
|
private fun initializePlayer(){
|
||||||
player = ExoPlayer.Builder(this).setSeekForwardIncrementMs(5000).build()
|
player = ExoPlayer.Builder(this).setSeekForwardIncrementMs(5000).build()
|
||||||
bindPlayer(player)
|
bindPlayer(player)
|
||||||
createPlaylist()
|
player.addMediaSource(createMediaSource(filePath))
|
||||||
for (e in mappedPlaylist) {
|
lifecycleScope.launch {
|
||||||
player.addMediaSource(createMediaSource(e.fullPath))
|
createPlaylist()
|
||||||
|
playlist.forEachIndexed { index, e ->
|
||||||
|
if (index != currentPlaylistIndex) {
|
||||||
|
player.addMediaSource(index, createMediaSource(e.fullPath))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
player.repeatMode = Player.REPEAT_MODE_ALL
|
player.repeatMode = Player.REPEAT_MODE_ALL
|
||||||
player.seekToDefaultPosition(currentPlaylistIndex)
|
|
||||||
player.playWhenReady = true
|
player.playWhenReady = true
|
||||||
player.addListener(object : Player.Listener{
|
player.addListener(object : Player.Listener{
|
||||||
override fun onVideoSizeChanged(videoSize: VideoSize) {
|
override fun onVideoSizeChanged(videoSize: VideoSize) {
|
||||||
@ -67,9 +73,11 @@ abstract class MediaPlayer: FileViewerActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
|
override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
|
||||||
if (player.repeatMode != Player.REPEAT_MODE_ONE) {
|
if (player.repeatMode != Player.REPEAT_MODE_ONE && currentPlaylistIndex != -1) {
|
||||||
playlistNext(player.currentMediaItemIndex == (currentPlaylistIndex + 1) % mappedPlaylist.size)
|
lifecycleScope.launch {
|
||||||
refreshFileName()
|
playlistNext(player.currentMediaItemIndex == (currentPlaylistIndex + 1) % player.mediaItemCount)
|
||||||
|
refreshFileName()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -28,7 +28,7 @@ object AndroidUtils {
|
|||||||
/**
|
/**
|
||||||
* A [Manifest.permission.POST_NOTIFICATIONS] permission helper.
|
* A [Manifest.permission.POST_NOTIFICATIONS] permission helper.
|
||||||
*
|
*
|
||||||
* Must be initialized before [Activity.onCreate].
|
* Must be initialized before [Activity.onCreate] finishes.
|
||||||
*/
|
*/
|
||||||
class NotificationPermissionHelper<out A: AppCompatActivity>(val activity: A) {
|
class NotificationPermissionHelper<out A: AppCompatActivity>(val activity: A) {
|
||||||
private var listener: ((Boolean) -> Unit)? = null
|
private var listener: ((Boolean) -> Unit)? = null
|
||||||
|
Loading…
Reference in New Issue
Block a user