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

Commit 6810338

Browse files
ooroscniftynei
authored andcommitted
Images are now loaded in however it is done in a hacky method. needs further discussion
changed modification deleted code Undid unrelated fixes Rebase completed, issues with master.
1 parent f0ecc8d commit 6810338

File tree

7 files changed

+116
-85
lines changed

7 files changed

+116
-85
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
gen/
22
bin/
3+
build.gradle
34
/res/raw/ormlite_config.txt
45
.settings
56
*-sources.jar

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package com.zulip.android.activities;
22

33
import android.content.Context;
4+
import android.content.Intent;
45
import android.content.res.ColorStateList;
56
import android.content.res.Resources;
67
import android.graphics.Bitmap;
78
import android.graphics.Color;
89
import android.graphics.drawable.GradientDrawable;
10+
import android.net.Uri;
911
import android.support.annotation.ColorInt;
1012
import android.support.v4.content.ContextCompat;
1113
import android.support.v4.view.ViewCompat;
1214
import android.support.v7.app.AppCompatDelegate;
1315
import android.support.v7.widget.RecyclerView;
1416
import android.text.format.DateUtils;
15-
import android.text.method.LinkMovementMethod;
1617
import android.util.Log;
18+
import android.text.method.LinkMovementMethod;
1719
import android.util.TypedValue;
1820
import android.view.LayoutInflater;
1921
import android.view.View;
@@ -365,25 +367,41 @@ public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int pos
365367

366368
MessageHolder messageHolder = ((MessageHolder) holder);
367369
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-
});
370+
375371
messageHolder.contentView.setText(message.getFormattedContent(zulipApp));
376372
messageHolder.contentView.setMovementMethod(LinkMovementMethod.getInstance());
377373

374+
final String url = message.extractImageUrl(zulipApp);
375+
if(url != null) {
376+
messageHolder.contentImageContainer.setVisibility(View.VISIBLE);
377+
Picasso.with(context).load(url)
378+
.into(messageHolder.contentImage);
379+
380+
messageHolder.contentImageContainer
381+
.setOnClickListener(new View.OnClickListener() {
382+
@Override
383+
public void onClick(View view) {
384+
Intent i = new Intent(Intent.ACTION_VIEW);
385+
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
386+
i.setData(Uri.parse(url));
387+
zulipApp.startActivity(i);
388+
}
389+
});
390+
}
391+
else {
392+
messageHolder.contentImageContainer.setVisibility(View.GONE);
393+
messageHolder.contentImage.setImageDrawable(null);
394+
}
378395
if (message.getType() == MessageType.STREAM_MESSAGE) {
379396
messageHolder.senderName.setText(message.getSender().getName());
380397
if (!isCurrentThemeNight)
381398
messageHolder.leftBar.setBackgroundColor(message.getStream().getParsedColor());
382399
messageHolder.messageTile.setBackgroundColor(streamMessageBackground);
383400
} else {
384401
messageHolder.senderName.setText(message.getSender().getName());
385-
if (!isCurrentThemeNight)
402+
if (!isCurrentThemeNight) {
386403
messageHolder.leftBar.setBackgroundColor(privateMessageBackground);
404+
}
387405
messageHolder.messageTile.setBackgroundColor(privateMessageBackground);
388406
}
389407

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

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,30 @@
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;
2123
import com.zulip.android.util.CustomHtmlToSpannedConverter;
2224
import com.zulip.android.util.ZLog;
23-
import com.zulip.android.ZulipApp;
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.HashMap;
42+
import java.util.List;
43+
import java.util.Map;
44+
import java.util.concurrent.Callable;
2445

2546
@DatabaseTable(tableName = "messages")
2647
public class Message {
@@ -34,6 +55,9 @@ public class Message {
3455
public static final String TIMESTAMP_FIELD = "timestamp";
3556
public static final String RECIPIENTS_FIELD = "recipients";
3657
public static final String STREAM_FIELD = "stream";
58+
public static final String MESSAGE_READ_FIELD = "read";
59+
private static final String MESSAGE_EDITED = "MESSAGE_EDITED";
60+
private static final String MESSAGE_EDIT_DATE = "MESSAGE_EDIT_DATE";
3761
private Map<String, Drawable> cachedImages = new HashMap<>(1);
3862

3963
//region fields
@@ -121,7 +145,8 @@ public class Message {
121145
public List<MessageHistory> _history;
122146

123147
//endregion
124-
private Runnable promise;
148+
149+
//endregion
125150

126151
/**
127152
* Construct an empty Message object.
@@ -505,7 +530,7 @@ public Spanned getFormattedContent(ZulipApp app) {
505530
* @param app
506531
* @return Span
507532
*/
508-
private static Spanned formatContent(String source, final ZulipApp app) {
533+
public static Spanned formatContent(String source, final ZulipApp app) {
509534
final Context context = app.getApplicationContext();
510535
final float density = context.getResources().getDisplayMetrics().density;
511536
Parser parser = new Parser();
@@ -738,44 +763,23 @@ public String getDisplayRecipient() {
738763
}
739764
}
740765

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-
// }
766+
public String extractImageUrl(ZulipApp zulipApp) {
767+
String match = "<img src=\"";
768+
int start = getFormattedContent().indexOf(match);
780769

770+
if(start == -1){
771+
return null;
772+
}
773+
start += match.length();
774+
match = getFormattedContent().substring(start);
775+
if(match.indexOf("\"") == -1) {
776+
return null;
777+
}
778+
match = match.substring(0, match.indexOf("\""));
779+
780+
if(match.indexOf("/") == 0) {
781+
return zulipApp.getServerURI().substring(0, zulipApp.getServerURI().indexOf("/api")) + match;
782+
}
783+
return match;
784+
}
781785
}

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ 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();
3635
private String method, path;
3736
private Object synchronization = new Object();
3837

@@ -58,22 +57,14 @@ void clearProperties() {
5857

5958
void abort() {
6059
aborting = true;
61-
synchronized (synchronization) {
62-
if (response != null) {
63-
final Response finalResponse = response;
64-
response = null;
65-
(new AsyncTask<Void, Void, Void>() {
66-
@Override
67-
protected Void doInBackground(Void... voids) {
68-
try {
69-
finalResponse.body().close();
70-
} catch (IllegalStateException e) {
71-
//fail silently
72-
}
73-
return null;
74-
}
75-
}).execute();
76-
}
60+
if (response != null) {
61+
(new AsyncTask<Void, Void, Void>() {
62+
@Override
63+
protected Void doInBackground(Void... voids) {
64+
response.body().close();
65+
return null;
66+
}
67+
}).execute();
7768
}
7869
}
7970

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ 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());
9897
Response response = request.execute();
9998
String responseString = response.body().string();
10099
if (response.isSuccessful()) {

app/src/main/java/com/zulip/android/viewholders/MessageHolder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class MessageHolder extends RecyclerView.ViewHolder implements View.OnCli
2424
public TextView contentView;
2525
public View leftBar;
2626
public RelativeLayout messageTile;
27+
public ImageView contentImage;
28+
public View contentImageContainer;
2729
public OnItemClickListener onItemClickListener;
2830

2931
public MessageHolder(final View itemView) {
@@ -35,6 +37,8 @@ public MessageHolder(final View itemView) {
3537
contentView.setMovementMethod(LinkMovementMethod.getInstance());
3638
leftBar = itemView.findViewById(R.id.leftBar);
3739
messageTile = (RelativeLayout) itemView.findViewById(R.id.messageTile);
40+
contentImage = (ImageView) itemView.findViewById(R.id.load_image);
41+
contentImageContainer = itemView.findViewById(R.id.load_image_container);
3842
contentView.setOnClickListener(this);
3943
contentView.setLongClickable(true);
4044
itemView.setOnCreateContextMenuListener(this);

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
4-
android:id="@+id/messageTile"
5-
android:layout_width="match_parent"
6-
android:layout_height="wrap_content"
7-
android:background="@color/stream_background"
8-
android:paddingEnd="8dp"
9-
android:paddingRight="8dp">
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:id="@+id/messageTile"
5+
android:layout_width="match_parent"
6+
android:layout_height="wrap_content"
7+
android:background="@color/stream_background"
8+
android:paddingEnd="8dp"
9+
android:paddingRight="8dp">
1010

1111
<View
1212
android:id="@+id/leftBar"
@@ -62,14 +62,28 @@
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/>-->
65+
<FrameLayout
66+
android:id="@+id/load_image_container"
67+
android:layout_width="match_parent"
68+
android:layout_height="175dp"
69+
android:layout_below="@id/contentView"
70+
android:layout_centerHorizontal="true"
71+
android:layout_marginLeft="16dp"
72+
android:layout_marginTop="20dp"
73+
android:maxHeight="200dp"
74+
android:visibility="gone"
75+
tools:visibility="visible">
76+
77+
<ImageView
78+
android:id="@+id/load_image"
79+
android:layout_width="wrap_content"
80+
android:layout_height="wrap_content"
81+
android:layout_gravity="center"
82+
android:background="@color/colorAccent"
83+
android:scaleType="centerInside"
84+
tools:src="@drawable/ic_arrow_back_24dp"/>
85+
86+
</FrameLayout>
7387

7488
<ImageView
7589
android:paddingTop="10dp"
@@ -83,4 +97,4 @@
8397
android:scaleType="centerInside"
8498
android:src="@android:drawable/presence_online" />
8599

86-
</RelativeLayout>
100+
</RelativeLayout>

0 commit comments

Comments
 (0)