#1482 RoundedImageView. Remove round corners on image decoding.

This commit is contained in:
sictiru 2021-06-30 08:02:27 -07:00
parent 381466322c
commit 61a11e77a3
20 changed files with 93 additions and 91 deletions

View file

@ -1,4 +1,4 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="@dimen/thumbnails_corner_radius" />
<corners android:radius="@dimen/rounded_corner_radius" />
</shape>

View file

@ -18,7 +18,7 @@
android:gravity="center_horizontal"
android:orientation="vertical" >
<ImageView
<com.newsblur.view.RoundedImageView
android:id="@+id/profile_picture"
android:layout_width="70dp"
android:layout_height="70dp"

View file

@ -13,7 +13,7 @@
android:paddingBottom="8dp"
android:paddingTop="8dp" >
<ImageView
<com.newsblur.view.RoundedImageView
android:id="@+id/comment_user_image"
android:layout_width="50dp"
android:layout_height="50dp"
@ -22,7 +22,7 @@
android:contentDescription="@string/description_comment_user"
android:scaleType="fitCenter" />
<ImageView
<com.newsblur.view.RoundedImageView
android:id="@+id/comment_sharesource_image"
android:layout_width="25dp"
android:layout_height="25dp"
@ -33,7 +33,7 @@
android:scaleType="fitCenter"
android:visibility="invisible" />
<ImageView
<com.newsblur.view.RoundedImageView
android:id="@+id/comment_user_reshare_image"
android:layout_width="35dp"
android:layout_height="35dp"

View file

@ -17,7 +17,7 @@
android:layout_marginBottom="10dp"
style="?storyCommentDivider" />
<ImageView
<com.newsblur.view.RoundedImageView
android:id="@+id/reply_user_image"
android:layout_width="30dp"
android:layout_height="30dp"

View file

@ -6,7 +6,7 @@
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<ImageView
<com.newsblur.view.RoundedImageView
android:id="@+id/row_activity_icon"
android:layout_width="25dp"
android:layout_height="25dp"

View file

@ -2,6 +2,6 @@
<resources>
<dimen name="thumbnails_small_size">54dp</dimen>
<dimen name="thumbnails_size">120dp</dimen>
<dimen name="thumbnails_corner_radius">4dp</dimen>
<dimen name="rounded_corner_radius">4dp</dimen>
<dimen name="extra_line_spacing">4dp</dimen>
</resources>

View file

@ -141,7 +141,7 @@ public class FeedChooserAdapter extends BaseExpandableListAdapter {
}
}
FeedUtils.iconLoader.displayImage(feed.faviconUrl, img, false, false, img.getHeight(), true);
FeedUtils.iconLoader.displayImage(feed.faviconUrl, img, false, img.getHeight(), true);
return convertView;
}

View file

@ -134,7 +134,7 @@ public class Premium extends NbActivity {
});
binding.textPolicies.setText(UIUtils.fromHtml(getString(R.string.premium_policies)));
binding.textSubTitle.setPaintFlags(binding.textSubTitle.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
FeedUtils.iconLoader.displayImage(AppConstants.SHILOH_PHOTO_URL, binding.imgShiloh, false, false);
FeedUtils.iconLoader.displayImage(AppConstants.SHILOH_PHOTO_URL, binding.imgShiloh, false);
}
private void setupBillingClient() {

View file

@ -251,7 +251,7 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
nameView.setText(f.feedTitle);
nameView.setTextSize(textSize * defaultTextSize_childName);
ImageView iconView = (ImageView) v.findViewById(R.id.row_socialfeed_icon);
FeedUtils.iconLoader.displayImage(f.photoUrl, iconView, false, false);
FeedUtils.iconLoader.displayImage(f.photoUrl, iconView, false);
TextView neutCounter = ((TextView) v.findViewById(R.id.row_socialsumneu));
if (f.neutralCount > 0 && currentState != StateFilter.BEST) {
neutCounter.setVisibility(View.VISIBLE);
@ -292,7 +292,7 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
nameView.setText(UIUtils.fromHtml(ss.feedTitle));
ImageView iconView = v.findViewById(R.id.row_saved_search_icon);
FeedUtils.iconLoader.preCheck(ss.faviconUrl, iconView);
FeedUtils.iconLoader.displayImage(ss.faviconUrl, iconView, false , false);
FeedUtils.iconLoader.displayImage(ss.faviconUrl, iconView, false);
} else {
if (v == null) v = inflater.inflate(R.layout.row_feed, parent, false);
Feed f = activeFolderChildren.get(groupPosition).get(childPosition);
@ -306,7 +306,7 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
nameView.setTextSize(textSize * defaultTextSize_childName);
ImageView iconView = (ImageView) v.findViewById(R.id.row_feedfavicon);
FeedUtils.iconLoader.preCheck(f.faviconUrl, iconView);
FeedUtils.iconLoader.displayImage(f.faviconUrl, iconView, false, false);
FeedUtils.iconLoader.displayImage(f.faviconUrl, iconView, false);
TextView neutCounter = ((TextView) v.findViewById(R.id.row_feedneutral));
TextView posCounter = ((TextView) v.findViewById(R.id.row_feedpositive));
TextView savedCounter = ((TextView) v.findViewById(R.id.row_feedsaved));

View file

@ -554,12 +554,12 @@ public class StoryViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
// the view will display a stale, recycled thumb before the new one loads if the old is not cleared
if (thumbnailStyle == ThumbnailStyle.LEFT_LARGE || thumbnailStyle == ThumbnailStyle.LEFT_SMALL) {
int thumbSizeGuess = vh.thumbViewLeft.getMeasuredHeight();
vh.thumbLoader = FeedUtils.thumbnailLoader.displayImage(story.thumbnailUrl, vh.thumbViewLeft.imageView, false, true, thumbSizeGuess, true);
vh.thumbLoader = FeedUtils.thumbnailLoader.displayImage(story.thumbnailUrl, vh.thumbViewLeft.imageView, true, thumbSizeGuess, true);
vh.thumbViewRight.setVisibility(View.GONE);
vh.thumbViewLeft.setVisibility(View.VISIBLE);
} else if (thumbnailStyle == ThumbnailStyle.RIGHT_LARGE || thumbnailStyle == ThumbnailStyle.RIGHT_SMALL) {
int thumbSizeGuess = vh.thumbViewRight.getMeasuredHeight();
vh.thumbLoader = FeedUtils.thumbnailLoader.displayImage(story.thumbnailUrl, vh.thumbViewRight.imageView, false, true, thumbSizeGuess, true);
vh.thumbLoader = FeedUtils.thumbnailLoader.displayImage(story.thumbnailUrl, vh.thumbViewRight.imageView, true, thumbSizeGuess, true);
vh.thumbViewLeft.setVisibility(View.GONE);
vh.thumbViewRight.setVisibility(View.VISIBLE);
}
@ -592,7 +592,7 @@ public class StoryViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
// lists with mixed feeds get added info, but single feeds do not
if (!singleFeed) {
FeedUtils.iconLoader.displayImage(story.extern_faviconUrl, vh.feedIconView, false, false);
FeedUtils.iconLoader.displayImage(story.extern_faviconUrl, vh.feedIconView, false);
vh.feedTitleView.setText(story.extern_feedTitle);
vh.feedIconView.setVisibility(View.VISIBLE);
vh.feedTitleView.setVisibility(View.VISIBLE);

View file

@ -12,7 +12,6 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.newsblur.R;
@ -21,13 +20,14 @@ import com.newsblur.network.APIManager;
import com.newsblur.util.FeedUtils;
import com.newsblur.util.PrefsUtils;
import com.newsblur.util.UIUtils;
import com.newsblur.view.RoundedImageView;
public class ProfileDetailsFragment extends Fragment implements OnClickListener {
UserDetails user;
private TextView username, bio, location, sharedCount, followerCount, followingCount, website;
private View locationIcon;
private ImageView imageView;
private RoundedImageView imageView;
private boolean viewingSelf = false;
private Button followButton, unfollowButton;
private APIManager apiManager;
@ -57,7 +57,7 @@ public class ProfileDetailsFragment extends Fragment implements OnClickListener
website = (TextView) v.findViewById(R.id.profile_website);
followerCount = (TextView) v.findViewById(R.id.profile_followercount);
followingCount = (TextView) v.findViewById(R.id.profile_followingcount);
imageView = (ImageView) v.findViewById(R.id.profile_picture);
imageView = (RoundedImageView) v.findViewById(R.id.profile_picture);
followButton = (Button) v.findViewById(R.id.profile_follow_button);
unfollowButton = (Button) v.findViewById(R.id.profile_unfollow_button);
followButton.setOnClickListener(this);
@ -99,7 +99,7 @@ public class ProfileDetailsFragment extends Fragment implements OnClickListener
followingCount.setText("" + user.followingCount);
if (!viewingSelf) {
FeedUtils.iconLoader.displayImage(user.photoUrl, imageView, true, false);
FeedUtils.iconLoader.displayImage(user.photoUrl, imageView, false);
if (user.followedByYou) {
unfollowButton.setVisibility(View.VISIBLE);
followButton.setVisibility(View.GONE);

View file

@ -437,7 +437,7 @@ public class ReadingItemFragment extends NbFragment implements PopupMenu.OnMenuI
binding.readingFeedTitle.setVisibility(View.GONE);
binding.readingFeedIcon.setVisibility(View.GONE);
} else {
FeedUtils.iconLoader.displayImage(feedIconUrl, binding.readingFeedIcon, false, false);
FeedUtils.iconLoader.displayImage(feedIconUrl, binding.readingFeedIcon, false);
binding.readingFeedTitle.setText(feedTitle);
}

View file

@ -33,6 +33,7 @@ import com.newsblur.util.PrefsUtils;
import com.newsblur.util.UIUtils;
import com.newsblur.util.ViewUtils;
import com.newsblur.view.FlowLayout;
import com.newsblur.view.RoundedImageView;
public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
@ -97,7 +98,7 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
View commentView = inflater.inflate(R.layout.include_comment, null);
TextView commentText = (TextView) commentView.findViewById(R.id.comment_text);
commentText.setText(UIUtils.fromHtml(comment.commentText));
ImageView commentImage = (ImageView) commentView.findViewById(R.id.comment_user_image);
RoundedImageView commentImage = (RoundedImageView) commentView.findViewById(R.id.comment_user_image);
TextView commentSharedDate = (TextView) commentView.findViewById(R.id.comment_shareddate);
// TODO: this uses hard-coded "ago" values, which will be wrong when reading prefetched stories
@ -115,10 +116,10 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
}
for (String id : comment.likingUsers) {
ImageView favouriteImage = new ImageView(context);
RoundedImageView favouriteImage = new RoundedImageView(context);
UserProfile user = FeedUtils.dbHelper.getUserProfile(id);
if (user != null) {
FeedUtils.iconLoader.displayImage(user.photoUrl, favouriteImage, true, false);
FeedUtils.iconLoader.displayImage(user.photoUrl, favouriteImage, false);
favouriteContainer.addView(favouriteImage);
}
}
@ -162,11 +163,11 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
View replyView = inflater.inflate(R.layout.include_reply, null);
TextView replyText = (TextView) replyView.findViewById(R.id.reply_text);
replyText.setText(UIUtils.fromHtml(reply.text));
ImageView replyImage = (ImageView) replyView.findViewById(R.id.reply_user_image);
RoundedImageView replyImage = (RoundedImageView) replyView.findViewById(R.id.reply_user_image);
final UserProfile replyUser = FeedUtils.dbHelper.getUserProfile(reply.userId);
if (replyUser != null) {
FeedUtils.iconLoader.displayImage(replyUser.photoUrl, replyImage, true, false);
FeedUtils.iconLoader.displayImage(replyUser.photoUrl, replyImage, false);
replyImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
@ -220,8 +221,8 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
if (!TextUtils.isEmpty(comment.sourceUserId)) {
commentImage.setVisibility(View.INVISIBLE);
ImageView usershareImage = (ImageView) commentView.findViewById(R.id.comment_user_reshare_image);
ImageView sourceUserImage = (ImageView) commentView.findViewById(R.id.comment_sharesource_image);
RoundedImageView usershareImage = (RoundedImageView) commentView.findViewById(R.id.comment_user_reshare_image);
RoundedImageView sourceUserImage = (RoundedImageView) commentView.findViewById(R.id.comment_sharesource_image);
sourceUserImage.setVisibility(View.VISIBLE);
usershareImage.setVisibility(View.VISIBLE);
commentImage.setVisibility(View.INVISIBLE);
@ -229,11 +230,11 @@ public class SetupCommentSectionTask extends AsyncTask<Void, Void, Void> {
UserProfile sourceUser = FeedUtils.dbHelper.getUserProfile(comment.sourceUserId);
if (sourceUser != null) {
FeedUtils.iconLoader.displayImage(sourceUser.photoUrl, sourceUserImage, true, false);
FeedUtils.iconLoader.displayImage(userPhoto, usershareImage, true, false);
FeedUtils.iconLoader.displayImage(sourceUser.photoUrl, sourceUserImage, false);
FeedUtils.iconLoader.displayImage(userPhoto, usershareImage, false);
}
} else {
FeedUtils.iconLoader.displayImage(userPhoto, commentImage, true, false);
FeedUtils.iconLoader.displayImage(userPhoto, commentImage, false);
}
commentImage.setOnClickListener(new OnClickListener() {

View file

@ -58,8 +58,8 @@ public class ImageLoader {
return new ImageLoader(cache, android.R.color.transparent, 32, false, (Runtime.getRuntime().maxMemory()/6));
}
public PhotoToLoad displayImage(String url, ImageView imageView, boolean roundCorners, boolean cropSquare) {
return displayImage(url, imageView, roundCorners, cropSquare, imageView.getHeight(), false);
public PhotoToLoad displayImage(String url, ImageView imageView, boolean cropSquare) {
return displayImage(url, imageView, cropSquare, imageView.getHeight(), false);
}
/**
@ -85,7 +85,7 @@ public class ImageLoader {
url = buildUrlIfNeeded(url);
// try from memory
Bitmap bitmap = memoryCache.get(url, false);
Bitmap bitmap = memoryCache.get(url);
if (bitmap != null) {
remoteViews.setImageViewBitmap(imageViewId, bitmap);
remoteViews.setViewVisibility(imageViewId, View.VISIBLE);
@ -93,14 +93,14 @@ public class ImageLoader {
}
// try from disk
bitmap = getImageFromDisk(url, maxDimPX, false, false);
bitmap = getImageFromDisk(url, maxDimPX, false);
if (bitmap == null) {
// try for network
bitmap = getImageFromNetwork(url, maxDimPX,false, false);
bitmap = getImageFromNetwork(url, maxDimPX, false);
}
if (bitmap != null) {
memoryCache.put(url, bitmap, false);
memoryCache.put(url, bitmap);
remoteViews.setImageViewBitmap(imageViewId, bitmap);
remoteViews.setViewVisibility(imageViewId, View.VISIBLE);
} else {
@ -108,7 +108,7 @@ public class ImageLoader {
}
}
public PhotoToLoad displayImage(String url, ImageView imageView, boolean roundCorners, boolean cropSquare, int maxDimPX, boolean allowDelay) {
public PhotoToLoad displayImage(String url, ImageView imageView, boolean cropSquare, int maxDimPX, boolean allowDelay) {
if (url == null) {
imageView.setImageResource(emptyRID);
return null;
@ -117,7 +117,7 @@ public class ImageLoader {
url = buildUrlIfNeeded(url);
imageViewMappings.put(imageView, url);
PhotoToLoad photoToLoad = new PhotoToLoad(url, imageView, roundCorners, cropSquare, maxDimPX, allowDelay);
PhotoToLoad photoToLoad = new PhotoToLoad(url, imageView, cropSquare, maxDimPX, allowDelay);
executorService.submit(new PhotosLoader(photoToLoad));
return photoToLoad;
@ -126,15 +126,13 @@ public class ImageLoader {
public static class PhotoToLoad {
public String url;
public ImageView imageView;
public boolean roundCorners;
public boolean cropSquare;
public int maxDimPX;
public boolean allowDelay;
public boolean cancel;
public PhotoToLoad(final String url, final ImageView imageView, boolean roundCorners, boolean cropSquare, int maxDimPX, boolean allowDelay) {
public PhotoToLoad(final String url, final ImageView imageView, boolean cropSquare, int maxDimPX, boolean allowDelay) {
PhotoToLoad.this.url = url;
PhotoToLoad.this.imageView = imageView;
PhotoToLoad.this.roundCorners = roundCorners;
PhotoToLoad.this.cropSquare = cropSquare;
PhotoToLoad.this.maxDimPX = maxDimPX;
PhotoToLoad.this.allowDelay = allowDelay;
@ -155,7 +153,7 @@ public class ImageLoader {
if (photoToLoad.cancel) return;
// try from memory
Bitmap bitmap = memoryCache.get(photoToLoad.url, photoToLoad.roundCorners);
Bitmap bitmap = memoryCache.get(photoToLoad.url);
if (bitmap != null) {
setViewImage(bitmap, photoToLoad);
@ -185,15 +183,15 @@ public class ImageLoader {
}
// try from disk
bitmap = getImageFromDisk(photoToLoad.url, photoToLoad.maxDimPX, photoToLoad.cropSquare, photoToLoad.roundCorners);
bitmap = getImageFromDisk(photoToLoad.url, photoToLoad.maxDimPX, photoToLoad.cropSquare);
if (bitmap == null) {
// try for network
if (photoToLoad.cancel) return;
bitmap = getImageFromNetwork(photoToLoad.url, photoToLoad.maxDimPX, photoToLoad.cropSquare, photoToLoad.roundCorners);
bitmap = getImageFromNetwork(photoToLoad.url, photoToLoad.maxDimPX, photoToLoad.cropSquare);
}
if (bitmap != null) {
memoryCache.put(photoToLoad.url, bitmap, photoToLoad.roundCorners);
memoryCache.put(photoToLoad.url, bitmap);
}
if (photoToLoad.cancel) return;
setViewImage(bitmap, photoToLoad);
@ -264,16 +262,16 @@ public class ImageLoader {
return url;
}
private Bitmap getImageFromDisk(String url, int maxDimPX, boolean cropSquare, boolean roundCorners) {
private Bitmap getImageFromDisk(String url, int maxDimPX, boolean cropSquare) {
// the only reliable way to check a cached file is to try decoding it. the util method will
// return null if it fails
File f = fileCache.getCachedFile(url);
return UIUtils.decodeImage(f, maxDimPX, cropSquare, roundCorners);
return UIUtils.decodeImage(f, maxDimPX, cropSquare);
}
private Bitmap getImageFromNetwork(String url, int maxDimPX, boolean cropSquare, boolean roundCorners) {
private Bitmap getImageFromNetwork(String url, int maxDimPX, boolean cropSquare) {
fileCache.cacheFile(url);
File f = fileCache.getCachedFile(url);
return UIUtils.decodeImage(f, maxDimPX, cropSquare, roundCorners);
return UIUtils.decodeImage(f, maxDimPX, cropSquare);
}
}

View file

@ -18,35 +18,29 @@ public class MemoryCache {
this.limit = limitBytes;
}
public Bitmap get(String url, boolean hasRoundCorners){
public Bitmap get(String url){
try {
String id = getPhotoCacheId(url, hasRoundCorners);
if (cache == null || !cache.containsKey(id)) {
if (cache == null || !cache.containsKey(url)) {
return null;
} else {
return cache.get(id);
return cache.get(url);
}
} catch (NullPointerException ex){
return null;
}
}
public void put(String url, Bitmap bitmap, boolean hasRoundCorners) {
public void put(String url, Bitmap bitmap) {
synchronized (this) {
String id = getPhotoCacheId(url, hasRoundCorners);
if (cache.containsKey(id)) {
size -= getSizeInBytes(cache.get(id));
if (cache.containsKey(url)) {
size -= getSizeInBytes(cache.get(url));
}
cache.put(id, bitmap);
cache.put(url, bitmap);
size += getSizeInBytes(bitmap);
checkSize();
}
}
public String getPhotoCacheId(String url, boolean hasRoundCorners) {
return hasRoundCorners ? url + "-rounded" : url;
}
private void checkSize() {
if (size > limit) {
final Iterator<Entry<String, Bitmap>> iter = cache.entrySet().iterator();

View file

@ -96,7 +96,7 @@ public class UIUtils {
}
@SuppressWarnings("deprecation")
public static Bitmap decodeImage(File f, int maxDim, boolean cropSquare, boolean roundCorners) {
public static Bitmap decodeImage(File f, int maxDim, boolean cropSquare) {
try {
// not only can cache misses occur, users can delete files, the system can clean up
// files, storage can be unmounted, etc. fail fast.
@ -141,23 +141,6 @@ public class UIUtils {
bitmap = Bitmap.createBitmap(bitmap, offsetX, offsetY, targetSize, targetSize);
}
// round the corners of the image if the caller would like
if (roundCorners) {
// rounded corners is applied at the bitmap decoding level
// bitmaps vary in size and to keep round corners consistent
// round corners are applied as a percentage based on bitmap size
int minBitmapSize = Math.min(bitmap.getWidth(), bitmap.getHeight());
float cornerRadiusPx = (minBitmapSize / 10f); // round corners at 10% of bitmap min size
Bitmap canvasMap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), ARGB_8888);
Canvas canvas = new Canvas(canvasMap);
BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setShader(shader);
canvas.drawRoundRect(0, 0, bitmap.getWidth(), bitmap.getHeight(), cornerRadiusPx, cornerRadiusPx, paint);
bitmap = canvasMap;
}
return bitmap;
} catch (Throwable t) {
// due to low memory, corrupt files, or bad source files, image processing can fail
@ -210,7 +193,7 @@ public class UIUtils {
*/
public static void setupToolbar(AppCompatActivity activity, String imageUrl, String title, boolean showHomeEnabled) {
ImageView iconView = setupCustomToolbar(activity, title, showHomeEnabled);
FeedUtils.iconLoader.displayImage(imageUrl, iconView, false, false);
FeedUtils.iconLoader.displayImage(imageUrl, iconView, false);
}
public static void setupToolbar(AppCompatActivity activity, int imageId, String title, boolean showHomeEnabled) {

View file

@ -9,13 +9,14 @@ import android.widget.ImageView;
import com.newsblur.activity.Profile;
import com.newsblur.view.FlowLayout;
import com.newsblur.view.RoundedImageView;
public class ViewUtils {
private ViewUtils() {} // util class - no instances
public static ImageView createSharebarImage(final Context context, final String photoUrl, final String userId) {
ImageView image = new ImageView(context);
RoundedImageView image = new RoundedImageView(context);
int imageLength = UIUtils.dp2px(context, 15);
image.setMaxHeight(imageLength);
image.setMaxWidth(imageLength);
@ -29,7 +30,7 @@ public class ViewUtils {
image.setMaxWidth(imageLength);
image.setLayoutParams(imageParameters);
FeedUtils.iconLoader.displayImage(photoUrl, image, true, false);
FeedUtils.iconLoader.displayImage(photoUrl, image, false);
image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {

View file

@ -7,7 +7,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.newsblur.R;
@ -44,7 +43,7 @@ public abstract class ActivityDetailsAdapter extends ArrayAdapter<ActivityDetail
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = null;
View view;
if (convertView == null) {
view = inflater.inflate(R.layout.row_activity, null);
} else {
@ -54,17 +53,17 @@ public abstract class ActivityDetailsAdapter extends ArrayAdapter<ActivityDetail
TextView activityText = (TextView) view.findViewById(R.id.row_activity_text);
TextView activityTime = (TextView) view.findViewById(R.id.row_activity_time);
ImageView imageView = (ImageView) view.findViewById(R.id.row_activity_icon);
RoundedImageView imageView = (RoundedImageView) view.findViewById(R.id.row_activity_icon);
activityTime.setText(activity.timeSince.toUpperCase() + " " + ago);
if (activity.category == Category.FEED_SUBSCRIPTION) {
FeedUtils.iconLoader.displayImage(APIConstants.S3_URL_FEED_ICONS + activity.feedId + ".png", imageView, true, false);
FeedUtils.iconLoader.displayImage(APIConstants.S3_URL_FEED_ICONS + activity.feedId + ".png", imageView, false);
} else if (activity.category == Category.SHARED_STORY) {
FeedUtils.iconLoader.displayImage(currentUserDetails.photoUrl, imageView, true, false);
FeedUtils.iconLoader.displayImage(currentUserDetails.photoUrl, imageView, false);
} else if (activity.category == Category.STAR) {
imageView.setImageResource(R.drawable.ic_clock);
} else if (activity.user != null) {
FeedUtils.iconLoader.displayImage(activity.user.photoUrl, imageView, true, false);
FeedUtils.iconLoader.displayImage(activity.user.photoUrl, imageView, false);
} else {
imageView.setImageResource(R.drawable.logo);
}

View file

@ -0,0 +1,26 @@
package com.newsblur.view
import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import com.newsblur.R
class RoundedImageView : AppCompatImageView {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init()
}
private fun init() {
setBackgroundResource(R.drawable.shape_rounded_corners)
clipToOutline = true
}
}

View file

@ -33,7 +33,7 @@ class StoryThumbnailView : FrameLayout {
fun setThumbnailStyle(thumbnailStyle: ThumbnailStyle) {
if (thumbnailStyle == ThumbnailStyle.LEFT_SMALL || thumbnailStyle == ThumbnailStyle.RIGHT_SMALL) {
setBackgroundResource(R.drawable.shape_story_thumbnail_small)
setBackgroundResource(R.drawable.shape_rounded_corners)
} else {
setBackgroundResource(0)
}