Skip to content

Commit

Permalink
Merge pull request #7130 from thundernest/move_subscribed_folders_set…
Browse files Browse the repository at this point in the history
…ting

Move "Show only subscribed folders" setting to folders section
  • Loading branch information
cketti authored Aug 18, 2023
2 parents 40d7db5 + b0ef477 commit 9cf974b
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,10 @@ public boolean supportsUpload(Account account) {
return getBackend(account).getSupportsUpload();
}

public boolean supportsFolderSubscriptions(Account account) {
return getBackend(account).getSupportsFolderSubscriptions();
}

public void checkIncomingServerSettings(Account account) throws MessagingException {
getBackend(account).checkIncomingServerSettings();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
private boolean mMakeDefault;
private CheckBox useCompressionCheckBox;
private CheckBox isSendClientIdEnabledCheckBox;
private CheckBox mSubscribedFoldersOnly;
private AuthTypeAdapter mAuthTypeAdapter;
private ConnectionSecurity[] mConnectionSecurityChoices = ConnectionSecurity.values();
private boolean editSettings;
Expand Down Expand Up @@ -128,7 +127,6 @@ public void onCreate(Bundle savedInstanceState) {
mNextButton = findViewById(R.id.next);
useCompressionCheckBox = findViewById(R.id.use_compression);
isSendClientIdEnabledCheckBox = findViewById(R.id.is_send_client_id_enabled);
mSubscribedFoldersOnly = findViewById(R.id.subscribed_folders_only);
mAllowClientCertificateView = findViewById(R.id.account_allow_client_certificate);

TextInputLayout serverLayoutView = findViewById(R.id.account_server_layout);
Expand Down Expand Up @@ -204,7 +202,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
findViewById(R.id.imap_path_prefix_section).setVisibility(View.GONE);
useCompressionCheckBox.setVisibility(View.GONE);
isSendClientIdEnabledCheckBox.setVisibility(View.GONE);
mSubscribedFoldersOnly.setVisibility(View.GONE);
} else if (settings.type.equals(Protocols.IMAP)) {
serverLayoutView.setHint(getString(R.string.account_setup_incoming_imap_server_label));

Expand All @@ -215,10 +212,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (pathPrefix != null) {
mImapPathPrefixView.setText(pathPrefix);
}

if (!editSettings) {
findViewById(R.id.imap_folder_setup_section).setVisibility(View.GONE);
}
} else {
throw new Exception("Unknown account type: " + settings.type);
}
Expand Down Expand Up @@ -265,8 +258,6 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
updatePortFromSecurityType();
}
mCurrentPortViewSetting = mPortView.getText().toString();

mSubscribedFoldersOnly.setChecked(mAccount.isSubscribedFoldersOnly());
} catch (Exception e) {
failure(e);
}
Expand Down Expand Up @@ -579,7 +570,6 @@ protected void onNext() {

mAccount.setUseCompression(useCompressionCheckBox.isChecked());
mAccount.setSendClientIdEnabled(isSendClientIdEnabledCheckBox.isChecked());
mAccount.setSubscribedFoldersOnly(mSubscribedFoldersOnly.isChecked());

AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.INCOMING);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ val settingsUiModule = module {
executorService = get(named("SaveSettingsExecutorService")),
notificationChannelManager = get(),
notificationController = get(),
messagingController = get(),
)
}
factory { getSystemVibrator(context = get()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.fsck.k9.Account.SpecialFolderSelection
import com.fsck.k9.NotificationLight
import com.fsck.k9.NotificationVibration
import com.fsck.k9.Preferences
import com.fsck.k9.controller.MessagingController
import com.fsck.k9.job.K9JobManager
import com.fsck.k9.notification.NotificationChannelManager
import com.fsck.k9.notification.NotificationController
Expand All @@ -18,6 +19,7 @@ class AccountSettingsDataStore(
private val jobManager: K9JobManager,
private val notificationChannelManager: NotificationChannelManager,
private val notificationController: NotificationController,
private val messagingController: MessagingController,
) : PreferenceDataStore() {
private var notificationSettingsChanged = false

Expand All @@ -41,6 +43,7 @@ class AccountSettingsDataStore(
"autocrypt_prefer_encrypt" -> account.autocryptPreferEncryptMutual
"upload_sent_messages" -> account.isUploadSentMessages
"ignore_chat_messages" -> account.isIgnoreChatMessages
"subscribed_folders_only" -> account.isSubscribedFoldersOnly
else -> defValue
}
}
Expand All @@ -65,6 +68,7 @@ class AccountSettingsDataStore(
"autocrypt_prefer_encrypt" -> account.autocryptPreferEncryptMutual = value
"upload_sent_messages" -> account.isUploadSentMessages = value
"ignore_chat_messages" -> account.isIgnoreChatMessages = value
"subscribed_folders_only" -> updateSubscribedFoldersOnly(value)
else -> return
}

Expand Down Expand Up @@ -286,4 +290,12 @@ class AccountSettingsDataStore(
}
notificationSettingsChanged = true
}

private fun updateSubscribedFoldersOnly(value: Boolean) {
if (account.isSubscribedFoldersOnly != value) {
account.isSubscribedFoldersOnly = value

messagingController.refreshFolderList(account)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.fsck.k9.ui.settings.account

import com.fsck.k9.Account
import com.fsck.k9.Preferences
import com.fsck.k9.controller.MessagingController
import com.fsck.k9.job.K9JobManager
import com.fsck.k9.notification.NotificationChannelManager
import com.fsck.k9.notification.NotificationController
Expand All @@ -13,6 +14,7 @@ class AccountSettingsDataStoreFactory(
private val executorService: ExecutorService,
private val notificationChannelManager: NotificationChannelManager,
private val notificationController: NotificationController,
private val messagingController: MessagingController,
) {
fun create(account: Account): AccountSettingsDataStore {
return AccountSettingsDataStore(
Expand All @@ -22,6 +24,7 @@ class AccountSettingsDataStoreFactory(
jobManager,
notificationChannelManager,
notificationController,
messagingController,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr

private fun initializeFolderSettings(account: Account) {
findPreference<Preference>(PREFERENCE_FOLDERS)?.let {
if (!messagingController.supportsFolderSubscriptions(account)) {
findPreference<Preference>(PREFERENCE_SUBSCRIBED_FOLDERS_ONLY).remove()
}

if (!messagingController.isMoveCapable(account)) {
findPreference<Preference>(PREFERENCE_ARCHIVE_FOLDER).remove()
findPreference<Preference>(PREFERENCE_DRAFTS_FOLDER).remove()
Expand Down Expand Up @@ -453,6 +457,7 @@ class AccountSettingsFragment : PreferenceFragmentCompat(), ConfirmationDialogFr
private const val PREFERENCE_AUTOCRYPT_TRANSFER = "autocrypt_transfer"
private const val PREFERENCE_FOLDERS = "folders"
private const val PREFERENCE_AUTO_EXPAND_FOLDER = "account_setup_auto_expand_folder"
private const val PREFERENCE_SUBSCRIBED_FOLDERS_ONLY = "subscribed_folders_only"
private const val PREFERENCE_ARCHIVE_FOLDER = "archive_folder"
private const val PREFERENCE_DRAFTS_FOLDER = "drafts_folder"
private const val PREFERENCE_SENT_FOLDER = "sent_folder"
Expand Down
14 changes: 0 additions & 14 deletions app/ui/legacy/src/main/res/layout/account_setup_incoming.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,6 @@
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imap_folder_setup_section"
android:orientation="vertical">

<CheckBox
android:id="@+id/subscribed_folders_only"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/account_setup_incoming_subscribed_folders_only_label"
/>
</LinearLayout>

<CheckBox
android:id="@+id/use_compression"
android:layout_height="wrap_content"
Expand Down
4 changes: 4 additions & 0 deletions app/ui/legacy/src/main/res/xml/account_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@
app:useSimpleSummaryProvider="true"
android:title="@string/account_settings_folder_display_mode_label" />

<CheckBoxPreference
android:key="subscribed_folders_only"
android:title="@string/account_setup_incoming_subscribed_folders_only_label" />

<ListPreference
android:dialogTitle="@string/account_settings_folder_target_mode_label"
android:entries="@array/folder_target_mode_entries"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Backend {
val supportsUpload: Boolean
val supportsTrashFolder: Boolean
val supportsSearchByDate: Boolean
val supportsFolderSubscriptions: Boolean
val isPushCapable: Boolean

@Throws(MessagingException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class DemoBackend(private val backendStorage: BackendStorage) : Backend {
override val supportsUpload: Boolean = true
override val supportsTrashFolder: Boolean = true
override val supportsSearchByDate: Boolean = false
override val supportsFolderSubscriptions: Boolean = false
override val isPushCapable: Boolean = false

override fun refreshFolderList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ImapBackend(
override val supportsUpload = true
override val supportsTrashFolder = true
override val supportsSearchByDate = true
override val supportsFolderSubscriptions = true
override val isPushCapable = true

override fun refreshFolderList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class JmapBackend(
override val supportsUpload = true
override val supportsTrashFolder = true
override val supportsSearchByDate = true
override val supportsFolderSubscriptions = false // TODO: add support
override val isPushCapable = false // FIXME

override fun refreshFolderList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Pop3Backend(
override val supportsUpload = false
override val supportsTrashFolder = false
override val supportsSearchByDate = false
override val supportsFolderSubscriptions = false
override val isPushCapable = false

override fun refreshFolderList() {
Expand Down

0 comments on commit 9cf974b

Please sign in to comment.