Skip to content

Commit

Permalink
Remove "Search subfolder" preference and make it default behavior for…
Browse files Browse the repository at this point in the history
… now, until it becomes a file source specific setting
  • Loading branch information
MizzleDK committed Jan 31, 2016
1 parent 9ae8279 commit 00f4eae
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class AbstractFileSource<T> {
protected T mFolder;
protected FileSource mFileSource = null;
protected Context mContext;
protected boolean mSubFolderSearch, mClearLibrary;
protected boolean mClearLibrary;
protected int mFileSizeLimit;

public void setFolder(T folder) {
Expand All @@ -53,10 +53,6 @@ public Context getContext() {
return mContext;
}

public boolean searchSubFolders() {
return mSubFolderSearch;
}

public boolean clearLibrary() {
return mClearLibrary;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ public abstract class MovieFileSource<T> extends AbstractFileSource<T> {

protected List<DbMovie> mDbMovies = new ArrayList<DbMovie>();

public MovieFileSource(Context context, FileSource fileSource, boolean subFolderSearch, boolean clearLibrary) {
public MovieFileSource(Context context, FileSource fileSource, boolean clearLibrary) {
mContext = context;
mFileSource = fileSource;
mSubFolderSearch = subFolderSearch;
mClearLibrary = clearLibrary;

mFileSizeLimit = MizLib.getFileSizeLimit(getContext());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ public abstract class TvShowFileSource<T> extends AbstractFileSource<T> {

protected List<DbEpisode> mDbEpisode = new ArrayList<DbEpisode>();

public TvShowFileSource(Context context, FileSource fileSource, boolean subFolderSearch, boolean clearLibrary) {
public TvShowFileSource(Context context, FileSource fileSource, boolean clearLibrary) {
mContext = context;
mFileSource = fileSource;
mSubFolderSearch = subFolderSearch;
mClearLibrary = clearLibrary;

mFileSizeLimit = MizLib.getFileSizeLimit(getContext());
Expand Down
76 changes: 35 additions & 41 deletions app/src/main/java/com/miz/filesources/FileMovie.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class FileMovie extends MovieFileSource<File> {
private HashMap<String, String> existingMovies = new HashMap<String, String>();
private File tempFile;

public FileMovie(Context context, FileSource fileSource, boolean subFolderSearch, boolean clearLibrary) {
super(context, fileSource, subFolderSearch, clearLibrary);
public FileMovie(Context context, FileSource fileSource, boolean clearLibrary) {
super(context, fileSource, clearLibrary);
}

@Override
Expand All @@ -55,7 +55,7 @@ public void removeUnidentifiedFiles() {
if (!dbMovies.get(i).isNetworkFile() && !dbMovies.get(i).isUpnpFile()) {
temp = new File(dbMovies.get(i).getFilepath());
if (temp.exists() && dbMovies.get(i).isUnidentified())
MovieDatabaseUtils.deleteMovie(mContext, dbMovies.get(i).getTmdbId());
MovieDatabaseUtils.deleteMovie(mContext, dbMovies.get(i).getTmdbId());
}
}
}
Expand All @@ -70,7 +70,7 @@ public void removeUnavailableFiles() {
if (!dbMovies.get(i).isNetworkFile()) {
temp = new File(dbMovies.get(i).getFilepath());
if (!temp.exists()) {
MovieDatabaseUtils.deleteMovie(mContext, dbMovies.get(i).getTmdbId());
MovieDatabaseUtils.deleteMovie(mContext, dbMovies.get(i).getTmdbId());
}
}
}
Expand All @@ -82,7 +82,7 @@ public List<String> searchFolder() {
DbAdapterMovieMappings dbHelper = MizuuApplication.getMovieMappingAdapter();
Cursor cursor = dbHelper.getAllFilepaths(false); // Query database to return all filepaths in a cursor
ColumnIndexCache cache = new ColumnIndexCache();

try {
while (cursor.moveToNext()) {// Add all movies in cursor to ArrayList of all existing movies
existingMovies.put(cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovieMappings.KEY_FILEPATH)), "");
Expand Down Expand Up @@ -110,54 +110,48 @@ public List<String> searchFolder() {
@Override
public void recursiveSearch(File folder, TreeSet<String> results) {
try {
if (searchSubFolders()) {
if (folder.isDirectory()) {
// Check if this is a DVD folder
if (folder.getName().equalsIgnoreCase("video_ts")) {
File[] children = folder.listFiles();
for (int i = 0; i < children.length; i++) {
if (children[i].getName().equalsIgnoreCase("video_ts.ifo"))
addToResults(children[i], results);
}
} // Check if this is a Blu-ray folder
else if (folder.getName().equalsIgnoreCase("bdmv")) {
File[] children = folder.listFiles();
for (int i = 0; i < children.length; i++) {
if (children[i].getName().equalsIgnoreCase("stream")) {
File[] m2tsVideoFiles = children[i].listFiles();

if (m2tsVideoFiles.length > 0) {
File largestFile = m2tsVideoFiles[0];

for (int j = 0; j < m2tsVideoFiles.length; j++)
if (largestFile.length() < m2tsVideoFiles[j].length())
largestFile = m2tsVideoFiles[j];

addToResults(largestFile, results);
}
if (folder.isDirectory()) {
// Check if this is a DVD folder
if (folder.getName().equalsIgnoreCase("video_ts")) {
File[] children = folder.listFiles();
for (int i = 0; i < children.length; i++) {
if (children[i].getName().equalsIgnoreCase("video_ts.ifo"))
addToResults(children[i], results);
}
} // Check if this is a Blu-ray folder
else if (folder.getName().equalsIgnoreCase("bdmv")) {
File[] children = folder.listFiles();
for (int i = 0; i < children.length; i++) {
if (children[i].getName().equalsIgnoreCase("stream")) {
File[] m2tsVideoFiles = children[i].listFiles();

if (m2tsVideoFiles.length > 0) {
File largestFile = m2tsVideoFiles[0];

for (int j = 0; j < m2tsVideoFiles.length; j++)
if (largestFile.length() < m2tsVideoFiles[j].length())
largestFile = m2tsVideoFiles[j];

addToResults(largestFile, results);
}
}
} else {
String[] childs = folder.list();
for (int i = 0; i < childs.length; i++) {
tempFile = new File(folder.getAbsolutePath(), childs[i]);
recursiveSearch(tempFile, results);
}
}
} else {
addToResults(folder, results);
String[] childs = folder.list();
for (int i = 0; i < childs.length; i++) {
tempFile = new File(folder.getAbsolutePath(), childs[i]);
recursiveSearch(tempFile, results);
}
}
} else {
File[] children = folder.listFiles();
for (int i = 0; i < children.length; i++)
addToResults(children[i], results);
addToResults(folder, results);
}
} catch (Exception e) {}
}

@Override
public void addToResults(File file, TreeSet<String> results) {
if (MizLib.checkFileTypes(file.getAbsolutePath())) {
if (MizLib.checkFileTypes(file.getAbsolutePath())) {
if (file.length() < getFileSizeLimit() && !file.getName().equalsIgnoreCase("video_ts.ifo"))
return;

Expand Down
22 changes: 8 additions & 14 deletions app/src/main/java/com/miz/filesources/FileTvShow.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class FileTvShow extends TvShowFileSource<File> {
private HashMap<String, String> existingEpisodes = new HashMap<String, String>();
private File tempFile;

public FileTvShow(Context context, FileSource fileSource, boolean subFolderSearch, boolean clearLibrary) {
super(context, fileSource, subFolderSearch, clearLibrary);
public FileTvShow(Context context, FileSource fileSource, boolean clearLibrary) {
super(context, fileSource, clearLibrary);
}

@Override
Expand Down Expand Up @@ -149,20 +149,14 @@ public List<String> searchFolder() {
@Override
public void recursiveSearch(File folder, TreeSet<String> results) {
try {
if (searchSubFolders()) {
if (folder.isDirectory()) {
String[] childs = folder.list();
for (int i = 0; i < childs.length; i++) {
tempFile = new File(folder.getAbsolutePath() + "/" + childs[i]);
recursiveSearch(tempFile, results);
}
} else {
addToResults(folder, results);
if (folder.isDirectory()) {
String[] childs = folder.list();
for (int i = 0; i < childs.length; i++) {
tempFile = new File(folder.getAbsolutePath() + "/" + childs[i]);
recursiveSearch(tempFile, results);
}
} else {
File[] children = folder.listFiles();
for (int i = 0; i < children.length; i++)
addToResults(children[i], results);
addToResults(folder, results);
}
} catch (Exception e) {}
}
Expand Down
96 changes: 45 additions & 51 deletions app/src/main/java/com/miz/filesources/SmbMovie.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class SmbMovie extends MovieFileSource<SmbFile> {
private HashMap<String, String> existingMovies = new HashMap<String, String>();
private SmbFile tempSmbFile;

public SmbMovie(Context context, FileSource fileSource, boolean subFolderSearch, boolean clearLibrary) {
super(context, fileSource, subFolderSearch, clearLibrary);
public SmbMovie(Context context, FileSource fileSource, boolean clearLibrary) {
super(context, fileSource, clearLibrary);
}

@Override
Expand All @@ -70,7 +70,7 @@ public void removeUnidentifiedFiles() {

if (source == null) {
if (dbMovies.get(i).isUnidentified())
MovieDatabaseUtils.deleteMovie(mContext, dbMovies.get(i).getTmdbId());
MovieDatabaseUtils.deleteMovie(mContext, dbMovies.get(i).getTmdbId());
continue;
}

Expand All @@ -81,10 +81,10 @@ public void removeUnidentifiedFiles() {
source.getPassword(),
dbMovies.get(i).getFilepath(),
false
));
));

if (temp.exists() && dbMovies.get(i).isUnidentified())
MovieDatabaseUtils.deleteMovie(mContext, dbMovies.get(i).getTmdbId());
MovieDatabaseUtils.deleteMovie(mContext, dbMovies.get(i).getTmdbId());
} catch (Exception e) {} // Do nothing - the file isn't available (either MalformedURLException or SmbException)
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ public void removeUnavailableFiles() {
}

if (source == null) {
MovieDatabaseUtils.deleteMovie(mContext, dbMovies.get(i).getTmdbId());
MovieDatabaseUtils.deleteMovie(mContext, dbMovies.get(i).getTmdbId());
continue;
}

Expand All @@ -123,10 +123,10 @@ public void removeUnavailableFiles() {
source.getPassword(),
dbMovies.get(i).getFilepath(),
false
));
));

if (!temp.exists()) {
MovieDatabaseUtils.deleteMovie(mContext, dbMovies.get(i).getTmdbId());
MovieDatabaseUtils.deleteMovie(mContext, dbMovies.get(i).getTmdbId());
}
} catch (Exception e) {} // Do nothing - the file isn't available (either MalformedURLException or SmbException)
}
Expand All @@ -145,7 +145,7 @@ public List<String> searchFolder() {
DbAdapterMovieMappings dbHelper = MizuuApplication.getMovieMappingAdapter();
Cursor cursor = dbHelper.getAllFilepaths(false); // Query database to return all filepaths in a cursor
ColumnIndexCache cache = new ColumnIndexCache();

try {
while (cursor.moveToNext()) {// Add all movies in cursor to ArrayList of all existing movies
existingMovies.put(cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovieMappings.KEY_FILEPATH)), "");
Expand Down Expand Up @@ -173,52 +173,46 @@ public List<String> searchFolder() {
@Override
public void recursiveSearch(SmbFile folder, TreeSet<String> results) {
try {
if (searchSubFolders()) {
if (folder.isDirectory()) {
// Check if this is a DVD folder
if (folder.getName().equalsIgnoreCase("video_ts/")) {
SmbFile[] children = folder.listFiles();
for (int i = 0; i < children.length; i++) {
if (children[i].getName().equalsIgnoreCase("video_ts.ifo"))
addToResults(children[i], results);
}
} // Check if this is a Blu-ray folder
else if (folder.getName().equalsIgnoreCase("bdmv/")) {
SmbFile[] children = folder.listFiles();
for (int i = 0; i < children.length; i++) {
if (children[i].getName().equalsIgnoreCase("stream/")) {
SmbFile[] m2tsVideoFiles = children[i].listFiles();

if (m2tsVideoFiles.length > 0) {
SmbFile largestFile = m2tsVideoFiles[0];

for (int j = 0; j < m2tsVideoFiles.length; j++)
if (largestFile.length() < m2tsVideoFiles[j].length())
largestFile = m2tsVideoFiles[j];

addToResults(largestFile, results);
}
}
}
} else {
String[] childs = folder.list();
for (int i = 0; i < childs.length; i++) {
tempSmbFile = new SmbFile(folder.getCanonicalPath() + childs[i] + "/");
if (tempSmbFile.isDirectory()) {
recursiveSearch(tempSmbFile, results);
} else {
tempSmbFile = new SmbFile(folder.getCanonicalPath() + childs[i]);
addToResults(tempSmbFile, results);
if (folder.isDirectory()) {
// Check if this is a DVD folder
if (folder.getName().equalsIgnoreCase("video_ts/")) {
SmbFile[] children = folder.listFiles();
for (int i = 0; i < children.length; i++) {
if (children[i].getName().equalsIgnoreCase("video_ts.ifo"))
addToResults(children[i], results);
}
} // Check if this is a Blu-ray folder
else if (folder.getName().equalsIgnoreCase("bdmv/")) {
SmbFile[] children = folder.listFiles();
for (int i = 0; i < children.length; i++) {
if (children[i].getName().equalsIgnoreCase("stream/")) {
SmbFile[] m2tsVideoFiles = children[i].listFiles();

if (m2tsVideoFiles.length > 0) {
SmbFile largestFile = m2tsVideoFiles[0];

for (int j = 0; j < m2tsVideoFiles.length; j++)
if (largestFile.length() < m2tsVideoFiles[j].length())
largestFile = m2tsVideoFiles[j];

addToResults(largestFile, results);
}
}
}
} else {
addToResults(folder, results);
String[] childs = folder.list();
for (int i = 0; i < childs.length; i++) {
tempSmbFile = new SmbFile(folder.getCanonicalPath() + childs[i] + "/");
if (tempSmbFile.isDirectory()) {
recursiveSearch(tempSmbFile, results);
} else {
tempSmbFile = new SmbFile(folder.getCanonicalPath() + childs[i]);
addToResults(tempSmbFile, results);
}
}
}
} else {
SmbFile[] children = folder.listFiles();
for (int i = 0; i < children.length; i++)
addToResults(children[i], results);
addToResults(folder, results);
}
} catch (Exception e) {}
}
Expand Down Expand Up @@ -248,14 +242,14 @@ public void addToResults(SmbFile file, TreeSet<String> results) {
public SmbFile getRootFolder() {
try {
FileSource fs = getFileSource();
return new SmbFile(
return new SmbFile(
MizLib.createSmbLoginString(
fs.getDomain(),
fs.getUser(),
fs.getPassword(),
fs.getFilepath(),
true
));
));
} catch (Exception e) {}
return null;
}
Expand Down
Loading

0 comments on commit 00f4eae

Please sign in to comment.