Skip to content

Commit

Permalink
Sort by the file last modified when modified metadata is missing
Browse files Browse the repository at this point in the history
The modified isn't always accurate as git doesn't set it, but it's still
better than nothing. I thought I was using it before.

Fixes #172
  • Loading branch information
vHanda committed Jul 7, 2021
1 parent d07acac commit f5ffebe
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/core/sorting_mode.dart
Expand Up @@ -171,7 +171,11 @@ int _sortModifiedDesc(Note a, Note b) {
return -1;
}
if (bDt == null && aDt == null) {
return a.fileName.compareTo(b.fileName);
if (a.fileLastModified != null && b.fileLastModified != null) {
return a.fileLastModified!.compareTo(b.fileLastModified!);
} else {
return a.fileName.compareTo(b.fileName);
}
}
return bDt!.compareTo(aDt!);
}
Expand Down

2 comments on commit f5ffebe

@YodaEmbedding
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be:

  if (aDt == null && bDt != null) {
    return 1;
  }
  if (aDt != null && bDt == null) {
    return -1;
  }
  if (bDt == null && aDt == null) {
    if (a.fileLastModified == null && b.fileLastModified != null) {
      return 1;
    } else if (a.fileLastModified != null && b.fileLastModified == null) {
      return -1;
    } else if (a.fileLastModified != null && b.fileLastModified != null) {
      return a.fileLastModified!.compareTo(b.fileLastModified!);
    } else {
      return a.fileName.compareTo(b.fileName);
    }
  }
  return bDt!.compareTo(aDt!);

@vHanda
Copy link
Contributor Author

@vHanda vHanda commented on f5ffebe Jul 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@YodaEmbedding : After the note has finished loading the fileLastModified should never be null. However, you're right, lets be on the safer side. Let me update it.

Please sign in to comment.