Show share with users option if the server supports search users function
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / adapter / SslCertificateViewAdapter.java
1 /**
2 * ownCloud Android client application
3 *
4 * @author masensio
5 * @author David A. Velasco
6 * Copyright (C) 2015 ownCloud Inc.
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21 package com.owncloud.android.ui.adapter;
22
23 import java.text.DateFormat;
24 import java.util.Date;
25
26 import com.owncloud.android.R;
27 import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
28 import android.net.http.SslCertificate;
29 import android.view.View;
30 import android.widget.TextView;
31
32 /**
33 * TODO
34 */
35 public class SslCertificateViewAdapter implements SslUntrustedCertDialog.CertificateViewAdapter {
36
37 //private final static String TAG = SslCertificateViewAdapter.class.getSimpleName();
38
39 private SslCertificate mCertificate;
40
41
42 /**
43 * Constructor
44 *
45 * @param
46 */
47 public SslCertificateViewAdapter(SslCertificate certificate) {
48 mCertificate = certificate;
49 }
50
51 @Override
52 public void updateCertificateView(View dialogView) {
53 TextView nullCerView = (TextView) dialogView.findViewById(R.id.null_cert);
54 if (mCertificate != null) {
55 nullCerView.setVisibility(View.GONE);
56 showSubject(mCertificate.getIssuedTo(), dialogView);
57 showIssuer(mCertificate.getIssuedBy(), dialogView);
58 showValidity(mCertificate.getValidNotBeforeDate(), mCertificate.getValidNotAfterDate(), dialogView);
59 hideSignature(dialogView);
60
61 } else {
62 nullCerView.setVisibility(View.VISIBLE);
63 }
64 }
65
66 private void showValidity(Date notBefore, Date notAfter, View dialogView) {
67 TextView fromView = ((TextView)dialogView.findViewById(R.id.value_validity_from));
68 TextView toView = ((TextView)dialogView.findViewById(R.id.value_validity_to));
69 DateFormat dateFormat = DateFormat.getDateInstance();
70 fromView.setText(dateFormat.format(notBefore));
71 toView.setText(dateFormat.format(notAfter));
72 }
73
74
75 private void showSubject(SslCertificate.DName subject, View dialogView) {
76 TextView cnView = ((TextView)dialogView.findViewById(R.id.value_subject_CN));
77 cnView.setText(subject.getCName());
78 cnView.setVisibility(View.VISIBLE);
79
80 TextView oView = ((TextView)dialogView.findViewById(R.id.value_subject_O));
81 oView.setText(subject.getOName());
82 oView.setVisibility(View.VISIBLE);
83
84 TextView ouView = ((TextView)dialogView.findViewById(R.id.value_subject_OU));
85 ouView.setText(subject.getUName());
86 ouView.setVisibility(View.VISIBLE);
87
88 // SslCertificates don't offer this information
89 ((TextView)dialogView.findViewById(R.id.value_subject_C)).setVisibility(View.GONE);
90 ((TextView)dialogView.findViewById(R.id.value_subject_ST)).setVisibility(View.GONE);
91 ((TextView)dialogView.findViewById(R.id.value_subject_L)).setVisibility(View.GONE);
92 ((TextView)dialogView.findViewById(R.id.label_subject_C)).setVisibility(View.GONE);
93 ((TextView)dialogView.findViewById(R.id.label_subject_ST)).setVisibility(View.GONE);
94 ((TextView)dialogView.findViewById(R.id.label_subject_L)).setVisibility(View.GONE);
95 }
96
97
98 private void showIssuer(SslCertificate.DName issuer, View dialogView) {
99 TextView cnView = ((TextView)dialogView.findViewById(R.id.value_issuer_CN));
100 cnView.setText(issuer.getCName());
101 cnView.setVisibility(View.VISIBLE);
102
103 TextView oView = ((TextView)dialogView.findViewById(R.id.value_issuer_O));
104 oView.setText(issuer.getOName());
105 oView.setVisibility(View.VISIBLE);
106
107 TextView ouView = ((TextView)dialogView.findViewById(R.id.value_issuer_OU));
108 ouView.setText(issuer.getUName());
109 ouView.setVisibility(View.VISIBLE);
110
111 // SslCertificates don't offer this information
112 ((TextView)dialogView.findViewById(R.id.value_issuer_C)).setVisibility(View.GONE);
113 ((TextView)dialogView.findViewById(R.id.value_issuer_ST)).setVisibility(View.GONE);
114 ((TextView)dialogView.findViewById(R.id.value_issuer_L)).setVisibility(View.GONE);
115 ((TextView)dialogView.findViewById(R.id.label_issuer_C)).setVisibility(View.GONE);
116 ((TextView)dialogView.findViewById(R.id.label_issuer_ST)).setVisibility(View.GONE);
117 ((TextView)dialogView.findViewById(R.id.label_issuer_L)).setVisibility(View.GONE);
118 }
119
120 private void hideSignature(View dialogView) {
121 ((TextView)dialogView.findViewById(R.id.label_signature)).setVisibility(View.GONE);
122 ((TextView)dialogView.findViewById(R.id.label_signature_algorithm)).setVisibility(View.GONE);
123 ((TextView)dialogView.findViewById(R.id.value_signature_algorithm)).setVisibility(View.GONE);
124 ((TextView)dialogView.findViewById(R.id.value_signature)).setVisibility(View.GONE);
125 }
126
127 }