@ -59,6 +59,7 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
switch ( intentAction ) {
switch ( intentAction ) {
case ACTION_CANCEL_UPLOAD :
case ACTION_CANCEL_UPLOAD :
String uploadID = intentBundle . getString ( UPLOAD_ID_KEY ) ;
String uploadID = intentBundle . getString ( UPLOAD_ID_KEY ) ;
Timber . d ( "Received ACTION_CANCEL_UPLOAD (id: %s)" , uploadID ) ;
UploadService . stopUpload ( uploadID ) ;
UploadService . stopUpload ( uploadID ) ;
break ;
break ;
/ * case ACTION_RETRY_UPLOAD :
/ * case ACTION_RETRY_UPLOAD :
@ -86,6 +87,7 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
@Override
@Override
public void onProgress ( Context context , UploadInfo uploadInfo ) {
public void onProgress ( Context context , UploadInfo uploadInfo ) {
Timber . i ( "Upload in progress (id: %s)" , uploadInfo . getUploadId ( ) ) ;
if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . LOLLIPOP & &
if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . LOLLIPOP & &
uploadInfo . getUploadId ( ) . equals ( dialogUploadID ) & &
uploadInfo . getUploadId ( ) . equals ( dialogUploadID ) & &
uploadProgressDialog ! = null ) {
uploadProgressDialog ! = null ) {
@ -94,8 +96,9 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
alertDialogNeutral . setOnClickListener ( v - > uploadProgressDialog . dismiss ( ) ) ;
alertDialogNeutral . setOnClickListener ( v - > uploadProgressDialog . dismiss ( ) ) ;
Button alertDialogNegative = uploadProgressDialog . getButton ( AlertDialog . BUTTON_NEGATIVE ) ;
Button alertDialogNegative = uploadProgressDialog . getButton ( AlertDialog . BUTTON_NEGATIVE ) ;
alertDialogNegative . setText ( R . string . upload_ cancel) ;
alertDialogNegative . setText ( R . string . cancel ) ;
alertDialogNegative . setOnClickListener ( v - > {
alertDialogNegative . setOnClickListener ( v - > {
Timber . d ( "Cancelling upload (id: %s)" , dialogUploadID ) ;
UploadService . stopUpload ( dialogUploadID ) ;
UploadService . stopUpload ( dialogUploadID ) ;
uploadProgressDialog . dismiss ( ) ;
uploadProgressDialog . dismiss ( ) ;
} ) ;
} ) ;
@ -124,6 +127,7 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
@Override
@Override
public void onError ( Context context , UploadInfo uploadInfo , ServerResponse serverResponse ,
public void onError ( Context context , UploadInfo uploadInfo , ServerResponse serverResponse ,
Exception exception ) {
Exception exception ) {
Timber . i ( "Error while uploading (id: %s)" , uploadInfo . getUploadId ( ) ) ;
if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . LOLLIPOP & &
if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . LOLLIPOP & &
uploadInfo . getUploadId ( ) . equals ( dialogUploadID ) & &
uploadInfo . getUploadId ( ) . equals ( dialogUploadID ) & &
uploadProgressDialog ! = null ) {
uploadProgressDialog ! = null ) {
@ -137,13 +141,9 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
} ) ; * /
} ) ; * /
Button alertDialogNegative = uploadProgressDialog . getButton ( AlertDialog . BUTTON_NEGATIVE ) ;
Button alertDialogNegative = uploadProgressDialog . getButton ( AlertDialog . BUTTON_NEGATIVE ) ;
alertDialogNegative . setText ( R . string . upload_ cancel) ;
alertDialogNegative . setText ( R . string . cancel ) ;
alertDialogNegative . setOnClickListener ( v - > {
alertDialogNegative . setOnClickListener ( v - > {
NotificationManager notificationManager = ( NotificationManager ) context . getApplicationContext ( ) .
cancelNotification ( context , uploadInfo . getNotificationID ( ) ) ;
getSystemService ( Context . NOTIFICATION_SERVICE ) ;
if ( notificationManager ! = null ) {
notificationManager . cancel ( uploadInfo . getNotificationID ( ) ) ;
}
UploadsHelper . deleteTempFiles ( storage ) ;
UploadsHelper . deleteTempFiles ( storage ) ;
uploadProgressDialog . dismiss ( ) ;
uploadProgressDialog . dismiss ( ) ;
} ) ;
} ) ;
@ -163,12 +163,7 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
}
}
}
}
} else {
} else {
NotificationManager notificationManager = ( NotificationManager ) context . getApplicationContext ( ) .
cancelNotification ( context , uploadInfo . getNotificationID ( ) ) ;
getSystemService ( Context . NOTIFICATION_SERVICE ) ;
if ( notificationManager ! = null ) {
notificationManager . cancel ( uploadInfo . getNotificationID ( ) ) ;
}
Intent combinedActionsIntent = new Intent ( UploadsReceiver . ACTION_COMBINED_UPLOAD ) ;
Intent combinedActionsIntent = new Intent ( UploadsReceiver . ACTION_COMBINED_UPLOAD ) ;
combinedActionsIntent . putExtra ( UploadsReceiver . UPLOAD_ID_KEY , uploadInfo . getUploadId ( ) ) ;
combinedActionsIntent . putExtra ( UploadsReceiver . UPLOAD_ID_KEY , uploadInfo . getUploadId ( ) ) ;
context . sendBroadcast ( combinedActionsIntent ) ;
context . sendBroadcast ( combinedActionsIntent ) ;
@ -189,6 +184,7 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
String response = serverResponse . getBodyAsString ( ) ;
String response = serverResponse . getBodyAsString ( ) ;
if ( response . contains ( "Η προσθήκη του αρχείου ήταν επιτυχημένη." ) | | response . contains ( "The upload was successful." ) ) {
if ( response . contains ( "Η προσθήκη του αρχείου ήταν επιτυχημένη." ) | | response . contains ( "The upload was successful." ) ) {
Timber . i ( "Upload completed successfully (id: %s)" , uploadInfo . getUploadId ( ) ) ;
Toast . makeText ( context . getApplicationContext ( ) , "Upload completed successfully" , Toast . LENGTH_SHORT ) . show ( ) ;
Toast . makeText ( context . getApplicationContext ( ) , "Upload completed successfully" , Toast . LENGTH_SHORT ) . show ( ) ;
BaseApplication . getInstance ( ) . logFirebaseAnalyticsEvent ( "file_upload" , null ) ;
BaseApplication . getInstance ( ) . logFirebaseAnalyticsEvent ( "file_upload" , null ) ;
}
}
@ -207,21 +203,17 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
@Override
@Override
public void onCancelled ( Context context , UploadInfo uploadInfo ) {
public void onCancelled ( Context context , UploadInfo uploadInfo ) {
Timber . i ( "Upload cancelled (id: %s)" , uploadInfo . getUploadId ( ) ) ;
if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . LOLLIPOP ) {
if ( Build . VERSION . SDK_INT < Build . VERSION_CODES . LOLLIPOP ) {
uploadProgressDialog = null ;
uploadProgressDialog = null ;
dialogUploadID = null ;
dialogUploadID = null ;
}
}
Toast . makeText ( context . getApplicationContext ( ) , R . string . upload_canceled , Toast . LENGTH_SHORT ) . show ( ) ;
Toast . makeText ( context . getApplicationContext ( ) , R . string . upload_cancell ed , Toast . LENGTH_SHORT ) . show ( ) ;
if ( storage = = null ) {
if ( storage = = null )
storage = new Storage ( context . getApplicationContext ( ) ) ;
storage = new Storage ( context . getApplicationContext ( ) ) ;
}
/ * NotificationManager notificationManager = ( NotificationManager ) context . getApplicationContext ( ) .
//cancelNotification(context, uploadInfo.getNotificationID());
getSystemService ( Context . NOTIFICATION_SERVICE ) ;
if ( notificationManager ! = null ) {
notificationManager . cancel ( uploadInfo . getNotificationID ( ) ) ;
} * /
UploadsHelper . deleteTempFiles ( storage ) ;
UploadsHelper . deleteTempFiles ( storage ) ;
}
}
@ -231,4 +223,11 @@ public class UploadsReceiver extends UploadServiceBroadcastReceiver {
UploadsReceiver . dialogUploadID = dialogUploadID ;
UploadsReceiver . dialogUploadID = dialogUploadID ;
//UploadsReceiver.multipartUploadRetryIntent = multipartUploadRetryIntent;
//UploadsReceiver.multipartUploadRetryIntent = multipartUploadRetryIntent;
}
}
private void cancelNotification ( Context context , int notificationId ) {
NotificationManager notificationManager = ( NotificationManager ) context . getApplicationContext ( ) .
getSystemService ( Context . NOTIFICATION_SERVICE ) ;
if ( notificationManager ! = null )
notificationManager . cancel ( notificationId ) ;
}
}
}