Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit f0ecc8d

Browse files
ooroscniftynei
authored andcommitted
More issues with image loading
1 parent 564472b commit f0ecc8d

File tree

5 files changed

+73
-30
lines changed

5 files changed

+73
-30
lines changed

app/src/main/java/com/zulip/android/activities/RecyclerMessageAdapter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(final ViewGroup parent, int vi
333333
}
334334

335335
@Override
336-
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
336+
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
337337
switch (getItemViewType(position)) {
338338
case VIEWTYPE_MESSAGE_HEADER:
339339
final MessageHeaderParent messageHeaderParent = (MessageHeaderParent) getItem(position);
@@ -365,6 +365,13 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
365365

366366
MessageHolder messageHolder = ((MessageHolder) holder);
367367
final Message message = ((Message) items.get(position));
368+
message.setValueChangedPromise(new Runnable() {
369+
@Override
370+
public void run() {
371+
onBindViewHolder(holder, position);
372+
message.setValueChangedPromise(null);
373+
}
374+
});
368375
messageHolder.contentView.setText(message.getFormattedContent(zulipApp));
369376
messageHolder.contentView.setMovementMethod(LinkMovementMethod.getInstance());
370377

app/src/main/java/com/zulip/android/models/Message.java

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,9 @@
1818
import com.j256.ormlite.misc.TransactionManager;
1919
import com.j256.ormlite.stmt.DeleteBuilder;
2020
import com.j256.ormlite.table.DatabaseTable;
21-
import com.zulip.android.R;
22-
import com.zulip.android.ZulipApp;
2321
import com.zulip.android.util.CustomHtmlToSpannedConverter;
2422
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;
4424

4525
@DatabaseTable(tableName = "messages")
4626
public class Message {
@@ -54,10 +34,7 @@ public class Message {
5434
public static final String TIMESTAMP_FIELD = "timestamp";
5535
public static final String RECIPIENTS_FIELD = "recipients";
5636
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);
6138

6239
//region fields
6340
@SerializedName("recipient_id")
@@ -144,8 +121,7 @@ public class Message {
144121
public List<MessageHistory> _history;
145122

146123
//endregion
147-
148-
124+
private Runnable promise;
149125

150126
/**
151127
* Construct an empty Message object.
@@ -487,6 +463,14 @@ public Void call() throws Exception {
487463

488464
}
489465

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+
490474
public String concatStreamAndTopic() {
491475
return getStream().getId() + getSubject();
492476
}
@@ -500,11 +484,12 @@ public String getIdForHolder() {
500484

501485
private static final HTMLSchema schema = new HTMLSchema();
502486

503-
504487
public Spanned getFormattedContent(ZulipApp app) {
488+
// if(getContent() != null && getContent().contains("<img"))
505489

506490
Spanned formattedMessage = formatContent(getFormattedContent(),
507491
app);
492+
508493
while (formattedMessage.length() != 0
509494
&& formattedMessage.charAt(formattedMessage.length() - 1) == '\n') {
510495
formattedMessage = (Spanned) formattedMessage.subSequence(0,
@@ -520,7 +505,7 @@ public Spanned getFormattedContent(ZulipApp app) {
520505
* @param app
521506
* @return Span
522507
*/
523-
public static Spanned formatContent(String source, ZulipApp app) {
508+
private static Spanned formatContent(String source, final ZulipApp app) {
524509
final Context context = app.getApplicationContext();
525510
final float density = context.getResources().getDisplayMetrics().density;
526511
Parser parser = new Parser();
@@ -753,4 +738,44 @@ public String getDisplayRecipient() {
753738
}
754739
}
755740

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+
756781
}

app/src/main/java/com/zulip/android/networking/HTTPRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class HTTPRequest {
3232
private HashMap<String, String> properties;
3333
private OkHttpClient okHttpClient;
3434
private Response response = null;
35+
private final Object synchronization = new Object();
3536
private String method, path;
3637
private Object synchronization = new Object();
3738

app/src/main/java/com/zulip/android/networking/ZulipAsyncPushTask.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ protected String doInBackground(String... api_path) {
9494
Crashlytics.log(Log.VERBOSE, "Network call", getClass().getCanonicalName() + request);
9595

9696
try {
97+
Crashlytics.log(Log.VERBOSE, "Network call", getClass().getCanonicalName() + request.toString());
9798
Response response = request.execute();
9899
String responseString = response.body().string();
99100
if (response.isSuccessful()) {

app/src/main/res/layout/message_tile.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@
6262
android:paddingStart="8dp"
6363
tools:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam mollis pretium purus, faucibus accumsan enim placerat non. " />
6464

65+
<!--<ImageView-->
66+
<!--android:layout_width="wrap_content"-->
67+
<!--android:layout_height="wrap_content"-->
68+
<!--android:scaleType="fitCenter"-->
69+
<!--android:maxHeight="200dp"-->
70+
<!--android:visibility="gone"-->
71+
<!--android:id="@+id/load_image"-->
72+
<!--l/>-->
73+
6574
<ImageView
6675
android:paddingTop="10dp"
6776
android:id="@+id/gravatar"

0 commit comments

Comments
 (0)