Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75475f14 authored by daquexian's avatar daquexian Committed by Vincent Breitmoser
Browse files

Use snackbar instead of dialog when settings checking failed, so accounts...

Use snackbar instead of dialog when settings checking failed, so accounts without imap/pop3 or smtp server cannot run on K-9 any more. Maybe there should be a formal support for them
parent a710a22e
Loading
Loading
Loading
Loading
+31 −38
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@ import android.os.Bundle;
import android.os.Looper;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TextInputEditText;
import android.support.design.widget.TextInputLayout;
import android.view.View;
@@ -82,7 +84,6 @@ public class AccountSetupActivity extends AppCompatActivity implements AccountSe
    private AccountSetupPresenter presenter;

    private TextView messageView;
    private Handler handler;

    private EditText usernameView;
    private EditText passwordView;
@@ -112,6 +113,7 @@ public class AccountSetupActivity extends AppCompatActivity implements AccountSe
    private CheckBox compressionOther;
    private CheckBox subscribedFoldersOnly;
    private AuthTypeAdapter authTypeAdapter;
    private CoordinatorLayout coordinatorLayout;

    @SuppressWarnings("FieldCanBeLocal")
    private MaterialProgressBar progressBar;
@@ -277,8 +279,6 @@ public class AccountSetupActivity extends AppCompatActivity implements AccountSe
        progressBar = (MaterialProgressBar) findViewById(R.id.progress);

        progressBar.setIndeterminate(true);

        handler = new Handler(Looper.getMainLooper());
    }

    private void accountTypeStart() {
@@ -387,9 +387,6 @@ public class AccountSetupActivity extends AppCompatActivity implements AccountSe
    public void showAcceptKeyDialog(final int msgResId, final String exMessage, final String message,
            final X509Certificate certificate) {

        handler.post(new Runnable() {
            @Override
            public void run() {
        // TODO: refactor with DialogFragment.
        // This is difficult because we need to pass through chain[0] for onClick()
        new AlertDialog.Builder(AccountSetupActivity.this)
@@ -414,17 +411,11 @@ public class AccountSetupActivity extends AppCompatActivity implements AccountSe
                        })
                .show();
    }
        });
    }

    @Override
    public void showErrorDialog(@StringRes final int msgResId, final Object... args) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                showDialogFragment(R.id.dialog_account_setup_error, getString(msgResId, args));
            }
        });
        // TODO: 8/13/17 add a "detail" button and show exception details here
        Snackbar.make(coordinatorLayout, getString(msgResId, args), Snackbar.LENGTH_LONG).show();
    }

    @Override
@@ -773,6 +764,7 @@ public class AccountSetupActivity extends AppCompatActivity implements AccountSe

    private void incomingStart() {
        View incomingView = findViewById(R.id.account_setup_incoming);
        coordinatorLayout = (CoordinatorLayout) findViewById(R.id.incoming_coordinator_layout);
        usernameView = (EditText) incomingView.findViewById(R.id.incoming_account_username);
        passwordView = (EditText) incomingView.findViewById(R.id.incoming_account_password);
        clientCertificateSpinner = (ClientCertificateSpinner) incomingView.findViewById(R.id.incoming_account_client_certificate_spinner);
@@ -1072,6 +1064,7 @@ public class AccountSetupActivity extends AppCompatActivity implements AccountSe

    private void outgoingStart() {
        final View outgoingView = findViewById(R.id.account_setup_outgoing);
        coordinatorLayout = (CoordinatorLayout) outgoingView.findViewById(R.id.outgoing_coordinator_layout);
        usernameView = (EditText) outgoingView.findViewById(R.id.outgoing_account_username);
        passwordView = (EditText) outgoingView.findViewById(R.id.outgoing_account_password);
        passwordViewLayout = (TextInputLayout) outgoingView.findViewById(R.id.outgoing_account_password_layout);
@@ -1233,7 +1226,7 @@ public class AccountSetupActivity extends AppCompatActivity implements AccountSe

    @Override
    public void goBack() {
        super.onBackPressed();
        onBackPressed();
    }

    @Override
+30 −10
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ package com.fsck.k9.activity.setup;
import android.content.Context;
import android.content.res.XmlResourceParser;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

@@ -111,10 +113,13 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter {

    private AccountConfig accountConfig;

    private Handler handler;

    public AccountSetupPresenter(Context context, Preferences preferences, View view) {
        this.context = context;
        this.preferences = preferences;
        this.view = view;
        this.handler = new Handler(Looper.getMainLooper());
    }

    // region basics
@@ -466,17 +471,26 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter {

                return true;

            } catch (AuthenticationFailedException afe) {
            } catch (final AuthenticationFailedException afe) {
                Timber.e(afe, "Error while testing settings");
                view.showErrorDialog(
                        R.string.account_setup_failed_dlg_auth_message_fmt,
                        afe.getMessage() == null ? "" : afe.getMessage());
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.goBack();
                        view.showErrorDialog(R.string.account_setup_failed_auth_message);
                    }
                });
            } catch (CertificateValidationException cve) {
                handleCertificateValidationException(cve);
            } catch (Exception e) {
            } catch (final Exception e) {
                Timber.e(e, "Error while testing settings");
                String message = e.getMessage() == null ? "" : e.getMessage();
                view.showErrorDialog(R.string.account_setup_failed_dlg_server_message_fmt, message);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.goBack();
                        view.showErrorDialog(R.string.account_setup_failed_server_message);
                    }
                });
            }
            return false;
        }
@@ -686,7 +700,7 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter {
            }
        }

        StringBuilder chainInfo = new StringBuilder(100);
        final StringBuilder chainInfo = new StringBuilder(100);
        MessageDigest sha1 = null;
        try {
            sha1 = MessageDigest.getInstance("SHA-1");
@@ -782,7 +796,13 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter {

        }

        view.showAcceptKeyDialog(msgResId, exMessage, chainInfo.toString(), chain[0]);
        final String finalExMessage = exMessage;
        handler.post(new Runnable() {
            @Override
            public void run() {
                view.showAcceptKeyDialog(msgResId, finalExMessage, chainInfo.toString(), chain[0]);
            }
        });
    }

    private void handleCertificateValidationException(CertificateValidationException cve) {
@@ -1470,7 +1490,7 @@ public class AccountSetupPresenter implements AccountSetupContract.Presenter {
                view.goToOutgoing();
                break;
            default:
                view.goBack();
                view.end();
                break;
        }
    }
+272 −262
Original line number Diff line number Diff line
@@ -6,6 +6,16 @@
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/incoming_coordinator_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
@@ -17,7 +27,7 @@
                android:text="@string/incoming_settings"/>

            <ScrollView
        android:layout_width="fill_parent"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:paddingTop="6dp"
@@ -282,13 +292,13 @@
                            android:contentDescription="@string/account_setup_incoming_compression_label"
                            />
                    </LinearLayout>
            <!--<View
                android:layout_width="fill_parent"
                android:layout_height="0dip"
                android:layout_weight="1" />-->
                </LinearLayout>

            </ScrollView>

        </LinearLayout>
    </android.support.design.widget.CoordinatorLayout>

    <View
        android:id="@+id/divider"
        android:layout_width="match_parent"
+198 −189
Original line number Diff line number Diff line
@@ -6,6 +6,17 @@
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/outgoing_coordinator_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
@@ -202,12 +213,10 @@
                    </LinearLayout>
                </LinearLayout>

        <!--<View
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" />-->
            </ScrollView>
        </LinearLayout>

    </android.support.design.widget.CoordinatorLayout>
    <View
        android:id="@+id/divider"
        android:layout_width="match_parent"
+2 −0
Original line number Diff line number Diff line
@@ -521,9 +521,11 @@ Please submit bug reports, contribute new features and ask questions at
    <string name="move_copy_cannot_copy_unsynced_message">Cannot copy or move a message that is not synchronized with the server</string>

    <string name="account_setup_failed_dlg_title">Setup could not finish</string>
    <string name="account_setup_failed_auth_message">Username or password incorrect</string>
    <string name="account_setup_failed_dlg_auth_message_fmt">Username or password incorrect.\n(<xliff:g id="error">%s</xliff:g>)</string>
    <string name="account_setup_failed_dlg_certificate_message_fmt">The server presented an invalid SSL certificate. Sometimes, this is because of a server misconfiguration. Sometimes it is because someone is trying to attack you or your mail server. If you\'re not sure what\'s up, click Reject and contact the folks who manage your mail server.\n\n(<xliff:g id="error">%s</xliff:g>)</string>
    <string name="account_setup_failed_dlg_server_message_fmt">Cannot connect to server.\n(<xliff:g id="error">%s</xliff:g>)</string>
    <string name="account_setup_failed_server_message">Cannot connect to server</string>
    <string name="account_setup_failed_dlg_edit_details_action">Edit details</string>
    <string name="account_setup_failed_dlg_continue_action">Continue</string>