Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Volley with Glide in the EditPostSettings fragment #7985

Merged
merged 12 commits into from
Jul 10, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.view.menu.MenuPopupHelper;
import android.support.v7.widget.CardView;
import android.support.v7.widget.PopupMenu;
Expand All @@ -21,6 +20,8 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;

Expand All @@ -39,6 +40,7 @@
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.fluxc.Dispatcher;
import org.wordpress.android.fluxc.action.TaxonomyAction;
import org.wordpress.android.fluxc.generated.SiteActionBuilder;
import org.wordpress.android.fluxc.generated.TaxonomyActionBuilder;
import org.wordpress.android.fluxc.model.MediaModel;
Expand Down Expand Up @@ -69,8 +71,8 @@
import org.wordpress.android.util.PhotonUtils;
import org.wordpress.android.util.SiteUtils;
import org.wordpress.android.util.ToastUtils;
import org.wordpress.android.util.WPMediaUtils;
import org.wordpress.android.widgets.WPNetworkImageView;
import org.wordpress.android.util.image.ImageManager;
import org.wordpress.android.util.image.ImageType;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -112,7 +114,7 @@ public class EditPostSettingsFragment extends Fragment {
private TextView mPostFormatTextView;
private TextView mPasswordTextView;
private TextView mPublishDateTextView;
private WPNetworkImageView mFeaturedImageView;
private ImageView mFeaturedImageView;
private Button mFeaturedImageButton;

private PostLocation mPostLocation;
Expand All @@ -124,6 +126,7 @@ public class EditPostSettingsFragment extends Fragment {
@Inject MediaStore mMediaStore;
@Inject TaxonomyStore mTaxonomyStore;
@Inject Dispatcher mDispatcher;
@Inject ImageManager mImageManager;


interface EditPostActivityHook {
Expand Down Expand Up @@ -210,26 +213,27 @@ public void onDestroy() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.edit_post_settings_fragment, container, false);

if (rootView == null) {
return null;
}

mExcerptTextView = (TextView) rootView.findViewById(R.id.post_excerpt);
mSlugTextView = (TextView) rootView.findViewById(R.id.post_slug);
mLocationTextView = (TextView) rootView.findViewById(R.id.post_location);
mCategoriesTextView = (TextView) rootView.findViewById(R.id.post_categories);
mTagsTextView = (TextView) rootView.findViewById(R.id.post_tags);
mStatusTextView = (TextView) rootView.findViewById(R.id.post_status);
mPostFormatTextView = (TextView) rootView.findViewById(R.id.post_format);
mPasswordTextView = (TextView) rootView.findViewById(R.id.post_password);
mPublishDateTextView = (TextView) rootView.findViewById(R.id.publish_date);
mExcerptTextView = rootView.findViewById(R.id.post_excerpt);
mSlugTextView = rootView.findViewById(R.id.post_slug);
mLocationTextView = rootView.findViewById(R.id.post_location);
mCategoriesTextView = rootView.findViewById(R.id.post_categories);
mTagsTextView = rootView.findViewById(R.id.post_tags);
mStatusTextView = rootView.findViewById(R.id.post_status);
mPostFormatTextView = rootView.findViewById(R.id.post_format);
mPasswordTextView = rootView.findViewById(R.id.post_password);
mPublishDateTextView = rootView.findViewById(R.id.publish_date);

mFeaturedImageView = (WPNetworkImageView) rootView.findViewById(R.id.post_featured_image);
mFeaturedImageButton = (Button) rootView.findViewById(R.id.post_add_featured_image_button);
CardView featuredImageCardView = (CardView) rootView.findViewById(R.id.post_featured_image_card_view);
mFeaturedImageView = rootView.findViewById(R.id.post_featured_image);
mFeaturedImageButton = rootView.findViewById(R.id.post_add_featured_image_button);
CardView featuredImageCardView = rootView.findViewById(R.id.post_featured_image_card_view);

if (AppPrefs.isVisualEditorEnabled() || AppPrefs.isAztecEditorEnabled()) {
registerForContextMenu(mFeaturedImageView);
Expand All @@ -249,71 +253,71 @@ public void onClick(View view) {
featuredImageCardView.setVisibility(View.GONE);
}

mExcerptContainer = (LinearLayout) rootView.findViewById(R.id.post_excerpt_container);
mExcerptContainer = rootView.findViewById(R.id.post_excerpt_container);
mExcerptContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showPostExcerptDialog();
}
});

final LinearLayout slugContainer = (LinearLayout) rootView.findViewById(R.id.post_slug_container);
final LinearLayout slugContainer = rootView.findViewById(R.id.post_slug_container);
slugContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showSlugDialog();
}
});

final LinearLayout locationContainer = (LinearLayout) rootView.findViewById(R.id.post_location_container);
final LinearLayout locationContainer = rootView.findViewById(R.id.post_location_container);
locationContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showLocationPickerOrPopupMenu(view);
}
});

mCategoriesContainer = (LinearLayout) rootView.findViewById(R.id.post_categories_container);
mCategoriesContainer = rootView.findViewById(R.id.post_categories_container);
mCategoriesContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showCategoriesActivity();
}
});

mTagsContainer = (LinearLayout) rootView.findViewById(R.id.post_tags_container);
mTagsContainer = rootView.findViewById(R.id.post_tags_container);
mTagsContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showTagsActivity();
}
});

final LinearLayout statusContainer = (LinearLayout) rootView.findViewById(R.id.post_status_container);
final LinearLayout statusContainer = rootView.findViewById(R.id.post_status_container);
statusContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showStatusDialog();
}
});

mFormatContainer = (LinearLayout) rootView.findViewById(R.id.post_format_container);
mFormatContainer = rootView.findViewById(R.id.post_format_container);
mFormatContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showPostFormatDialog();
}
});

final LinearLayout passwordContainer = (LinearLayout) rootView.findViewById(R.id.post_password_container);
final LinearLayout passwordContainer = rootView.findViewById(R.id.post_password_container);
passwordContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showPostPasswordDialog();
}
});

final LinearLayout publishDateContainer = (LinearLayout) rootView.findViewById(R.id.publish_date_container);
final LinearLayout publishDateContainer = rootView.findViewById(R.id.publish_date_container);
publishDateContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down Expand Up @@ -511,7 +515,7 @@ private void showStatusDialog() {
}

int index = getCurrentPostStatusIndex();
FragmentManager fm = ((AppCompatActivity) getActivity()).getSupportFragmentManager();
FragmentManager fm = getActivity().getSupportFragmentManager();
PostSettingsListDialogFragment fragment =
PostSettingsListDialogFragment.newInstance(DialogType.POST_STATUS, index);
fragment.show(fm, PostSettingsListDialogFragment.TAG);
Expand All @@ -533,7 +537,7 @@ private void showPostFormatDialog() {
}
}

FragmentManager fm = ((AppCompatActivity) getActivity()).getSupportFragmentManager();
FragmentManager fm = getActivity().getSupportFragmentManager();
PostSettingsListDialogFragment fragment =
PostSettingsListDialogFragment.newInstance(DialogType.POST_FORMAT, checkedIndex);
fragment.show(fm, PostSettingsListDialogFragment.TAG);
Expand Down Expand Up @@ -564,7 +568,7 @@ private void showPostDateSelectionDialog() {
Calendar calendar = getCurrentPublishDateAsCalendar();
PostDatePickerDialogFragment fragment =
PostDatePickerDialogFragment.newInstance(PickerDialogType.DATE_PICKER, getPost(), calendar);
FragmentManager fm = ((AppCompatActivity) getActivity()).getSupportFragmentManager();
FragmentManager fm = getActivity().getSupportFragmentManager();
fragment.show(fm, PostDatePickerDialogFragment.TAG_DATE);
}

Expand All @@ -576,7 +580,7 @@ private void showPostTimeSelectionDialog() {
Calendar calendar = getCurrentPublishDateAsCalendar();
PostDatePickerDialogFragment fragment =
PostDatePickerDialogFragment.newInstance(PickerDialogType.TIME_PICKER, getPost(), calendar);
FragmentManager fm = ((AppCompatActivity) getActivity()).getSupportFragmentManager();
FragmentManager fm = getActivity().getSupportFragmentManager();
fragment.show(fm, PostDatePickerDialogFragment.TAG_TIME);
}

Expand Down Expand Up @@ -762,10 +766,13 @@ private int getCurrentPostStatusIndex() {
return 2;
case PRIVATE:
return 3;
default:
// PUBLISHED, SCHEDULED, UNKNOWN
case TRASHED:
case UNKNOWN:
case PUBLISHED:
case SCHEDULED:
return 0;
}
return 0;
}

// Post Format Helpers
Expand Down Expand Up @@ -856,7 +863,7 @@ private void updateFeaturedImageView() {
mediaUri = PhotonUtils.getPhotonImageUrl(mediaUri, size, 0);
}

WPMediaUtils.loadNetworkImage(mediaUri, mFeaturedImageView);
mImageManager.load(mFeaturedImageView, ImageType.PHOTO, mediaUri, ScaleType.FIT_CENTER);
}

private void launchFeaturedMediaPicker() {
Expand Down Expand Up @@ -899,10 +906,8 @@ public void onTaxonomyChanged(OnTaxonomyChanged event) {
AppLog.e(T.POSTS, "An error occurred while updating taxonomy with type: " + event.error.type);
return;
}
switch (event.causeOfChange) {
case FETCH_CATEGORIES:
updateCategoriesTextView();
break;
if (event.causeOfChange == TaxonomyAction.FETCH_CATEGORIES) {
updateCategoriesTextView();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import android.view.ContextThemeWrapper;
import android.view.ViewConfiguration;

import com.android.volley.toolbox.NetworkImageView;

import org.wordpress.android.R;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.fluxc.model.MediaModel;
Expand All @@ -28,7 +26,6 @@
import org.wordpress.android.ui.RequestCodes;
import org.wordpress.android.ui.prefs.AppPrefs;
import org.wordpress.android.util.AppLog.T;
import org.wordpress.android.widgets.WPNetworkImageView;
import org.wordpress.passcodelock.AppLockManager;

import java.io.File;
Expand Down Expand Up @@ -206,7 +203,6 @@ String getErrorMessage(final Context context, final MediaModel media, final Medi
case GENERIC_ERROR:
return context.getString(R.string.error_generic_error);
}

return null;
}

Expand Down Expand Up @@ -378,32 +374,6 @@ public static boolean canDeleteMedia(MediaModel mediaModel) {
return state == null || (!state.equalsIgnoreCase("uploading") && !state.equalsIgnoreCase("deleted"));
}

/**
* Loads the given network image URL into the {@link NetworkImageView}.
*/
public static void loadNetworkImage(String imageUrl, WPNetworkImageView imageView) {
if (imageUrl != null) {
Uri uri = Uri.parse(imageUrl);
String filepath = uri.getLastPathSegment();

// re-use the default background drawable as error image for now.
// See: https://github.com/wordpress-mobile/WordPress-Android/pull/6295#issuecomment-315129759
imageView.setErrorImageResId(R.drawable.media_item_background);

// default image while downloading
imageView.setDefaultImageResId(R.drawable.media_item_background);

if (MediaUtils.isValidImage(filepath)) {
imageView.setTag(imageUrl);
imageView.setImageUrl(imageUrl, WPNetworkImageView.ImageType.PHOTO);
} else {
imageView.setImageResource(R.drawable.media_item_background);
}
} else {
imageView.setImageResource(0);
}
}

/**
* Returns a poster (thumbnail) URL given a VideoPress video URL
*
Expand Down Expand Up @@ -441,12 +411,9 @@ public void onScanCompleted(String path, Uri uri) {
* returns true if the current user has permission to upload new media to the passed site
*/
public static boolean currentUserCanUploadMedia(@NonNull SiteModel site) {
if (site.isUsingWpComRestApi()) {
return site.getHasCapabilityUploadFiles();
} else {
// self-hosted sites don't have capabilities so always return true
return true;
}
boolean isSelfHosted = !site.isUsingWpComRestApi();
// self-hosted sites don't have capabilities so always return true
return isSelfHosted || site.getHasCapabilityUploadFiles();
}

public static boolean currentUserCanDeleteMedia(@NonNull SiteModel site) {
Expand Down
5 changes: 3 additions & 2 deletions WordPress/src/main/res/layout/edit_post_settings_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@
android:layout_height="wrap_content"
android:text="@string/post_settings_set_featured_image"/>

<org.wordpress.android.widgets.WPNetworkImageView
<ImageView
android:id="@+id/post_featured_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxHeight="@dimen/post_settings_featured_image_height_max"
android:minHeight="@dimen/post_settings_featured_image_height_min"
android:scaleType="fitStart"
android:contentDescription="@string/featured_image_desc"
android:adjustViewBounds="true"
android:visibility="gone"/>
</LinearLayout>

Expand Down
2 changes: 1 addition & 1 deletion WordPress/src/main/res/layout/post_cardview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
android:layout_height="@dimen/postlist_featured_image_height"
android:scaleType="centerCrop"
android:visibility="gone"
android:contentDescription="@string/post_cardview_featured_desc"
android:contentDescription="@string/featured_image_desc"
tools:visibility="visible" />

<org.wordpress.android.widgets.WPTextView
Expand Down
2 changes: 1 addition & 1 deletion WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2113,6 +2113,7 @@
<string name="change_photo">Change photo</string>

<!-- Content description for accessibility -->
<string name="featured_image_desc">featured image</string>
<string name="comment_checkmark_desc">check mark</string>
<string name="profile_picture">%s\'s profile picture</string>
<string name="invite_user_delete_desc">remove %s</string>
Expand All @@ -2131,7 +2132,6 @@
<string name="photo_picker_wpmedia_desc">pick from WordPress media</string>
<string name="plugin_detail_banner_desc">plugin banner</string>
<string name="plugin_detail_logo_desc">plugin logo</string>
<string name="post_cardview_featured_desc">featured image</string>
<string name="reader_cardview_post_play_video_desc">play featured video</string>
<string name="photo_picker_thumbnail_desc">Play video</string>
<string name="reader_list_item_suggestion_remove_desc">delete</string>
Expand Down