From 2304670d3aa5d94d95eb8c8df32827b1e60d8489 Mon Sep 17 00:00:00 2001 From: malinajirka Date: Fri, 22 Jun 2018 13:20:36 +0200 Subject: [PATCH 1/3] Replace Volley with Glide in EditPostSettingsFragment --- .../ui/posts/EditPostSettingsFragment.java | 76 ++++++++++--------- .../layout/edit_post_settings_fragment.xml | 5 +- WordPress/src/main/res/values/strings.xml | 1 + 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostSettingsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostSettingsFragment.java index 3f07136db09a..5dcc80589f31 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostSettingsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostSettingsFragment.java @@ -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; @@ -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; @@ -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; @@ -54,6 +56,7 @@ import org.wordpress.android.fluxc.store.TaxonomyStore; import org.wordpress.android.fluxc.store.TaxonomyStore.OnTaxonomyChanged; import org.wordpress.android.ui.ActivityLauncher; +import org.wordpress.android.ui.ImageManager; import org.wordpress.android.ui.RequestCodes; import org.wordpress.android.ui.media.MediaBrowserType; import org.wordpress.android.ui.posts.PostDatePickerDialogFragment.PickerDialogType; @@ -69,8 +72,6 @@ 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 java.lang.reflect.Field; import java.lang.reflect.Method; @@ -112,7 +113,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; @@ -124,6 +125,7 @@ public class EditPostSettingsFragment extends Fragment { @Inject MediaStore mMediaStore; @Inject TaxonomyStore mTaxonomyStore; @Inject Dispatcher mDispatcher; + @Inject ImageManager mImageManager; interface EditPostActivityHook { @@ -210,26 +212,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); @@ -249,7 +252,7 @@ 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) { @@ -257,7 +260,7 @@ public void onClick(View view) { } }); - 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) { @@ -265,7 +268,7 @@ public void onClick(View view) { } }); - 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) { @@ -273,7 +276,7 @@ public void onClick(View 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) { @@ -281,7 +284,7 @@ public void onClick(View view) { } }); - 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) { @@ -289,7 +292,7 @@ public void onClick(View view) { } }); - 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) { @@ -297,7 +300,7 @@ public void onClick(View view) { } }); - 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) { @@ -305,7 +308,7 @@ public void onClick(View view) { } }); - 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) { @@ -313,7 +316,7 @@ public void onClick(View view) { } }); - 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) { @@ -511,7 +514,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); @@ -533,7 +536,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); @@ -564,7 +567,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); } @@ -576,7 +579,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); } @@ -762,8 +765,11 @@ private int getCurrentPostStatusIndex() { return 2; case PRIVATE: return 3; + case TRASHED: + case UNKNOWN: + case PUBLISHED: + case SCHEDULED: default: - // PUBLISHED, SCHEDULED, UNKNOWN return 0; } } @@ -856,7 +862,7 @@ private void updateFeaturedImageView() { mediaUri = PhotonUtils.getPhotonImageUrl(mediaUri, size, 0); } - WPMediaUtils.loadNetworkImage(mediaUri, mFeaturedImageView); + mImageManager.load(mFeaturedImageView, mediaUri, null, ScaleType.FIT_CENTER); } private void launchFeaturedMediaPicker() { @@ -899,10 +905,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(); } } diff --git a/WordPress/src/main/res/layout/edit_post_settings_fragment.xml b/WordPress/src/main/res/layout/edit_post_settings_fragment.xml index 87b1347cb697..290665eac04b 100644 --- a/WordPress/src/main/res/layout/edit_post_settings_fragment.xml +++ b/WordPress/src/main/res/layout/edit_post_settings_fragment.xml @@ -140,13 +140,14 @@ android:layout_height="wrap_content" android:text="@string/post_settings_set_featured_image"/> - diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 9099fb0a64cb..e4ac04ef9b1a 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -2118,6 +2118,7 @@ plugin banner plugin logo featured image + featured image play featured video Play video delete From d24c947c4e66aac119b751673a7bde10e292b249 Mon Sep 17 00:00:00 2001 From: malinajirka Date: Fri, 29 Jun 2018 17:25:54 +0200 Subject: [PATCH 2/3] Add fallthrough comment to switch --- .../wordpress/android/ui/posts/EditPostSettingsFragment.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostSettingsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostSettingsFragment.java index 5dcc80589f31..a4f6d47e6740 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostSettingsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostSettingsFragment.java @@ -766,9 +766,13 @@ private int getCurrentPostStatusIndex() { case PRIVATE: return 3; case TRASHED: + // fallthrough case UNKNOWN: + // fallthrough case PUBLISHED: + // fallthrough case SCHEDULED: + // fallthrough default: return 0; } From f85c01623a820622fd2d5d20166bd59df64eb3a5 Mon Sep 17 00:00:00 2001 From: malinajirka Date: Mon, 2 Jul 2018 10:19:34 +0200 Subject: [PATCH 3/3] Fix post feature image preview quality --- .../wordpress/android/ui/posts/EditPostSettingsFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostSettingsFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostSettingsFragment.java index a4f6d47e6740..f4d937ebeb1d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostSettingsFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/EditPostSettingsFragment.java @@ -861,7 +861,7 @@ private void updateFeaturedImageView() { int height = DisplayUtils.getDisplayPixelHeight(getActivity()); int size = Math.max(width, height); - String mediaUri = media.getThumbnailUrl(); + String mediaUri = media.getUrl(); if (SiteUtils.isPhotonCapable(siteModel)) { mediaUri = PhotonUtils.getPhotonImageUrl(mediaUri, size, 0); }