1111import net .sharksystem .R ;
1212import net .sharksystem .asap .ASAPChannel ;
1313import net .sharksystem .asap .ASAPException ;
14+ import net .sharksystem .asap .ASAPSecurityException ;
1415import net .sharksystem .asap .sharknet .InMemoSNMessage ;
1516import net .sharksystem .asap .sharknet .SNMessage ;
17+ import net .sharksystem .asap .util .DateTimeHelper ;
1618import net .sharksystem .crypto .BasicKeyStore ;
1719import net .sharksystem .makan .Makan ;
1820import net .sharksystem .makan .android .MakanApp ;
1921
2022import java .io .IOException ;
23+ import java .sql .Timestamp ;
2124import java .text .DateFormat ;
25+ import java .util .Set ;
2226
2327public class SNChannelViewContentAdapter extends
2428 RecyclerView .Adapter <SNChannelViewContentAdapter .MyViewHolder > {
@@ -45,13 +49,21 @@ public SNChannelViewContentAdapter.MyViewHolder onCreateViewHolder(
4549 }
4650
4751 public class MyViewHolder extends RecyclerView .ViewHolder {
52+ private final TextView encryptedTextView ;
53+ private final TextView verifiedTextView ;
54+ private final TextView identityAssuranceTextView ;
55+ private final TextView recipientsTextView ;
4856 public TextView dateTextView , messageTextView , senderTextView ;
4957
5058 public MyViewHolder (View view ) {
5159 super (view );
5260 dateTextView = (TextView ) view .findViewById (R .id .sn_channel_message_row_date );
5361 messageTextView = (TextView ) view .findViewById (R .id .sn_channel_message_row_message );
5462 senderTextView = (TextView ) view .findViewById (R .id .sn_channel_message_row_sender );
63+ encryptedTextView = (TextView ) view .findViewById (R .id .sn_channel_message_row_encrypted );
64+ verifiedTextView = (TextView ) view .findViewById (R .id .sn_channel_message_row_verified );
65+ identityAssuranceTextView = (TextView ) view .findViewById (R .id .sn_channel_message_row_identityassurance );
66+ recipientsTextView = (TextView ) view .findViewById (R .id .sn_channel_message_row_recipients );
5567 }
5668 }
5769
@@ -75,32 +87,85 @@ public void onBindViewHolder(SNChannelViewContentAdapter.MyViewHolder holder, in
7587 public static SharkNetMessage parseMessage(byte[] message, String sender, String uri,
7688 CharSequence ownerID, BasicKeyStore basicKeyStore) throws IOException, ASAPException {
7789 */
78- CharSequence sender ;
7990 BasicKeyStore basicKeyStore =
8091 SNChannelsComponent .getSharkNetChannelComponent ().getBasicKeyStore ();
8192
82- SNMessage snMessage =
83- InMemoSNMessage .parseMessage (asapMessage , basicKeyStore );
84-
85- // produce SNMessage
86- String date = "dummy Date" ;
87- String content = "dummy message" ;
88- sender = "dummy Sender" ;
89-
90- holder .dateTextView .setText (date );
91- /*
92- holder.dateTextView.setText(
93- DateFormat.getInstance().format(message.getSentDate()));
94- */
95-
96- holder .messageTextView .setText (content );
97- holder .senderTextView .setText (sender );
98-
99- /*
100- holder.messageTextView.setText(message.getContentAsString());
101- holder.senderTextView.setText(PersonsStorageAndroidComponent.
102- getPersonsStorage().getPersonName(message.getSenderID()));
103- */
93+ SNMessage snMessage = null ;
94+ try {
95+ snMessage = InMemoSNMessage .parseMessage (asapMessage , basicKeyStore );
96+ }
97+ catch (ASAPSecurityException e ) {
98+ // could not be parsed
99+ Log .d (LOGSTART , "could not parse SNMessage " + position );
100+ return ;
101+ }
102+
103+ CharSequence recipients2View ;
104+
105+ Set <CharSequence > recipients = snMessage .getRecipients ();
106+ if (recipients == null || recipients .isEmpty ()) {
107+ recipients2View = "anybody" ;
108+ } else {
109+ StringBuilder sb = new StringBuilder ();
110+
111+ boolean firstRound = true ;
112+ for (CharSequence recipientID : recipients ) {
113+ if (firstRound ) {
114+ firstRound = false ;
115+ sb .append ("to: " );
116+ } else {
117+ sb .append ("|" );
118+ }
119+
120+ CharSequence recipientName = null ;
121+ try {
122+ sb .append (SNChannelsComponent .getSharkNetChannelComponent ().
123+ getPersonName (recipientID ));
124+ }
125+ catch (ASAPException e ) {
126+ // no name found
127+ sb .append (recipientID );
128+ }
129+ }
130+
131+ recipients2View = sb .toString ();
132+ }
133+
134+ CharSequence encrypted2View = "E2E encrypted: no" ;
135+ if (snMessage .encrypted ()) {
136+ encrypted2View = "E2E encrypted: yes" ;
137+ }
138+
139+ // assume defaults at first
140+ CharSequence sender2View = "from: unknown" ;
141+ CharSequence content2View = "decrypted message" ;
142+ CharSequence verified2View = "verified: no" ;
143+ CharSequence timestamp2View = "time: unknown" ;
144+ CharSequence iA2View = "iA: unknown" ;
145+
146+
147+ // do we have an decrypted message?
148+ if (snMessage .couldBeDecrypted ()) {
149+ byte [] snContent = snMessage .getContent ();
150+ content2View = String .valueOf (snMessage );
151+
152+ Timestamp creationTime = snMessage .getCreationTime ();
153+ timestamp2View = DateTimeHelper .long2DateString (creationTime .getTime ());
154+
155+ sender2View = "from: " + snMessage .getSender ();
156+
157+ if (snMessage .verified ()) {
158+ verified2View = "verified" ;
159+ }
160+ }
161+
162+ holder .dateTextView .setText (timestamp2View );
163+ holder .messageTextView .setText (content2View );
164+ holder .senderTextView .setText (sender2View );
165+ holder .encryptedTextView .setText (encrypted2View );
166+ holder .verifiedTextView .setText (verified2View );
167+ holder .identityAssuranceTextView .setText (iA2View );
168+ holder .recipientsTextView .setText (recipients2View );
104169
105170 } catch (Throwable e ) {
106171 Log .e (LOGSTART , "cannot access message storage (yet?)" );
0 commit comments