From c7a644533f423da0525996ec4f5eb413f6b85d3f Mon Sep 17 00:00:00 2001 From: Muhammad Ali Rauf Date: Mon, 22 Jul 2024 12:28:04 +0500 Subject: [PATCH 1/3] fix NPE on LoadFilesListTask#listTrashBinFiles --- .../asynctasks/LoadFilesListTask.java | 39 +++++++++++-------- .../filemanager/filesystem/HybridFile.java | 2 +- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java b/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java index 2f1d29ef2f..a0e8603002 100644 --- a/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java +++ b/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java @@ -605,24 +605,29 @@ else if (cursor.getCount() > 0 && cursor.moveToFirst()) { TrashBin trashBin = AppConfig.getInstance().getTrashBinInstance(); List deletedFiles = new ArrayList<>(); if (trashBin != null) { - for (TrashBinFile trashBinFile : trashBin.listFilesInBin()) { - HybridFile hybridFile = - new HybridFile( - OpenMode.TRASH_BIN, - trashBinFile.getDeletedPath( - AppConfig.getInstance().getTrashBinInstance().getConfig()), - trashBinFile.getFileName(), - trashBinFile.isDirectory()); - if (trashBinFile.getDeleteTime() != null) { - hybridFile.setLastModified(trashBinFile.getDeleteTime() * 1000); + + List filesInBin = trashBin.listFilesInBin(); + + if (filesInBin != null) { + for (TrashBinFile trashBinFile : filesInBin) { + HybridFile hybridFile = + new HybridFile( + OpenMode.TRASH_BIN, + trashBinFile.getDeletedPath( + AppConfig.getInstance().getTrashBinInstance().getConfig()), + trashBinFile.getFileName(), + trashBinFile.isDirectory()); + if (trashBinFile.getDeleteTime() != null) { + hybridFile.setLastModified(trashBinFile.getDeleteTime() * 1000); + } + LayoutElementParcelable element = hybridFile.generateLayoutElement(context, true); + element.date = trashBinFile.getDeleteTime(); + element.longSize = trashBinFile.getSizeBytes(); + element.size = Formatter.formatFileSize(context, trashBinFile.getSizeBytes()); + element.dateModification = Utils.getDate(context, trashBinFile.getDeleteTime() * 1000); + element.isDirectory = trashBinFile.isDirectory(); + deletedFiles.add(element); } - LayoutElementParcelable element = hybridFile.generateLayoutElement(context, true); - element.date = trashBinFile.getDeleteTime(); - element.longSize = trashBinFile.getSizeBytes(); - element.size = Formatter.formatFileSize(context, trashBinFile.getSizeBytes()); - element.dateModification = Utils.getDate(context, trashBinFile.getDeleteTime() * 1000); - element.isDirectory = trashBinFile.isDirectory(); - deletedFiles.add(element); } } return deletedFiles; diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java b/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java index 7a900475c4..37b01b01df 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java +++ b/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java @@ -1863,7 +1863,7 @@ public TrashBinFile toTrashBinRestoreFile(Context context) { TrashBin trashBin = AppConfig.getInstance().getTrashBinInstance(); for (TrashBinFile trashBinFile : trashBin.listFilesInBin()) { if (trashBinFile.getDeletedPath(trashBin.getConfig()).equals(path)) { - // finding path to restore to + // finding path to restore tof return new TrashBinFile( getName(context), isDirectory(context), trashBinFile.getPath(), length(context), null); } From aa5eb50993ab3147776578e8d64ea56b0e1e4704 Mon Sep 17 00:00:00 2001 From: Muhammad Ali Rauf Date: Wed, 31 Jul 2024 10:00:31 +0500 Subject: [PATCH 2/3] Code Cleaning --- .../asynctasks/LoadFilesListTask.java | 94 +++++++++---------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java b/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java index a0e8603002..1e642d4c83 100644 --- a/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java +++ b/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java @@ -23,17 +23,23 @@ import static android.os.Build.VERSION.SDK_INT; import static android.os.Build.VERSION_CODES.Q; -import java.io.File; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; +import android.content.ContentResolver; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.database.Cursor; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Bundle; +import android.provider.MediaStore; +import android.text.format.Formatter; +import android.widget.Toast; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; +import androidx.core.util.Pair; import com.amaze.filemanager.R; import com.amaze.filemanager.adapters.data.LayoutElementParcelable; @@ -65,23 +71,17 @@ import com.amaze.trashbin.TrashBinFile; import com.cloudrail.si.interfaces.CloudStorage; -import android.content.ContentResolver; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.database.Cursor; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Bundle; -import android.provider.MediaStore; -import android.text.format.Formatter; -import android.widget.Toast; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import androidx.core.util.Pair; +import java.io.File; +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; import jcifs.smb.SmbAuthException; import jcifs.smb.SmbException; @@ -604,31 +604,31 @@ else if (cursor.getCount() > 0 && cursor.moveToFirst()) { TrashBin trashBin = AppConfig.getInstance().getTrashBinInstance(); List deletedFiles = new ArrayList<>(); - if (trashBin != null) { - List filesInBin = trashBin.listFilesInBin(); + if (trashBin == null) return deletedFiles; + + List filesInBin = trashBin.listFilesInBin(); - if (filesInBin != null) { - for (TrashBinFile trashBinFile : filesInBin) { - HybridFile hybridFile = + if (filesInBin == null) return deletedFiles; + + for (TrashBinFile trashBinFile : filesInBin) { + HybridFile hybridFile = new HybridFile( - OpenMode.TRASH_BIN, - trashBinFile.getDeletedPath( - AppConfig.getInstance().getTrashBinInstance().getConfig()), - trashBinFile.getFileName(), - trashBinFile.isDirectory()); - if (trashBinFile.getDeleteTime() != null) { - hybridFile.setLastModified(trashBinFile.getDeleteTime() * 1000); - } - LayoutElementParcelable element = hybridFile.generateLayoutElement(context, true); - element.date = trashBinFile.getDeleteTime(); - element.longSize = trashBinFile.getSizeBytes(); - element.size = Formatter.formatFileSize(context, trashBinFile.getSizeBytes()); - element.dateModification = Utils.getDate(context, trashBinFile.getDeleteTime() * 1000); - element.isDirectory = trashBinFile.isDirectory(); - deletedFiles.add(element); - } + OpenMode.TRASH_BIN, + trashBinFile.getDeletedPath( + AppConfig.getInstance().getTrashBinInstance().getConfig()), + trashBinFile.getFileName(), + trashBinFile.isDirectory()); + if (trashBinFile.getDeleteTime() != null) { + hybridFile.setLastModified(trashBinFile.getDeleteTime() * 1000); } + LayoutElementParcelable element = hybridFile.generateLayoutElement(context, true); + element.date = trashBinFile.getDeleteTime(); + element.longSize = trashBinFile.getSizeBytes(); + element.size = Formatter.formatFileSize(context, trashBinFile.getSizeBytes()); + element.dateModification = Utils.getDate(context, trashBinFile.getDeleteTime() * 1000); + element.isDirectory = trashBinFile.isDirectory(); + deletedFiles.add(element); } return deletedFiles; } From dd33caae933a7436568af4f9cb8ce97b617c97b4 Mon Sep 17 00:00:00 2001 From: Muhammad Ali Rauf Date: Wed, 31 Jul 2024 10:01:51 +0500 Subject: [PATCH 3/3] Code Cleaning --- .../asynctasks/LoadFilesListTask.java | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java b/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java index 1e642d4c83..6de0985902 100644 --- a/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java +++ b/app/src/main/java/com/amaze/filemanager/asynchronous/asynctasks/LoadFilesListTask.java @@ -23,23 +23,17 @@ import static android.os.Build.VERSION.SDK_INT; import static android.os.Build.VERSION_CODES.Q; -import android.content.ContentResolver; -import android.content.Context; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.content.pm.ResolveInfo; -import android.database.Cursor; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Bundle; -import android.provider.MediaStore; -import android.text.format.Formatter; -import android.widget.Toast; +import java.io.File; +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; -import androidx.core.util.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.amaze.filemanager.R; import com.amaze.filemanager.adapters.data.LayoutElementParcelable; @@ -71,17 +65,23 @@ import com.amaze.trashbin.TrashBinFile; import com.cloudrail.si.interfaces.CloudStorage; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import android.content.ContentResolver; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.database.Cursor; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Bundle; +import android.provider.MediaStore; +import android.text.format.Formatter; +import android.widget.Toast; -import java.io.File; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; +import androidx.core.util.Pair; import jcifs.smb.SmbAuthException; import jcifs.smb.SmbException; @@ -613,12 +613,12 @@ else if (cursor.getCount() > 0 && cursor.moveToFirst()) { for (TrashBinFile trashBinFile : filesInBin) { HybridFile hybridFile = - new HybridFile( - OpenMode.TRASH_BIN, - trashBinFile.getDeletedPath( - AppConfig.getInstance().getTrashBinInstance().getConfig()), - trashBinFile.getFileName(), - trashBinFile.isDirectory()); + new HybridFile( + OpenMode.TRASH_BIN, + trashBinFile.getDeletedPath( + AppConfig.getInstance().getTrashBinInstance().getConfig()), + trashBinFile.getFileName(), + trashBinFile.isDirectory()); if (trashBinFile.getDeleteTime() != null) { hybridFile.setLastModified(trashBinFile.getDeleteTime() * 1000); }