diff --git a/src/org/wordpress/android/ui/media/MediaEditFragment.java b/src/org/wordpress/android/ui/media/MediaEditFragment.java index e1c66b5e3788..cc3531a2d484 100644 --- a/src/org/wordpress/android/ui/media/MediaEditFragment.java +++ b/src/org/wordpress/android/ui/media/MediaEditFragment.java @@ -143,11 +143,24 @@ public void onClick(View v) { } }); + disableEditingOnOldVersion(); + restoreState(savedInstanceState); return mScrollView; } + private void disableEditingOnOldVersion() { + + if( MediaUtils.isWordPressVersionWithMediaEditingCapabilities() ) + return; + + mSaveButton.setEnabled(false); + mTitleView.setEnabled(false); + mCaptionView.setEnabled(false); + mDescriptionView.setEnabled(false); + } + private void restoreState(Bundle savedInstanceState) { if (savedInstanceState != null) { if (savedInstanceState.containsKey(BUNDLE_MEDIA_ID)) { @@ -325,6 +338,8 @@ private void refreshViews(Cursor cursor) { mNetworkImageView.setVisibility(View.GONE); mLocalImageView.setVisibility(View.GONE); } + + disableEditingOnOldVersion(); } @Override @@ -342,6 +357,9 @@ public void onPrepareOptionsMenu(Menu menu) { menu.findItem(R.id.menu_new_media).setVisible(false); menu.findItem(R.id.menu_search).setVisible(false); } + + if( ! MediaUtils.isWordPressVersionWithMediaEditingCapabilities() ) + menu.findItem(R.id.menu_save_media).setVisible(false); } @Override diff --git a/src/org/wordpress/android/ui/media/MediaItemFragment.java b/src/org/wordpress/android/ui/media/MediaItemFragment.java index 70fc5041702e..1616b719f3c0 100644 --- a/src/org/wordpress/android/ui/media/MediaItemFragment.java +++ b/src/org/wordpress/android/ui/media/MediaItemFragment.java @@ -307,7 +307,7 @@ public void onPrepareOptionsMenu(Menu menu) { menu.findItem(R.id.menu_new_media).setVisible(false); menu.findItem(R.id.menu_search).setVisible(false); - if (mIsLocal) + if (mIsLocal || ! MediaUtils.isWordPressVersionWithMediaEditingCapabilities() ) menu.findItem(R.id.menu_edit_media).setVisible(false); } diff --git a/src/org/wordpress/android/ui/media/MediaUtils.java b/src/org/wordpress/android/ui/media/MediaUtils.java index e99c405fdc90..ec0bed8b8856 100644 --- a/src/org/wordpress/android/ui/media/MediaUtils.java +++ b/src/org/wordpress/android/ui/media/MediaUtils.java @@ -21,6 +21,8 @@ import org.wordpress.passcodelock.AppLockManager; import org.wordpress.android.R; +import org.wordpress.android.WordPress; +import org.wordpress.android.util.Version; public class MediaUtils { @@ -235,4 +237,30 @@ public static Uri getLastRecordedVideoUri(Activity activity) { return uri; } + /** + * This is a workaround for WP3.4.2 that deletes the media from the server when editing media properties within the app. + * See: https://github.com/wordpress-mobile/WordPress-Android/issues/204 + * @return + */ + public static boolean isWordPressVersionWithMediaEditingCapabilities() { + + if( WordPress.currentBlog.isDotcomFlag()) + return true; + + Version minVersion; + Version currentVersion; + try { + minVersion = new Version("3.5.2"); + currentVersion = new Version(WordPress.currentBlog.getWpVersion()); + + if( currentVersion.compareTo(minVersion) == -1 ) + return false; + + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + + return true; + } + } diff --git a/src/org/wordpress/android/util/Version.java b/src/org/wordpress/android/util/Version.java new file mode 100644 index 000000000000..63c024b2f318 --- /dev/null +++ b/src/org/wordpress/android/util/Version.java @@ -0,0 +1,49 @@ +package org.wordpress.android.util; + +//See: http://stackoverflow.com/a/11024200 +public class Version implements Comparable { + + private String version; + + public final String get() { + return this.version; + } + + public Version(String version) { + if(version == null) + throw new IllegalArgumentException("Version can not be null"); + if(!version.matches("[0-9]+(\\.[0-9]+)*")) + throw new IllegalArgumentException("Invalid version format"); + this.version = version; + } + + @Override public int compareTo(Version that) { + if(that == null) + return 1; + String[] thisParts = this.get().split("\\."); + String[] thatParts = that.get().split("\\."); + int length = Math.max(thisParts.length, thatParts.length); + for(int i = 0; i < length; i++) { + int thisPart = i < thisParts.length ? + Integer.parseInt(thisParts[i]) : 0; + int thatPart = i < thatParts.length ? + Integer.parseInt(thatParts[i]) : 0; + if(thisPart < thatPart) + return -1; + if(thisPart > thatPart) + return 1; + } + return 0; + } + + @Override public boolean equals(Object that) { + if(this == that) + return true; + if(that == null) + return false; + if(this.getClass() != that.getClass()) + return false; + return this.compareTo((Version) that) == 0; + } + +} \ No newline at end of file