Show uploaded date in my contributions

This commit is contained in:
YuviPanda 2013-02-02 15:22:25 +05:30
parent fe47b00081
commit da92ec7235
4 changed files with 58 additions and 14 deletions

View file

@ -11,21 +11,29 @@
android:scaleType="centerCrop" android:scaleType="centerCrop"
/> />
<LinearLayout <RelativeLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center|bottom" android:layout_gravity="center|bottom"
android:orientation="vertical" > android:background="#AA000000"
android:padding="10dp"
>
<TextView <TextView
android:id="@+id/contributionTitle" android:id="@+id/contributionTitle"
android:layout_width="fill_parent" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="#AA000000"
android:padding="10dp"
android:textColor="#FFFFFFFF" android:textColor="#FFFFFFFF"
android:textSize="18dp" android:textSize="18dp"
android:typeface="serif" /> android:typeface="serif" />
</LinearLayout> <TextView
android:id="@+id/contributionState"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
style="?android:textAppearanceSmall"
android:textColor="#FFFFFFFF"
/>
</RelativeLayout>
</FrameLayout> </FrameLayout>

View file

@ -1,6 +1,7 @@
package org.wikimedia.commons; package org.wikimedia.commons;
import java.io.*; import java.io.*;
import java.text.*;
import java.util.Date; import java.util.Date;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
@ -263,10 +264,19 @@ public class UploadService extends IntentService {
Log.d("Commons", "Response is" + CommonsApplication.getStringFromDOM(result.getDocument())); Log.d("Commons", "Response is" + CommonsApplication.getStringFromDOM(result.getDocument()));
stopForeground(true); stopForeground(true);
curProgressNotification = null; curProgressNotification = null;
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // Assuming MW always gives me UTC
String descUrl = result.getString("/api/upload/imageinfo/@descriptionurl"); String descUrl = result.getString("/api/upload/imageinfo/@descriptionurl");
Date dateUploaded = null;
Intent openUploadedPageIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(descUrl)); try {
dateUploaded = isoFormat.parse(result.getString("/api/upload/imageinfo/@timestamp"));
} catch (java.text.ParseException e) {
throw new RuntimeException(e); // Hopefully mediawiki doesn't give me bogus stuff?
}
Intent openUploadedPageIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(descUrl));
Notification doneNotification = new NotificationCompat.Builder(this) Notification doneNotification = new NotificationCompat.Builder(this)
.setAutoCancel(true) .setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher) .setSmallIcon(R.drawable.ic_launcher)
@ -278,6 +288,7 @@ public class UploadService extends IntentService {
notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_COMPLETE, doneNotification); notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_COMPLETE, doneNotification);
contribution.setState(Contribution.STATE_COMPLETED); contribution.setState(Contribution.STATE_COMPLETED);
contribution.setDateUploaded(dateUploaded);
contribution.save(); contribution.save();
} }
} }

View file

@ -47,6 +47,10 @@ public class Contribution extends Media {
this.state = state; this.state = state;
} }
public void setDateUploaded(Date date) {
this.dateUploaded = date;
}
public String getPageContents() { public String getPageContents() {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd");
@ -93,6 +97,9 @@ public class Contribution extends Media {
if(getRemoteUri() != null) { if(getRemoteUri() != null) {
cv.put(Table.COLUMN_REMOTE_URI, getRemoteUri().toString()); cv.put(Table.COLUMN_REMOTE_URI, getRemoteUri().toString());
} }
if(getDateUploaded() != null) {
cv.put(Table.COLUMN_UPLOADED, getDateUploaded().getTime());
}
cv.put(Table.COLUMN_LENGTH, getDataLength()); cv.put(Table.COLUMN_LENGTH, getDataLength());
cv.put(Table.COLUMN_TIMESTAMP, getTimestamp().getTime()); cv.put(Table.COLUMN_TIMESTAMP, getTimestamp().getTime());
cv.put(Table.COLUMN_STATE, getState()); cv.put(Table.COLUMN_STATE, getState());
@ -110,8 +117,7 @@ public class Contribution extends Media {
public static final String COLUMN_TIMESTAMP = "timestamp"; public static final String COLUMN_TIMESTAMP = "timestamp";
public static final String COLUMN_STATE = "state"; public static final String COLUMN_STATE = "state";
public static final String COLUMN_LENGTH = "length"; public static final String COLUMN_LENGTH = "length";
public static final String COLUMN_UPLOADED = "uploaded";
private static final String CREATE_TABLE_STATEMENT = "CREATE TABLE " + TABLE_NAME + " (" private static final String CREATE_TABLE_STATEMENT = "CREATE TABLE " + TABLE_NAME + " ("
@ -119,6 +125,7 @@ public class Contribution extends Media {
+ "filename STRING," + "filename STRING,"
+ "local_uri STRING," + "local_uri STRING,"
+ "remote_uri STRING," + "remote_uri STRING,"
+ "uploaded INTEGER,"
+ "timestamp INTEGER," + "timestamp INTEGER,"
+ "state INTEGER," + "state INTEGER,"
+ "length INTEGER" + "length INTEGER"

View file

@ -31,6 +31,9 @@ import org.wikimedia.commons.UploadService;
import org.wikimedia.commons.auth.AuthenticatedActivity; import org.wikimedia.commons.auth.AuthenticatedActivity;
import org.wikimedia.commons.auth.WikiAccountAuthenticator; import org.wikimedia.commons.auth.WikiAccountAuthenticator;
import java.text.SimpleDateFormat;
import java.util.Date;
// Inherit from SherlockFragmentActivity but not use Fragments. Because Loaders are available only from FragmentActivities // Inherit from SherlockFragmentActivity but not use Fragments. Because Loaders are available only from FragmentActivities
public class ContributionsActivity extends AuthenticatedActivity implements LoaderManager.LoaderCallbacks<Cursor> { public class ContributionsActivity extends AuthenticatedActivity implements LoaderManager.LoaderCallbacks<Cursor> {
@ -42,10 +45,14 @@ public class ContributionsActivity extends AuthenticatedActivity implements Load
private final int COLUMN_FILENAME; private final int COLUMN_FILENAME;
private final int COLUMN_LOCALURI; private final int COLUMN_LOCALURI;
private final int COLUMN_STATE;
private final int COLUMN_UPLOADED;
public ContributionAdapter(Context context, Cursor c, int flags) { public ContributionAdapter(Context context, Cursor c, int flags) {
super(context, c, flags); super(context, c, flags);
COLUMN_FILENAME = c.getColumnIndex(Contribution.Table.COLUMN_FILENAME); COLUMN_FILENAME = c.getColumnIndex(Contribution.Table.COLUMN_FILENAME);
COLUMN_STATE = c.getColumnIndex(Contribution.Table.COLUMN_STATE);
COLUMN_LOCALURI = c.getColumnIndex(Contribution.Table.COLUMN_LOCAL_URI); COLUMN_LOCALURI = c.getColumnIndex(Contribution.Table.COLUMN_LOCAL_URI);
COLUMN_UPLOADED = c.getColumnIndex(Contribution.Table.COLUMN_UPLOADED);
} }
@Override @Override
@ -56,13 +63,23 @@ public class ContributionsActivity extends AuthenticatedActivity implements Load
@Override @Override
public void bindView(View view, Context context, Cursor cursor) { public void bindView(View view, Context context, Cursor cursor) {
ImageView image = (ImageView)view.findViewById(R.id.contributionImage); ImageView image = (ImageView)view.findViewById(R.id.contributionImage);
TextView title = (TextView)view.findViewById(R.id.contributionTitle); TextView titleView = (TextView)view.findViewById(R.id.contributionTitle);
TextView stateView = (TextView)view.findViewById(R.id.contributionState);
Uri imageUri = Uri.parse(cursor.getString(COLUMN_LOCALURI)); Uri imageUri = Uri.parse(cursor.getString(COLUMN_LOCALURI));
int state = cursor.getInt(COLUMN_STATE);
ImageLoader.getInstance().displayImage(imageUri.toString(), image, contributionDisplayOptions); ImageLoader.getInstance().displayImage(imageUri.toString(), image, contributionDisplayOptions);
title.setText(cursor.getString(COLUMN_FILENAME)); titleView.setText(cursor.getString(COLUMN_FILENAME));
if(state == Contribution.STATE_COMPLETED) {
Date uploaded = new Date(cursor.getLong(COLUMN_UPLOADED));
stateView.setText(SimpleDateFormat.getDateInstance().format(uploaded));
} else if(state == Contribution.STATE_QUEUED) {
stateView.setText("Queued");
} else if(state == Contribution.STATE_IN_PROGRESS) {
stateView.setText("Uploading");
}
} }
} }
@ -82,7 +99,8 @@ public class ContributionsActivity extends AuthenticatedActivity implements Load
Contribution.Table.COLUMN_ID, Contribution.Table.COLUMN_ID,
Contribution.Table.COLUMN_FILENAME, Contribution.Table.COLUMN_FILENAME,
Contribution.Table.COLUMN_LOCAL_URI, Contribution.Table.COLUMN_LOCAL_URI,
Contribution.Table.COLUMN_STATE Contribution.Table.COLUMN_STATE,
Contribution.Table.COLUMN_UPLOADED
}; };
private String CONTRIBUTION_SELECTION = ""; private String CONTRIBUTION_SELECTION = "";