Close volume onPause & FileViewer fullscreen fixes

This commit is contained in:
Hardcore Sushi 2020-08-08 14:09:34 +02:00
parent 62e04027d2
commit 35a2e35bdc
12 changed files with 110 additions and 40 deletions

View File

@ -552,6 +552,12 @@ func gcf_close(sessionID int){
delete(sessions, sessionID)
}
//export gcf_is_closed
func gcf_is_closed(sessionID int) bool {
_, ok := sessions[sessionID]
return !ok
}
//export gcf_create_volume
func gcf_create_volume(root_cipher_dir string, password []byte, logN int, creator string) bool {
err := configfile.Create(filepath.Join(root_cipher_dir, configfile.ConfDefaultName), password, false, logN, creator, false, false)

View File

@ -54,6 +54,7 @@ open class BaseExplorerActivity : BaseActivity() {
protected lateinit var explorerElements: MutableList<ExplorerElement>
protected lateinit var explorerAdapter: ExplorerElementAdapter
private var isCreating = true
protected var isStartingActivity = false
private var usf_open = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -97,6 +98,7 @@ open class BaseExplorerActivity : BaseActivity() {
if (sortOrder.isNotEmpty()){
intent.putExtra("sortOrder", sortOrder)
}
isStartingActivity = true
startActivity(intent)
}
@ -196,15 +198,6 @@ open class BaseExplorerActivity : BaseActivity() {
.show()
}
protected open fun closeVolumeOnUserExit() {
finish()
}
protected open fun closeVolumeOnDestroy() {
gocryptfsVolume.close()
RestrictedFileProvider.wipeAll(this) //additional security
}
override fun onBackPressed() {
if (explorerAdapter.selectedItems.isEmpty()) {
val parentPath = PathUtils.getParentPath(currentDirectoryPath)
@ -387,6 +380,7 @@ open class BaseExplorerActivity : BaseActivity() {
}
R.id.external_open -> {
if (usf_open){
isStartingActivity = true
ExternalProvider.open(this, gocryptfsVolume, PathUtils.path_join(currentDirectoryPath, explorerElements[explorerAdapter.selectedItems[0]].name))
unselectAll()
}
@ -400,6 +394,17 @@ open class BaseExplorerActivity : BaseActivity() {
}
}
protected open fun closeVolumeOnUserExit() {
finish()
}
protected open fun closeVolumeOnDestroy() {
if (!gocryptfsVolume.isClosed()){
gocryptfsVolume.close()
}
RestrictedFileProvider.wipeAll(this) //additional security
}
override fun onDestroy() {
super.onDestroy()
if (!isChangingConfigurations) { //activity won't be recreated
@ -407,12 +412,24 @@ open class BaseExplorerActivity : BaseActivity() {
}
}
override fun onPause() {
super.onPause()
if (!isChangingConfigurations && !isStartingActivity){
finish()
}
}
override fun onResume() {
super.onResume()
if (isCreating){
isCreating = false
} else {
ExternalProvider.removeFiles(this)
if (gocryptfsVolume.isClosed()){
finish()
} else {
isStartingActivity = false
ExternalProvider.removeFiles(this)
}
}
}
}

View File

@ -79,6 +79,7 @@ class ExplorerActivity : BaseExplorerActivity() {
"importFromOtherVolumes" -> {
val intent = Intent(this, OpenActivity::class.java)
intent.action = "pick"
isStartingActivity = true
startActivityForResult(intent, PICK_OTHER_VOLUME_ITEMS_REQUEST_CODE)
}
"importFiles" -> {
@ -86,6 +87,7 @@ class ExplorerActivity : BaseExplorerActivity() {
intent.type = "*/*"
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
intent.addCategory(Intent.CATEGORY_OPENABLE)
isStartingActivity = true
startActivityForResult(intent, PICK_FILES_REQUEST_CODE)
}
"createFile" -> {
@ -116,6 +118,7 @@ class ExplorerActivity : BaseExplorerActivity() {
val intent = Intent(this, CameraActivity::class.java)
intent.putExtra("path", currentDirectoryPath)
intent.putExtra("sessionID", gocryptfsVolume.sessionID)
isStartingActivity = true
startActivity(intent)
}
}
@ -425,12 +428,14 @@ class ExplorerActivity : BaseExplorerActivity() {
for (i in explorerAdapter.selectedItems) {
paths.add(explorerElements[i].fullPath)
}
isStartingActivity = true
ExternalProvider.share(this, gocryptfsVolume, paths)
unselectAll()
true
}
R.id.decrypt -> {
val i = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
isStartingActivity = true
startActivityForResult(i, PICK_DIRECTORY_REQUEST_CODE)
true
}

View File

@ -10,10 +10,10 @@ import sushi.hardcore.droidfs.util.PathUtils
import java.util.*
class ExplorerActivityPick : BaseExplorerActivity() {
private var result_intent = Intent()
private var resultIntent = Intent()
override fun init() {
super.init()
result_intent.putExtra("sessionID", gocryptfsVolume.sessionID)
resultIntent.putExtra("sessionID", gocryptfsVolume.sessionID)
}
override fun onExplorerItemClick(position: Int) {
@ -30,7 +30,7 @@ class ExplorerActivityPick : BaseExplorerActivity() {
setCurrentPath(PathUtils.getParentPath(currentDirectoryPath))
}
else -> {
result_intent.putExtra("path", full_path)
resultIntent.putExtra("path", full_path)
returnActivityResult()
}
}
@ -42,9 +42,9 @@ class ExplorerActivityPick : BaseExplorerActivity() {
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.explorer_pick, menu)
handleMenuItems(menu)
val any_item_selected = explorerAdapter.selectedItems.isNotEmpty()
menu.findItem(R.id.select_all).isVisible = any_item_selected
menu.findItem(R.id.validate).isVisible = any_item_selected
val anyItemSelected = explorerAdapter.selectedItems.isNotEmpty()
menu.findItem(R.id.select_all).isVisible = anyItemSelected
menu.findItem(R.id.validate).isVisible = anyItemSelected
return true
}
@ -63,8 +63,8 @@ class ExplorerActivityPick : BaseExplorerActivity() {
paths.add(PathUtils.path_join(currentDirectoryPath, e.name))
types.add(e.elementType.toInt())
}
result_intent.putStringArrayListExtra("paths", paths)
result_intent.putIntegerArrayListExtra("types", types)
resultIntent.putStringArrayListExtra("paths", paths)
resultIntent.putIntegerArrayListExtra("types", types)
returnActivityResult()
true
}
@ -73,7 +73,7 @@ class ExplorerActivityPick : BaseExplorerActivity() {
}
private fun returnActivityResult() {
setResult(Activity.RESULT_OK, result_intent)
setResult(Activity.RESULT_OK, resultIntent)
finish()
}

View File

@ -7,8 +7,8 @@ import java.io.File
class AudioPlayer: MediaPlayer(){
override fun viewFile() {
super.viewFile()
setContentView(R.layout.activity_audio_player)
super.viewFile()
val filename = File(filePath).name
val pos = filename.lastIndexOf('.')
music_title.text = if (pos != -1){

View File

@ -4,12 +4,14 @@ import android.os.Bundle
import android.view.View
import sushi.hardcore.droidfs.BaseActivity
import sushi.hardcore.droidfs.R
import sushi.hardcore.droidfs.provider.RestrictedFileProvider
import sushi.hardcore.droidfs.util.GocryptfsVolume
import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder
abstract class FileViewerActivity: BaseActivity() {
lateinit var gocryptfsVolume: GocryptfsVolume
lateinit var filePath: String
private var isGoingBackToExplorer = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
filePath = intent.getStringExtra("path")!!
@ -28,6 +30,12 @@ abstract class FileViewerActivity: BaseActivity() {
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION*/
}
abstract fun viewFile()
override fun onUserInteraction() {
super.onUserInteraction()
if (window.decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_FULLSCREEN == 0){
hideSystemUi()
}
}
fun loadWholeFile(path: String): ByteArray? {
val fileSize = gocryptfsVolume.getSize(path)
if (fileSize >= 0){
@ -53,7 +61,7 @@ abstract class FileViewerActivity: BaseActivity() {
.setTitle(R.string.error)
.setMessage(R.string.read_file_failed)
.setCancelable(false)
.setPositiveButton(R.string.ok) { _, _ -> finish() }
.setPositiveButton(R.string.ok) { _, _ -> goBackToExplorer() }
.show()
}
} catch (e: OutOfMemoryError){
@ -61,7 +69,7 @@ abstract class FileViewerActivity: BaseActivity() {
.setTitle(R.string.error)
.setMessage(R.string.outofmemoryerror_msg)
.setCancelable(false)
.setPositiveButton(getString(R.string.ok)) { _, _ -> finish() }
.setPositiveButton(getString(R.string.ok)) { _, _ -> goBackToExplorer() }
.show()
}
@ -70,9 +78,32 @@ abstract class FileViewerActivity: BaseActivity() {
.setTitle(R.string.error)
.setMessage(R.string.get_size_failed)
.setCancelable(false)
.setPositiveButton(R.string.ok) { _, _ -> finish() }
.setPositiveButton(R.string.ok) { _, _ -> goBackToExplorer() }
.show()
}
return null
}
protected fun goBackToExplorer(){
isGoingBackToExplorer = true
finish()
}
override fun onDestroy() {
super.onDestroy()
if (!isGoingBackToExplorer) {
gocryptfsVolume.close()
RestrictedFileProvider.wipeAll(this)
}
}
override fun onPause() {
super.onPause()
finish()
}
override fun onBackPressed() {
super.onBackPressed()
isGoingBackToExplorer = true
}
}

View File

@ -113,10 +113,14 @@ class ImageViewer: FileViewerActivity() {
override fun onUserInteraction() {
super.onUserInteraction()
if (action_buttons.visibility == View.GONE){
action_buttons.visibility = View.VISIBLE
action_buttons?.let {
handler.removeCallbacks(hideActionButtons)
handler.postDelayed(hideActionButtons, hideDelay)
if (it.visibility == View.GONE){
it.visibility = View.VISIBLE
handler.postDelayed(hideActionButtons, hideDelay)
} else {
it.visibility = View.GONE
}
}
}
}

View File

@ -29,8 +29,10 @@ abstract class MediaPlayer: FileViewerActivity() {
.setTitle(R.string.error)
.setMessage(R.string.playing_failed)
.setCancelable(false)
.setPositiveButton(R.string.ok) { _, _ -> finish() }
.setPositiveButton(R.string.ok) { _, _ -> goBackToExplorer()}
.create()
hideSystemUi()
initializePlayer()
}
abstract fun bindPlayer(player: SimpleExoPlayer)
@ -77,14 +79,8 @@ abstract class MediaPlayer: FileViewerActivity() {
}
}
override fun onResume() {
super.onResume()
hideSystemUi()
initializePlayer()
}
override fun onPause() {
super.onPause()
override fun onDestroy() {
super.onDestroy()
releasePlayer()
}
}

View File

@ -34,7 +34,7 @@ class TextEditor: FileViewerActivity() {
.setTitle(R.string.error)
.setMessage(R.string.outofmemoryerror_msg)
.setCancelable(false)
.setPositiveButton(getString(R.string.ok)) { _, _ -> finish() }
.setPositiveButton(getString(R.string.ok)) { _, _ -> goBackToExplorer()}
.show()
}
}
@ -103,13 +103,13 @@ class TextEditor: FileViewerActivity() {
.setMessage(R.string.ask_save)
.setPositiveButton(getString(R.string.save)) { _, _ ->
if (save()){
finish()
goBackToExplorer()
}
}
.setNegativeButton(getString(R.string.discard)){ _, _ -> finish() }
.setNegativeButton(getString(R.string.discard)){ _, _ -> goBackToExplorer()}
.show()
} else {
finish()
goBackToExplorer()
}
}

View File

@ -6,8 +6,8 @@ import sushi.hardcore.droidfs.R
class VideoPlayer: MediaPlayer() {
override fun viewFile() {
super.viewFile()
setContentView(R.layout.activity_video_player)
super.viewFile()
}
override fun bindPlayer(player: SimpleExoPlayer) {

View File

@ -7,6 +7,7 @@ import java.io.*
class GocryptfsVolume(var sessionID: Int) {
private external fun native_close(sessionID: Int)
private external fun native_is_closed(sessionID: Int): Boolean
private external fun native_list_dir(sessionID: Int, dir_path: String): MutableList<ExplorerElement>
private external fun native_open_read_mode(sessionID: Int, file_path: String): Int
private external fun native_open_write_mode(sessionID: Int, file_path: String): Int
@ -38,6 +39,10 @@ class GocryptfsVolume(var sessionID: Int) {
native_close(sessionID)
}
fun isClosed(): Boolean {
return native_is_closed(sessionID)
}
fun listDir(dir_path: String): MutableList<ExplorerElement> {
return native_list_dir(sessionID, dir_path)
}

View File

@ -126,6 +126,12 @@ Java_sushi_hardcore_droidfs_util_GocryptfsVolume_00024Companion_init(JNIEnv *env
return sessionID;
}
JNIEXPORT jboolean JNICALL
Java_sushi_hardcore_droidfs_util_GocryptfsVolume_native_1is_1closed(JNIEnv *env, jobject thiz,
jint sessionID) {
return gcf_is_closed(sessionID);
}
JNIEXPORT jboolean JNICALL
Java_sushi_hardcore_droidfs_util_GocryptfsVolume_00024Companion_changePassword(JNIEnv *env, jclass clazz,
jstring jroot_cipher_dir,