mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fix to make notifications not crash in 2.3
This removes the progressbar from the notifications on 2.3, which is much less than ideal. However after blindly debugging for about a week, I couldn't really figure out a way to make custom views in Notifications work across both platforms. So this will have to do until I figure a proper way out.
This commit is contained in:
parent
5396541f4e
commit
1ec9be01f8
2 changed files with 20 additions and 89 deletions
|
|
@ -1,61 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:padding="10dp" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/uploadNotificationIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:src="@drawable/ic_launcher"
|
||||
android:layout_marginRight="10dp" />
|
||||
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/uploadNotificationTitle"
|
||||
style="@style/NotificationTitle"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Uploading image to commons"
|
||||
android:singleLine="true"
|
||||
android:marqueeRepeatLimit="marquee_forever"
|
||||
android:scrollHorizontally="true"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:ellipsize="marquee"/>
|
||||
|
||||
<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: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:focusableInTouchMode="true"
|
||||
style="@style/NotificationText"
|
||||
android:layout_marginLeft="8dp"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
@ -3,6 +3,7 @@ package org.wikimedia.commons;
|
|||
import java.io.*;
|
||||
import java.util.Date;
|
||||
|
||||
import android.graphics.BitmapFactory;
|
||||
import org.mediawiki.api.*;
|
||||
import org.wikimedia.commons.contributions.Contribution;
|
||||
import org.wikimedia.commons.contributions.ContributionsActivity;
|
||||
|
|
@ -34,7 +35,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
private ContentProviderClient contributionsProviderClient;
|
||||
private CommonsApplication app;
|
||||
|
||||
private Notification curProgressNotification;
|
||||
private NotificationCompat.Builder curProgressNotification;
|
||||
|
||||
private int toUpload;
|
||||
|
||||
|
|
@ -47,7 +48,6 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
|
||||
private class NotificationUpdateProgressListener implements ProgressListener {
|
||||
|
||||
Notification curNotification;
|
||||
String notificationTag;
|
||||
boolean notificationTitleChanged;
|
||||
Contribution contribution;
|
||||
|
|
@ -55,8 +55,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
String notificationProgressTitle;
|
||||
String notificationFinishingTitle;
|
||||
|
||||
public NotificationUpdateProgressListener(Notification curNotification, String notificationTag, String notificationProgressTitle, String notificationFinishingTitle, Contribution contribution) {
|
||||
this.curNotification = curNotification;
|
||||
public NotificationUpdateProgressListener(String notificationTag, String notificationProgressTitle, String notificationFinishingTitle, Contribution contribution) {
|
||||
this.notificationTag = notificationTag;
|
||||
this.notificationProgressTitle = notificationProgressTitle;
|
||||
this.notificationFinishingTitle = notificationFinishingTitle;
|
||||
|
|
@ -66,24 +65,20 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
@Override
|
||||
public void onProgress(long transferred, long total) {
|
||||
Log.d("Commons", String.format("Uploaded %d of %d", transferred, total));
|
||||
RemoteViews curView = curNotification.contentView;
|
||||
if(!notificationTitleChanged) {
|
||||
curView.setTextViewText(R.id.uploadNotificationTitle, notificationProgressTitle);
|
||||
if(toUpload != 1) {
|
||||
curView.setTextViewText(R.id.uploadNotificationsCount, String.format(getString(R.string.uploads_pending_notification_indicator), toUpload));
|
||||
Log.d("Commons", String.format("%d uploads left", toUpload));
|
||||
}
|
||||
curProgressNotification.setContentTitle(notificationProgressTitle);
|
||||
Log.d("Commons", String.format("%d uploads left", toUpload));
|
||||
notificationTitleChanged = true;
|
||||
contribution.setState(Contribution.STATE_IN_PROGRESS);
|
||||
}
|
||||
if(transferred == total) {
|
||||
// Completed!
|
||||
curView.setTextViewText(R.id.uploadNotificationTitle, notificationFinishingTitle);
|
||||
notificationManager.notify(NOTIFICATION_UPLOAD_IN_PROGRESS, curNotification);
|
||||
curProgressNotification.setContentTitle(notificationFinishingTitle);
|
||||
curProgressNotification.setProgress(0, 100, true);
|
||||
} else {
|
||||
curNotification.contentView.setProgressBar(R.id.uploadNotificationProgress, 100, (int) (((double) transferred / (double) total) * 100), false);
|
||||
notificationManager.notify(NOTIFICATION_UPLOAD_IN_PROGRESS, curNotification);
|
||||
curProgressNotification.setProgress(100, (int) (((double) transferred / (double) total) * 100), false);
|
||||
}
|
||||
notificationManager.notify(NOTIFICATION_UPLOAD_IN_PROGRESS, curProgressNotification.build());
|
||||
contribution.setTransferred(transferred);
|
||||
contribution.save();
|
||||
}
|
||||
|
|
@ -129,9 +124,9 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
contribution.save();
|
||||
toUpload++;
|
||||
if (curProgressNotification != null && toUpload != 1) {
|
||||
curProgressNotification.contentView.setTextViewText(R.id.uploadNotificationsCount, String.format(getString(R.string.uploads_pending_notification_indicator), toUpload));
|
||||
curProgressNotification.setContentText(String.format(getString(R.string.uploads_pending_notification_indicator), toUpload));
|
||||
Log.d("Commons", String.format("%d uploads left", toUpload));
|
||||
notificationManager.notify(NOTIFICATION_UPLOAD_IN_PROGRESS, curProgressNotification);
|
||||
notificationManager.notify(NOTIFICATION_UPLOAD_IN_PROGRESS, curProgressNotification.build());
|
||||
}
|
||||
|
||||
super.queue(what, contribution);
|
||||
|
|
@ -166,7 +161,6 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
MWApi api = app.getApi();
|
||||
|
||||
ApiResult result;
|
||||
RemoteViews notificationView;
|
||||
InputStream file = null;
|
||||
|
||||
String notificationTag = contribution.getLocalUri().toString();
|
||||
|
|
@ -178,21 +172,19 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
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), contribution.getFilename()));
|
||||
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)
|
||||
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
|
||||
.setAutoCancel(true)
|
||||
.setContent(notificationView)
|
||||
.setContentTitle(String.format(getString(R.string.upload_progress_notification_title_start), contribution.getFilename()))
|
||||
.setContentText(String.format(getString(R.string.uploads_pending_notification_indicator), toUpload))
|
||||
.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();
|
||||
.setProgress(100, 0, true)
|
||||
.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(this, ContributionsActivity.class), 0))
|
||||
.setTicker(String.format(getString(R.string.upload_progress_notification_title_in_progress), contribution.getFilename()));
|
||||
|
||||
this.startForeground(NOTIFICATION_UPLOAD_IN_PROGRESS, curProgressNotification);
|
||||
this.startForeground(NOTIFICATION_UPLOAD_IN_PROGRESS, curProgressNotification.build());
|
||||
|
||||
try {
|
||||
if(!api.validateLogin()) {
|
||||
|
|
@ -208,7 +200,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
return;
|
||||
}
|
||||
}
|
||||
NotificationUpdateProgressListener notificationUpdater = new NotificationUpdateProgressListener(curProgressNotification, notificationTag,
|
||||
NotificationUpdateProgressListener notificationUpdater = new NotificationUpdateProgressListener(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
|
||||
|
|
@ -266,7 +258,7 @@ public class UploadService extends HandlerService<Contribution> {
|
|||
.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();
|
||||
.build();
|
||||
notificationManager.notify(NOTIFICATION_UPLOAD_FAILED, failureNotification);
|
||||
|
||||
contribution.setState(Contribution.STATE_FAILED);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue