2020-07-17 16:35:39 +02:00
|
|
|
package sushi.hardcore.droidfs.explorers
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.net.Uri
|
|
|
|
import android.view.Menu
|
|
|
|
import android.view.MenuItem
|
|
|
|
import sushi.hardcore.droidfs.R
|
2020-07-26 21:16:06 +02:00
|
|
|
import sushi.hardcore.droidfs.util.PathUtils
|
2020-07-17 16:35:39 +02:00
|
|
|
import sushi.hardcore.droidfs.widgets.ColoredAlertDialog
|
|
|
|
|
2020-07-19 21:46:29 +02:00
|
|
|
class ExplorerActivityDrop : BaseExplorerActivity() {
|
2020-07-17 16:35:39 +02:00
|
|
|
override fun init() {
|
|
|
|
setContentView(R.layout.activity_explorer_drop)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
|
|
menuInflater.inflate(R.menu.explorer_drop, menu)
|
2020-07-18 18:44:53 +02:00
|
|
|
handleMenuItems(menu)
|
2020-07-26 21:16:06 +02:00
|
|
|
menu.findItem(R.id.explorer_menu_validate).isVisible = explorerAdapter.selectedItems.isEmpty()
|
2020-07-17 16:35:39 +02:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
|
|
|
return when (item.itemId) {
|
|
|
|
R.id.explorer_menu_validate -> {
|
|
|
|
val alertDialog = ColoredAlertDialog(this)
|
|
|
|
alertDialog.setCancelable(false)
|
|
|
|
alertDialog.setPositiveButton(R.string.ok) { _, _ -> finish() }
|
|
|
|
var error_msg: String? = null
|
|
|
|
val extras = intent.extras
|
|
|
|
if (extras != null && extras.containsKey(Intent.EXTRA_STREAM)){
|
|
|
|
if (intent.action == Intent.ACTION_SEND) {
|
|
|
|
val uri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
|
2020-07-26 21:16:06 +02:00
|
|
|
val output_path = PathUtils.path_join(currentDirectoryPath, PathUtils.getFilenameFromURI(this, uri))
|
2020-07-17 16:35:39 +02:00
|
|
|
error_msg = if (gocryptfsVolume.import_file(this, uri, output_path)) null else getString(R.string.import_failed, output_path)
|
|
|
|
} else if (intent.action == Intent.ACTION_SEND_MULTIPLE) {
|
|
|
|
val uris = intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)
|
|
|
|
if (uris != null){
|
|
|
|
for (uri in uris) {
|
2020-07-26 21:16:06 +02:00
|
|
|
val output_path = PathUtils.path_join(currentDirectoryPath, PathUtils.getFilenameFromURI(this, uri))
|
2020-07-17 16:35:39 +02:00
|
|
|
if (!gocryptfsVolume.import_file(this, uri, output_path)) {
|
|
|
|
error_msg = getString(R.string.import_failed, output_path)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error_msg = getString(R.string.share_intent_parsing_failed)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error_msg = getString(R.string.share_intent_parsing_failed)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error_msg = getString(R.string.share_intent_parsing_failed)
|
|
|
|
}
|
|
|
|
if (error_msg == null) {
|
|
|
|
alertDialog.setTitle(R.string.success_import)
|
|
|
|
alertDialog.setMessage(R.string.success_import_msg)
|
|
|
|
} else {
|
|
|
|
alertDialog.setTitle(R.string.error)
|
|
|
|
alertDialog.setMessage(error_msg)
|
|
|
|
}
|
|
|
|
alertDialog.show()
|
|
|
|
true
|
|
|
|
}
|
|
|
|
else -> super.onOptionsItemSelected(item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|