Add move and copy button to folder picker

Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
alperozturk 2023-10-12 09:05:29 +02:00 committed by Alper Öztürk (Rebase PR Action)
parent 47181bd0c6
commit 78fa3851fd
3 changed files with 43 additions and 35 deletions

View file

@ -73,7 +73,9 @@ open class FolderPickerActivity :
var isDoNotEnterEncryptedFolder = false
private set
private var mCancelBtn: MaterialButton? = null
private var mChooseBtn: MaterialButton? = null
private var mCopyBtn: MaterialButton? = null
private var mMoveBtn: MaterialButton? = null
private var caption: String? = null
private var mAction: String? = null
@ -85,6 +87,7 @@ open class FolderPickerActivity :
override fun onCreate(savedInstanceState: Bundle?) {
Log_OC.d(TAG, "onCreate() start")
super.onCreate(savedInstanceState)
if (this is FilePickerActivity) {
setContentView(R.layout.files_picker)
} else {
@ -101,29 +104,15 @@ open class FolderPickerActivity :
findViewById<View>(R.id.switch_grid_view_button).visibility =
View.GONE
mAction = intent.getStringExtra(EXTRA_ACTION)
if (mAction != null) {
when (mAction) {
MOVE -> {
caption = resources.getText(R.string.move_to).toString()
mSearchOnlyFolders = true
isDoNotEnterEncryptedFolder = true
}
COPY -> {
caption = resources.getText(R.string.copy_to).toString()
mSearchOnlyFolders = true
isDoNotEnterEncryptedFolder = true
}
CHOOSE_LOCATION -> {
caption = resources.getText(R.string.choose_location).toString()
mSearchOnlyFolders = true
isDoNotEnterEncryptedFolder = true
mChooseBtn!!.text = resources.getString(R.string.common_select)
}
else -> caption = themeUtils.getDefaultDisplayNameForRootFolder(this)
}
caption = resources.getText(R.string.folder_picker_choose_caption_text).toString()
mSearchOnlyFolders = true
isDoNotEnterEncryptedFolder = true
} else {
caption = themeUtils.getDefaultDisplayNameForRootFolder(this)
}
mTargetFilePaths = intent.getStringArrayListExtra(EXTRA_FILE_PATHS)
if (savedInstanceState == null) {
@ -351,7 +340,8 @@ open class FolderPickerActivity :
}
private fun toggleChooseEnabled() {
mChooseBtn?.isEnabled = checkFolderSelectable()
mCopyBtn?.isEnabled = checkFolderSelectable()
mMoveBtn?.isEnabled = checkFolderSelectable()
}
// for copy and move, disable selecting parent folder of target files
@ -385,10 +375,16 @@ open class FolderPickerActivity :
*/
private fun initControls() {
mCancelBtn = findViewById(R.id.folder_picker_btn_cancel)
mChooseBtn = findViewById(R.id.folder_picker_btn_choose)
if (mChooseBtn != null) {
viewThemeUtils.material.colorMaterialButtonPrimaryFilled(mChooseBtn!!)
mChooseBtn!!.setOnClickListener(this)
mCopyBtn = findViewById(R.id.btnCopy)
mMoveBtn = findViewById(R.id.btnMove)
if (mCopyBtn != null) {
viewThemeUtils.material.colorMaterialButtonPrimaryFilled(mCopyBtn!!)
mCopyBtn!!.setOnClickListener(this)
}
if (mMoveBtn != null) {
viewThemeUtils.material.colorMaterialButtonPrimaryFilled(mMoveBtn!!)
mMoveBtn!!.setOnClickListener(this)
}
if (mCancelBtn != null) {
if (this is FilePickerActivity) {
@ -403,7 +399,7 @@ open class FolderPickerActivity :
override fun onClick(v: View) {
if (v == mCancelBtn) {
finish()
} else if (v == mChooseBtn) {
} else if (v == mCopyBtn || v == mMoveBtn) {
val i = intent
val resultData = Intent()
resultData.putExtra(EXTRA_FOLDER, listOfFilesFragment!!.currentFile)

View file

@ -46,27 +46,34 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:gravity="end"
android:orientation="horizontal"
android:padding="@dimen/standard_padding">
<com.google.android.material.button.MaterialButton
android:id="@+id/folder_picker_btn_cancel"
style="@style/OutlinedButton"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/common_cancel"
android:layout_marginEnd="@dimen/standard_half_margin"
app:cornerRadius="@dimen/button_corner_radius" />
<com.google.android.material.button.MaterialButton
android:id="@+id/folder_picker_btn_choose"
android:theme="@style/Button.Primary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/folder_picker_choose_button_text"
android:id="@+id/btnCopy"
style="@style/Widget.Material3.Button.IconButton.Filled"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/folder_picker_copy_button_text"
android:layout_marginEnd="@dimen/standard_half_margin"
app:cornerRadius="@dimen/button_corner_radius" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btnMove"
style="@style/Widget.Material3.Button.IconButton.Filled.Tonal"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/folder_picker_move_button_text"
app:cornerRadius="@dimen/button_corner_radius" />
</LinearLayout>

View file

@ -433,6 +433,11 @@
<string name="file_list_empty_moving">Nothing in here. You can add a folder.</string>
<string name="folder_picker_choose_button_text">Choose</string>
<string name="folder_picker_copy_button_text">Copy</string>
<string name="folder_picker_move_button_text">Move</string>
<string name="folder_picker_choose_caption_text">Choose target folder</string>
<string name="move_file_not_found">Unable to move file. Please check whether it exists.</string>
<string name="move_file_invalid_into_descendent">It is not possible to move a folder into one of its own underlying folders</string>
<string name="move_file_invalid_overwrite">The file is already present in the destination folder</string>