Change title of ChooseFolderActivity for copy/move operations

This commit is contained in:
cketti 2021-09-28 18:46:40 +02:00
parent 4d0d81fc79
commit 4eb0c692d3
5 changed files with 59 additions and 7 deletions

View file

@ -58,6 +58,7 @@ class UnreadWidgetConfigurationFragment : PreferenceFragmentCompat() {
unreadFolder.onPreferenceClickListener = Preference.OnPreferenceClickListener {
val intent = ChooseFolderActivity.buildLaunchIntent(
context = requireContext(),
action = ChooseFolderActivity.Action.CHOOSE,
accountUuid = selectedAccountUuid!!,
showDisplayableOnly = true
)

View file

@ -985,7 +985,14 @@ class MessageListFragment :
else -> null
}
displayFolderChoice(ACTIVITY_CHOOSE_FOLDER_MOVE, folderId, messages.first().accountUuid, null, messages)
displayFolderChoice(
operation = FolderOperation.MOVE,
requestCode = ACTIVITY_CHOOSE_FOLDER_MOVE,
sourceFolderId = folderId,
accountUuid = messages.first().accountUuid,
lastSelectedFolderId = null,
messages = messages
)
}
private fun onCopy(message: MessageReference) {
@ -1001,18 +1008,31 @@ class MessageListFragment :
else -> null
}
displayFolderChoice(ACTIVITY_CHOOSE_FOLDER_COPY, folderId, messages.first().accountUuid, null, messages)
displayFolderChoice(
operation = FolderOperation.COPY,
requestCode = ACTIVITY_CHOOSE_FOLDER_COPY,
sourceFolderId = folderId,
accountUuid = messages.first().accountUuid,
lastSelectedFolderId = null,
messages = messages
)
}
private fun displayFolderChoice(
operation: FolderOperation,
requestCode: Int,
sourceFolderId: Long?,
accountUuid: String,
lastSelectedFolderId: Long?,
messages: List<MessageReference>
) {
val action = when (operation) {
FolderOperation.COPY -> ChooseFolderActivity.Action.COPY
FolderOperation.MOVE -> ChooseFolderActivity.Action.MOVE
}
val intent = ChooseFolderActivity.buildLaunchIntent(
context = requireContext(),
action = action,
accountUuid = accountUuid,
currentFolderId = sourceFolderId,
scrollToFolderId = lastSelectedFolderId,

View file

@ -36,6 +36,7 @@ class ChooseFolderActivity : K9Activity() {
private lateinit var recyclerView: RecyclerView
private lateinit var itemAdapter: ItemAdapter<FolderListItem>
private lateinit var account: Account
private lateinit var action: Action
private var currentFolderId: Long? = null
private var scrollToFolderId: Long? = null
private var messageReference: String? = null
@ -44,13 +45,18 @@ class ChooseFolderActivity : K9Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setLayout(R.layout.folder_list)
setTitle(R.string.choose_folder_title)
if (!decodeArguments(savedInstanceState)) {
finish()
return
}
when (action) {
Action.MOVE -> setTitle(R.string.choose_folder_move_title)
Action.COPY -> setTitle(R.string.choose_folder_copy_title)
else -> setTitle(R.string.choose_folder_title)
}
initializeActionBar()
initializeFolderList()
@ -65,6 +71,8 @@ class ChooseFolderActivity : K9Activity() {
}
private fun decodeArguments(savedInstanceState: Bundle?): Boolean {
action = intent.action?.toAction() ?: error("Missing Intent action")
val accountUuid = intent.getStringExtra(EXTRA_ACCOUNT) ?: return false
account = preferences.getAccount(accountUuid) ?: return false
@ -219,6 +227,14 @@ class ChooseFolderActivity : K9Activity() {
return if (containsKey(name)) getLong(name) else null
}
private fun String.toAction() = Action.valueOf(this)
enum class Action {
MOVE,
COPY,
CHOOSE
}
companion object {
private const val STATE_SCROLL_TO_FOLDER_ID = "scrollToFolderId"
private const val STATE_DISPLAY_MODE = "displayMode"
@ -234,6 +250,7 @@ class ChooseFolderActivity : K9Activity() {
@JvmStatic
fun buildLaunchIntent(
context: Context,
action: Action,
accountUuid: String,
currentFolderId: Long? = null,
scrollToFolderId: Long? = null,
@ -241,6 +258,7 @@ class ChooseFolderActivity : K9Activity() {
messageReference: MessageReference? = null
): Intent {
return Intent(context, ChooseFolderActivity::class.java).apply {
this.action = action.toString()
putExtra(EXTRA_ACCOUNT, accountUuid)
currentFolderId?.let { putExtra(EXTRA_CURRENT_FOLDER_ID, currentFolderId) }
scrollToFolderId?.let { putExtra(EXTRA_SCROLL_TO_FOLDER_ID, scrollToFolderId) }

View file

@ -385,7 +385,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
return;
}
startRefileActivity(ACTIVITY_CHOOSE_FOLDER_MOVE);
startRefileActivity(FolderOperation.MOVE, ACTIVITY_CHOOSE_FOLDER_MOVE);
}
@ -400,7 +400,7 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
return;
}
startRefileActivity(ACTIVITY_CHOOSE_FOLDER_COPY);
startRefileActivity(FolderOperation.COPY, ACTIVITY_CHOOSE_FOLDER_COPY);
}
public void onMoveToDrafts() {
@ -421,11 +421,18 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
onRefile(mAccount.getSpamFolderId());
}
private void startRefileActivity(int requestCode) {
private void startRefileActivity(FolderOperation operation, int requestCode) {
String accountUuid = mAccount.getUuid();
long currentFolderId = mMessageReference.getFolderId();
Long scrollToFolderId = mAccount.getLastSelectedFolderId();
Intent intent = ChooseFolderActivity.buildLaunchIntent(requireActivity(), accountUuid, currentFolderId,
final ChooseFolderActivity.Action action;
if (operation == FolderOperation.MOVE) {
action = ChooseFolderActivity.Action.MOVE;
} else {
action = ChooseFolderActivity.Action.COPY;
}
Intent intent = ChooseFolderActivity.buildLaunchIntent(requireActivity(), action, accountUuid, currentFolderId,
scrollToFolderId, false, mMessageReference);
startActivityForResult(intent, requestCode);
@ -853,4 +860,8 @@ public class MessageViewFragment extends Fragment implements ConfirmationDialogF
private AttachmentController getAttachmentController(AttachmentViewInfo attachment) {
return new AttachmentController(mController, this, attachment);
}
private enum FolderOperation {
COPY, MOVE
}
}

View file

@ -97,6 +97,8 @@ Please submit bug reports, contribute new features and ask questions at
<string name="choose_account_title">Choose Account</string>
<string name="choose_folder_title">Choose Folder</string>
<string name="choose_folder_move_title">Move to…</string>
<string name="choose_folder_copy_title">Copy to…</string>
<string name="status_loading_account_folder">Poll <xliff:g id="account">%s</xliff:g>:<xliff:g id="folder">%s</xliff:g><xliff:g id="progress">%s</xliff:g></string>
<string name="status_loading_account_folder_headers">Fetching headers <xliff:g id="account">%s</xliff:g>:<xliff:g id="folder">%s</xliff:g><xliff:g id="progress">%s</xliff:g></string>