-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filebrowser: Improve performance a lot (speed of file list appearing)
- Loading branch information
Showing
2 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
app/src/main/java/net/gsantner/opoc/util/FileWithCachedData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// | ||
// License of this file FileWithCachedData.java: Public Domain | ||
// Created by Gregor Santner, 2021 - https://gsantner.net | ||
// | ||
|
||
package net.gsantner.opoc.util; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
|
||
import java.io.File; | ||
import java.net.URI; | ||
|
||
@SuppressWarnings({"unused", "RedundantSuppression"}) | ||
public class FileWithCachedData extends File { | ||
private Integer cHashCode; | ||
private Boolean cCanRead, cCanWrite, cExists, cIsAbsolute, cIsDirectory, cIsFile; | ||
private Long cLastModified, cLength; | ||
private String cAbsolutePath; | ||
private File cAbsoluteFile; | ||
private String[] cList; | ||
|
||
public FileWithCachedData(@NonNull String pathname) { | ||
super(pathname); | ||
} | ||
|
||
public FileWithCachedData(@Nullable String parent, @NonNull String child) { | ||
super(parent, child); | ||
} | ||
|
||
public FileWithCachedData(@Nullable File parent, @NonNull String child) { | ||
super(parent, child); | ||
} | ||
|
||
public FileWithCachedData(@NonNull URI uri) { | ||
super(uri); | ||
} | ||
|
||
public FileWithCachedData(@NonNull File f) { | ||
super(f.getPath()); | ||
} | ||
|
||
|
||
@NonNull | ||
@Override | ||
public synchronized String getAbsolutePath() { | ||
if (cAbsolutePath == null) { | ||
cAbsolutePath = super.getAbsolutePath(); | ||
} | ||
return cAbsolutePath; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public File getAbsoluteFile() { | ||
if (cAbsoluteFile == null) { | ||
cAbsoluteFile = super.getAbsoluteFile(); | ||
} | ||
return cAbsoluteFile; | ||
} | ||
|
||
@Override | ||
public boolean isAbsolute() { | ||
if (cIsAbsolute == null) { | ||
cIsAbsolute = super.isAbsolute(); | ||
} | ||
return cIsAbsolute; | ||
} | ||
|
||
@Override | ||
public boolean canRead() { | ||
if (cCanRead == null) { | ||
cCanRead = super.canRead(); | ||
} | ||
return cCanRead; | ||
} | ||
|
||
@Override | ||
public boolean canWrite() { | ||
if (cCanWrite == null) { | ||
cCanWrite = super.canWrite(); | ||
} | ||
return cCanWrite; | ||
} | ||
|
||
@Override | ||
public boolean exists() { | ||
if (cExists == null) { | ||
cExists = super.exists(); | ||
} | ||
return cExists; | ||
} | ||
|
||
@Override | ||
public boolean isDirectory() { | ||
if (cIsDirectory == null) { | ||
cIsDirectory = super.isDirectory(); | ||
} | ||
return cIsDirectory; | ||
} | ||
|
||
@Override | ||
public boolean isFile() { | ||
if (cIsFile == null) { | ||
cIsFile = super.isFile(); | ||
} | ||
return cIsFile; | ||
} | ||
|
||
@Override | ||
public long lastModified() { | ||
if (cLastModified == null) { | ||
cLastModified = super.lastModified(); | ||
} | ||
return cLastModified; | ||
} | ||
|
||
@Override | ||
public long length() { | ||
if (cLength == null) { | ||
cLength = super.length(); | ||
} | ||
return cLength; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String[] list() { | ||
if (cList == null) { | ||
cList = super.list(); | ||
} | ||
return cList; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
if (cHashCode == null) { | ||
cHashCode = super.hashCode(); | ||
} | ||
return cHashCode; | ||
} | ||
} |
83a4e2f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, do you know when this will be released please ?
Thank you very much for your work !!
83a4e2f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1-4 weeks.
83a4e2f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay thanks. I will try to build it myself. Good training to know how to build an android app.