Merge pull request #5703 from k9mail/choose_folder_ui
Tweak toolbar in 'choose folder' screen
This commit is contained in:
commit
e1aef32042
5 changed files with 67 additions and 7 deletions
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,19 @@ 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()
|
||||
|
||||
viewModel.getFolders().observe(this) { folders ->
|
||||
|
@ -64,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
|
||||
|
||||
|
@ -84,6 +93,12 @@ class ChooseFolderActivity : K9Activity() {
|
|||
return if (showDisplayableOnly) account.folderDisplayMode else account.folderTargetMode
|
||||
}
|
||||
|
||||
private fun initializeActionBar() {
|
||||
val actionBar = supportActionBar ?: error("Action bar missing")
|
||||
actionBar.setDisplayHomeAsUpEnabled(true)
|
||||
actionBar.setHomeAsUpIndicator(R.drawable.ic_close)
|
||||
}
|
||||
|
||||
private fun initializeFolderList() {
|
||||
itemAdapter = ItemAdapter()
|
||||
itemAdapter.itemFilter.filterPredicate = ::folderListFilter
|
||||
|
@ -161,6 +176,7 @@ class ChooseFolderActivity : K9Activity() {
|
|||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> finish()
|
||||
R.id.display_1st_class -> setDisplayMode(FolderMode.FIRST_CLASS)
|
||||
R.id.display_1st_and_2nd_class -> setDisplayMode(FolderMode.FIRST_AND_SECOND_CLASS)
|
||||
R.id.display_not_second_class -> setDisplayMode(FolderMode.NOT_SECOND_CLASS)
|
||||
|
@ -211,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"
|
||||
|
@ -226,6 +250,7 @@ class ChooseFolderActivity : K9Activity() {
|
|||
@JvmStatic
|
||||
fun buildLaunchIntent(
|
||||
context: Context,
|
||||
action: Action,
|
||||
accountUuid: String,
|
||||
currentFolderId: Long? = null,
|
||||
scrollToFolderId: Long? = null,
|
||||
|
@ -233,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) }
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue