2020-07-17 16:35:39 +02:00
|
|
|
package sushi.hardcore.droidfs.explorers
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.net.Uri
|
2020-08-07 19:25:16 +02:00
|
|
|
import android.os.Looper
|
2020-07-17 16:35:39 +02:00
|
|
|
import android.view.Menu
|
|
|
|
import android.view.MenuItem
|
2020-08-05 14:06:54 +02:00
|
|
|
import android.view.View
|
2020-08-07 19:25:16 +02:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2020-07-17 16:35:39 +02:00
|
|
|
import sushi.hardcore.droidfs.R
|
2020-08-07 19:25:16 +02:00
|
|
|
import sushi.hardcore.droidfs.util.LoadingTask
|
2020-07-26 21:16:06 +02:00
|
|
|
import sushi.hardcore.droidfs.util.PathUtils
|
2020-07-27 16:20:52 +02:00
|
|
|
import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder
|
2020-07-17 16:35:39 +02:00
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-08-05 14:06:54 +02:00
|
|
|
fun onClickFAB(view: View) {
|
|
|
|
openDialogCreateFolder()
|
|
|
|
}
|
|
|
|
|
2020-07-17 16:35:39 +02:00
|
|
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
|
|
menuInflater.inflate(R.menu.explorer_drop, menu)
|
2020-07-18 18:44:53 +02:00
|
|
|
handleMenuItems(menu)
|
2020-08-01 15:39:00 +02:00
|
|
|
menu.findItem(R.id.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) {
|
2020-08-01 15:39:00 +02:00
|
|
|
R.id.validate -> {
|
2020-08-07 19:25:16 +02:00
|
|
|
object : LoadingTask(this, R.string.loading_msg_import) {
|
|
|
|
override fun doTask(activity: AppCompatActivity) {
|
|
|
|
val alertDialog = ColoredAlertDialogBuilder(activity)
|
|
|
|
alertDialog.setCancelable(false)
|
|
|
|
alertDialog.setPositiveButton(R.string.ok) { _, _ -> finish() }
|
|
|
|
var errorMsg: String? = null
|
|
|
|
val extras = intent.extras
|
|
|
|
if (extras != null && extras.containsKey(Intent.EXTRA_STREAM)){
|
|
|
|
Looper.prepare()
|
|
|
|
if (intent.action == Intent.ACTION_SEND) {
|
|
|
|
val uri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)
|
|
|
|
errorMsg = if (uri == null){
|
|
|
|
getString(R.string.share_intent_parsing_failed)
|
|
|
|
} else {
|
2020-08-09 14:34:42 +02:00
|
|
|
val outputPath = checkPathOverwrite(PathUtils.path_join(currentDirectoryPath, PathUtils.getFilenameFromURI(activity, uri)), false)
|
2020-08-07 19:25:16 +02:00
|
|
|
if (outputPath == null) {
|
|
|
|
""
|
|
|
|
} else {
|
2020-08-09 14:34:42 +02:00
|
|
|
if (gocryptfsVolume.importFile(activity, uri, outputPath)) null else getString(R.string.import_failed, uri)
|
2020-08-07 19:25:16 +02:00
|
|
|
}
|
2020-07-17 16:35:39 +02:00
|
|
|
}
|
2020-08-07 19:25:16 +02:00
|
|
|
} else if (intent.action == Intent.ACTION_SEND_MULTIPLE) {
|
|
|
|
val uris = intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM)
|
|
|
|
if (uris != null){
|
|
|
|
for (uri in uris) {
|
2020-08-09 14:34:42 +02:00
|
|
|
val outputPath = checkPathOverwrite(PathUtils.path_join(currentDirectoryPath, PathUtils.getFilenameFromURI(activity, uri)), false)
|
2020-08-07 19:25:16 +02:00
|
|
|
if (outputPath == null){
|
|
|
|
errorMsg = ""
|
|
|
|
break
|
|
|
|
} else {
|
|
|
|
if (!gocryptfsVolume.importFile(activity, uri, outputPath)) {
|
2020-08-09 14:34:42 +02:00
|
|
|
errorMsg = getString(R.string.import_failed, uri)
|
2020-08-07 19:25:16 +02:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errorMsg = getString(R.string.share_intent_parsing_failed)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errorMsg = getString(R.string.share_intent_parsing_failed)
|
2020-07-17 16:35:39 +02:00
|
|
|
}
|
|
|
|
} else {
|
2020-08-01 15:39:00 +02:00
|
|
|
errorMsg = getString(R.string.share_intent_parsing_failed)
|
2020-07-17 16:35:39 +02:00
|
|
|
}
|
2020-08-07 19:25:16 +02:00
|
|
|
if (errorMsg == null || errorMsg.isNotEmpty()){
|
|
|
|
if (errorMsg == null) {
|
|
|
|
alertDialog.setTitle(R.string.success_import)
|
|
|
|
alertDialog.setMessage(R.string.success_import_msg)
|
|
|
|
} else if (errorMsg.isNotEmpty()) {
|
|
|
|
alertDialog.setTitle(R.string.error)
|
|
|
|
alertDialog.setMessage(errorMsg)
|
|
|
|
}
|
|
|
|
stopTask { alertDialog.show() }
|
|
|
|
}
|
2020-07-17 16:35:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
true
|
|
|
|
}
|
|
|
|
else -> super.onOptionsItemSelected(item)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|