18
18
import com .j256 .ormlite .misc .TransactionManager ;
19
19
import com .j256 .ormlite .stmt .DeleteBuilder ;
20
20
import com .j256 .ormlite .table .DatabaseTable ;
21
- import com .zulip .android .R ;
22
- import com .zulip .android .ZulipApp ;
23
21
import com .zulip .android .util .CustomHtmlToSpannedConverter ;
24
22
import com .zulip .android .util .ZLog ;
25
-
26
- import org .apache .commons .lang .builder .EqualsBuilder ;
27
- import org .apache .commons .lang .builder .HashCodeBuilder ;
28
- import org .ccil .cowan .tagsoup .HTMLSchema ;
29
- import org .ccil .cowan .tagsoup .Parser ;
30
- import org .json .JSONArray ;
31
- import org .json .JSONException ;
32
- import org .json .JSONObject ;
33
- import org .xml .sax .SAXNotRecognizedException ;
34
- import org .xml .sax .SAXNotSupportedException ;
35
-
36
- import java .io .IOException ;
37
- import java .sql .SQLException ;
38
- import java .util .ArrayList ;
39
- import java .util .Arrays ;
40
- import java .util .Date ;
41
- import java .util .List ;
42
- import java .util .Map ;
43
- import java .util .concurrent .Callable ;
23
+ import com .zulip .android .ZulipApp ;
44
24
45
25
@ DatabaseTable (tableName = "messages" )
46
26
public class Message {
@@ -54,10 +34,7 @@ public class Message {
54
34
public static final String TIMESTAMP_FIELD = "timestamp" ;
55
35
public static final String RECIPIENTS_FIELD = "recipients" ;
56
36
public static final String STREAM_FIELD = "stream" ;
57
- public static final String MESSAGE_READ_FIELD = "read" ;
58
- private static final String MESSAGE_EDITED = "MESSAGE_EDITED" ;
59
- private static final String MESSAGE_EDIT_DATE = "MESSAGE_EDIT_DATE" ;
60
-
37
+ private Map <String , Drawable > cachedImages = new HashMap <>(1 );
61
38
62
39
//region fields
63
40
@ SerializedName ("recipient_id" )
@@ -144,8 +121,7 @@ public class Message {
144
121
public List <MessageHistory > _history ;
145
122
146
123
//endregion
147
-
148
-
124
+ private Runnable promise ;
149
125
150
126
/**
151
127
* Construct an empty Message object.
@@ -487,6 +463,14 @@ public Void call() throws Exception {
487
463
488
464
}
489
465
466
+ /**
467
+ * Used to notify an outside observer if the state of a message has changed... e.g. offthread loaded images.
468
+ * @param runnable
469
+ */
470
+ public void setValueChangedPromise (Runnable runnable ){
471
+ this .promise = runnable ;
472
+ }
473
+
490
474
public String concatStreamAndTopic () {
491
475
return getStream ().getId () + getSubject ();
492
476
}
@@ -500,11 +484,12 @@ public String getIdForHolder() {
500
484
501
485
private static final HTMLSchema schema = new HTMLSchema ();
502
486
503
-
504
487
public Spanned getFormattedContent (ZulipApp app ) {
488
+ // if(getContent() != null && getContent().contains("<img"))
505
489
506
490
Spanned formattedMessage = formatContent (getFormattedContent (),
507
491
app );
492
+
508
493
while (formattedMessage .length () != 0
509
494
&& formattedMessage .charAt (formattedMessage .length () - 1 ) == '\n' ) {
510
495
formattedMessage = (Spanned ) formattedMessage .subSequence (0 ,
@@ -520,7 +505,7 @@ public Spanned getFormattedContent(ZulipApp app) {
520
505
* @param app
521
506
* @return Span
522
507
*/
523
- public static Spanned formatContent (String source , ZulipApp app ) {
508
+ private static Spanned formatContent (String source , final ZulipApp app ) {
524
509
final Context context = app .getApplicationContext ();
525
510
final float density = context .getResources ().getDisplayMetrics ().density ;
526
511
Parser parser = new Parser ();
@@ -753,4 +738,44 @@ public String getDisplayRecipient() {
753
738
}
754
739
}
755
740
741
+ // private static Drawable getDrawable(final String source, final Context context, final Message message) {
742
+ //
743
+ // Drawable val = message.cachedImages.get(source);
744
+ // if(val != null) {
745
+ // message.cachedImages.remove(source);
746
+ // return val;
747
+ // }
748
+ //
749
+ // AsyncTask<Void, Void, Drawable> k = new AsyncTask<Void, Void, Drawable>() {
750
+ // @Override
751
+ // protected Drawable doInBackground(Void... voids) {
752
+ // Bitmap res = null;
753
+ // try {
754
+ // res = Picasso.with(context)
755
+ // .load(source)
756
+ // .priority(Picasso.Priority.HIGH)
757
+ // .get();
758
+ // } catch (IOException e) {
759
+ // e.printStackTrace();
760
+ // }
761
+ //
762
+ // if (res == null) {
763
+ // return null;
764
+ // }
765
+ // return new BitmapDrawable(context.getResources(), res);
766
+ // }
767
+ //
768
+ // @Override
769
+ // protected void onPostExecute(Drawable drawable) {
770
+ // super.onPostExecute(drawable);
771
+ // if(message.promise != null) {
772
+ // message.cachedImages.put(source, drawable);
773
+ // message.promise.run();
774
+ // }
775
+ // }
776
+ // }.execute();
777
+ //
778
+ // return null;
779
+ // }
780
+
756
781
}
0 commit comments