From 03e3d0599b98ba6305eccbd814c1c48c35441856 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Tue, 2 Apr 2019 15:05:06 +0530 Subject: [PATCH] BugFix #2720 (#2831) BugFix deprecated licenes #2720 --- .../main/java/fr/free/nrw/commons/Utils.java | 8 ++---- .../commons/contributions/Contribution.java | 4 --- .../fr/free/nrw/commons/settings/Prefs.java | 4 --- .../nrw/commons/upload/UploadPresenter.java | 26 ++++++++++++------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/Utils.java b/app/src/main/java/fr/free/nrw/commons/Utils.java index 168371735..3af2c38cf 100644 --- a/app/src/main/java/fr/free/nrw/commons/Utils.java +++ b/app/src/main/java/fr/free/nrw/commons/Utils.java @@ -103,12 +103,8 @@ public class Utils { return R.string.license_name_cc_by_sa_four; case Prefs.Licenses.CC0: return R.string.license_name_cc0; - case Prefs.Licenses.CC_BY: // for backward compatibility to v2.1 - return R.string.license_name_cc_by_3_0; - case Prefs.Licenses.CC_BY_SA: // for backward compatibility to v2.1 - return R.string.license_name_cc_by_sa_3_0; } - throw new RuntimeException("Unrecognized license value: " + license); + throw new IllegalStateException("Unrecognized license value: " + license); } /** @@ -132,7 +128,7 @@ public class Utils { case Prefs.Licenses.CC0: return "https://creativecommons.org/publicdomain/zero/1.0/"; default: - throw new RuntimeException("Unrecognized license value: " + license); + throw new IllegalStateException("Unrecognized license value: " + license); } } diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/Contribution.java b/app/src/main/java/fr/free/nrw/commons/contributions/Contribution.java index 22ae03b59..2354a7131 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/Contribution.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/Contribution.java @@ -258,10 +258,6 @@ public class Contribution extends Media { return "{{self|cc-by-sa-4.0}}"; case Prefs.Licenses.CC0: return "{{self|cc-zero}}"; - case Prefs.Licenses.CC_BY: - return "{{self|cc-by-3.0}}"; - case Prefs.Licenses.CC_BY_SA: - return "{{self|cc-by-sa-3.0}}"; } throw new RuntimeException("Unrecognized license value: " + license); diff --git a/app/src/main/java/fr/free/nrw/commons/settings/Prefs.java b/app/src/main/java/fr/free/nrw/commons/settings/Prefs.java index 722733393..d059c862e 100644 --- a/app/src/main/java/fr/free/nrw/commons/settings/Prefs.java +++ b/app/src/main/java/fr/free/nrw/commons/settings/Prefs.java @@ -14,9 +14,5 @@ public class Prefs { public static final String CC_BY_SA_4 = "CC BY-SA 4.0"; public static final String CC_BY_4 = "CC BY 4.0"; public static final String CC0 = "CC0"; - - // kept for backward compatibility to v2.1 - @Deprecated public static final String CC_BY = "CC BY"; - @Deprecated public static final String CC_BY_SA = "CC BY-SA"; } } diff --git a/app/src/main/java/fr/free/nrw/commons/upload/UploadPresenter.java b/app/src/main/java/fr/free/nrw/commons/upload/UploadPresenter.java index 05d13ed9d..c4e468007 100644 --- a/app/src/main/java/fr/free/nrw/commons/upload/UploadPresenter.java +++ b/app/src/main/java/fr/free/nrw/commons/upload/UploadPresenter.java @@ -2,16 +2,8 @@ package fr.free.nrw.commons.upload; import android.annotation.SuppressLint; import android.content.Context; - -import java.lang.reflect.Proxy; -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - import fr.free.nrw.commons.R; +import fr.free.nrw.commons.Utils; import fr.free.nrw.commons.category.CategoriesModel; import fr.free.nrw.commons.contributions.Contribution; import fr.free.nrw.commons.filepicker.UploadableFile; @@ -23,6 +15,12 @@ import fr.free.nrw.commons.utils.StringUtils; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.List; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; import timber.log.Timber; import static fr.free.nrw.commons.upload.UploadModel.UploadItem; @@ -330,7 +328,15 @@ public class UploadPresenter { * Sets the list of licences and the default license. */ private void updateLicenses() { - String selectedLicense = defaultKvStore.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3); + String selectedLicense = defaultKvStore.getString(Prefs.DEFAULT_LICENSE, + Prefs.Licenses.CC_BY_SA_4);//CC_BY_SA_4 is the default one used by the commons web app + try {//I have to make sure that the stored default license was not one of the deprecated one's + Utils.licenseNameFor(selectedLicense); + } catch (IllegalStateException exception) { + Timber.e(exception.getMessage()); + selectedLicense = Prefs.Licenses.CC_BY_SA_4; + defaultKvStore.putString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_4); + } view.updateLicenses(uploadModel.getLicenses(), selectedLicense); view.updateLicenseSummary(selectedLicense, uploadModel.getCount()); }