diff --git a/app/build.gradle b/app/build.gradle index 7d557a0..f9e85e9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -104,17 +104,17 @@ android { dependencies { implementation project(":libpdfviewer:app") - implementation 'androidx.core:core-ktx:1.12.0' - implementation "androidx.appcompat:appcompat:1.6.1" + implementation 'androidx.core:core-ktx:1.13.1' + implementation "androidx.appcompat:appcompat:1.7.0" implementation "androidx.constraintlayout:constraintlayout:2.1.4" - def lifecycle_version = "2.6.2" + def lifecycle_version = "2.8.1" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version" - implementation "androidx.sqlite:sqlite-ktx:2.3.1" + implementation "androidx.sqlite:sqlite-ktx:2.4.0" implementation "androidx.preference:preference-ktx:1.2.1" implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" - implementation 'com.google.android.material:material:1.9.0' + implementation 'com.google.android.material:material:1.12.0' implementation 'com.github.bumptech.glide:glide:4.16.0' implementation "androidx.biometric:biometric-ktx:1.2.0-alpha05" diff --git a/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt index 7c2c2e2..1955915 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/BaseExplorerActivity.kt @@ -268,6 +268,27 @@ open class BaseExplorerActivity : BaseActivity(), ExplorerElementAdapter.Listene .show() } + protected fun createNewFile(callback: (Long) -> Unit) { + EditTextDialog(this, R.string.enter_file_name) { + if (it.isEmpty()) { + Toast.makeText(this, R.string.error_filename_empty, Toast.LENGTH_SHORT).show() + createNewFile(callback) + } else { + val filePath = PathUtils.pathJoin(currentDirectoryPath, it) + val handleID = encryptedVolume.openFileWriteMode(filePath) + if (handleID == -1L) { + CustomAlertDialogBuilder(this, theme) + .setTitle(R.string.error) + .setMessage(R.string.file_creation_failed) + .setPositiveButton(R.string.ok, null) + .show() + } else { + callback(handleID) + } + } + }.show() + } + private fun setVolumeNameTitle() { titleText.text = getString(R.string.volume, volumeName) } diff --git a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt index 6f0e619..abdca09 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivity.kt @@ -189,9 +189,11 @@ class ExplorerActivity : BaseExplorerActivity() { pickImportDirectory.launch(null) } "createFile" -> { - EditTextDialog(this, R.string.enter_file_name) { - createNewFile(it) - }.show() + createNewFile { + encryptedVolume.closeFile(it) + setCurrentPath(currentDirectoryPath) + invalidateOptionsMenu() + } } "createFolder" -> { openDialogCreateFolder() @@ -219,26 +221,6 @@ class ExplorerActivity : BaseExplorerActivity() { cancelItemAction() } - private fun createNewFile(fileName: String){ - if (fileName.isEmpty()) { - Toast.makeText(this, R.string.error_filename_empty, Toast.LENGTH_SHORT).show() - } else { - val filePath = PathUtils.pathJoin(currentDirectoryPath, fileName) - val handleID = encryptedVolume.openFileWriteMode(filePath) - if (handleID == -1L) { - CustomAlertDialogBuilder(this, theme) - .setTitle(R.string.error) - .setMessage(R.string.file_creation_failed) - .setPositiveButton(R.string.ok, null) - .show() - } else { - encryptedVolume.closeFile(handleID) - setCurrentPath(currentDirectoryPath) - invalidateOptionsMenu() - } - } - } - override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.explorer, menu) val result = super.onCreateOptionsMenu(menu) diff --git a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityDrop.kt b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityDrop.kt index c2d9080..5c5f4cc 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityDrop.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/explorers/ExplorerActivityDrop.kt @@ -9,6 +9,8 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton import sushi.hardcore.droidfs.R import sushi.hardcore.droidfs.util.IntentUtils import sushi.hardcore.droidfs.widgets.CustomAlertDialogBuilder +import java.nio.CharBuffer +import java.nio.charset.StandardCharsets class ExplorerActivityDrop : BaseExplorerActivity() { @@ -30,15 +32,15 @@ class ExplorerActivityDrop : BaseExplorerActivity() { return when (item.itemId) { R.id.validate -> { val extras = intent.extras - val errorMsg: String? = if (extras != null && extras.containsKey(Intent.EXTRA_STREAM)) { + val success = if (extras != null && extras.containsKey(Intent.EXTRA_STREAM)) { when (intent.action) { Intent.ACTION_SEND -> { val uri = IntentUtils.getParcelableExtra(intent, Intent.EXTRA_STREAM) if (uri == null) { - getString(R.string.share_intent_parsing_failed) + false } else { importFilesFromUris(listOf(uri), ::onImported) - null + true } } Intent.ACTION_SEND_MULTIPLE -> { @@ -50,20 +52,34 @@ class ExplorerActivityDrop : BaseExplorerActivity() { } if (uris != null) { importFilesFromUris(uris, ::onImported) - null + true } else { - getString(R.string.share_intent_parsing_failed) + false } } - else -> getString(R.string.share_intent_parsing_failed) + else -> false } + } else if ((intent.clipData?.itemCount ?: 0) > 0) { + val byteBuffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(intent.clipData!!.getItemAt(0).text)) + val byteArray = ByteArray(byteBuffer.remaining()) + byteBuffer.get(byteArray) + val size = byteArray.size.toLong() + createNewFile { + var offset = 0L + while (offset < size) { + offset += encryptedVolume.write(it, offset, byteArray, offset, size-offset) + } + encryptedVolume.closeFile(it) + onImported() + } + true } else { - getString(R.string.share_intent_parsing_failed) + false } - errorMsg?.let { + if (!success) { CustomAlertDialogBuilder(this, theme) .setTitle(R.string.error) - .setMessage(it) + .setMessage(R.string.share_intent_parsing_failed) .setPositiveButton(R.string.ok, null) .show() }