Skip to content

Commit

Permalink
Refactored speaker image url binding
Browse files Browse the repository at this point in the history
  • Loading branch information
konifar committed Feb 24, 2017
1 parent 17370e0 commit 7984c05
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static void setImageUrlWithSize(ImageView imageView, @Nullable String im
final int size = Math.round(sizeInDimen);
imageView.setBackground(ContextCompat.getDrawable(imageView.getContext(), R.drawable.circle_border_grey200));
Picasso.with(imageView.getContext())
.load(convertToFullImageUrl(imageUrl))
.load(imageUrl)
.resize(size, size)
.centerInside()
.placeholder(placeholderResId)
Expand All @@ -78,14 +78,6 @@ private static void setImageUrlWithSize(ImageView imageView, @Nullable String im
}
}

private static String convertToFullImageUrl(String imageUrl) {
if (imageUrl.startsWith("/")) {
return "https://droidkaigi.github.io/2017" + imageUrl;
}

return imageUrl;
}

@BindingAdapter("textLinkify")
public static void setTextLinkify(TextView textView, boolean isLinkify) {
if (isLinkify) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.databinding.BaseObservable;
import android.support.annotation.ColorRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.annotation.StyleRes;
import android.text.TextUtils;
Expand All @@ -16,6 +17,7 @@

import io.github.droidkaigi.confsched2017.R;
import io.github.droidkaigi.confsched2017.model.Session;
import io.github.droidkaigi.confsched2017.model.Speaker;
import io.github.droidkaigi.confsched2017.repository.sessions.MySessionsRepository;
import io.github.droidkaigi.confsched2017.repository.sessions.SessionsRepository;
import io.github.droidkaigi.confsched2017.util.AlarmUtil;
Expand All @@ -29,6 +31,8 @@ public class SessionDetailViewModel extends BaseObservable implements ViewModel

private static final String TAG = SessionDetailViewModel.class.getSimpleName();

private static final String SPEAKER_IMAGE_URL = "https://droidkaigi.github.io/2017";

private final Context context;

private final Navigator navigator;
Expand All @@ -39,6 +43,8 @@ public class SessionDetailViewModel extends BaseObservable implements ViewModel

private String sessionTitle;

private String speakerImageUrl;

@ColorRes
private int sessionVividColorResId = R.color.white;

Expand Down Expand Up @@ -79,6 +85,7 @@ public SessionDetailViewModel(Context context, Navigator navigator, SessionsRepo
private void setSession(@NonNull Session session) {
this.session = session;
this.sessionTitle = session.title;
this.speakerImageUrl = createSpeakerImageUrl(session.speaker);
TopicColor topicColor = TopicColor.from(session.topic);
this.sessionVividColorResId = topicColor.vividColorResId;
this.sessionPaleColorResId = topicColor.paleColorResId;
Expand Down Expand Up @@ -114,6 +121,21 @@ public void destroy() {
// Do nothing
}

@Nullable
private String createSpeakerImageUrl(@Nullable Speaker speaker) {
if (speaker == null) {
return null;
}

String imageUrl = speaker.imageUrl;

if (!TextUtils.isEmpty(imageUrl) && imageUrl.startsWith("/")) {
return SPEAKER_IMAGE_URL + imageUrl;
}
return imageUrl;
}


public boolean shouldShowShareMenuItem() {
return !TextUtils.isEmpty(session.shareUrl);
}
Expand Down Expand Up @@ -177,6 +199,10 @@ public String getSessionTitle() {
return sessionTitle;
}

public String getSpeakerImageUrl() {
return speakerImageUrl;
}

public int getSessionVividColorResId() {
return sessionVividColorResId;
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_session_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
android:layout_marginTop="@dimen/space_16dp"
android:contentDescription="@string/speaker"
app:speakerImageSize="@{@dimen/user_image_large}"
app:speakerImageUrl="@{viewModel.session.speaker.imageUrl}"
app:speakerImageUrl="@{viewModel.speakerImageUrl}"
/>

<TextView
Expand Down

0 comments on commit 7984c05

Please sign in to comment.