Allow configuring account without drafts folder

This commit is contained in:
M66B 2020-08-20 20:06:36 +02:00
parent 72827e45bb
commit 1d99df3f6f
13 changed files with 39 additions and 59 deletions

View File

@ -80,6 +80,7 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
private TextView tvSignKeyId;
private TextView tvLast;
private TextView tvMaxSize;
private TextView tvDrafts;
private TextView tvError;
private TwoStateOwner powner = new TwoStateOwner(owner, "IdentityPopup");
@ -101,6 +102,7 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
tvSignKeyId = itemView.findViewById(R.id.tvSignKeyId);
tvLast = itemView.findViewById(R.id.tvLast);
tvMaxSize = itemView.findViewById(R.id.tvMaxSize);
tvDrafts = itemView.findViewById(R.id.tvDrafts);
tvError = itemView.findViewById(R.id.tvError);
}
@ -165,6 +167,8 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
tvMaxSize.setText(identity.max_size == null ? null : Helper.humanReadableByteCount(identity.max_size));
tvMaxSize.setVisibility(identity.max_size == null ? View.GONE : View.VISIBLE);
tvDrafts.setVisibility(identity.drafts == null ? View.VISIBLE : View.GONE);
tvError.setText(identity.error);
tvError.setVisibility(identity.error == null ? View.GONE : View.VISIBLE);
}

View File

@ -32,18 +32,22 @@ public interface DaoIdentity {
@Query(TupleIdentityView.query)
LiveData<List<TupleIdentityView>> liveIdentityView();
@Query("SELECT identity.*, account.name AS accountName FROM identity" +
" JOIN account ON account.id = identity.account")
@Query("SELECT identity.*, account.name AS accountName, folder.id AS drafts" +
" FROM identity" +
" JOIN account ON account.id = identity.account" +
" LEFT JOIN folder ON folder.account = account.id AND folder.type = '" + EntityFolder.DRAFTS + "'")
LiveData<List<TupleIdentityEx>> liveIdentities();
@Query("SELECT identity.*, account.name AS accountName FROM identity" +
@Query("SELECT identity.*, account.name AS accountName, folder.id AS drafts" +
" FROM identity" +
" JOIN account ON account.id = identity.account" +
" JOIN folder ON folder.account = identity.account AND folder.type = '" + EntityFolder.DRAFTS + "'" +
" AND identity.synchronize" +
" AND account.synchronize")
LiveData<List<TupleIdentityEx>> liveComposableIdentities();
@Query("SELECT identity.*, account.name AS accountName FROM identity" +
@Query("SELECT identity.*, account.name AS accountName, folder.id AS drafts" +
" FROM identity" +
" JOIN account ON account.id = identity.account" +
" JOIN folder ON folder.account = identity.account AND folder.type = '" + EntityFolder.DRAFTS + "'" +
" WHERE (:account IS NULL OR account.id = :account)" +

View File

@ -635,15 +635,14 @@ public class EmailService implements AutoCloseable {
EntityFolder.guessTypes(folders, getStore().getDefaultFolder().getSeparator());
boolean inbox = false;
boolean drafts = false;
for (EntityFolder folder : folders)
if (EntityFolder.INBOX.equals(folder.type))
if (EntityFolder.INBOX.equals(folder.type)) {
inbox = true;
else if (EntityFolder.DRAFTS.equals(folder.type))
drafts = true;
break;
}
if (!inbox || !drafts)
return null;
if (!inbox)
throw new IllegalArgumentException(context.getString(R.string.title_setup_no_inbox));
return folders;
}

View File

@ -3646,7 +3646,7 @@ public class FragmentCompose extends FragmentBase {
EntityFolder drafts = db.folder().getFolderByType(selected.account, EntityFolder.DRAFTS);
if (drafts == null)
throw new IllegalArgumentException(context.getString(R.string.title_no_primary_drafts));
throw new IllegalArgumentException(context.getString(R.string.title_no_drafts));
data.draft.account = drafts.account;
data.draft.folder = drafts.id;

View File

@ -373,9 +373,6 @@ public class FragmentGmail extends FragmentBase {
null, null);
folders = iservice.getFolders();
if (folders == null)
throw new IllegalArgumentException(context.getString(R.string.title_setup_no_system_folders));
}
Long max_size;

View File

@ -987,7 +987,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override
protected void onExecuted(Bundle args, EntityFolder drafts) {
if (drafts == null)
Snackbar.make(view, R.string.title_no_primary_drafts, Snackbar.LENGTH_LONG)
Snackbar.make(view, R.string.title_no_drafts, Snackbar.LENGTH_LONG)
.setGestureInsetBottomIgnored(true).show();
else {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(getContext());

View File

@ -485,9 +485,6 @@ public class FragmentOAuth extends FragmentBase {
null, null);
folders = iservice.getFolders();
if (folders == null)
throw new IllegalArgumentException(context.getString(R.string.title_setup_no_system_folders));
}
Log.i("OAuth checking SMTP provider=" + provider.id);

View File

@ -337,9 +337,6 @@ public class FragmentQuickSetup extends FragmentBase {
}
folders = iservice.getFolders();
if (folders == null)
throw new IllegalArgumentException(context.getString(R.string.title_setup_no_system_folders));
}
Long max_size = null;

View File

@ -67,7 +67,6 @@ public class FragmentSetup extends FragmentBase {
private TextView tvAccountDone;
private Button btnAccount;
private TextView tvNoPrimaryDrafts;
private TextView tvIdentityDone;
private Button btnIdentity;
@ -115,7 +114,6 @@ public class FragmentSetup extends FragmentBase {
tvAccountDone = view.findViewById(R.id.tvAccountDone);
btnAccount = view.findViewById(R.id.btnAccount);
tvNoPrimaryDrafts = view.findViewById(R.id.tvNoPrimaryDrafts);
tvIdentityDone = view.findViewById(R.id.tvIdentityDone);
btnIdentity = view.findViewById(R.id.btnIdentity);
@ -309,7 +307,6 @@ public class FragmentSetup extends FragmentBase {
tvAccountDone.setText(null);
tvAccountDone.setCompoundDrawables(null, null, null, null);
tvNoPrimaryDrafts.setVisibility(View.GONE);
tvIdentityDone.setText(null);
tvIdentityDone.setCompoundDrawables(null, null, null, null);
@ -386,25 +383,6 @@ public class FragmentSetup extends FragmentBase {
btnInbox.setEnabled(done);
prefs.edit().putBoolean("has_accounts", done).apply();
if (done)
new SimpleTask<EntityFolder>() {
@Override
protected EntityFolder onExecute(Context context, Bundle args) {
DB db = DB.getInstance(context);
return db.folder().getPrimaryDrafts();
}
@Override
protected void onExecuted(Bundle args, EntityFolder drafts) {
tvNoPrimaryDrafts.setVisibility(drafts == null ? View.VISIBLE : View.GONE);
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentSetup.this, new Bundle(), "setup:drafts");
}
});

View File

@ -23,13 +23,15 @@ import java.util.Objects;
public class TupleIdentityEx extends EntityIdentity {
public String accountName;
public Long drafts;
@Override
public boolean equals(Object obj) {
if (obj instanceof TupleIdentityEx) {
TupleIdentityEx other = (TupleIdentityEx) obj;
return (super.equals(obj) &&
Objects.equals(accountName, other.accountName));
Objects.equals(accountName, other.accountName) &&
Objects.equals(drafts, other.drafts));
} else
return false;
}

View File

@ -240,17 +240,6 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tvAccountDone" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvNoPrimaryDrafts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_no_primary_drafts"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnAccount" />
<!-- identity -->
<View
@ -261,7 +250,7 @@
android:background="?attr/colorSeparator"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNoPrimaryDrafts" />
app:layout_constraintTop_toBottomOf="@id/btnAccount" />
<ImageView
android:id="@+id/two"

View File

@ -178,6 +178,19 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/tvLast" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvDrafts"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginEnd="6dp"
android:text="@string/title_drafts_required"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toBottomOf="@id/tvLast" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvError"
android:layout_width="0dp"
@ -190,7 +203,7 @@
android:textIsSelectable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/vwColor"
app:layout_constraintTop_toBottomOf="@id/tvLast" />
app:layout_constraintTop_toBottomOf="@id/tvDrafts" />
<View
android:id="@+id/marginBottom"

View File

@ -181,7 +181,7 @@
<string name="title_setup_no_settings_hint">Please try setting up an account and identity in setup steps 1 and 2 using the settings provided by your email provider</string>
<string name="title_setup_no_auth_hint">Please double check your email address and password and make sure external access (IMAP/SMTP) is enabled for your account</string>
<string name="title_setup_app_password_hint">This provider requires an app password instead of the account password, please check the instructions of your provider</string>
<string name="title_setup_no_system_folders">Inbox or draft folder not found</string>
<string name="title_setup_no_inbox">Inbox not found</string>
<string name="title_setup_advanced_protection">When enrolled in the advanced protection program it is not possible to use a third party email app. This is a restriction imposed by Google.</string>
<string name="title_setup_quick_success">An account and an identity have successfully been added</string>
<string name="title_setup_quick_failed">You can try to configure an account and an identity below too</string>
@ -658,7 +658,7 @@
<string name="title_no_user">User name missing</string>
<string name="title_no_password">Password missing</string>
<string name="title_no_inbox">Inbox not found</string>
<string name="title_no_primary_drafts">No primary account or no drafts folder</string>
<string name="title_no_drafts">No drafts folder</string>
<string name="title_no_junk_folder">There is no spam folder selected for this account</string>
<string name="title_no_identities">Sending emails requires at least one identity and a drafts folder</string>
<string name="title_no_standard">This provider uses a proprietary email protocol and therefore it is not possible to use third party email clients</string>