mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
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:
parent
86a39e9d13
commit
55525bc100
11 changed files with 112 additions and 10 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue