Cleanup gridview code to use appropriate Java object

This commit is contained in:
YuviPanda 2013-02-19 23:40:00 +05:30
parent 8b0d0b3a4e
commit 1a860c6729
4 changed files with 22 additions and 18 deletions

View file

@ -1,6 +1,7 @@
package org.wikimedia.commons;
import android.net.Uri;
import org.wikimedia.commons.contributions.Contribution;
import java.io.Serializable;
import java.util.Date;
@ -43,7 +44,7 @@ public class Media implements Serializable {
}
public String getThumbnailUrl(int width) {
return String.format("%s/%dpx-%s", imageUrl, width, filename);
return Utils.makeThumbUrl(imageUrl, filename, width);
}

View file

@ -110,4 +110,15 @@ public class Utils {
}
return count;
}
public static String makeThumbUrl(String imageUrl, String filename, int width) {
// Ugly Hack!
// Update: OH DEAR GOD WHAT A HORRIBLE HACK I AM SO SORRY
String thumbUrl = imageUrl.replaceFirst("test/", "test/thumb/").replace("commons/", "commons/thumb/") + "/" + width + "px-" + filename.replaceAll("File:", "").replaceAll(" ", "_");
if(thumbUrl.endsWith("jpg") || thumbUrl.endsWith("png") || thumbUrl.endsWith("jpeg")) {
return thumbUrl;
} else {
return thumbUrl + ".png";
}
}
}

View file

@ -114,16 +114,7 @@ public class Contribution extends Media {
}
}
public static String makeThumbUrl(String imageUrl, String filename, int width) {
// Ugly Hack!
// Update: OH DEAR GOD WHAT A HORRIBLE HACK I AM SO SORRY
String thumbUrl = imageUrl.replaceFirst("test/", "test/thumb/").replace("commons/", "commons/thumb/") + "/" + width + "px-" + filename.replaceAll("File:", "").replaceAll(" ", "_");
if(thumbUrl.endsWith("jpg") || thumbUrl.endsWith("png") || thumbUrl.endsWith("jpeg")) {
return thumbUrl;
} else {
return thumbUrl + ".png";
}
}
public ContentValues toContentValues() {
ContentValues cv = new ContentValues();
cv.put(Table.COLUMN_FILENAME, getFilename());

View file

@ -95,21 +95,22 @@ public class ContributionsActivity extends AuthenticatedActivity implements Load
TextView titleView = (TextView)view.findViewById(R.id.contributionTitle);
TextView stateView = (TextView)view.findViewById(R.id.contributionState);
String localUri = cursor.getString(COLUMN_LOCALURI);
String imageUrl = cursor.getString(COLUMN_IMAGE_URL);
String title = cursor.getString(COLUMN_FILENAME);
int state = cursor.getInt(COLUMN_STATE);
Contribution contribution = Contribution.fromCursor(cursor);
String actualUrl = TextUtils.isEmpty(imageUrl) ? localUri : Contribution.makeThumbUrl(imageUrl, title, 320);
String actualUrl = TextUtils.isEmpty(contribution.getImageUrl()) ? contribution.getLocalUri().toString() : contribution.getThumbnailUrl(320);
Log.d("Commons", "Trying URL " + actualUrl);
Log.d("Commons", "For " + contribution.toContentValues());
if(imageView.getTag() == null || !imageView.getTag().equals(actualUrl)) {
Log.d("Commons", "Tag is " + imageView.getTag() + " url is " + actualUrl); //+ " equals is " + imageView.getTag().equals(actualUrl) + " the other thing is " + (imageView.getTag() == null));
ImageLoader.getInstance().displayImage(actualUrl, imageView, contributionDisplayOptions);
imageView.setTag(actualUrl);
}
titleView.setText(Utils.displayTitleFromTitle(title));
switch(state) {
titleView.setText(Utils.displayTitleFromTitle(contribution.getFilename()));
switch(contribution.getState()) {
case Contribution.STATE_COMPLETED:
Date uploaded = new Date(cursor.getLong(COLUMN_UPLOADED));
stateView.setText(SimpleDateFormat.getDateInstance().format(uploaded));