@@ -355,7 +355,7 @@ public void onClick(View v) {
355355 onTextChangeOfPeopleSearchEditText ();
356356 mNotificationManager = (NotificationManager ) getSystemService (Context .NOTIFICATION_SERVICE );
357357 mBuilder = (NotificationCompat .Builder ) new NotificationCompat .Builder (this )
358- .setColor (getColor (R .color .notif_background ));
358+ .setColor (ContextCompat . getColor (this , R .color .notif_background ));
359359 ivSearchPeopleCancel .setOnClickListener (new View .OnClickListener () {
360360 @ Override
361361 public void onClick (View v ) {
@@ -899,7 +899,7 @@ protected void onNewIntent(Intent intent) {
899899 if (mBuilder == null ) {
900900 mBuilder = (NotificationCompat .Builder ) new NotificationCompat .Builder (this )
901901 .setContentTitle (getString (R .string .notif_title ))
902- .setColor (getColor (R .color .notif_background ));
902+ .setColor (ContextCompat . getColor (this , R .color .notif_background ));
903903 }
904904
905905 // Get action and MIME type of intent
@@ -941,8 +941,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
941941
942942 // activity transition animation
943943 ActivityTransitionAnim .transition (ZulipActivity .this );
944- }
945- else if (requestCode == REQUEST_PICK_FILE && resultCode == RESULT_OK ) {
944+ } else if (requestCode == REQUEST_PICK_FILE && resultCode == RESULT_OK ) {
946945 List <Uri > fileUris = new ArrayList <>();
947946 if (data .getData () != null ) {
948947 fileUris .add (data .getData ());
@@ -1214,8 +1213,6 @@ private void uploadFile(final File file) {
12141213 // MultipartBody.Part is used to send also the actual file name
12151214 MultipartBody .Part body = prepareFilePart ("file" , file , notifId );
12161215
1217- final String loadingMsg = getResources ().getString (R .string .uploading_message );
1218-
12191216 // start notification
12201217 setNotification (notifId , getString (R .string .init_notif_title ));
12211218
@@ -1225,40 +1222,44 @@ private void uploadFile(final File file) {
12251222 call .enqueue (new DefaultCallback <UploadResponse >() {
12261223 @ Override
12271224 public void onSuccess (Call <UploadResponse > call , Response <UploadResponse > response ) {
1228- if (!isDestroyed ()) {
1229- String filePathOnServer = "" ;
1230- UploadResponse uploadResponse = response .body ();
1231- filePathOnServer = uploadResponse .getUri ();
1232- if (!filePathOnServer .equals ("" )) {
1233- endNotification (notifId , getString (R .string .finish_notif_title ));
1234-
1235- // add uploaded file url on server to composed message
1236- messageEt .append ("\n [" + file .getName () + "](" +
1237- UrlHelper .addHost (filePathOnServer ) + ")" );
1238- displayFAB (false );
1239- displayChatBox (true );
1240- } else {
1241- endNotification (notifId , getString (R .string .failed_to_upload ));
1242- }
1243- mNotificationManager .cancel (notifId );
1225+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 && isDestroyed ()) {
1226+ return ;
12441227 }
1228+ String filePathOnServer = "" ;
1229+ UploadResponse uploadResponse = response .body ();
1230+ filePathOnServer = uploadResponse .getUri ();
1231+ if (!filePathOnServer .equals ("" )) {
1232+ endNotification (notifId , getString (R .string .finish_notif_title ));
1233+
1234+ // add uploaded file url on server to composed message
1235+ messageEt .append ("\n [" + file .getName () + "](" +
1236+ UrlHelper .addHost (filePathOnServer ) + ")" );
1237+ displayFAB (false );
1238+ displayChatBox (true );
1239+ } else {
1240+ endNotification (notifId , getString (R .string .failed_to_upload ));
1241+ }
1242+ mNotificationManager .cancel (notifId );
1243+
12451244 }
12461245
12471246 @ Override
12481247 public void onError (Call <UploadResponse > call , Response <UploadResponse > response ) {
1249- if (!isDestroyed ()) {
1250- endNotification (notifId , getString (R .string .failed_to_upload ));
1251- mNotificationManager .cancel (notifId );
1248+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 && isDestroyed ()) {
1249+ return ;
12521250 }
1251+ endNotification (notifId , getString (R .string .failed_to_upload ));
1252+ mNotificationManager .cancel (notifId );
12531253 }
12541254
12551255 @ Override
12561256 public void onFailure (Call <UploadResponse > call , Throwable t ) {
1257- if (!isDestroyed ()) {
1258- endNotification (notifId , getString (R .string .failed_to_upload ));
1259- mNotificationManager .cancel (notifId );
1260- ZLog .logException (t );
1257+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 && isDestroyed ()) {
1258+ return ;
12611259 }
1260+ endNotification (notifId , getString (R .string .failed_to_upload ));
1261+ mNotificationManager .cancel (notifId );
1262+ ZLog .logException (t );
12621263 }
12631264 });
12641265 }
0 commit comments