Merge branch 'develop' into release-1.6.0
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / adapter / SslErrorViewAdapter.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2014 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17 package com.owncloud.android.ui.adapter;
18
19 import com.owncloud.android.R;
20 import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
21 import android.net.http.SslError;
22 import android.view.View;
23 import android.widget.TextView;
24
25 /**
26 * Dialog to show an Untrusted Certificate
27 *
28 * @author masensio
29 * @author David A. Velasco
30 *
31 */
32 public class SslErrorViewAdapter implements SslUntrustedCertDialog.ErrorViewAdapter {
33
34 //private final static String TAG = SslErrorViewAdapter.class.getSimpleName();
35
36 private SslError mSslError;
37
38 public SslErrorViewAdapter(SslError sslError) {
39 mSslError = sslError;
40 }
41
42 @Override
43 public void updateErrorView(View dialogView) {
44 /// clean
45 dialogView.findViewById(R.id.reason_no_info_about_error).setVisibility(View.GONE);
46
47 /// refresh
48 if (mSslError.hasError(SslError.SSL_UNTRUSTED)) {
49 ((TextView)dialogView.findViewById(R.id.reason_cert_not_trusted)).setVisibility(View.VISIBLE);
50 } else {
51 dialogView.findViewById(R.id.reason_cert_not_trusted).setVisibility(View.GONE);
52 }
53
54 if (mSslError.hasError(SslError.SSL_EXPIRED)) {
55 ((TextView)dialogView.findViewById(R.id.reason_cert_expired)).setVisibility(View.VISIBLE);
56 } else {
57 dialogView.findViewById(R.id.reason_cert_expired).setVisibility(View.GONE);
58 }
59
60 if (mSslError.getPrimaryError() == SslError.SSL_NOTYETVALID) {
61 ((TextView)dialogView.findViewById(R.id.reason_cert_not_yet_valid)).setVisibility(View.VISIBLE);
62 } else {
63 dialogView.findViewById(R.id.reason_cert_not_yet_valid).setVisibility(View.GONE);
64 }
65
66 if (mSslError.getPrimaryError() == SslError.SSL_IDMISMATCH) {
67 ((TextView)dialogView.findViewById(R.id.reason_hostname_not_verified)).setVisibility(View.VISIBLE);
68 } else {
69 dialogView.findViewById(R.id.reason_hostname_not_verified).setVisibility(View.GONE);
70 }
71 }
72
73 }