forked from hardcoresushi/DroidFS
"New file" feature
This commit is contained in:
parent
2e4c432976
commit
cf0753e74a
@ -11,7 +11,7 @@ android {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionName "1.0.1"
|
||||
|
||||
ndk {
|
||||
abiFilters 'x86_64', 'armeabi-v7a', 'arm64-v8a'
|
||||
|
@ -48,7 +48,6 @@ type SessionVars struct {
|
||||
fileIDs map[int][]byte
|
||||
}
|
||||
|
||||
//var fdebug *os.File
|
||||
var sessions map[int]SessionVars
|
||||
|
||||
func err_to_bool(e error) bool {
|
||||
@ -519,7 +518,6 @@ func init_new_session(root_cipher_dir string, masterkey []byte) int {
|
||||
c++
|
||||
}
|
||||
if sessions == nil {
|
||||
//fdebug, _ = os.OpenFile("/storage/emulated/0/gologs.txt", os.O_WRONLY | os.O_TRUNC | os.O_CREATE, os.FileMode(file_mode))
|
||||
sessions = make(map[int]SessionVars)
|
||||
}
|
||||
sessions[sessionID] = new_session;
|
||||
|
@ -44,7 +44,7 @@ func Faccessat(dirfd int, path string, mode uint32) error {
|
||||
|
||||
// Openat wraps the Openat syscall.
|
||||
func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) {
|
||||
if flags&syscall.O_CREAT != 0 {
|
||||
/*if flags&syscall.O_CREAT != 0 {
|
||||
// O_CREAT should be used with O_EXCL. O_NOFOLLOW has no effect with O_EXCL.
|
||||
if flags&syscall.O_EXCL == 0 {
|
||||
flags |= syscall.O_EXCL
|
||||
@ -54,6 +54,12 @@ func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
|
||||
if flags&syscall.O_NOFOLLOW == 0 {
|
||||
flags |= syscall.O_NOFOLLOW
|
||||
}
|
||||
}*/
|
||||
if flags&syscall.O_CREAT == 0 {
|
||||
// If O_CREAT is not used, we should use O_NOFOLLOW
|
||||
if flags&syscall.O_NOFOLLOW == 0 {
|
||||
flags |= syscall.O_NOFOLLOW
|
||||
}
|
||||
}
|
||||
return unix.Openat(dirfd, path, flags, mode)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import android.widget.EditText
|
||||
import android.widget.ListView
|
||||
import android.widget.Toast
|
||||
import com.github.clans.fab.FloatingActionMenu
|
||||
import kotlinx.android.synthetic.main.activity_explorer_ro.*
|
||||
import kotlinx.android.synthetic.main.activity_explorer_base.*
|
||||
import kotlinx.android.synthetic.main.explorer_info_bar.*
|
||||
import kotlinx.android.synthetic.main.toolbar.*
|
||||
import sushi.hardcore.droidfs.ColoredActivity
|
||||
@ -36,7 +36,7 @@ import sushi.hardcore.droidfs.util.GocryptfsVolume
|
||||
import sushi.hardcore.droidfs.widgets.ColoredAlertDialog
|
||||
import java.util.*
|
||||
|
||||
open class ExplorerActivityRO : ColoredActivity() {
|
||||
open class BaseExplorerActivity : ColoredActivity() {
|
||||
private lateinit var shared_prefs_editor: SharedPreferences.Editor
|
||||
private lateinit var sort_modes_entries: Array<String>
|
||||
private lateinit var sort_modes_values: Array<String>
|
||||
@ -81,7 +81,7 @@ open class ExplorerActivityRO : ColoredActivity() {
|
||||
}
|
||||
|
||||
protected open fun init() {
|
||||
setContentView(R.layout.activity_explorer_ro)
|
||||
setContentView(R.layout.activity_explorer_base)
|
||||
}
|
||||
|
||||
private fun startFileViewer(cls: Class<*>, filePath: String){
|
||||
@ -232,21 +232,21 @@ open class ExplorerActivityRO : ColoredActivity() {
|
||||
|
||||
fun onClickAddFolder(view: View?) {
|
||||
findViewById<FloatingActionMenu>(R.id.fam_explorer).close(true)
|
||||
val dialog_edit_text_view = layoutInflater.inflate(R.layout.dialog_edit_text, null)
|
||||
val dialog_edit_text = dialog_edit_text_view.findViewById<EditText>(R.id.dialog_edit_text)
|
||||
val dialogEditTextView = layoutInflater.inflate(R.layout.dialog_edit_text, null)
|
||||
val dialogEditText = dialogEditTextView.findViewById<EditText>(R.id.dialog_edit_text)
|
||||
val dialog = ColoredAlertDialog(this)
|
||||
.setView(dialog_edit_text_view)
|
||||
.setView(dialogEditTextView)
|
||||
.setTitle(R.string.enter_folder_name)
|
||||
.setPositiveButton(R.string.ok) { _, _ ->
|
||||
val folder_name = dialog_edit_text.text.toString()
|
||||
createFolder(folder_name)
|
||||
val folderName = dialogEditText.text.toString()
|
||||
createFolder(folderName)
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create()
|
||||
dialog_edit_text.setOnEditorActionListener { _, _, _ ->
|
||||
val folder_name = dialog_edit_text.text.toString()
|
||||
dialogEditText.setOnEditorActionListener { _, _, _ ->
|
||||
val folderName = dialogEditText.text.toString()
|
||||
dialog.dismiss()
|
||||
createFolder(folder_name)
|
||||
createFolder(folderName)
|
||||
true
|
||||
}
|
||||
dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
@ -6,6 +6,10 @@ import android.net.Uri
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import com.github.clans.fab.FloatingActionMenu
|
||||
import kotlinx.android.synthetic.main.activity_explorer.*
|
||||
import sushi.hardcore.droidfs.OpenActivity
|
||||
import sushi.hardcore.droidfs.R
|
||||
@ -17,7 +21,7 @@ import sushi.hardcore.droidfs.widgets.ColoredAlertDialog
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class ExplorerActivity : ExplorerActivityRO() {
|
||||
class ExplorerActivity : BaseExplorerActivity() {
|
||||
private val PICK_DIRECTORY_REQUEST_CODE = 1
|
||||
private val PICK_FILES_REQUEST_CODE = 2
|
||||
private val PICK_OTHER_VOLUME_ITEMS_REQUEST_CODE = 3
|
||||
@ -29,6 +33,48 @@ class ExplorerActivity : ExplorerActivityRO() {
|
||||
usf_share = sharedPrefs.getBoolean("usf_share", false)
|
||||
}
|
||||
|
||||
private fun createNewFile(fileName: String){
|
||||
if (fileName.isEmpty()) {
|
||||
Toast.makeText(this, R.string.error_filename_empty, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
val handleID = gocryptfsVolume.open_write_mode(FilesUtils.path_join(current_path, fileName))
|
||||
if (handleID == -1) {
|
||||
ColoredAlertDialog(this)
|
||||
.setTitle(R.string.error)
|
||||
.setMessage(getString(R.string.file_creation_failed))
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.show()
|
||||
} else {
|
||||
gocryptfsVolume.close_file(handleID)
|
||||
setCurrentPath(current_path)
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onClickCreateFile(view: View) {
|
||||
findViewById<FloatingActionMenu>(R.id.fam_explorer).close(true)
|
||||
val dialogEditTextView = layoutInflater.inflate(R.layout.dialog_edit_text, null)
|
||||
val dialogEditText = dialogEditTextView.findViewById<EditText>(R.id.dialog_edit_text)
|
||||
val dialog = ColoredAlertDialog(this)
|
||||
.setView(dialogEditTextView)
|
||||
.setTitle(getString(R.string.enter_file_name))
|
||||
.setPositiveButton(R.string.ok) { _, _ ->
|
||||
val fileName = dialogEditText.text.toString()
|
||||
createNewFile(fileName)
|
||||
}
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create()
|
||||
dialogEditText.setOnEditorActionListener { _, _, _ ->
|
||||
val fileName = dialogEditText.text.toString()
|
||||
dialog.dismiss()
|
||||
createNewFile(fileName)
|
||||
true
|
||||
}
|
||||
dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE)
|
||||
dialog.show()
|
||||
}
|
||||
|
||||
fun onClickAddFile(view: View?) {
|
||||
fam_explorer.close(true)
|
||||
val i = Intent(Intent.ACTION_OPEN_DOCUMENT)
|
||||
|
@ -8,7 +8,7 @@ import sushi.hardcore.droidfs.R
|
||||
import sushi.hardcore.droidfs.util.FilesUtils
|
||||
import sushi.hardcore.droidfs.widgets.ColoredAlertDialog
|
||||
|
||||
class ExplorerActivityDrop : ExplorerActivityRO() {
|
||||
class ExplorerActivityDrop : BaseExplorerActivity() {
|
||||
override fun init() {
|
||||
setContentView(R.layout.activity_explorer_drop)
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import sushi.hardcore.droidfs.provider.TemporaryFileProvider
|
||||
import sushi.hardcore.droidfs.util.FilesUtils
|
||||
import java.util.*
|
||||
|
||||
class ExplorerActivityPick : ExplorerActivityRO() {
|
||||
class ExplorerActivityPick : BaseExplorerActivity() {
|
||||
private var result_intent = Intent()
|
||||
override fun init() {
|
||||
super.init()
|
||||
|
@ -1,5 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape android:shape="rectangle" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/themeColor"/>
|
||||
<size android:width="2sp"/>
|
||||
</shape>
|
@ -62,6 +62,15 @@
|
||||
android:src="@drawable/icon_add"
|
||||
android:onClick="onClickAddFile"/>
|
||||
|
||||
<sushi.hardcore.droidfs.widgets.ColoredFAB
|
||||
android:id="@+id/fab_explorer_add_file"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:fab_size="mini"
|
||||
app:fab_label="@string/new_file"
|
||||
android:src="@drawable/icon_add"
|
||||
android:onClick="onClickCreateFile"/>
|
||||
|
||||
<sushi.hardcore.droidfs.widgets.ColoredFAB
|
||||
android:id="@+id/fab_explorer_add_folder"
|
||||
android:layout_width="wrap_content"
|
||||
@ -69,7 +78,8 @@
|
||||
app:fab_size="mini"
|
||||
app:fab_label="@string/mkdir"
|
||||
android:src="@drawable/icon_add"
|
||||
android:onClick="onClickAddFolder"/>
|
||||
android:onClick="onClickAddFolder"
|
||||
tools:ignore="OnClick" />
|
||||
|
||||
</sushi.hardcore.droidfs.widgets.ColoredFAM>
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="sushi.hardcore.droidfs.explorers.ExplorerActivityRO">
|
||||
tools:context="sushi.hardcore.droidfs.explorers.BaseExplorerActivity">
|
||||
|
||||
<include layout="@layout/toolbar"/>
|
||||
|
@ -6,6 +6,7 @@
|
||||
<color name="cyanea_primary_reference">@color/colorPrimaryDark</color>
|
||||
<color name="cyanea_primary_dark_reference">@color/colorPrimaryDark</color>
|
||||
<color name="themeColor">@color/colorAccent</color>
|
||||
<color name="cyanea_accent">@color/themeColor</color>
|
||||
<color name="backgroundColor">#333333</color>
|
||||
<color name="fullScreenBackgroundColor">#000000</color>
|
||||
<color name="textColor">#ffffff</color>
|
||||
|
@ -118,4 +118,7 @@
|
||||
<string name="discard">Discard</string>
|
||||
<string name="word_wrap">Word Wrap</string>
|
||||
<string name="outofmemoryerror_msg">OutOfMemoryError: This file is too large to be loaded in memory.</string>
|
||||
<string name="new_file">New File</string>
|
||||
<string name="enter_file_name">File name:</string>
|
||||
<string name="file_creation_failed">Failed to create the file.</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user