Brion VIBBER has submitted this change and it was merged.

Change subject: Allow users to select preferred license for their contributions
......................................................................


Allow users to select preferred license for their contributions

Needs some UI love on both selection & intimation, but works otherwise

People can pick from CC BY-SA, CC BY, or CC0. The commons templates
are set using {[self}}, which I think is good enough.

GitHub: https://github.com/wikimedia/apps-android-commons/pull/14
Change-Id: Iffca6f75c63de6fbe61c4dc41b93dd5f692065a5
---
M commons/res/layout/fragment_single_upload.xml
M commons/res/values-qq/strings.xml
M commons/res/values/strings.xml
M commons/res/xml/preferences.xml
M commons/src/main/java/org/wikimedia/commons/Media.java
M commons/src/main/java/org/wikimedia/commons/Prefs.java
M commons/src/main/java/org/wikimedia/commons/SettingsActivity.java
M commons/src/main/java/org/wikimedia/commons/SingleUploadFragment.java
M commons/src/main/java/org/wikimedia/commons/StartUploadTask.java
M commons/src/main/java/org/wikimedia/commons/Utils.java
M commons/src/main/java/org/wikimedia/commons/contributions/Contribution.java
11 files changed, 112 insertions(+), 10 deletions(-)

Approvals:
  Brion VIBBER: Verified; Looks good to me, approved



diff --git a/commons/res/layout/fragment_single_upload.xml 
b/commons/res/layout/fragment_single_upload.xml
index 30046ec..a11df61 100644
--- a/commons/res/layout/fragment_single_upload.xml
+++ b/commons/res/layout/fragment_single_upload.xml
@@ -36,5 +36,7 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/share_license_summary"
-            android:id="@+id/licenseLabel" android:layout_gravity="center" 
android:layout_marginTop="16dp"/>
+            android:id="@+id/share_license_summary"
+            android:layout_gravity="center"
+            android:layout_marginTop="16dp"/>
 </LinearLayout>
diff --git a/commons/res/values-qq/strings.xml 
b/commons/res/values-qq/strings.xml
index dbd9e3b..4d35d6c 100644
--- a/commons/res/values-qq/strings.xml
+++ b/commons/res/values-qq/strings.xml
@@ -75,7 +75,10 @@
   <string name="menu_retry">Menu item text prompting user to retry a failed 
upload.
 {{Identical|Retry}}</string>
   <string name="menu_abort">Menu item text prompting user to abort and delete 
a failed upload.</string>
-  <string name="share_license_summary">Text label briefly describing CC-BY-SA 
license.</string>
+  <string name="share_license_summary">Text label telling user the license of 
the current upload in progress. %1$s refers to appropriate display text for the 
chosen CC license</string>
   <string name="menu_download">Menu item text prompting user to download a 
selected photo or media file locally.
 {{Identical|Download}}</string>
+    <string name="license_name_cc_by_sa">CC Attribution-Sharelike License 
display name. Use the non-breaking space character(\u00A0) between \'CC\' and 
\'Attribution-Sharealike\'</string>
+    <string name="license_name_cc_by">CC Attribution License display name. Use 
the non-breaking space character(\u00A0) between \'CC\' and 
\'Attribution\'</string>
+    <string name="license_name_cc0">CC0 License display name.</string>
 </resources>
diff --git a/commons/res/values/strings.xml b/commons/res/values/strings.xml
index c76dc96..64f6140 100644
--- a/commons/res/values/strings.xml
+++ b/commons/res/values/strings.xml
@@ -88,7 +88,12 @@
     <string name="menu_retry">Retry</string>
     <string name="menu_abort">Abort</string>
 
-    <string name="share_license_summary">You agree to upload under the terms 
of the CC-BY-SA 3.0 license.</string>
+    <string name="share_license_summary">This image will be licensed under 
%1$s</string>
 
     <string name="menu_download">Download</string>
+    <string name="preference_license">License</string>
+
+    <string 
name="license_name_cc_by_sa">CC\u00A0Attribution-ShareAlike</string>
+    <string name="license_name_cc_by">CC\u00A0Attribution</string>
+    <string name="license_name_cc0">CC0</string>
 </resources>
diff --git a/commons/res/xml/preferences.xml b/commons/res/xml/preferences.xml
index b489e2e..50457fc 100644
--- a/commons/res/xml/preferences.xml
+++ b/commons/res/xml/preferences.xml
@@ -7,5 +7,11 @@
         android:summary="@string/preference_tracking_summary"
         android:defaultValue="true"
         />
+    <ListPreference
+        android:key="defaultLicense"
+        android:title="@string/preference_license"
+        android:defaultValue="CC BY-SA"
+        />
+
 
 </PreferenceScreen>
\ No newline at end of file
diff --git a/commons/src/main/java/org/wikimedia/commons/Media.java 
b/commons/src/main/java/org/wikimedia/commons/Media.java
index f96e0cf..d300f30 100644
--- a/commons/src/main/java/org/wikimedia/commons/Media.java
+++ b/commons/src/main/java/org/wikimedia/commons/Media.java
@@ -119,6 +119,14 @@
         this.height = height;
     }
 
+    public String getLicense() {
+        return license;
+    }
+
+    public void setLicense(String license) {
+        this.license = license;
+    }
+
     protected Uri localUri;
     protected String imageUrl;
     protected String filename;
@@ -128,6 +136,7 @@
     protected Date dateUploaded;
     protected int width;
     protected int height;
+    protected String license;
 
 
     protected String creator;
@@ -160,6 +169,7 @@
         parcel.writeSerializable(tags);
         parcel.writeInt(width);
         parcel.writeInt(height);
+        parcel.writeString(license);
     }
 
     public Media(Parcel in) {
@@ -174,6 +184,7 @@
         tags = (HashMap<String, Object>)in.readSerializable();
         width = in.readInt();
         height = in.readInt();
+        license = in.readString();
     }
 
     public void setDescription(String description) {
diff --git a/commons/src/main/java/org/wikimedia/commons/Prefs.java 
b/commons/src/main/java/org/wikimedia/commons/Prefs.java
index 9dbf173..b59dce6 100644
--- a/commons/src/main/java/org/wikimedia/commons/Prefs.java
+++ b/commons/src/main/java/org/wikimedia/commons/Prefs.java
@@ -4,4 +4,12 @@
     public static String GLOBAL_PREFS = "org.wikimedia.commons.preferences";
 
     public static String TRACKING_ENABLED = "eventLogging";
+    public static final String DEFAULT_LICENSE = "defaultLicense";
+
+
+    public static class Licenses {
+        public static final String CC_BY_SA = "CC BY-SA";
+        public static final String CC_BY = "CC BY";
+        public static final String CC0 = "CC0";
+    }
 }
diff --git a/commons/src/main/java/org/wikimedia/commons/SettingsActivity.java 
b/commons/src/main/java/org/wikimedia/commons/SettingsActivity.java
index 9c59c86..967e9d8 100644
--- a/commons/src/main/java/org/wikimedia/commons/SettingsActivity.java
+++ b/commons/src/main/java/org/wikimedia/commons/SettingsActivity.java
@@ -3,7 +3,9 @@
 
 import android.content.SharedPreferences;
 import android.os.Bundle;
+import android.preference.ListPreference;
 import android.preference.Preference;
+import android.util.Log;
 import com.actionbarsherlock.app.SherlockPreferenceActivity;
 
 public class SettingsActivity extends SherlockPreferenceActivity implements 
SharedPreferences.OnSharedPreferenceChangeListener {
@@ -12,6 +14,18 @@
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         addPreferencesFromResource(R.xml.preferences);
+        ListPreference licensePreference = (ListPreference) 
findPreference(Prefs.DEFAULT_LICENSE);
+        // WARNING: ORDERING NEEDS TO MATCH FOR THE LICENSE NAMES AND DISPLAY 
VALUES
+        licensePreference.setEntries(new String[]{
+                getString(R.string.license_name_cc0),
+                getString(R.string.license_name_cc_by),
+                getString(R.string.license_name_cc_by_sa)
+        });
+        licensePreference.setEntryValues(new String[]{
+                Prefs.Licenses.CC0,
+                Prefs.Licenses.CC_BY,
+                Prefs.Licenses.CC_BY_SA
+        });
         app = (CommonsApplication)getApplicationContext();
     }
 
diff --git 
a/commons/src/main/java/org/wikimedia/commons/SingleUploadFragment.java 
b/commons/src/main/java/org/wikimedia/commons/SingleUploadFragment.java
index 7b142b5..cdd4855 100644
--- a/commons/src/main/java/org/wikimedia/commons/SingleUploadFragment.java
+++ b/commons/src/main/java/org/wikimedia/commons/SingleUploadFragment.java
@@ -3,8 +3,10 @@
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
+import android.content.SharedPreferences;
 import android.net.Uri;
 import android.os.Bundle;
+import android.preference.PreferenceManager;
 import android.text.Editable;
 import android.text.TextWatcher;
 import android.view.LayoutInflater;
@@ -29,7 +31,7 @@
 
     private EditText titleEdit;
     private EditText descEdit;
-    private TextView licenseLabel;
+    private TextView licenseSummaryView;
 
     private OnUploadActionInitiated uploadActionInitiatedHandler;
 
@@ -58,7 +60,7 @@
 
         titleEdit = (EditText)rootView.findViewById(R.id.titleEdit);
         descEdit = (EditText)rootView.findViewById(R.id.descEdit);
-        licenseLabel = (TextView)rootView.findViewById(R.id.licenseLabel);
+        licenseSummaryView = 
(TextView)rootView.findViewById(R.id.share_license_summary);
 
         TextWatcher uploadEnabler = new TextWatcher() {
             public void beforeTextChanged(CharSequence charSequence, int i, 
int i2, int i3) { }
@@ -74,13 +76,17 @@
 
         titleEdit.addTextChangedListener(uploadEnabler);
 
+        SharedPreferences prefs = 
PreferenceManager.getDefaultSharedPreferences(getActivity());
+        final String license = prefs.getString(Prefs.DEFAULT_LICENSE, 
Prefs.Licenses.CC_BY_SA);
+        licenseSummaryView.setText(getString(R.string.share_license_summary, 
getString(Utils.licenseNameFor(license))));
+
         // Open license page on touch
-        licenseLabel.setOnTouchListener(new View.OnTouchListener() {
+        licenseSummaryView.setOnTouchListener(new View.OnTouchListener() {
             public boolean onTouch(View view, MotionEvent motionEvent) {
                 if (motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) {
                     Intent intent = new Intent();
                     intent.setAction(Intent.ACTION_VIEW);
-                    
intent.setData(Uri.parse("https://creativecommons.org/licenses/by-sa/3.0/";));
+                    intent.setData(Uri.parse(Utils.licenseUrlFor(license)));
                     startActivity(intent);
                     return true;
                 } else {
diff --git a/commons/src/main/java/org/wikimedia/commons/StartUploadTask.java 
b/commons/src/main/java/org/wikimedia/commons/StartUploadTask.java
index eb53b9b..63971f1 100644
--- a/commons/src/main/java/org/wikimedia/commons/StartUploadTask.java
+++ b/commons/src/main/java/org/wikimedia/commons/StartUploadTask.java
@@ -1,9 +1,12 @@
 package org.wikimedia.commons;
 
 import android.app.*;
+import android.content.Context;
+import android.content.SharedPreferences;
 import android.database.Cursor;
 import android.net.*;
 import android.os.*;
+import android.preference.PreferenceManager;
 import android.provider.*;
 import android.text.TextUtils;
 import android.webkit.MimeTypeMap;
@@ -42,6 +45,10 @@
         contribution = new Contribution(mediaUri, null, title, description, 
-1, null, null, app.getCurrentAccount().name, 
CommonsApplication.DEFAULT_EDIT_SUMMARY);
         contribution.setTag("mimeType", mimeType);
         contribution.setSource(source);
+
+        SharedPreferences prefs = 
PreferenceManager.getDefaultSharedPreferences(context);
+        String license = prefs.getString(Prefs.DEFAULT_LICENSE, 
Prefs.Licenses.CC_BY_SA);
+        contribution.setLicense(license);
     }
 
     public StartUploadTask(Activity context, UploadService uploadService, 
Contribution contribution) {
diff --git a/commons/src/main/java/org/wikimedia/commons/Utils.java 
b/commons/src/main/java/org/wikimedia/commons/Utils.java
index 455f050..0a9915a 100644
--- a/commons/src/main/java/org/wikimedia/commons/Utils.java
+++ b/commons/src/main/java/org/wikimedia/commons/Utils.java
@@ -141,4 +141,37 @@
         return string.substring(0,1).toUpperCase() + string.substring(1);
     }
 
+    public static String licenseTemplateFor(String license) {
+        if(license.equals(Prefs.Licenses.CC_BY)) {
+            return "{{self|cc-by}}";
+        } else if(license.equals(Prefs.Licenses.CC_BY_SA)) {
+            return "{{self|cc-by-sa}}";
+        } else if(license.equals(Prefs.Licenses.CC0)) {
+            return "{{self|cc0}}";
+        }
+        throw new RuntimeException("Unrecognized license value");
+    }
+
+    public static int licenseNameFor(String license) {
+        if(license.equals(Prefs.Licenses.CC_BY)) {
+            return R.string.license_name_cc_by;
+        } else if(license.equals(Prefs.Licenses.CC_BY_SA)) {
+            return R.string.license_name_cc_by_sa;
+        } else if(license.equals(Prefs.Licenses.CC0)) {
+            return R.string.license_name_cc0;
+        }
+        throw new RuntimeException("Unrecognized license value");
+    }
+
+    public static String licenseUrlFor(String license) {
+        if(license.equals(Prefs.Licenses.CC_BY)) {
+            return "https://creativecommons.org/licenses/by/3.0/";;
+        } else if(license.equals(Prefs.Licenses.CC_BY_SA)) {
+            return "https://creativecommons.org/licenses/by-sa/3.0/";;
+        } else if(license.equals(Prefs.Licenses.CC0)) {
+            return "https://creativecommons.org/publicdomain/zero/1.0/";;
+        }
+        throw new RuntimeException("Unrecognized license value");
+    }
+
 }
diff --git 
a/commons/src/main/java/org/wikimedia/commons/contributions/Contribution.java 
b/commons/src/main/java/org/wikimedia/commons/contributions/Contribution.java
index 25e0554..f0f5a24 100644
--- 
a/commons/src/main/java/org/wikimedia/commons/contributions/Contribution.java
+++ 
b/commons/src/main/java/org/wikimedia/commons/contributions/Contribution.java
@@ -133,7 +133,7 @@
         buffer
                 .append("}}").append("\n")
             .append("== {{int:license-header}} ==\n")
-                .append("{{self|cc-by-sa-3.0}}\n\n")
+                .append(Utils.licenseTemplateFor(license)).append("\n\n")
             .append("{{Uploaded from 
Mobile|platform=Android|version=").append(CommonsApplication.APPLICATION_VERSION).append("}}\n")
             .append("{{subst:unc}}");  // Remove when we have categorization
         return buffer.toString();
@@ -191,6 +191,7 @@
         cv.put(Table.COLUMN_MULTIPLE, isMultiple ? 1 : 0);
         cv.put(Table.COLUMN_WIDTH, width);
         cv.put(Table.COLUMN_HEIGHT, height);
+        cv.put(Table.COLUMN_LICENSE, license);
         return cv;
     }
 
@@ -224,6 +225,7 @@
         c.isMultiple = cursor.getInt(12) == 1;
         c.width = cursor.getInt(13);
         c.height = cursor.getInt(14);
+        c.license = cursor.getString(15);
 
         return c;
     }
@@ -259,6 +261,7 @@
         public static final String COLUMN_MULTIPLE = "multiple";
         public static final String COLUMN_WIDTH = "width";
         public static final String COLUMN_HEIGHT = "height";
+        public static final String COLUMN_LICENSE = "license";
 
         // NOTE! KEEP IN SAME ORDER AS THEY ARE DEFINED UP THERE. HELPS HARD 
CODE COLUMN INDICES.
         public static final String[] ALL_FIELDS = {
@@ -276,7 +279,8 @@
                 COLUMN_CREATOR,
                 COLUMN_MULTIPLE,
                 COLUMN_WIDTH,
-                COLUMN_HEIGHT
+                COLUMN_HEIGHT,
+                COLUMN_LICENSE
         };
 
 
@@ -295,7 +299,8 @@
                 + "creator STRING,"
                 + "multiple INTEGER,"
                 + "width INTEGER,"
-                + "height INTEGER"
+                + "height INTEGER,"
+                + "LICENSE STRING"
         + ");";
 
 
@@ -339,6 +344,8 @@
                 db.execSQL("UPDATE " + TABLE_NAME + " SET width = 0");
                 db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN height 
INTEGER;");
                 db.execSQL("UPDATE " + TABLE_NAME + " SET height = 0");
+                db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD COLUMN license 
STRING;");
+                db.execSQL("UPDATE " + TABLE_NAME + " SET license='" + 
Prefs.Licenses.CC_BY_SA + "';");
                 from++;
                 onUpdate(db, from, to);
                 return;

-- 
To view, visit https://gerrit.wikimedia.org/r/69274
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iffca6f75c63de6fbe61c4dc41b93dd5f692065a5
Gerrit-PatchSet: 4
Gerrit-Project: apps/android/commons
Gerrit-Branch: master
Gerrit-Owner: SuchABot <yuvipanda+sucha...@gmail.com>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Yuvipanda <yuvipa...@gmail.com>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to