Indentation fixing.

Unsure how it got so out of whack to begin with
This commit is contained in:
YuviPanda 2013-02-02 15:30:01 +05:30
parent da92ec7235
commit 569143e44b

View file

@ -45,7 +45,7 @@ public class UploadService extends IntentService {
private Notification curProgressNotification; private Notification curProgressNotification;
private int toUpload; private int toUpload;
public UploadService(String name) { public UploadService(String name) {
super(name); super(name);
} }
@ -53,6 +53,7 @@ public class UploadService extends IntentService {
public UploadService() { public UploadService() {
super("UploadService"); super("UploadService");
} }
// DO NOT HAVE NOTIFICATION ID OF 0 FOR ANYTHING // DO NOT HAVE NOTIFICATION ID OF 0 FOR ANYTHING
// See http://stackoverflow.com/questions/8725909/startforeground-does-not-show-my-notification // See http://stackoverflow.com/questions/8725909/startforeground-does-not-show-my-notification
// Seriously, Android? // Seriously, Android?
@ -66,7 +67,7 @@ public class UploadService extends IntentService {
String notificationTag; String notificationTag;
boolean notificationTitleChanged; boolean notificationTitleChanged;
Contribution contribution; Contribution contribution;
String notificationProgressTitle; String notificationProgressTitle;
String notificationFinishingTitle; String notificationFinishingTitle;
@ -77,6 +78,7 @@ public class UploadService extends IntentService {
this.notificationFinishingTitle = notificationFinishingTitle; this.notificationFinishingTitle = notificationFinishingTitle;
this.contribution = contribution; this.contribution = contribution;
} }
@Override @Override
public void onProgress(long transferred, long total) { public void onProgress(long transferred, long total) {
Log.d("Commons", String.format("Uploaded %d of %d", transferred, total)); Log.d("Commons", String.format("Uploaded %d of %d", transferred, total));
@ -96,17 +98,18 @@ public class UploadService extends IntentService {
curView.setTextViewText(R.id.uploadNotificationTitle, notificationFinishingTitle); curView.setTextViewText(R.id.uploadNotificationTitle, notificationFinishingTitle);
notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification); notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
} else { } else {
curNotification.contentView.setProgressBar(R.id.uploadNotificationProgress, 100, (int)(((double)transferred / (double)total) * 100), false); curNotification.contentView.setProgressBar(R.id.uploadNotificationProgress, 100, (int) (((double) transferred / (double) total) * 100), false);
notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification); notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
Intent mediaUploadProgressIntent = new Intent(INTENT_CONTRIBUTION_STATE_CHANGED); Intent mediaUploadProgressIntent = new Intent(INTENT_CONTRIBUTION_STATE_CHANGED);
// mediaUploadProgressIntent.putExtra(EXTRA_MEDIA contribution); // mediaUploadProgressIntent.putExtra(EXTRA_MEDIA contribution);
mediaUploadProgressIntent.putExtra(EXTRA_TRANSFERRED_BYTES, transferred); mediaUploadProgressIntent.putExtra(EXTRA_TRANSFERRED_BYTES, transferred);
localBroadcastManager.sendBroadcast(mediaUploadProgressIntent); localBroadcastManager.sendBroadcast(mediaUploadProgressIntent);
} }
} }
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -117,14 +120,14 @@ public class UploadService extends IntentService {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
localBroadcastManager = LocalBroadcastManager.getInstance(this); localBroadcastManager = LocalBroadcastManager.getInstance(this);
app = (CommonsApplication)this.getApplicationContext(); app = (CommonsApplication) this.getApplicationContext();
contributionsProviderClient = this.getContentResolver().acquireContentProviderClient(ContributionsContentProvider.AUTHORITY); contributionsProviderClient = this.getContentResolver().acquireContentProviderClient(ContributionsContentProvider.AUTHORITY);
} }
private String getRealPathFromURI(Uri contentUri) { private String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA }; String[] proj = {MediaStore.Images.Media.DATA};
CursorLoader loader = new CursorLoader(this, contentUri, proj, null, null, null); CursorLoader loader = new CursorLoader(this, contentUri, proj, null, null, null);
Cursor cursor = loader.loadInBackground(); Cursor cursor = loader.loadInBackground();
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
@ -134,7 +137,7 @@ public class UploadService extends IntentService {
private Contribution mediaFromIntent(Intent intent) { private Contribution mediaFromIntent(Intent intent) {
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
Uri mediaUri = (Uri)extras.getParcelable(EXTRA_MEDIA_URI); Uri mediaUri = (Uri) extras.getParcelable(EXTRA_MEDIA_URI);
String filename = intent.getStringExtra(EXTRA_TARGET_FILENAME); String filename = intent.getStringExtra(EXTRA_TARGET_FILENAME);
String description = intent.getStringExtra(EXTRA_DESCRIPTION); String description = intent.getStringExtra(EXTRA_DESCRIPTION);
String editSummary = intent.getStringExtra(EXTRA_EDIT_SUMMARY); String editSummary = intent.getStringExtra(EXTRA_EDIT_SUMMARY);
@ -144,16 +147,16 @@ public class UploadService extends IntentService {
Long length = null; Long length = null;
try { try {
length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength(); length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength();
} catch (FileNotFoundException e) { } catch(FileNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
Log.d("Commons", "MimeType is " + mimeType); Log.d("Commons", "MimeType is " + mimeType);
if (mimeType.startsWith("image/")) { if(mimeType.startsWith("image/")) {
Cursor cursor = this.getContentResolver().query(mediaUri, Cursor cursor = this.getContentResolver().query(mediaUri,
new String[]{MediaStore.Images.ImageColumns.DATE_TAKEN}, null, null, null); new String[]{MediaStore.Images.ImageColumns.DATE_TAKEN}, null, null, null);
if (cursor.getCount() != 0) { if(cursor.getCount() != 0) {
cursor.moveToFirst(); cursor.moveToFirst();
dateCreated = new Date(cursor.getLong(0)); dateCreated = new Date(cursor.getLong(0));
} }
@ -163,6 +166,7 @@ public class UploadService extends IntentService {
Contribution contribution = new Contribution(mediaUri, null, filename, description, null, length, dateCreated, null, app.getCurrentAccount().name, editSummary); Contribution contribution = new Contribution(mediaUri, null, filename, description, null, length, dateCreated, null, app.getCurrentAccount().name, editSummary);
return contribution; return contribution;
} }
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
toUpload++; toUpload++;
@ -186,109 +190,109 @@ public class UploadService extends IntentService {
@Override @Override
protected void onHandleIntent(Intent intent) { protected void onHandleIntent(Intent intent) {
MWApi api = app.getApi(); MWApi api = app.getApi();
ApiResult result; ApiResult result;
RemoteViews notificationView; RemoteViews notificationView;
Contribution contribution; Contribution contribution;
InputStream file = null; InputStream file = null;
contribution = (Contribution)intent.getSerializableExtra("dummy-data"); contribution = (Contribution) intent.getSerializableExtra("dummy-data");
String notificationTag = contribution.getLocalUri().toString(); String notificationTag = contribution.getLocalUri().toString();
try { try {
file = this.getContentResolver().openInputStream(contribution.getLocalUri()); file = this.getContentResolver().openInputStream(contribution.getLocalUri());
} catch (FileNotFoundException e) { } catch(FileNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
notificationView = new RemoteViews(getPackageName(), R.layout.layout_upload_progress); notificationView = new RemoteViews(getPackageName(), R.layout.layout_upload_progress);
notificationView.setTextViewText(R.id.uploadNotificationTitle, String.format(getString(R.string.upload_progress_notification_title_start), contribution.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); notificationView.setProgressBar(R.id.uploadNotificationProgress, 100, 0, false);
Log.d("Commons", "Before execution!");
curProgressNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContent(notificationView)
.setOngoing(true)
.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, ContributionsActivity.class), 0))
.setTicker(String.format(getString(R.string.upload_progress_notification_title_in_progress), contribution.getFilename()))
.getNotification();
this.startForeground(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curProgressNotification);
Log.d("Commons", "Just before");
try { Log.d("Commons", "Before execution!");
if(!api.validateLogin()) { curProgressNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
// Need to revalidate! .setSmallIcon(R.drawable.ic_launcher)
if(app.revalidateAuthToken()) { .setAutoCancel(true)
Log.d("Commons", "Successfully revalidated token!"); .setContent(notificationView)
} else { .setOngoing(true)
Log.d("Commons", "Unable to revalidate :("); .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, ContributionsActivity.class), 0))
// TODO: Put up a new notification, ask them to re-login .setTicker(String.format(getString(R.string.upload_progress_notification_title_in_progress), contribution.getFilename()))
stopForeground(true); .getNotification();
Toast failureToast = Toast.makeText(this, R.string.authentication_failed, Toast.LENGTH_LONG);
failureToast.show();
return;
}
}
NotificationUpdateProgressListener notificationUpdater = new NotificationUpdateProgressListener(curProgressNotification, notificationTag,
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(contribution.getFilename(), file, contribution.getDataLength(), contribution.getPageContents(), contribution.getEditSummary(), notificationUpdater);
} catch (IOException e) {
Log.d("Commons", "I have a network fuckup");
stopForeground(true);
Notification failureNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContentIntent(PendingIntent.getService(getApplicationContext(), 0, intent, 0))
.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);
contribution.setState(Contribution.STATE_QUEUED); this.startForeground(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curProgressNotification);
contribution.save();
return;
} finally {
toUpload--;
}
Log.d("Commons", "Response is" + CommonsApplication.getStringFromDOM(result.getDocument()));
stopForeground(true);
curProgressNotification = null;
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // Assuming MW always gives me UTC Log.d("Commons", "Just before");
try {
if(!api.validateLogin()) {
// Need to revalidate!
if(app.revalidateAuthToken()) {
Log.d("Commons", "Successfully revalidated token!");
} else {
Log.d("Commons", "Unable to revalidate :(");
// TODO: Put up a new notification, ask them to re-login
stopForeground(true);
Toast failureToast = Toast.makeText(this, R.string.authentication_failed, Toast.LENGTH_LONG);
failureToast.show();
return;
}
}
NotificationUpdateProgressListener notificationUpdater = new NotificationUpdateProgressListener(curProgressNotification, notificationTag,
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(contribution.getFilename(), file, contribution.getDataLength(), contribution.getPageContents(), contribution.getEditSummary(), notificationUpdater);
} catch(IOException e) {
Log.d("Commons", "I have a network fuckup");
stopForeground(true);
Notification failureNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContentIntent(PendingIntent.getService(getApplicationContext(), 0, intent, 0))
.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);
contribution.setState(Contribution.STATE_QUEUED);
contribution.save();
return;
} finally {
toUpload--;
}
Log.d("Commons", "Response is" + CommonsApplication.getStringFromDOM(result.getDocument()));
stopForeground(true);
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; Date dateUploaded = null;
try { try {
dateUploaded = isoFormat.parse(result.getString("/api/upload/imageinfo/@timestamp")); dateUploaded = isoFormat.parse(result.getString("/api/upload/imageinfo/@timestamp"));
} catch (java.text.ParseException e) { } catch(java.text.ParseException e) {
throw new RuntimeException(e); // Hopefully mediawiki doesn't give me bogus stuff? throw new RuntimeException(e); // Hopefully mediawiki doesn't give me bogus stuff?
} }
Intent openUploadedPageIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(descUrl)); 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)
.setContentTitle(String.format(getString(R.string.upload_completed_notification_title), contribution.getFilename())) .setContentTitle(String.format(getString(R.string.upload_completed_notification_title), contribution.getFilename()))
.setContentText(getString(R.string.upload_completed_notification_text)) .setContentText(getString(R.string.upload_completed_notification_text))
.setTicker(String.format(getString(R.string.upload_completed_notification_title), contribution.getFilename())) .setTicker(String.format(getString(R.string.upload_completed_notification_title), contribution.getFilename()))
.setContentIntent(PendingIntent.getActivity(this, 0, openUploadedPageIntent, 0)) .setContentIntent(PendingIntent.getActivity(this, 0, openUploadedPageIntent, 0))
.getNotification(); .getNotification();
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.setDateUploaded(dateUploaded);
contribution.save(); contribution.save();
} }
} }