Show count of uploads being queued up

This commit is contained in:
YuviPanda 2013-01-30 02:41:02 +05:30
parent 738cdd4c8a
commit dd758a7964
5 changed files with 52 additions and 8 deletions

View file

@ -29,15 +29,34 @@
android:focusableInTouchMode="true"
android:ellipsize="marquee"/>
<ProgressBar
android:id="@+id/uploadNotificationProgress"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ProgressBar
android:id="@+id/uploadNotificationProgress"
android:layout_width="0px"
android:layout_height="fill_parent"
android:indeterminate="false"
android:indeterminateOnly="false"
android:progressDrawable="@android:drawable/progress_horizontal" >
android:layout_weight="1"
style="@style/NotificationProgress" >
</ProgressBar>
<TextView
android:id="@+id/uploadNotificationsCount"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:singleLine="true"
android:focusable="true"
android:text="1 left"
android:focusableInTouchMode="true"
style="@style/NotificationText"
android:layout_marginLeft="8dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -1,5 +1,7 @@
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />
<style name="AppTheme" parent="android:Theme.Holo.Light" />
<style name="NotificationProgress" parent="android:Widget.Holo.ProgressBar.Horizontal" />
</resources>

View file

@ -28,6 +28,7 @@
<string name="upload_progress_notification_title_finishing">Finishing uploading %1$s</string>
<string name="upload_failed_notification_title">Uploading %1$s failed</string>
<string name="upload_failed_notification_subtitle">Tap to retry</string>
<string name="uploads_pending_notification_indicator">%d</string>
<string name="transcoding_progress_title_start">Starting %1$s Transcoding</string>
<string name="transcoding_progress_title_in_progress">Transcoding %1$s</string>

View file

@ -15,4 +15,6 @@
<item name="android:textStyle">bold</item>
</style>
<style name="NotificationProgress" parent="Theme.Commons" />
</resources>

View file

@ -32,6 +32,10 @@ public class UploadService extends IntentService {
private NotificationManager notificationManager;
private CommonsApplication app;
private Notification curProgressNotification;
private int toUpload;
public UploadService(String name) {
super(name);
@ -68,6 +72,8 @@ public class UploadService extends IntentService {
RemoteViews curView = curNotification.contentView;
if(!notificationTitleChanged) {
curView.setTextViewText(R.id.uploadNotificationTitle, notificationProgressTitle);
curView.setTextViewText(R.id.uploadNotificationsCount, String.format(getString(R.string.uploads_pending_notification_indicator), toUpload));
Log.d("Commons", String.format("%d uploads left", toUpload));
notificationTitleChanged = true;
}
if(transferred == total) {
@ -102,7 +108,18 @@ public class UploadService extends IntentService {
cursor.moveToFirst();
return cursor.getString(column_index);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
toUpload++;
if(curProgressNotification != null) {
curProgressNotification.contentView.setTextViewText(R.id.uploadNotificationsCount, String.format(getString(R.string.uploads_pending_notification_indicator), toUpload));
Log.d("Commons", String.format("%d uploads left", toUpload));
notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curProgressNotification);
}
return super.onStartCommand(intent, flags, startId);
}
@Override
protected void onHandleIntent(Intent intent) {
MWApi api = app.getApi();
@ -145,7 +162,7 @@ public class UploadService extends IntentService {
notificationView.setProgressBar(R.id.uploadNotificationProgress, 100, 0, false);
Log.d("Commons", "Before execution!");
Notification progressNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
curProgressNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContent(notificationView)
@ -154,10 +171,10 @@ public class UploadService extends IntentService {
.setTicker(String.format(getString(R.string.upload_progress_notification_title_in_progress), filename))
.getNotification();
this.startForeground(NOTIFICATION_DOWNLOAD_IN_PROGRESS, progressNotification);
this.startForeground(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curProgressNotification);
Log.d("Commons", "Just before");
NotificationUpdateProgressListener notificationUpdater = new NotificationUpdateProgressListener(progressNotification, notificationTag,
NotificationUpdateProgressListener notificationUpdater = new NotificationUpdateProgressListener(curProgressNotification, notificationTag,
String.format(getString(R.string.upload_progress_notification_title_in_progress), filename),
String.format(getString(R.string.upload_progress_notification_title_finishing), filename)
);
@ -190,10 +207,13 @@ public class UploadService extends IntentService {
.getNotification();
notificationManager.notify(NOTIFICATION_UPLOAD_FAILED, failureNotification);
return;
} finally {
toUpload--;
}
Log.d("Commons", "Response is" + CommonsApplication.getStringFromDOM(result.getDocument()));
stopForeground(true);
curProgressNotification = null;
String descUrl = result.getString("/api/upload/imageinfo/@descriptionurl");