mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Added a Contributions Content Provider!
Also refactored Media class into a base class and a Contribution subclass
This commit is contained in:
parent
420ec8061c
commit
9540284b00
9 changed files with 350 additions and 162 deletions
|
|
@ -63,6 +63,11 @@
|
|||
android:name="android.accounts.AccountAuthenticator"
|
||||
android:resource="@xml/authenticator" />
|
||||
</service>
|
||||
<provider
|
||||
android:name=".contributions.ContributionsContentProvider"
|
||||
android:authorities="org.wikimedia.commons.contributions.contentprovider"
|
||||
android:exported="false">
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
|
|||
|
|
@ -17,9 +17,12 @@ import org.apache.http.HttpVersion;
|
|||
import org.apache.http.conn.ConnectionKeepAliveStrategy;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
import org.wikimedia.commons.data.DBOpenHelper;
|
||||
|
||||
public class CommonsApplication extends Application {
|
||||
|
||||
private DBOpenHelper dbOpenHelper;
|
||||
|
||||
private MWApi api;
|
||||
private Account currentAccount = null; // Unlike a savings account...
|
||||
public static final String API_URL = "http://test.wikipedia.org/w/api.php";
|
||||
|
|
@ -28,7 +31,15 @@ public class CommonsApplication extends Application {
|
|||
DefaultHttpClient client = new DefaultHttpClient();
|
||||
return new MWApi(API_URL, client);
|
||||
}
|
||||
|
||||
|
||||
public DBOpenHelper getDbOpenHelper() {
|
||||
if(dbOpenHelper == null) {
|
||||
dbOpenHelper = new DBOpenHelper(this);
|
||||
}
|
||||
return dbOpenHelper;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
// TODO Auto-generated method stub
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import android.os.Bundle;
|
|||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
import com.actionbarsherlock.app.SherlockActivity;
|
||||
import org.wikimedia.commons.media.Media;
|
||||
import org.wikimedia.commons.contributions.Contribution;
|
||||
|
||||
public class ContributionsActivity extends SherlockActivity {
|
||||
|
||||
|
|
@ -22,8 +22,8 @@ public class ContributionsActivity extends SherlockActivity {
|
|||
private BroadcastReceiver messageReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Media media = (Media)intent.getParcelableExtra(UploadService.EXTRA_MEDIA);
|
||||
Log.d("Commons", "Completed " + intent.getAction() +" of " + media.getFileName());
|
||||
Contribution contribution = (Contribution)intent.getParcelableExtra(UploadService.EXTRA_MEDIA);
|
||||
Log.d("Commons", "Completed " + intent.getAction() +" of " + contribution.getFilename());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
71
commons/src/main/java/org/wikimedia/commons/Media.java
Normal file
71
commons/src/main/java/org/wikimedia/commons/Media.java
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
package org.wikimedia.commons;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
public class Media implements Serializable {
|
||||
|
||||
public Uri getLocalUri() {
|
||||
return localUri;
|
||||
}
|
||||
|
||||
public Uri getRemoteUri() {
|
||||
return remoteUri;
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getCommonsURL() {
|
||||
return commonsURL;
|
||||
}
|
||||
|
||||
public long getDataLength() {
|
||||
return dataLength;
|
||||
}
|
||||
|
||||
public Date getDateCreated() {
|
||||
return dateCreated;
|
||||
}
|
||||
|
||||
public Date getDateUploaded() {
|
||||
return dateUploaded;
|
||||
}
|
||||
|
||||
public String getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
|
||||
protected Uri localUri;
|
||||
protected Uri remoteUri;
|
||||
protected String filename;
|
||||
protected String description;
|
||||
protected String commonsURL;
|
||||
protected long dataLength;
|
||||
protected Date dateCreated;
|
||||
protected Date dateUploaded;
|
||||
|
||||
|
||||
protected String creator;
|
||||
|
||||
|
||||
public Media(Uri localUri, Uri remoteUri, String filename, String description, String commonsURL, long dataLength, Date dateCreated, Date dateUploaded, String creator) {
|
||||
this.localUri = localUri;
|
||||
this.remoteUri = remoteUri;
|
||||
this.filename = filename;
|
||||
this.description = description;
|
||||
this.commonsURL = commonsURL;
|
||||
this.dataLength = dataLength;
|
||||
this.dateCreated = dateCreated;
|
||||
this.dateUploaded = dateUploaded;
|
||||
this.creator = creator;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,12 @@
|
|||
package org.wikimedia.commons;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import org.wikimedia.commons.auth.AuthenticatedActivity;
|
||||
import org.wikimedia.commons.auth.WikiAccountAuthenticator;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import android.widget.ImageView;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
|
|
@ -18,7 +14,7 @@ import com.actionbarsherlock.view.MenuItem;
|
|||
import com.actionbarsherlock.view.Window;
|
||||
import android.widget.*;
|
||||
import android.view.*;
|
||||
import org.wikimedia.commons.media.Media;
|
||||
import org.wikimedia.commons.contributions.Contribution;
|
||||
|
||||
|
||||
public class ShareActivity extends AuthenticatedActivity {
|
||||
|
|
@ -57,11 +53,11 @@ public class ShareActivity extends AuthenticatedActivity {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent uploadIntent = new Intent(getApplicationContext(), UploadService.class);
|
||||
uploadIntent.putExtra(Media.EXTRA_MEDIA_URI, mediaUri);
|
||||
uploadIntent.putExtra(Media.EXTRA_TARGET_FILENAME, titleEdit.getText().toString());
|
||||
uploadIntent.putExtra(Media.EXTRA_DESCRIPTION, descEdit.getText().toString());
|
||||
uploadIntent.putExtra(Media.EXTRA_MIMETYPE, mimeType);
|
||||
uploadIntent.putExtra(Media.EXTRA_EDIT_SUMMARY, "Mobile upload from Wikimedia Commons Android app");
|
||||
uploadIntent.putExtra(UploadService.EXTRA_MEDIA_URI, mediaUri);
|
||||
uploadIntent.putExtra(UploadService.EXTRA_TARGET_FILENAME, titleEdit.getText().toString());
|
||||
uploadIntent.putExtra(UploadService.EXTRA_DESCRIPTION, descEdit.getText().toString());
|
||||
uploadIntent.putExtra(UploadService.EXTRA_MIMETYPE, mimeType);
|
||||
uploadIntent.putExtra(UploadService.EXTRA_EDIT_SUMMARY, "Mobile upload from Wikimedia Commons Android app");
|
||||
startService(uploadIntent);
|
||||
Toast startingToast = Toast.makeText(that, R.string.uploading_started, Toast.LENGTH_LONG);
|
||||
startingToast.show();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ import java.util.Date;
|
|||
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import org.mediawiki.api.*;
|
||||
import org.wikimedia.commons.media.Media;
|
||||
import org.wikimedia.commons.contributions.Contribution;
|
||||
import org.wikimedia.commons.contributions.ContributionsContentProvider;
|
||||
|
||||
import in.yuvi.http.fluent.ProgressListener;
|
||||
|
||||
|
|
@ -15,9 +16,7 @@ import android.database.Cursor;
|
|||
import android.os.*;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.text.method.DateTimeKeyListener;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
import android.widget.Toast;
|
||||
import android.net.*;
|
||||
|
|
@ -32,8 +31,16 @@ public class UploadService extends IntentService {
|
|||
public static final String EXTRA_MEDIA = ".media";
|
||||
public static final String EXTRA_TRANSFERRED_BYTES = ".progress.transferred";
|
||||
|
||||
|
||||
public static final String EXTRA_MEDIA_URI = EXTRA_PREFIX + ".uri";
|
||||
public static final String EXTRA_TARGET_FILENAME = EXTRA_PREFIX + ".filename";
|
||||
public static final String EXTRA_DESCRIPTION = EXTRA_PREFIX + ".description";
|
||||
public static final String EXTRA_EDIT_SUMMARY = EXTRA_PREFIX + ".summary";
|
||||
public static final String EXTRA_MIMETYPE = EXTRA_PREFIX + ".mimetype";
|
||||
|
||||
private NotificationManager notificationManager;
|
||||
private LocalBroadcastManager localBroadcastManager;
|
||||
private ContentProviderClient contributionsProviderClient;
|
||||
private CommonsApplication app;
|
||||
|
||||
private Notification curProgressNotification;
|
||||
|
|
@ -59,17 +66,17 @@ public class UploadService extends IntentService {
|
|||
Notification curNotification;
|
||||
String notificationTag;
|
||||
boolean notificationTitleChanged;
|
||||
Media media;
|
||||
Contribution contribution;
|
||||
|
||||
String notificationProgressTitle;
|
||||
String notificationFinishingTitle;
|
||||
|
||||
public NotificationUpdateProgressListener(Notification curNotification, String notificationTag, String notificationProgressTitle, String notificationFinishingTitle, Media media) {
|
||||
public NotificationUpdateProgressListener(Notification curNotification, String notificationTag, String notificationProgressTitle, String notificationFinishingTitle, Contribution contribution) {
|
||||
this.curNotification = curNotification;
|
||||
this.notificationTag = notificationTag;
|
||||
this.notificationProgressTitle = notificationProgressTitle;
|
||||
this.notificationFinishingTitle = notificationFinishingTitle;
|
||||
this.media = media;
|
||||
this.contribution = contribution;
|
||||
}
|
||||
@Override
|
||||
public void onProgress(long transferred, long total) {
|
||||
|
|
@ -83,7 +90,7 @@ public class UploadService extends IntentService {
|
|||
}
|
||||
notificationTitleChanged = true;
|
||||
Intent mediaUploadStartedEvent = new Intent(INTENT_UPLOAD_STARTED);
|
||||
mediaUploadStartedEvent.putExtra(EXTRA_MEDIA, media);
|
||||
// mediaUploadStartedEvent.putExtra(EXTRA_MEDIA, contribution);
|
||||
localBroadcastManager.sendBroadcast(mediaUploadStartedEvent);
|
||||
}
|
||||
if(transferred == total) {
|
||||
|
|
@ -94,7 +101,7 @@ public class UploadService extends IntentService {
|
|||
curNotification.contentView.setProgressBar(R.id.uploadNotificationProgress, 100, (int)(((double)transferred / (double)total) * 100), false);
|
||||
notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
|
||||
Intent mediaUploadProgressIntent = new Intent(INTENT_UPLOAD_PROGRESS);
|
||||
mediaUploadProgressIntent.putExtra(EXTRA_MEDIA, media);
|
||||
// mediaUploadProgressIntent.putExtra(EXTRA_MEDIA, contribution);
|
||||
mediaUploadProgressIntent.putExtra(EXTRA_TRANSFERRED_BYTES, transferred);
|
||||
localBroadcastManager.sendBroadcast(mediaUploadProgressIntent);
|
||||
}
|
||||
|
|
@ -104,6 +111,7 @@ public class UploadService extends IntentService {
|
|||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
contributionsProviderClient.release();
|
||||
Log.d("Commons", "ZOMG I AM BEING KILLED HALP!");
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +121,7 @@ public class UploadService extends IntentService {
|
|||
notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||
localBroadcastManager = LocalBroadcastManager.getInstance(this);
|
||||
app = (CommonsApplication)this.getApplicationContext();
|
||||
contributionsProviderClient = this.getContentResolver().acquireContentProviderClient(ContributionsContentProvider.AUTHORITY);
|
||||
}
|
||||
|
||||
private String getRealPathFromURI(Uri contentUri) {
|
||||
|
|
@ -124,13 +133,13 @@ public class UploadService extends IntentService {
|
|||
return cursor.getString(column_index);
|
||||
}
|
||||
|
||||
private Media mediaFromIntent(Intent intent) {
|
||||
private Contribution mediaFromIntent(Intent intent) {
|
||||
Bundle extras = intent.getExtras();
|
||||
Uri mediaUri = (Uri)extras.getParcelable(Media.EXTRA_MEDIA_URI);
|
||||
String filename = intent.getStringExtra(Media.EXTRA_TARGET_FILENAME);
|
||||
String description = intent.getStringExtra(Media.EXTRA_DESCRIPTION);
|
||||
String editSummary = intent.getStringExtra(Media.EXTRA_EDIT_SUMMARY);
|
||||
String mimeType = intent.getStringExtra(Media.EXTRA_MIMETYPE);
|
||||
Uri mediaUri = (Uri)extras.getParcelable(EXTRA_MEDIA_URI);
|
||||
String filename = intent.getStringExtra(EXTRA_TARGET_FILENAME);
|
||||
String description = intent.getStringExtra(EXTRA_DESCRIPTION);
|
||||
String editSummary = intent.getStringExtra(EXTRA_EDIT_SUMMARY);
|
||||
String mimeType = intent.getStringExtra(EXTRA_MIMETYPE);
|
||||
Date dateCreated = null;
|
||||
|
||||
Long length = null;
|
||||
|
|
@ -152,8 +161,8 @@ public class UploadService extends IntentService {
|
|||
} /* else if (mimeType.startsWith("audio/")) {
|
||||
Removed Audio implementationf or now
|
||||
} */
|
||||
Media media = new Media(mediaUri, filename, description, editSummary, app.getCurrentAccount().name, dateCreated, length);
|
||||
return media;
|
||||
Contribution contribution = new Contribution(mediaUri, null, filename, description, null, length, dateCreated, null, app.getCurrentAccount().name, editSummary);
|
||||
return contribution;
|
||||
}
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
|
@ -164,10 +173,16 @@ public class UploadService extends IntentService {
|
|||
notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curProgressNotification);
|
||||
}
|
||||
|
||||
Media media = mediaFromIntent(intent);
|
||||
Contribution contribution = mediaFromIntent(intent);
|
||||
|
||||
try {
|
||||
contributionsProviderClient.insert(ContributionsContentProvider.BASE_URI, contribution.toContentValues());
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Intent mediaUploadQueuedIntent = new Intent(INTENT_UPLOAD_QUEUED);
|
||||
mediaUploadQueuedIntent.putExtra(EXTRA_MEDIA, media);
|
||||
mediaUploadQueuedIntent.putExtra(EXTRA_MEDIA, contribution);
|
||||
localBroadcastManager.sendBroadcast(mediaUploadQueuedIntent);
|
||||
return super.onStartCommand(mediaUploadQueuedIntent, flags, startId);
|
||||
}
|
||||
|
|
@ -178,21 +193,21 @@ public class UploadService extends IntentService {
|
|||
|
||||
ApiResult result;
|
||||
RemoteViews notificationView;
|
||||
Media media;
|
||||
Contribution contribution;
|
||||
InputStream file = null;
|
||||
media = (Media)intent.getParcelableExtra(EXTRA_MEDIA);
|
||||
contribution = (Contribution)intent.getSerializableExtra(EXTRA_MEDIA);
|
||||
|
||||
String notificationTag = media.getMediaUri().toString();
|
||||
String notificationTag = contribution.getLocalUri().toString();
|
||||
|
||||
|
||||
try {
|
||||
file = this.getContentResolver().openInputStream(media.getMediaUri());
|
||||
file = this.getContentResolver().openInputStream(contribution.getLocalUri());
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
notificationView = new RemoteViews(getPackageName(), R.layout.layout_upload_progress);
|
||||
notificationView.setTextViewText(R.id.uploadNotificationTitle, String.format(getString(R.string.upload_progress_notification_title_start), media.getFileName()));
|
||||
notificationView.setTextViewText(R.id.uploadNotificationTitle, String.format(getString(R.string.upload_progress_notification_title_start), contribution.getFilename()));
|
||||
notificationView.setProgressBar(R.id.uploadNotificationProgress, 100, 0, false);
|
||||
|
||||
Log.d("Commons", "Before execution!");
|
||||
|
|
@ -202,7 +217,7 @@ public class UploadService extends IntentService {
|
|||
.setContent(notificationView)
|
||||
.setOngoing(true)
|
||||
.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0))
|
||||
.setTicker(String.format(getString(R.string.upload_progress_notification_title_in_progress), media.getFileName()))
|
||||
.setTicker(String.format(getString(R.string.upload_progress_notification_title_in_progress), contribution.getFilename()))
|
||||
.getNotification();
|
||||
|
||||
this.startForeground(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curProgressNotification);
|
||||
|
|
@ -224,11 +239,11 @@ public class UploadService extends IntentService {
|
|||
}
|
||||
}
|
||||
NotificationUpdateProgressListener notificationUpdater = new NotificationUpdateProgressListener(curProgressNotification, notificationTag,
|
||||
String.format(getString(R.string.upload_progress_notification_title_in_progress), media.getFileName()),
|
||||
String.format(getString(R.string.upload_progress_notification_title_finishing), media.getFileName()),
|
||||
media
|
||||
String.format(getString(R.string.upload_progress_notification_title_in_progress), contribution.getFilename()),
|
||||
String.format(getString(R.string.upload_progress_notification_title_finishing), contribution.getFilename()),
|
||||
contribution
|
||||
);
|
||||
result = api.upload(media.getFileName(), file, media.getLength(), media.getPageContents(), media.getEditSummary(), notificationUpdater);
|
||||
result = api.upload(contribution.getFilename(), file, contribution.getDataLength(), contribution.getPageContents(), contribution.getEditSummary(), notificationUpdater);
|
||||
} catch (IOException e) {
|
||||
Log.d("Commons", "I have a network fuckup");
|
||||
stopForeground(true);
|
||||
|
|
@ -236,8 +251,8 @@ public class UploadService extends IntentService {
|
|||
.setSmallIcon(R.drawable.ic_launcher)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(PendingIntent.getService(getApplicationContext(), 0, intent, 0))
|
||||
.setTicker(String.format(getString(R.string.upload_failed_notification_title), media.getFileName()))
|
||||
.setContentTitle(String.format(getString(R.string.upload_failed_notification_title), media.getFileName()))
|
||||
.setTicker(String.format(getString(R.string.upload_failed_notification_title), contribution.getFilename()))
|
||||
.setContentTitle(String.format(getString(R.string.upload_failed_notification_title), contribution.getFilename()))
|
||||
.setContentText(getString(R.string.upload_failed_notification_subtitle))
|
||||
.getNotification();
|
||||
notificationManager.notify(NOTIFICATION_UPLOAD_FAILED, failureNotification);
|
||||
|
|
@ -256,16 +271,16 @@ public class UploadService extends IntentService {
|
|||
Notification doneNotification = new NotificationCompat.Builder(this)
|
||||
.setAutoCancel(true)
|
||||
.setSmallIcon(R.drawable.ic_launcher)
|
||||
.setContentTitle(String.format(getString(R.string.upload_completed_notification_title), media.getFileName()))
|
||||
.setContentTitle(String.format(getString(R.string.upload_completed_notification_title), contribution.getFilename()))
|
||||
.setContentText(getString(R.string.upload_completed_notification_text))
|
||||
.setTicker(String.format(getString(R.string.upload_completed_notification_title), media.getFileName()))
|
||||
.setTicker(String.format(getString(R.string.upload_completed_notification_title), contribution.getFilename()))
|
||||
.setContentIntent(PendingIntent.getActivity(this, 0, openUploadedPageIntent, 0))
|
||||
.getNotification();
|
||||
|
||||
notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_COMPLETE, doneNotification);
|
||||
|
||||
Intent mediaUploadedIntent = new Intent(INTENT_UPLOAD_COMPLETE);
|
||||
mediaUploadedIntent.putExtra(EXTRA_MEDIA, media);
|
||||
//mediaUploadedIntent.putExtra(EXTRA_MEDIA, contribution);
|
||||
localBroadcastManager.sendBroadcast(mediaUploadedIntent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,117 @@
|
|||
package org.wikimedia.commons.contributions;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.*;
|
||||
import org.wikimedia.commons.Media;
|
||||
|
||||
public class Contribution extends Media {
|
||||
|
||||
|
||||
public String getEditSummary() {
|
||||
return editSummary;
|
||||
}
|
||||
|
||||
private String editSummary;
|
||||
|
||||
public Date getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
private Date timestamp;
|
||||
private int state;
|
||||
|
||||
public Contribution(Uri localUri, Uri remoteUri, String filename, String description, String commonsURL, long dataLength, Date dateCreated, Date dateUploaded, String creator, String editSummary) {
|
||||
super(localUri, remoteUri, filename, description, commonsURL, dataLength, dateCreated, dateUploaded, creator);
|
||||
this.editSummary = editSummary;
|
||||
timestamp = new Date(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getPageContents() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
buffer
|
||||
.append("== {{int:filedesc}} ==\n")
|
||||
.append("{{Information")
|
||||
.append("|Description=").append(description)
|
||||
.append("|source=").append("{{own}}")
|
||||
.append("|author=[[User:").append(creator).append("]]");
|
||||
if(dateCreated != null) {
|
||||
buffer
|
||||
.append("|date={{According to EXIF data|").append(isoFormat.format(dateCreated)).append("}}");
|
||||
}
|
||||
buffer
|
||||
.append("}}").append("\n")
|
||||
.append("== {{int:license-header}} ==\n")
|
||||
.append("{{self|cc-by-sa-3.0}}")
|
||||
;
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public ContentValues toContentValues() {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(Table.COLUMN_FILENAME, getFilename());
|
||||
if(getLocalUri() != null) {
|
||||
cv.put(Table.COLUMN_LOCAL_URI, getLocalUri().toString());
|
||||
}
|
||||
if(getRemoteUri() != null) {
|
||||
cv.put(Table.COLUMN_REMOTE_URI, getRemoteUri().toString());
|
||||
}
|
||||
cv.put(Table.COLUMN_LENGTH, getDataLength());
|
||||
cv.put(Table.COLUMN_TIMESTAMP, getTimestamp().getTime());
|
||||
cv.put(Table.COLUMN_STATE, getState());
|
||||
return cv;
|
||||
}
|
||||
|
||||
|
||||
public static class Table {
|
||||
public static final String TABLE_NAME = "contributions";
|
||||
|
||||
public static final String COLUMN_ID = "_id";
|
||||
public static final String COLUMN_FILENAME = "filename";
|
||||
public static final String COLUMN_LOCAL_URI = "local_uri";
|
||||
public static final String COLUMN_REMOTE_URI = "remote_uri";
|
||||
public static final String COLUMN_TIMESTAMP = "timestamp";
|
||||
public static final String COLUMN_STATE = "state";
|
||||
public static final String COLUMN_LENGTH = "length";
|
||||
|
||||
// No need to be bitwise - they're mutually exclusive
|
||||
public static final int STATE_COMPLETED = 0;
|
||||
public static final int STATE_QUEUED = 1;
|
||||
public static final int STATE_IN_PROGRESS = 2;
|
||||
|
||||
|
||||
private static final String CREATE_TABLE_STATEMENT = "CREATE TABLE " + TABLE_NAME + " ("
|
||||
+ "_id INTEGER PRIMARY KEY,"
|
||||
+ "filename STRING,"
|
||||
+ "local_uri STRING,"
|
||||
+ "remote_uri STRING,"
|
||||
+ "timestamp INTEGER,"
|
||||
+ "state INTEGER,"
|
||||
+ "length INTEGER"
|
||||
+ ");";
|
||||
|
||||
|
||||
public static void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL(CREATE_TABLE_STATEMENT);
|
||||
}
|
||||
|
||||
public static void onUpdate(SQLiteDatabase db) {
|
||||
// Drop everything and recreate stuff
|
||||
// FIXME: Understatement
|
||||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
package org.wikimedia.commons.contributions;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteQueryBuilder;
|
||||
import android.net.Uri;
|
||||
import org.wikimedia.commons.CommonsApplication;
|
||||
import org.wikimedia.commons.data.DBOpenHelper;
|
||||
|
||||
public class ContributionsContentProvider extends ContentProvider{
|
||||
|
||||
private static final int CONTRIBUTIONS = 1;
|
||||
|
||||
public static final String AUTHORITY = "org.wikimedia.commons.contributions.contentprovider";
|
||||
private static final String BASE_PATH = "contributions";
|
||||
|
||||
public static final Uri BASE_URI = Uri.parse("content://" + AUTHORITY + "/" + BASE_PATH);
|
||||
|
||||
private static final UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
static {
|
||||
uriMatcher.addURI(AUTHORITY, BASE_PATH, CONTRIBUTIONS);
|
||||
}
|
||||
|
||||
|
||||
private DBOpenHelper dbOpenHelper;
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
dbOpenHelper = ((CommonsApplication)this.getContext().getApplicationContext()).getDbOpenHelper();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
|
||||
queryBuilder.setTables(Contribution.Table.TABLE_NAME);
|
||||
|
||||
int uriType = uriMatcher.match(uri);
|
||||
|
||||
switch(uriType) {
|
||||
case CONTRIBUTIONS:
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown URI" + uri);
|
||||
}
|
||||
|
||||
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
|
||||
|
||||
Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
|
||||
cursor.setNotificationUri(getContext().getContentResolver(), uri);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType(Uri uri) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues contentValues) {
|
||||
int uriType = uriMatcher.match(uri);
|
||||
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
|
||||
int rowsDeleted = 0;
|
||||
long id = 0;
|
||||
switch (uriType) {
|
||||
case CONTRIBUTIONS:
|
||||
id = sqlDB.insert(Contribution.Table.TABLE_NAME, null, contentValues);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown URI: " + uri);
|
||||
}
|
||||
getContext().getContentResolver().notifyChange(uri, null);
|
||||
return Uri.parse(BASE_PATH + "/" + id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Uri uri, String s, String[] strings) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Uri uri, ContentValues contentValues, String s, String[] strings) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
package org.wikimedia.commons.media;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import android.net.*;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class Media implements Parcelable {
|
||||
|
||||
private static final String EXTRA_PREFIX = "org.wikimedia.commons.media";
|
||||
public static final String EXTRA_MEDIA_URI = EXTRA_PREFIX + ".uri";
|
||||
public static final String EXTRA_TARGET_FILENAME = EXTRA_PREFIX + ".filename";
|
||||
public static final String EXTRA_DESCRIPTION = EXTRA_PREFIX + ".description";
|
||||
public static final String EXTRA_EDIT_SUMMARY = EXTRA_PREFIX + ".summary";
|
||||
public static final String EXTRA_MIMETYPE = EXTRA_PREFIX + ".mimetype";
|
||||
|
||||
private Uri mediaUri;
|
||||
private String fileName;
|
||||
private String editSummary;
|
||||
private String mimeType;
|
||||
private String description;
|
||||
private String userName;
|
||||
private Date dateCreated;
|
||||
private long length;
|
||||
private Date dateUploaded;
|
||||
|
||||
public Media(Uri mediaUri, String fileName, String description, String editSummary, String userName, Date dateCreated, long length) {
|
||||
this.mediaUri = mediaUri;
|
||||
this.fileName = fileName;
|
||||
this.description = description;
|
||||
this.editSummary = editSummary;
|
||||
this.userName = userName;
|
||||
this.dateCreated = dateCreated;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public long getLength() {
|
||||
return length;
|
||||
}
|
||||
public Uri getMediaUri() {
|
||||
return mediaUri;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public String getEditSummary() {
|
||||
return editSummary;
|
||||
}
|
||||
|
||||
public String getPageContents() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
buffer
|
||||
.append("== {{int:filedesc}} ==\n")
|
||||
.append("{{Information")
|
||||
.append("|Description=").append(description)
|
||||
.append("|source=").append("{{own}}")
|
||||
.append("|author=[[User:").append(userName).append("]]");
|
||||
if(dateCreated != null) {
|
||||
buffer
|
||||
.append("|date={{According to EXIF data|").append(isoFormat.format(dateCreated)).append("}}");
|
||||
}
|
||||
buffer
|
||||
.append("}}").append("\n")
|
||||
.append("== {{int:license-header}} ==\n")
|
||||
.append("{{self|cc-by-sa-3.0}}")
|
||||
;
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public String getMimeType() {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel parcel, int flags) {
|
||||
parcel.writeParcelable(mediaUri, flags);
|
||||
parcel.writeString(fileName);
|
||||
parcel.writeString(description);
|
||||
parcel.writeString(editSummary);
|
||||
parcel.writeString(userName);
|
||||
parcel.writeLong(length);
|
||||
parcel.writeSerializable(dateCreated);
|
||||
}
|
||||
|
||||
public static Media fromParcel(Parcel parcel) {
|
||||
Uri mediaUri = parcel.readParcelable(Uri.class.getClassLoader());
|
||||
String fileName = parcel.readString();
|
||||
String description = parcel.readString();
|
||||
String editSummary = parcel.readString();
|
||||
String userName = parcel.readString();
|
||||
Long length = parcel.readLong();
|
||||
Date dateCreated = (Date)parcel.readSerializable();
|
||||
return new Media(mediaUri, fileName, description, editSummary, userName, dateCreated, length);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<Media> CREATOR = new Parcelable.Creator<Media>() {
|
||||
|
||||
public Media createFromParcel(Parcel in) {
|
||||
return fromParcel(in);
|
||||
}
|
||||
|
||||
public Media[] newArray(int size) {
|
||||
return new Media[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue