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
This commit is contained in:
YuviPanda 2013-06-18 14:16:00 +00:00 committed by Brion Vibber
parent 86a39e9d13
commit 55525bc100
11 changed files with 112 additions and 10 deletions

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -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>

View file

@ -119,6 +119,14 @@ public class Media implements Parcelable {
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 @@ public class Media implements Parcelable {
protected Date dateUploaded;
protected int width;
protected int height;
protected String license;
protected String creator;
@ -160,6 +169,7 @@ public class Media implements Parcelable {
parcel.writeSerializable(tags);
parcel.writeInt(width);
parcel.writeInt(height);
parcel.writeString(license);
}
public Media(Parcel in) {
@ -174,6 +184,7 @@ public class Media implements Parcelable {
tags = (HashMap<String, Object>)in.readSerializable();
width = in.readInt();
height = in.readInt();
license = in.readString();
}
public void setDescription(String description) {

View file

@ -4,4 +4,12 @@ public class Prefs {
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";
}
}

View file

@ -3,7 +3,9 @@ package org.wikimedia.commons;
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 @@ public class SettingsActivity extends SherlockPreferenceActivity implements Shar
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();
}

View file

@ -3,8 +3,10 @@ package org.wikimedia.commons;
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 @@ public class SingleUploadFragment extends SherlockFragment {
private EditText titleEdit;
private EditText descEdit;
private TextView licenseLabel;
private TextView licenseSummaryView;
private OnUploadActionInitiated uploadActionInitiatedHandler;
@ -58,7 +60,7 @@ public class SingleUploadFragment extends SherlockFragment {
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 @@ public class SingleUploadFragment extends SherlockFragment {
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 {

View file

@ -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 @@ public class StartUploadTask extends AsyncTask<Void, Void, Contribution> {
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) {

View file

@ -141,4 +141,37 @@ public class Utils {
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");
}
}

View file

@ -133,7 +133,7 @@ public class Contribution extends Media {
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 @@ public class Contribution extends Media {
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 @@ public class Contribution extends Media {
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 class Contribution extends Media {
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 @@ public class Contribution extends Media {
COLUMN_CREATOR,
COLUMN_MULTIPLE,
COLUMN_WIDTH,
COLUMN_HEIGHT
COLUMN_HEIGHT,
COLUMN_LICENSE
};
@ -295,7 +299,8 @@ public class Contribution extends Media {
+ "creator STRING,"
+ "multiple INTEGER,"
+ "width INTEGER,"
+ "height INTEGER"
+ "height INTEGER,"
+ "LICENSE STRING"
+ ");";
@ -339,6 +344,8 @@ public class Contribution extends Media {
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;