Allow importing from ClipData
This commit is contained in:
parent
d1e042c347
commit
bd60e62635
@ -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"
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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<Uri>(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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user