Skip to content

Commit

Permalink
Merge pull request #8065 from wordpress-mobile/feature/glide-my-site
Browse files Browse the repository at this point in the history
Feature/glide my site
  • Loading branch information
0nko authored Jul 20, 2018
2 parents 82b4122 + 248dce6 commit 5fd458f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.ToastUtils.Duration;
import org.wordpress.android.util.WPMediaUtils;
import org.wordpress.android.widgets.WPNetworkImageView;
import org.wordpress.android.widgets.WPNetworkImageView.ImageType;
import org.wordpress.android.util.image.ImageManager;
import org.wordpress.android.util.image.ImageType;
import org.wordpress.android.widgets.WPTextView;

import java.io.File;
Expand All @@ -91,7 +91,7 @@ public class MySiteFragment extends Fragment implements SiteSettingsListener,
public static final String TAG_CHANGE_SITE_ICON_DIALOG = "TAG_CHANGE_SITE_ICON_DIALOG";
public static final String TAG_EDIT_SITE_ICON_PERMISSIONS_DIALOG = "TAG_EDIT_SITE_ICON_PERMISSIONS_DIALOG";

private WPNetworkImageView mBlavatarImageView;
private ImageView mBlavatarImageView;
private ProgressBar mBlavatarProgressBar;
private WPTextView mBlogTitleTextView;
private WPTextView mBlogSubtitleTextView;
Expand Down Expand Up @@ -122,6 +122,7 @@ public class MySiteFragment extends Fragment implements SiteSettingsListener,
@Inject PostStore mPostStore;
@Inject Dispatcher mDispatcher;
@Inject MediaStore mMediaStore;
@Inject ImageManager mImageManager;

public static MySiteFragment newInstance() {
return new MySiteFragment();
Expand Down Expand Up @@ -591,8 +592,7 @@ private void refreshSelectedSiteDetails(SiteModel site) {
int settingsVisibility = (isAdminOrSelfHosted || site.getHasCapabilityListUsers()) ? View.VISIBLE : View.GONE;
mConfigurationHeader.setVisibility(settingsVisibility);

mBlavatarImageView.setImageUrl(SiteUtils.getSiteIconUrl(site, mBlavatarSz), WPNetworkImageView
.ImageType.BLAVATAR);
mImageManager.load(mBlavatarImageView, ImageType.BLAVATAR, SiteUtils.getSiteIconUrl(site, mBlavatarSz));
String homeUrl = SiteUtils.getHomeURLOrHostName(site);
String blogTitle = SiteUtils.getSiteNameOrHomeURL(site);

Expand Down Expand Up @@ -715,8 +715,8 @@ public void onEventMainThread(UploadService.UploadMediaSuccessEvent event) {
if (isMediaUploadInProgress()) {
if (event.mediaModelList.size() > 0) {
MediaModel media = event.mediaModelList.get(0);
mBlavatarImageView.setImageUrl(PhotonUtils.getPhotonImageUrl(
media.getUrl(), mBlavatarSz, mBlavatarSz, PhotonUtils.Quality.HIGH), ImageType.BLAVATAR);
mImageManager.load(mBlavatarImageView, ImageType.BLAVATAR, PhotonUtils
.getPhotonImageUrl(media.getUrl(), mBlavatarSz, mBlavatarSz, PhotonUtils.Quality.HIGH));
mSiteSettings.setSiteIconMediaId((int) media.getMediaId());
mSiteSettings.saveSettings();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import org.apache.commons.text.StringEscapeUtils;
Expand All @@ -33,7 +36,8 @@
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.GravatarUtils;
import org.wordpress.android.util.NetworkUtils;
import org.wordpress.android.widgets.WPNetworkImageView;
import org.wordpress.android.util.image.ImageManager;
import org.wordpress.android.util.image.ImageType;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand All @@ -51,6 +55,7 @@ public class PeopleListFragment extends Fragment {
private PeopleListFilter mPeopleListFilter;

@Inject SiteStore mSiteStore;
@Inject ImageManager mImageManager;

public static PeopleListFragment newInstance(SiteModel site) {
PeopleListFragment peopleListFragment = new PeopleListFragment();
Expand Down Expand Up @@ -96,7 +101,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mSite = (SiteModel) getArguments().getSerializable(WordPress.SITE);
final boolean isPrivate = mSite != null && mSite.isPrivate();

mFilteredRecyclerView = (FilteredRecyclerView) rootView.findViewById(R.id.filtered_recycler_view);
mFilteredRecyclerView = rootView.findViewById(R.id.filtered_recycler_view);
mFilteredRecyclerView
.addItemDecoration(new PeopleItemDecoration(getActivity(), R.drawable.people_list_divider));
mFilteredRecyclerView.setLogT(AppLog.T.PEOPLE);
Expand Down Expand Up @@ -385,7 +390,7 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

if (person != null) {
String avatarUrl = GravatarUtils.fixGravatarUrl(person.getAvatarUrl(), mAvatarSz);
peopleViewHolder.mImgAvatar.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
mImageManager.loadIntoCircle(peopleViewHolder.mImgAvatar, ImageType.AVATAR, avatarUrl);
peopleViewHolder.mTxtDisplayName.setText(StringEscapeUtils.unescapeHtml4(person.getDisplayName()));
if (person.getRole() != null) {
peopleViewHolder.mTxtRole.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -416,20 +421,26 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
}
}

@Override public void onViewRecycled(@NonNull ViewHolder holder) {
super.onViewRecycled(holder);
PeopleViewHolder peopleViewHolder = (PeopleViewHolder) holder;
mImageManager.cancelRequestAndClearImageView(peopleViewHolder.mImgAvatar);
}

public class PeopleViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private final WPNetworkImageView mImgAvatar;
private final ImageView mImgAvatar;
private final TextView mTxtDisplayName;
private final TextView mTxtUsername;
private final TextView mTxtRole;
private final TextView mTxtSubscribed;

public PeopleViewHolder(View view) {
super(view);
mImgAvatar = (WPNetworkImageView) view.findViewById(R.id.person_avatar);
mTxtDisplayName = (TextView) view.findViewById(R.id.person_display_name);
mTxtUsername = (TextView) view.findViewById(R.id.person_username);
mTxtRole = (TextView) view.findViewById(R.id.person_role);
mTxtSubscribed = (TextView) view.findViewById(R.id.follower_subscribed_date);
mImgAvatar = view.findViewById(R.id.person_avatar);
mTxtDisplayName = view.findViewById(R.id.person_display_name);
mTxtUsername = view.findViewById(R.id.person_username);
mTxtRole = view.findViewById(R.id.person_role);
mTxtSubscribed = view.findViewById(R.id.follower_subscribed_date);

itemView.setOnClickListener(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

Expand All @@ -22,7 +23,8 @@
import org.wordpress.android.models.RoleUtils;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.GravatarUtils;
import org.wordpress.android.widgets.WPNetworkImageView;
import org.wordpress.android.util.image.ImageManager;
import org.wordpress.android.util.image.ImageType;

import java.text.SimpleDateFormat;
import java.util.List;
Expand All @@ -42,7 +44,7 @@ public class PersonDetailFragment extends Fragment {

private List<RoleModel> mUserRoles;

private WPNetworkImageView mAvatarImageView;
private ImageView mAvatarImageView;
private TextView mDisplayNameTextView;
private TextView mUsernameTextView;
private LinearLayout mRoleContainer;
Expand All @@ -52,6 +54,7 @@ public class PersonDetailFragment extends Fragment {
private TextView mSubscribedDateTextView;

@Inject SiteStore mSiteStore;
@Inject ImageManager mImageManager;

public static PersonDetailFragment newInstance(long currentUserId, long personId, int localTableBlogId,
Person.PersonType personType) {
Expand Down Expand Up @@ -105,14 +108,14 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.person_detail_fragment, container, false);

mAvatarImageView = (WPNetworkImageView) rootView.findViewById(R.id.person_avatar);
mDisplayNameTextView = (TextView) rootView.findViewById(R.id.person_display_name);
mUsernameTextView = (TextView) rootView.findViewById(R.id.person_username);
mRoleContainer = (LinearLayout) rootView.findViewById(R.id.person_role_container);
mRoleTextView = (TextView) rootView.findViewById(R.id.person_role);
mSubscribedDateContainer = (LinearLayout) rootView.findViewById(R.id.subscribed_date_container);
mSubscribedDateTitleView = (TextView) rootView.findViewById(R.id.subscribed_date_title);
mSubscribedDateTextView = (TextView) rootView.findViewById(R.id.subscribed_date_text);
mAvatarImageView = rootView.findViewById(R.id.person_avatar);
mDisplayNameTextView = rootView.findViewById(R.id.person_display_name);
mUsernameTextView = rootView.findViewById(R.id.person_username);
mRoleContainer = rootView.findViewById(R.id.person_role_container);
mRoleTextView = rootView.findViewById(R.id.person_role);
mSubscribedDateContainer = rootView.findViewById(R.id.subscribed_date_container);
mSubscribedDateTitleView = rootView.findViewById(R.id.subscribed_date_title);
mSubscribedDateTextView = rootView.findViewById(R.id.subscribed_date_text);

boolean isCurrentUser = mCurrentUserId == mPersonId;
SiteModel site = mSiteStore.getSiteByLocalId(mLocalTableBlogId);
Expand Down Expand Up @@ -140,7 +143,7 @@ public void refreshPersonDetails() {
int avatarSz = getResources().getDimensionPixelSize(R.dimen.people_avatar_sz);
String avatarUrl = GravatarUtils.fixGravatarUrl(person.getAvatarUrl(), avatarSz);

mAvatarImageView.setImageUrl(avatarUrl, WPNetworkImageView.ImageType.AVATAR);
mImageManager.loadIntoCircle(mAvatarImageView, ImageType.AVATAR, avatarUrl);
mDisplayNameTextView.setText(StringEscapeUtils.unescapeHtml4(person.getDisplayName()));
if (person.getRole() != null) {
mRoleTextView.setText(RoleUtils.getDisplayName(person.getRole(), mUserRoles));
Expand Down
2 changes: 1 addition & 1 deletion WordPress/src/main/res/layout/my_site_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
android:visibility="gone"
android:gravity="center_vertical" />

<org.wordpress.android.widgets.WPNetworkImageView
<ImageView
android:id="@+id/my_site_blavatar"
android:layout_width="@dimen/blavatar_sz"
android:layout_height="@dimen/blavatar_sz"
Expand Down
5 changes: 3 additions & 2 deletions WordPress/src/main/res/layout/people_list_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
android:background="?android:selectableItemBackground"
android:minHeight="@dimen/people_list_row_height">

<org.wordpress.android.widgets.WPNetworkImageView
<ImageView
android:id="@+id/person_avatar"
style="@style/PersonAvatar"
android:layout_centerVertical="true"/>
android:layout_centerVertical="true"
android:contentDescription="@null"/>

<RelativeLayout
android:layout_width="match_parent"
Expand Down
5 changes: 3 additions & 2 deletions WordPress/src/main/res/layout/person_detail_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
android:paddingBottom="@dimen/margin_medium"
tools:targetApi="LOLLIPOP">

<org.wordpress.android.widgets.WPNetworkImageView
<ImageView
android:id="@+id/person_avatar"
style="@style/PersonAvatar"
android:layout_centerVertical="true"/>
android:layout_centerVertical="true"
android:contentDescription="@null"/>

<LinearLayout
android:layout_width="match_parent"
Expand Down

0 comments on commit 5fd458f

Please sign in to comment.