Эх сурвалжийг харах

Fixed all complaints

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 жил өмнө
parent
commit
79fcaec2a6

+ 14 - 3
src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java

@@ -31,10 +31,15 @@ import android.database.Cursor;
 import android.graphics.Point;
 import android.os.Build;
 import android.os.CancellationSignal;
+import android.os.Handler;
+import android.os.Looper;
 import android.os.ParcelFileDescriptor;
 import android.provider.DocumentsProvider;
 import android.util.Log;
+import android.widget.Toast;
 
+import com.owncloud.android.MainApp;
+import com.owncloud.android.R;
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
@@ -42,7 +47,6 @@ import com.owncloud.android.files.services.FileDownloader;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.operations.SynchronizeFileOperation;
 import com.owncloud.android.ui.activity.ConflictsResolveActivity;
-import com.owncloud.android.ui.notifications.NotificationUtils;
 import com.owncloud.android.utils.FileStorageUtils;
 
 import org.nextcloud.providers.cursors.FileCursor;
@@ -161,11 +165,11 @@ public class DocumentsStorageProvider extends DocumentsProvider {
                     } else {
                         FileStorageUtils.checkIfFileFinishedSaving(finalFile);
                         if (!result.isSuccess()) {
-                            NotificationUtils.showSyncFailedNotification();
+                            showToast();
                         }
                     }
                 } catch (Exception exception) {
-                    NotificationUtils.showSyncFailedNotification();
+                    showToast();
                 }
             });
 
@@ -180,6 +184,13 @@ public class DocumentsStorageProvider extends DocumentsProvider {
         return ParcelFileDescriptor.open(new File(file.getStoragePath()), ParcelFileDescriptor.parseMode(mode));
     }
 
+    private void showToast() {
+        Handler handler = new Handler(Looper.getMainLooper());
+        handler.post(() -> Toast.makeText(MainApp.getAppContext(),
+                R.string.file_not_synced,
+                Toast.LENGTH_SHORT).show());
+    }
+
     @Override
     public boolean onCreate() {
         return true;

+ 11 - 0
src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

@@ -34,6 +34,7 @@ import android.support.design.widget.Snackbar;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
 import android.support.v4.content.FileProvider;
+import android.util.Log;
 import android.view.View;
 import android.webkit.MimeTypeMap;
 
@@ -178,6 +179,11 @@ public class FileOperationsHelper {
                         FileStorageUtils.checkIfFileFinishedSaving(file);
                         if (!result.isSuccess()) {
                             DisplayUtils.showSnackMessage(mFileActivity, R.string.file_not_synced);
+                            try {
+                                Thread.sleep(3000);
+                            } catch (InterruptedException e) {
+                                Log.e(TAG, "Failed to sleep for a bit");
+                            }
                         }
                         EventBus.getDefault().post(new SyncEventFinished(intent));
                     }
@@ -250,6 +256,11 @@ public class FileOperationsHelper {
                             try {
                                 if (!result.isSuccess()) {
                                     DisplayUtils.showSnackMessage(mFileActivity, R.string.file_not_synced);
+                                    try {
+                                        Thread.sleep(3000);
+                                    } catch (InterruptedException e) {
+                                        Log.e(TAG, "Failed to sleep");
+                                    }
                                 }
 
                                 mFileActivity.startActivity(

+ 0 - 24
src/main/java/com/owncloud/android/ui/notifications/NotificationUtils.java

@@ -26,16 +26,12 @@ import android.os.HandlerThread;
 import android.os.Process;
 import android.support.v4.app.NotificationCompat;
 
-import com.owncloud.android.MainApp;
-import com.owncloud.android.R;
 import com.owncloud.android.utils.ThemeUtils;
 
 import java.util.Random;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 
-import static android.content.Context.NOTIFICATION_SERVICE;
-
 public class NotificationUtils {
 
     public static final String NOTIFICATION_CHANNEL_DOWNLOAD = "NOTIFICATION_CHANNEL_DOWNLOAD";
@@ -82,24 +78,4 @@ public class NotificationUtils {
              } 
         }, delayInMillis);
     }
-
-    public static void showSyncFailedNotification() {
-        Context context = MainApp.getAppContext();
-        NotificationCompat.Builder mNotificationBuilder = NotificationUtils.newNotificationBuilder(context);
-        mNotificationBuilder
-                .setTicker(context.getString(R.string.sync_fail_ticker))
-                .setSmallIcon(R.drawable.notification_icon)
-                .setContentTitle(context.getString(R.string.sync_fail_ticker))
-                .setContentText(context.getString(R.string.file_not_synced_short));
-
-
-        if ((android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)) {
-            mNotificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_DOWNLOAD);
-        }
-
-        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
-        if (mNotificationManager != null) {
-            mNotificationManager.notify(R.string.sync_fail_ticker, mNotificationBuilder.build());
-        }
-    }
 }