Skip to content

Commit

Permalink
launch the image viewer when tapping an avatar, refs #177
Browse files Browse the repository at this point in the history
  • Loading branch information
c99koder committed Dec 9, 2019
1 parent 3d1988a commit d74b56a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ dependencies {
implementation 'android.arch.work:work-runtime:1.0.1'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.drawerlayout:drawerlayout:1.1.0-alpha03'
implementation 'androidx.sharetarget:sharetarget:1.0.0-beta02'
implementation 'androidx.sharetarget:sharetarget:1.0.0-rc01'
implementation "androidx.cardview:cardview:1.0.0"
implementation "com.google.android.material:material:1.0.0"
implementation "androidx.recyclerview:recyclerview:1.1.0"
Expand Down
4 changes: 2 additions & 2 deletions irccloud-android.iml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<orderEntry type="library" name="Gradle: androidx.legacy:legacy-support-v4:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.legacy:legacy-support-core-ui:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.drawerlayout:drawerlayout:1.1.0-alpha03@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.sharetarget:sharetarget:1.0.0-beta02@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.sharetarget:sharetarget:1.0.0-rc01@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.recyclerview:recyclerview:1.1.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.emoji:emoji:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: com.google.firebase:firebase-messaging:20.0.1@aar" level="project" />
Expand Down Expand Up @@ -146,7 +146,7 @@
<orderEntry type="library" name="Gradle: androidx.swiperefreshlayout:swiperefreshlayout:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.asynclayoutinflater:asynclayoutinflater:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.media:media:1.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.core:core:1.2.0-beta01@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.core:core:1.2.0-rc01@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-process:2.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-service:2.0.0@aar" level="project" />
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-runtime:2.1.0@aar" level="project" />
Expand Down
7 changes: 6 additions & 1 deletion src/com/irccloud/android/data/model/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,12 @@ public String getAvatarURL(int size, boolean isChannel, boolean isSlack) {
} else if (avatar_url != null && avatar_url.length() > 0 && avatar_url.startsWith("https://")) {
cachedAvatarURL = avatar_url;
if (cachedAvatarURL.contains("{size}")) {
cachedAvatarURL = UriTemplate.fromTemplate(cachedAvatarURL).set("size", size == 512 ? "512" : "72").expand();
if(size <= 72)
cachedAvatarURL = UriTemplate.fromTemplate(cachedAvatarURL).set("size", "72").expand();
else if(size <= 192)
cachedAvatarURL = UriTemplate.fromTemplate(cachedAvatarURL).set("size", "192").expand();
else
cachedAvatarURL = UriTemplate.fromTemplate(cachedAvatarURL).set("size", "512").expand();
}
} else if (NetworkConnection.avatar_redirect_uri_template != null) {
if (hostmask != null && hostmask.length() > 0 && hostmask.contains("@")) {
Expand Down
19 changes: 19 additions & 0 deletions src/com/irccloud/android/fragment/MessageViewFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@ public void onImageFetched(Bitmap image) {
e1.printStackTrace();
}
}
boolean hasAvatarImage = (b != null);
if(b == null) {
b = mAvatarsList.getAvatar(e.cid, e.type.equals("buffer_me_msg")?e.nick:e.from_nick, e.from).getBitmap(ColorScheme.getInstance().isDarkTheme, width, e.self);
}
Expand Down Expand Up @@ -946,6 +947,15 @@ public void draw(Canvas canvas, CharSequence text, int start, int end, float x,
canvas.restore();
}
}, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if(avatarURL != null && hasAvatarImage) {
final Uri uri = Uri.parse(e.getAvatarURL(512));
s.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
IRCCloudLinkMovementMethod.launchURI(uri, getContext());
}
}, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
s.setSpan(new ColorFormatter.TypefaceSpan(ColorFormatter.sourceSansPro), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
formatted = s;
}
Expand Down Expand Up @@ -1054,6 +1064,15 @@ public void onImageFetched(Bitmap image) {
Avatar a = mAvatarsList.getAvatar(e.cid, e.from_nick, e.from);
b = a.getBitmap(ColorScheme.getInstance().isDarkTheme, lp.width, e.self);
holder.avatar.setTag(a);
holder.avatar.setOnClickListener(null);
} else {
final Uri uri = Uri.parse(e.getAvatarURL(512));
holder.avatar.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
IRCCloudLinkMovementMethod.launchURI(uri, getContext());
}
});
}
holder.avatar.setVisibility(View.VISIBLE);
}
Expand Down

0 comments on commit d74b56a

Please sign in to comment.