Skip to content

Commit

Permalink
#133 Show activity cover image in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelsvensson committed Apr 3, 2016
1 parent e713730 commit e7dea2c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
40 changes: 34 additions & 6 deletions app/src/main/java/se/devscout/android/view/ActivitiesListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,31 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import se.devscout.android.R;
import se.devscout.android.controller.activity.ActivitiesActivity;
import se.devscout.android.controller.activity.SingleFragmentActivity;
import se.devscout.android.controller.fragment.RangeComparator;
import se.devscout.android.model.*;
import se.devscout.android.model.Activity;
import se.devscout.android.model.ObjectIdentifierBean;
import se.devscout.android.model.Range;
import se.devscout.android.model.SearchHistoryDataBean;
import se.devscout.android.model.SearchHistoryPropertiesBean;
import se.devscout.android.model.activityfilter.ActivityFilter;
import se.devscout.android.model.repo.ActivityBank;
import se.devscout.android.util.ActivityBankFactory;
import se.devscout.android.util.auth.CredentialsManager;
import se.devscout.android.util.http.UnauthorizedException;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ActivitiesListView extends NonBlockingSearchView<ActivitiesListItem> {
private Sorter mSortOrder;
private ActivityFilter mFilter;
Expand Down Expand Up @@ -173,6 +182,25 @@ public View getView(int position, View convertView, ViewGroup parent) {

initPeople(convertView, activity);

AsyncImageView imageView = (AsyncImageView) convertView.findViewById(R.id.activitiesListItemImage);
final int width = getContext().getResources().getDimensionPixelSize(R.dimen.uiBlockSize);
URI imageURI = activity.getCoverMedia() != null ? ActivityBankFactory.getInstance(getContext()).getMediaItemURI(activity.getCoverMedia(), width, width) : null;
if (imageURI != null) {
URI[] uris = {imageURI};
// int limitSmall = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getContext()).getString("server_download_limit_small", "10")) * 1000;
imageView.setImage(new AsyncImageBean(null, uris), ((SingleFragmentActivity) getContext()).getBackgroundTasksHandlerThread());
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(imageView.getLayoutParams());
params.width = width;
imageView.setLayoutParams(params);
} else {
final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(imageView.getLayoutParams());
params.width = 0;
imageView.setLayoutParams(params);
}
imageView.setVisibility(imageURI != null ? View.VISIBLE : View.INVISIBLE);

return convertView;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void apply(SpannableStringBuilder sb, int sequencePos, Context context, Matcher
if (sequencePos == 0) {
addEmptyLine(sb, 0.5f);
}
if (textMatcher.groupCount() >= 3) {
if (textMatcher.groupCount() >= 3 && textMatcher.group(3) != null) {
String text = textMatcher.group(3).trim();
int number = Integer.parseInt(textMatcher.group(2));
if (text != null) {
Expand Down
15 changes: 12 additions & 3 deletions app/src/main/res/layout/activities_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:devscout="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:paddingLeft="@dimen/sideMargin"
android:paddingRight="@dimen/sideMargin"
android:layout_height="@dimen/uiBlockSize">

Expand All @@ -15,12 +14,13 @@
android:textStyle="bold"
android:textSize="@dimen/mediumTextSize"
android:ellipsize="end"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:singleLine="true"
android:gravity="center_vertical"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="@+id/linearLayout" />
android:layout_toLeftOf="@+id/linearLayout"
android:layout_toRightOf="@+id/activitiesListItemImage"
android:layout_marginLeft="@dimen/sideMargin" />

<LinearLayout
android:orientation="vertical"
Expand Down Expand Up @@ -62,4 +62,13 @@
android:layout_alignParentTop="true" />
</LinearLayout>

<se.devscout.android.view.AsyncThumbnailImageView
android:layout_width="@dimen/uiBlockSize"
android:layout_height="match_parent"
android:id="@+id/activitiesListItemImage"
android:src="@drawable/launcher"
android:baselineAlignBottom="false"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true" />

</RelativeLayout>

0 comments on commit e7dea2c

Please sign in to comment.